Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Comms Database public interface
22 @deprecated since v9.1. Functionality is replaced with commsdat.
29 #include <metadatabase.h>
31 using namespace CommsDat;
38 Protection of settings: when the entire table is protected, write operations
39 fail with KErrWrite. However KErrAccessDenied should be returned to client
42 #define TRAPD_CONVERT(_r,_s) TRAPD(_r,_s); if(ret == KErrWrite) ret = KErrAccessDenied;
46 #define TRAP_CONVERT(_r,_s) TRAP(_r,_s); if(ret == KErrWrite) ret = KErrAccessDenied;
48 class CCommsDbTableView;
49 class CCommsDbConnectionPrefTableView;
50 class CCommDbTableExtension;
51 class CCommsDatabaseImpl;
53 class CCommsDatabaseBase : public CBase
54 /** Base class for CCommsDatabase.
56 This class is never instantiated, but its member functions are used through
59 Responsible for Transactions, Notifications, Write protection, Hidden
60 records, Phone number resolution and Creating views. Stores the database, the
61 session, transaction and notifier information.
63 CCommsDatabaseBase is an abstract base class as the CreateDatabaseL() and
64 Open() methods are pure virtual.
69 // These classes added as friends for commdb shim
70 friend class CCommsDbTableView;
71 friend class CCommsDbConnectionPrefTableView;
72 friend class CCommsDbProtectTableView;
73 friend class CCommsDbProtectConnectPrefTableView;
74 friend class CCommsDbTemplateRecord;
76 IMPORT_C virtual ~CCommsDatabaseBase();
78 // Returns the version of the database server.
79 IMPORT_C TVersion Version() const;
80 // Begin a transaction. Call before `InsertRecord()` or `UpdateRecord()`.
81 IMPORT_C TInt BeginTransaction();
82 // End a transaction. Call after `InsertRecord()` or `UpdateRecord()`.
83 IMPORT_C TInt CommitTransaction();
84 // Cancel a transaction.
85 IMPORT_C void RollbackTransaction();
86 // True if BeginTransaction() has been called but not
87 // `CommitTransaction()` or `RollbackTransaction()`.
88 IMPORT_C TBool InTransaction();
89 // True if the database has been locked.
90 IMPORT_C TBool IsDatabaseWriteLockedL();
92 // Enable a notification event on any change to the database.
93 IMPORT_C TInt RequestNotification(TRequestStatus& aStatus);
94 // Cancels notifications.
95 IMPORT_C void CancelRequestNotification();
97 // Obtain a view of all records in a table.
98 IMPORT_C CCommsDbTableView* OpenTableLC(const TDesC& aTableName);
99 // Obtain a view of the records in a table that match the query.
100 IMPORT_C CCommsDbTableView* OpenViewLC(const TDesC& aTableName, const TDesC& aSqlQuery);
101 // Obtain a view of all the records in a table for which the field
102 // `aColumnToMatch` matches `aValueToMatch`.
103 IMPORT_C CCommsDbTableView* OpenViewMatchingUintLC(const TDesC& aTableName, const TDesC& aColumnToMatch, TUint32 aValueToMatch);
104 IMPORT_C CCommsDbTableView* OpenViewMatchingBoolLC(const TDesC& aTableName, const TDesC& aColumnToMatch, TBool aValueToMatch);
105 IMPORT_C CCommsDbTableView* OpenViewMatchingTextLC(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC8& aValueToMatch);
106 IMPORT_C CCommsDbTableView* OpenViewMatchingTextLC(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC16& aValueToMatch);
108 // Make hidden records visible
109 IMPORT_C void ShowHiddenRecords();
111 // Set `aDialString` to be the appropriate string based on the directory
112 // number, where the dial is being performed and the chargecard to use.
113 // `ResolvePhoneNumberL()` opens a comms database to perform the
115 IMPORT_C static void ResolvePhoneNumberL(TDesC& aNumber, TDes& aDialString, TParseMode aDialParseMode, TUint32 aLocationId, TUint32 aChargecardId);
116 // Set `aDialString` to be the appropriate string based on the directory
117 // number, where the dial is being performed and the chargecard to use.
118 IMPORT_C void ResolvePhoneNumberFromDatabaseL(TDesC& aNumber, TDes& aDialString, TParseMode aDialParseMode, TUint32 aLocationId, TUint32 aChargecardId);
119 IMPORT_C static TInt InitializeFilestore();
121 // Check access to database fields
122 IMPORT_C TInt CheckReadCapability( const TDesC& aField, const RMessagePtr2* aMessage );
123 IMPORT_C TInt CheckWriteCapability( const TDesC& aField, const RMessagePtr2* aMessage );
127 // Please note that as of v9.0 TCommDbSystemAgentNotification now actually contains
128 // the notification information for the Publish and Subscribe notifications, not
129 // for System Agent notifications.
130 class TCommDbSystemAgentNotification
137 TCommDbSystemAgentNotification();
138 void Set(TUid aUid, TInt aVal);
144 class TCommDbPublishSubscribeNotification
151 TCommDbPublishSubscribeNotification();
152 void Set(TUid aUid, TInt aVal);
160 IMPORT_C CCommsDatabaseBase();
162 virtual void CreateDatabaseL() =0;
165 CCommsDbTableView* DoOpenViewMatchingUintL(const TDesC& aTableName, const TDesC& aColumnToMatch, TUint32 aValueToMatch, TBool aIncludeHiddenRecords);
166 CCommsDbTableView* DoOpenViewMatchingTextL(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC8& aValueToMatch, TBool aIncludeHiddenRecords);
167 CCommsDbTableView* DoOpenViewMatchingTextL(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC16& aValueToMatch, TBool aIncludeHiddenRecords);
168 CCommsDbTableView* DoOpenTableViewL(const TDesC& aTableName, const TDesC& aSqlQuery);
169 CCommsDbTableView* DoOpenIAPTableViewL(const TDesC& aTableName,const TDesC& aSqlQuery);
171 void PopulateDialLocationL(TUint32 aId, TDialLocation& aLocation);
172 void PopulateChargeCardL(TUint32 aId, TChargeCard& aChargeCard);
173 void BeginInternalTransactionL();
174 TInt CommitInternalTransaction();
175 void RollbackInternalTransaction();
176 void DatabaseUpdateHasOccurred();
177 void NotifyChangeL(const TDesC& aSetting, TUint32 aVal);
178 TInt NotifyAllChanges();
180 TUint32 GetNewNumber(TUid aUid);
181 TInt CheckDBCapability( RDbs::TPolicyType aType, const TDesC& aField, const RMessagePtr2* aMessage );
182 void ConvertToUid(const TDesC& aSetting, TUint32 aVal, TCommDbPublishSubscribeNotification& aNotification);
184 inline RDbNamedDatabase* Database();
187 CCommsDatabaseImpl* iImpl;
188 RDbNamedDatabase iDatabase;
189 RDbNotifier iNotifier;
190 // store container data for deletion after session is finished
191 //RPointerArray<CMDBElement> iTransactionCache;
193 TInt iNotifierOpenError;
194 TBool iShowHiddenRecords;
195 TBool iImplNotCreated;
196 TBool iInInternalTransaction;
198 RArray<TCommDbPublishSubscribeNotification> iNotifications;
200 // Check access to database fields
201 TInt DoCheckReadCapabilityL( const TDesC& aField, const RMessagePtr2* aMessage );
202 TInt DoCheckWriteCapabilityL( const TDesC& aField, const RMessagePtr2* aMessage );
204 TBool ConvertTableName(const TDesC& aTableName, TDes& aResult);
207 class CCommsDatabase : public CCommsDatabaseBase
209 Accesses the communications database through the DBMS.
211 An object of this type must be constructed and opened by a client before any
212 of the tables in the database can be accessed, e.g. to create views and access
215 Implements the pure virtual functions CreateDatabaseL() and DoOpen().
216 Responsible for Global settings and Connection Preferences. Has utility
217 functions for accessing Global and Agent tables. No additional state (to
218 CCommsDatabaseBase) is stored.
223 IMPORT_C static CCommsDatabase* NewL();
224 IMPORT_C static CCommsDatabase* NewL(TBool aUseDefaultDb);
225 IMPORT_C static CCommsDatabase* NewL(TCommDbOpeningMethod &aOpeningMethod);
226 IMPORT_C virtual ~CCommsDatabase();
227 IMPORT_C void GetGlobalSettingL(const TDesC& aSetting, TUint32& aValue);
228 IMPORT_C void GetGlobalSettingL(const TDesC& aSetting, TDes& aValue);
229 IMPORT_C void SetGlobalSettingL(const TDesC& aSetting, TUint32 aValue);
230 IMPORT_C void SetGlobalSettingL(const TDesC& aSetting, const TDesC& aValue);
231 IMPORT_C void ClearGlobalSettingL(const TDesC& aSetting);
232 IMPORT_C void GetDefaultTsyL(TDes& aValue);
234 // Deprecated. Past use: Gets settings (Modem, Chargecard, and Service) for the dial out IAP.
235 IMPORT_C void GetCurrentDialOutSettingL(const TDesC& aSetting, TUint32& aValue);
236 // Deprecated. Past use: Retrieve settings for the dial in IAP.
237 IMPORT_C void GetCurrentDialInSettingL(const TDesC& aSetting, TUint32& aValue);
238 // Open a connection preference view.
239 IMPORT_C CCommsDbConnectionPrefTableView* OpenConnectionPrefTableLC();
240 // Open a connection preference view containing connections of the
241 // specified direction.
242 IMPORT_C CCommsDbConnectionPrefTableView* OpenConnectionPrefTableLC(TCommDbConnectionDirection aDirection);
243 // Open a connection preference view containing connections of the
244 // specified direction excluding connections of rank zero.
245 IMPORT_C CCommsDbConnectionPrefTableView* OpenConnectionPrefTableInRankOrderLC(TCommDbConnectionDirection aDirection);
246 // Open a connection preference view containing connections of the
247 // specified direction and rank.
248 IMPORT_C CCommsDbConnectionPrefTableView* OpenConnectionPrefTableViewOnRankLC(TCommDbConnectionDirection aDirection, TUint32 aRank);
250 //DEPRECATED : Agent table has been removed. These functions have been
251 // stubbed to return KErrNotSupported or leave with the same error.
252 // Access agent settings. `aService` is one of: (`DIAL_OUT_ISP`,
253 // `DIAL_IN_ISP`, `OUTGOING_WCDMA` or `CDMA2000_PACKET_SERVICE_TABLE`). */
254 IMPORT_C void SetAgentL(const TDesC& aService, const TDesC& aAgent);
256 IMPORT_C void SetAgentExtL(const TDesC& aService, const TDesC& aAgentExt);
257 IMPORT_C void GetAgentL(const TDesC& aService, TDes& aAgent);
258 IMPORT_C void GetAgentExtL(const TDesC& aService, TDes& aAgentExt);
259 IMPORT_C void ClearAgentAndExtL(const TDesC& aService);
260 IMPORT_C void SetAgentClientTimeoutL(const TDesC& aService, TInt aClientTimeout);
261 IMPORT_C void SetAgentRouteTimeoutL(const TDesC& aService, TInt aRouteTimeout);
262 IMPORT_C TInt GetAgentClientTimeoutL(const TDesC& aService);
263 IMPORT_C TInt GetAgentRouteTimeoutL(const TDesC& aService);
265 /** Open a view on the IAP table containing records that match the
266 bearers and direction specified. `aBearerSet` is a bit mask of type
268 IMPORT_C CCommsDbTableView* OpenIAPTableViewMatchingBearerSetLC(TUint32 aBearerSet, TCommDbConnectionDirection aDirection);
270 /** Open a viewon the IAP table containing records which match the specified network */
271 IMPORT_C CCommsDbTableView* OpenIAPTableViewMatchingNetworkLC(TUint32 aNetwork);
273 // Open a view on the proxy table containing records that match the
274 // service id and type specified.
275 IMPORT_C CCommsDbTableView* OpenViewOnProxyRecordLC(TUint32 aServiceId, const TDesC& aServiceType);
277 // Functionality re-implemented to facilitate BC with 6.1
278 IMPORT_C static CCommsDatabase* NewL(TCommDbDatabaseType aDbType);
279 // Creates a `CCommsDatabase` as with `NewL()`. The method of opening:
280 // (Created, CopiedDefault or Opened) is returned in `aOpeningMethod`.
281 IMPORT_C static CCommsDatabase* NewL(TCommDbDatabaseType aDbType, TCommDbOpeningMethod &aOpeningMethod);
284 enum TGlobalSettingType
288 ECompatibilitySetting
292 void DoOpenL(TCommDbOpeningMethod& aOpeningMethod,TBool aUseDefaultDb);
294 /** CCommsDatabaseBase pure virtuals */
296 virtual void CreateDatabaseL();
297 CCommsDbTableView* OpenGlobalSettingsTableLC(const TDesC& aSetting, TBool& aExists);
298 TGlobalSettingType GlobalSettingTypeL(const TDesC& aSetting) const;
302 class CCommsDbTemplateRecord;
304 class CCommsDbTableView : public CBase
307 The view on a specific table in the database.
309 Includes the necessary behaviour for navigating through the records in
310 the view and reading and writing to columns within a record.
312 Uses a CCommsDatabase and has an RDbView to read from and write to database. Created via
313 CCommsDatabase::OpenTableLC() (which opens a view of all the records in the table) or one
314 of the OpenViewLC...() functions (which open a specific view of the table):
316 CCommsDatabase::OpenTableLC()
318 CCommsDatabase::OpenViewMatchingUintLC()
320 CCommsDatabase::OpenViewMatchingBoolLC()
322 CCommsDatabase::OpenViewMatchingTextLC()
324 CCommsDatabase::OpenViewLC()
326 Note that the above five functions have been withdrawn in CCommsDatabase and
327 are now implemented in CCommsDatabaseBase.
332 friend class CCommsDatabaseBase;
333 friend class CCommsDbTemplateRecord;
335 // Low level view creation. Use if `CCommsDatabase::OpenTableLC()` or
336 //`CCommsDatabase::OpenViewLC...()` are not sufficient.
337 static CCommsDbTableView* NewL(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDbQuery& aQuery, TBool aUseTemplate = ETrue);
338 static CCommsDbTableView* NewLC(const TDesC& aTableName, CCommsDatabaseBase& aDb);
339 // additional constructors, commdb shim specific
340 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, const TDesC& aTableName, TBool aUseTamplate = ETrue); // ETrue if template is instantiating
341 static CCommsDbTableView* NewL(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC8& aValueToMatch);
342 static CCommsDbTableView* NewL(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC16& aValueToMatch);
343 static CCommsDbTableView* NewL(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDesC& aColumnToMatch, TUint32 aValueToMatch);
344 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDesC& aColumnToMatch, TBool aValueToMatch);
345 // this two are for IAP table only so table name is not needed
346 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, TUint32 aBearerSet, TCommDbConnectionDirection aDirection);
347 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, TUint32 aNetworkId);
348 // this one is for Proxie table only
349 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, TUint32 aServiceId, const TDesC& aServiceType);
351 CCommsDbTableView(CCommsDatabaseBase& aDb, const TDesC& aTableName);
353 IMPORT_C virtual ~CCommsDbTableView();
355 // Add a new record to this table. The record number is returned.
356 // `PutRecordChanges()` is called to complete the transaction
357 IMPORT_C TInt InsertRecord(TUint32& aId);
358 /** Add a new record to this table. Filling all empty fields with values copied
359 from record currently pointed at. The record number is returned.
360 `PutRecordChanges()` is called to complete the transaction */
361 IMPORT_C TInt InsertCopyRecord(TUint32& aId);
362 /** Modify the current record of this view. `PutRecordChanges()` is called
363 to complete the transaction */
364 IMPORT_C TInt UpdateRecord();
365 // Remove the current record from the table.
366 IMPORT_C TInt DeleteRecord();
367 // Store an inserted or updated record back to the database.
368 IMPORT_C TInt PutRecordChanges(TBool aHidden = EFalse, TBool aReadOnly = EFalse);
369 // Cancel pending changes since an insert or update.
370 IMPORT_C void CancelRecordChanges();
372 // Navigate throught the records in the view
374 IMPORT_C TInt GotoFirstRecord();
375 IMPORT_C TInt GotoNextRecord();
376 IMPORT_C TInt GotoPreviousRecord();
378 // Access data from the current record
380 IMPORT_C void ReadTextL(const TDesC& aColumn, TDes8& aValue);
381 IMPORT_C void ReadTextL(const TDesC& aColumn, TDes16& aValue);
382 IMPORT_C HBufC* ReadLongTextLC(const TDesC& aColumn);
383 IMPORT_C void ReadUintL(const TDesC& aColumn, TUint32& aValue);
384 IMPORT_C void ReadBoolL(const TDesC& aColumn, TBool& aValue);
385 // Determine the type and attributes of a column. The type is one of:
386 // (EDbColBit, EDbColUint32, EDbColText8, EDbColText16, EDbColLongText16).
387 // The attribute is a bit mask of: (ENotNull and EAutoIncrement).
388 IMPORT_C void ReadTypeAttribL(const TDesC& aColumn, TDbColType& aColType, TUint32& aAttrib);
389 // Null columns return 0, integers and bools 1, strings return their length in characters.
390 IMPORT_C void ReadColumnLengthL(const TDesC& aColumn, TInt& aLength);
393 // Modify an inserted or modified record. Must call `PutRecordChanges()`
394 // to store the changes.
396 IMPORT_C void WriteTextL(const TDesC& aColumn, const TDesC8& aValue);
397 IMPORT_C void WriteTextL(const TDesC& aColumn, const TDesC16& aValue);
398 IMPORT_C void WriteLongTextL(const TDesC& aColumn, const TDesC& aValue);
399 IMPORT_C void WriteUintL(const TDesC& aColumn, const TUint32& aValue);
400 IMPORT_C void WriteBoolL(const TDesC& aColumn, const TBool& aValue);
401 IMPORT_C void SetNullL(const TDesC& aColumn);
403 IMPORT_C void ReadColumnMaxLengthL(const TDesC& aColumn, TInt& aLength);
404 inline CCommsDatabaseBase* Database() const { return &iDb; }
406 void OpenL(const TDbQuery& aQuery);
408 inline void GetTableName(TDes& aTableName) const;
410 TDbColNo ColNumL(const TDesC& aColumn) const;
412 void ConstructL(const TDesC& aTableName, TBool aShowHidden, TBool aUseTemplate);
413 void ConstructL(const TDbQuery& aQuery, TBool aUseTemplate);
414 RDbRowSet::TAccess GetL();
416 // All other ConstructructL methods are added for commdb shimm
417 void ConstructL(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC8& aValueToMatch);
418 void ConstructL(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC16& aValueToMatch);
419 void ConstructL(const TDesC& aTableName, const TDesC& aColumnToMatch, TUint32 aValueToMatch);
420 void ConstructL(const TDesC& aTableName, const TDesC& aColumnToMatch, TBool aValueToMatch);
421 void ConstructL(TUint32 aBearerSet, TCommDbConnectionDirection aDirection);
422 void ConstructL(TUint32 aNetworkId);
423 void ConstructL(TUint32 aServiceId, const TDesC& aServiceType);
424 // used for template creation only
425 void ConstructL(const TDesC& aTableName);
435 TBool TableWithTemplateRecord() const;
436 TInt InsertTemplateRecord();
437 TInt DoInsertRecord(TBool aType, TUint32& aId, TBool aIsTemplate);
438 TInt DoPutRecordChanges(TBool aHidden = EFalse, TBool aReadOnly = EFalse, TBool aIsTemplateCall = EFalse);
442 CCommsDbTemplateRecord* iTemplate;
443 TBool iTsyNameChanged;
444 TUint32 iInsertedRecordIndex;
448 CCommsDatabaseBase& iDb;
449 TBuf<KCommsDbSvrMaxColumnNameLength> iTableName;
451 CCommDbTableExtension* iTableExt;
458 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
460 Convert a legacy field name to a CommsDat element Id
464 @param aFieldName A legacy commdb field name in the format "tableName\fieldName"
465 @return A Commsdat element Id
470 IMPORT_C static TMDBElementId GetElementIdFromFieldNameL(const TDesC& aFieldName);
474 // SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
477 #include <commdb.inl>