wvuing/IMPSServiceSettingsUI/SharedDataSrc/CIMPSCenrepHandler.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Central repository handler
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    "CIMPSCenrepHandler.h"
       
    20 #include	"MIMPSSharedDataObserver.h"
       
    21 #include    "CIMPSCenrepObserver.h"
       
    22 #include    "IMPSSharedDataDefs.h"
       
    23 #include	<centralrepository.h>
       
    24 
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CIMPSCenrepHandler::NewL
       
    30 // Two-phased constructor.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CIMPSCenrepHandler* CIMPSCenrepHandler::NewL( MIMPSSharedDataObserver* aObserver, const TUid aUid )
       
    34     {
       
    35     CIMPSCenrepHandler* self = new( ELeave ) CIMPSCenrepHandler( aObserver );
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL( aUid );
       
    38     CleanupStack::Pop( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 
       
    43 // Symbian OS default constructor can leave.
       
    44 void CIMPSCenrepHandler::ConstructL( const TUid aUid )
       
    45     {
       
    46     // assign
       
    47     iUid = aUid;
       
    48 
       
    49     iRepository = CRepository::NewL( iUid );
       
    50 
       
    51     AppendKeyPairsL();
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CIMPSCenrepHandler::SubscribeChange( const TUid aUid, const TDesC* aKey )
       
    56 //
       
    57 // (other items were commented in a header).
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 TInt CIMPSCenrepHandler::SubscribeChange( const TUid aUid, const TIMPSSharedKeys aKey )
       
    61     {
       
    62     TRAPD( err, DoSubscribeChangeL( aUid, aKey ) );
       
    63     return err;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CIMPSCenrepHandler::SubscribeSet( const TUid aUid, const TDesC* aKey )
       
    68 //
       
    69 // (other items were commented in a header).
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 TInt CIMPSCenrepHandler::SubscribeSet( const TUid aUid, const TIMPSSharedKeys aKey )
       
    73     {
       
    74     TRAPD( err, DoSubscribeSetL( aUid, aKey ) );
       
    75     return err;
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CIMPSCenrepHandler::UnSubscribe( const TUid aUid, const TDesC* aKey )
       
    80 //
       
    81 // (other items were commented in a header).
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CIMPSCenrepHandler::UnSubscribe( const TUid aUid, const TIMPSSharedKeys aKey )
       
    85     {
       
    86     for ( TInt count( 0 ); count < iCenrepObservers.Count(); count++ )
       
    87         {
       
    88         CIMPSCenrepObserver* observer = iCenrepObservers[ count ];
       
    89         if ( ( observer->Category() == aUid ) &&
       
    90              ( ( TInt )observer->Key() == aKey ) )
       
    91             {
       
    92             iCenrepObservers.Remove( count );
       
    93             delete observer;
       
    94             }
       
    95         }
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CIMPSCenrepHandler::GetStringKey( const TDesC& aKey, TDes& aValue )
       
   100 //
       
   101 // (other items were commented in a header).
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TInt CIMPSCenrepHandler::GetStringKey( const TIMPSSharedKeys aKey, TDes& aValue )
       
   105     {
       
   106     TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> temp;
       
   107     TInt err = iRepository->Get( aKey, temp );
       
   108     if ( err != KErrNone )
       
   109         {
       
   110         return err;
       
   111         }
       
   112     // empty the value
       
   113     aValue.Zero();
       
   114     aValue.Copy( temp );
       
   115 
       
   116     return KErrNone;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CIMPSCenrepHandler::GetIntKey( const TDesC& aKey, TInt& aValue )
       
   121 //
       
   122 // (other items were commented in a header).
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 TInt CIMPSCenrepHandler::GetIntKey( const TIMPSSharedKeys aKey, TInt& aValue )
       
   126     {
       
   127     TInt err = iRepository->Get( aKey, aValue );
       
   128     return err;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CIMPSCenrepHandler::SetStringKey( const TDesC& aKey, const TDesC& aValue )
       
   133 //
       
   134 // (other items were commented in a header).
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 TInt CIMPSCenrepHandler::SetStringKey( const TIMPSSharedKeys aKey, const TDesC& aValue )
       
   138     {
       
   139     TInt err = iRepository->Set( aKey, aValue );
       
   140     return err;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CIMPSCenrepHandler::SetIntKey( const TDesC& aKey, TInt aValue )
       
   145 //
       
   146 // (other items were commented in a header).
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 TInt CIMPSCenrepHandler::SetIntKey( const TIMPSSharedKeys aKey, TInt aValue )
       
   150     {
       
   151     // we can ignore the return value here, since we know the type is correct
       
   152     // and if the key is already defined we can safely set it
       
   153     TInt err = iRepository->Set( aKey, aValue );
       
   154     return err;
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CIMPSCenrepHandler::Signal( const TDesC& aKey )
       
   159 //
       
   160 // (other items were commented in a header).
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 TInt CIMPSCenrepHandler::Signal( const TIMPSSharedKeys aKey )
       
   164     {
       
   165     TRAPD( err, DoSignalL( aKey ) );
       
   166     return err;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CIMPSCenrepHandler::DoSignalL( const TDesC& aKey )
       
   171 //
       
   172 // (other items were commented in a header).
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CIMPSCenrepHandler::DoSignalL( const TIMPSSharedKeys aKey )
       
   176     {
       
   177     TInt current( 0 );
       
   178     TInt err = iRepository->Get( aKey, current );
       
   179     if ( err == KErrNotFound )
       
   180         {
       
   181         // we don't need to worry about this since if the key is not found
       
   182         // the correct value for the current value is 0
       
   183         // but we have to define the key
       
   184         err = KErrNone;
       
   185 
       
   186         // we can ignore the return value here, since we know the type is correct
       
   187         // and if the key is already defined we can safely set it
       
   188         // we set the initial value to 0
       
   189         iRepository->Create( aKey, 0 );
       
   190         }
       
   191     User::LeaveIfError( err );
       
   192 
       
   193 
       
   194     User::LeaveIfError( iRepository->Set( aKey, ( current + 1 ) ) );
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CIMPSCenrepHandler::CancelSignal( const TDesC& aKey )
       
   199 //
       
   200 // (other items were commented in a header).
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TInt CIMPSCenrepHandler::CancelSignal( const TIMPSSharedKeys aKey )
       
   204     {
       
   205     TRAPD( err, DoCancelSignalL( aKey ) );
       
   206     return err;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CIMPSCenrepHandler::DoCancelSignalL( const TDesC& aKey )
       
   211 //
       
   212 // (other items were commented in a header).
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CIMPSCenrepHandler::DoCancelSignalL( const TIMPSSharedKeys aKey )
       
   216     {
       
   217     TInt current( 0 );
       
   218     TInt err = iRepository->Get( aKey, current );
       
   219     if ( err == KErrNotFound )
       
   220         {
       
   221         // we don't need to worry about this since if the key is not found
       
   222         // the correct value for the current value is 0
       
   223         // but we have to define the key
       
   224         err = KErrNone;
       
   225 
       
   226         // we can ignore the return value here, since we know the type is correct
       
   227         // and if the key is already defined we can safely set it
       
   228         // we set the initial value to 0
       
   229         iRepository->Create( aKey, 0 );
       
   230         }
       
   231     User::LeaveIfError( err );
       
   232 
       
   233     User::LeaveIfError( iRepository->Set( aKey, ( current - 1 ) ) );
       
   234     }
       
   235 
       
   236 
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CIMPSCenrepHandler::DoSubscribeChangeL( const TUid aUid, const TIMPSSharedKeys aKey )
       
   240 //
       
   241 // (other items were commented in a header).
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CIMPSCenrepHandler::DoSubscribeChangeL( const TUid aUid, const TIMPSSharedKeys aKey )
       
   245     {
       
   246     CIMPSCenrepObserver* observer = CIMPSCenrepObserver::NewL( *this );
       
   247     CleanupStack::PushL( observer );
       
   248     observer->ObservePropertyChangeL( aUid, aKey );
       
   249     User::LeaveIfError( iCenrepObservers.Append( observer ) );
       
   250     CleanupStack::Pop( observer );
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CIMPSCenrepHandler::DoSubscribeSetL( const TUid aUid, const TIMPSSharedKeys aKey )
       
   255 //
       
   256 // (other items were commented in a header).
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CIMPSCenrepHandler::DoSubscribeSetL( const TUid aUid, const TIMPSSharedKeys aKey )
       
   260     {
       
   261     CIMPSCenrepObserver* observer = CIMPSCenrepObserver::NewL( *this );
       
   262     CleanupStack::PushL( observer );
       
   263     observer->ObservePropertyChangeL( aUid, aKey );
       
   264     User::LeaveIfError( iCenrepObservers.Append( observer ) );
       
   265     CleanupStack::Pop( observer );
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CIMPSCenrepHandler::ConvertSharedDataKey( const TDesC& aSrc, TIMPSSharedKeys& aKey )
       
   270 //
       
   271 // (other items were commented in a header).
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 TInt CIMPSCenrepHandler::ConvertSharedDataKey( const TDesC& aSrc, TIMPSSharedKeys& aDest )
       
   275     {
       
   276     TInt err = MapKeysToClient( aDest, aSrc );
       
   277     return err;
       
   278     }
       
   279 
       
   280 // C++ default constructor can NOT contain any code, that
       
   281 // might leave.
       
   282 //
       
   283 CIMPSCenrepHandler::CIMPSCenrepHandler( MIMPSSharedDataObserver* aObserver )
       
   284         : iObserver( aObserver )
       
   285     {
       
   286     }
       
   287 
       
   288 // Destructor
       
   289 CIMPSCenrepHandler::~CIMPSCenrepHandler()
       
   290     {
       
   291     iCenrepObservers.ResetAndDestroy();
       
   292     iCenrepObservers.Close();
       
   293     iKeys.Close();
       
   294     delete iRepository;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CIMPSCenrepHandler::HandlePropertyNotificationEventL( TUid aCategory, TUint aKey )
       
   299 //
       
   300 // (other items were commented in a header).
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CIMPSCenrepHandler::HandlePropertyNotificationEventL( TUid aCategory, TUint aKey )
       
   304     {
       
   305     if ( iObserver )
       
   306         {
       
   307         iObserver->HandleTemporaryKeyNotifyL( aCategory, ( TIMPSSharedKeys )aKey );
       
   308         }
       
   309     }
       
   310 
       
   311 
       
   312 // ---------------------------------------------------------
       
   313 // CIMPSCenrepHandler::MapKeysToClient()
       
   314 //
       
   315 // (other items were commented in a header).
       
   316 // ---------------------------------------------------------
       
   317 //
       
   318 TInt CIMPSCenrepHandler::MapKeysToClient( TIMPSSharedKeys& aKey, const TDesC& aSharedDataKey )
       
   319     {
       
   320     TInt count( 0 );
       
   321     for ( count = 0; count < iKeys.Count(); count++ )
       
   322         {
       
   323         if ( 0 == iKeys[count].iKeyForSharedData.Compare( aSharedDataKey ) )
       
   324             {
       
   325             aKey = iKeys[count].iKeyForClient;
       
   326             return KErrNone;
       
   327             }
       
   328         }
       
   329     return KErrNotFound;
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------
       
   333 // CIMPSCenrepHandler::DoAppendKeyPairL()
       
   334 //
       
   335 // (other items were commented in a header).
       
   336 // ---------------------------------------------------------
       
   337 //
       
   338 void CIMPSCenrepHandler::DoAppendKeyPairL( TIMPSSharedKeys aKey, const TDesC& aSharedDataKey )
       
   339     {
       
   340     TIMPSSharedKeyPairs temp;
       
   341     temp.iKeyForSharedData.Set( aSharedDataKey );
       
   342     temp.iKeyForClient = aKey;
       
   343     User::LeaveIfError( iKeys.Append( temp ) );
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------
       
   347 // CIMPSCenrepHandler::AppendKeyPairsL()
       
   348 //
       
   349 // (other items were commented in a header).
       
   350 // ---------------------------------------------------------
       
   351 //
       
   352 void CIMPSCenrepHandler::AppendKeyPairsL()
       
   353     {
       
   354     // Connection UI keys
       
   355     // Connection UI Group channel keys
       
   356     DoAppendKeyPairL( EIMPSSharedKeysIMClientLoginLogoutStateChannel,
       
   357                       KIMPSSharedKeysIMClientLoginLogoutStateChannel );
       
   358     DoAppendKeyPairL( EIMPSSharedKeysIMLoginLogoutEventChannel,
       
   359                       KIMPSSharedKeysIMLoginLogoutEventChannel );
       
   360     DoAppendKeyPairL( EIMPSSharedKeysIMSSClientReqistrationChannel,
       
   361                       KIMPSSharedKeysIMSSClientReqistrationChannel );
       
   362     DoAppendKeyPairL( EIMPSSharedKeysIMGlobalOperationSignalChannel,
       
   363                       KIMPSSharedKeysIMGlobalOperationSignalChannel );
       
   364     DoAppendKeyPairL( EIMPSSharedKeysIMRemoteUiNotificationsChannel,
       
   365                       KIMPSSharedKeysIMRemoteUiNotificationsChannel );
       
   366     DoAppendKeyPairL( EIMPSSharedKeysPECClientLoginLogoutStateChannel,
       
   367                       KIMPSSharedKeysPECClientLoginLogoutStateChannel );
       
   368     DoAppendKeyPairL( EIMPSSharedKeysPECLoginLogoutEventChannel,
       
   369                       KIMPSSharedKeysPECLoginLogoutEventChannel );
       
   370     DoAppendKeyPairL( EIMPSSharedKeysPECSSClientReqistrationChannel,
       
   371                       KIMPSSharedKeysPECSSClientReqistrationChannel );
       
   372     DoAppendKeyPairL( EIMPSSharedKeysPECGlobalOperationSignalChannel,
       
   373                       KIMPSSharedKeysPECGlobalOperationSignalChannel );
       
   374     DoAppendKeyPairL( EIMPSSharedKeysPECRemoteUiNotificationsChannel,
       
   375                       KIMPSSharedKeysPECRemoteUiNotificationsChannel );
       
   376 
       
   377     DoAppendKeyPairL( EIMPSSharedKeysCommonClientLoginLogoutStateChannel,
       
   378                       KIMPSSharedKeysCommonClientLoginLogoutStateChannel );
       
   379     DoAppendKeyPairL( EIMPSSharedKeysCommonLoginLogoutEventChannel,
       
   380                       KIMPSSharedKeysCommonLoginLogoutEventChannel );
       
   381     DoAppendKeyPairL( EIMPSSharedKeysCommonSSClientReqistrationChannel,
       
   382                       KIMPSSharedKeysCommonSSClientReqistrationChannel );
       
   383     DoAppendKeyPairL( EIMPSSharedKeysCommonGlobalOperationSignalChannel,
       
   384                       KIMPSSharedKeysCommonGlobalOperationSignalChannel );
       
   385     DoAppendKeyPairL( EIMPSSharedKeysCommonRemoteUiNotificationsChannel,
       
   386                       KIMPSSharedKeysCommonRemoteUiNotificationsChannel );
       
   387     // Connection UI Group data keys
       
   388     DoAppendKeyPairL( EIMPSSharedKeysIMClientLoginLogoutStateData,
       
   389                       KIMPSSharedKeysIMClientLoginLogoutStateData );
       
   390     DoAppendKeyPairL( EIMPSSharedKeysIMLoginLogoutEventData,
       
   391                       KIMPSSharedKeysIMLoginLogoutEventData );
       
   392     DoAppendKeyPairL( EIMPSSharedKeysIMSSClientReqistrationData,
       
   393                       KIMPSSharedKeysIMSSClientReqistrationData );
       
   394     DoAppendKeyPairL( EIMPSSharedKeysIMGlobalOperationSignalData,
       
   395                       KIMPSSharedKeysIMGlobalOperationSignalData );
       
   396     DoAppendKeyPairL( EIMPSSharedKeysIMRemoteUiNotificationsData,
       
   397                       KIMPSSharedKeysIMRemoteUiNotificationsData );
       
   398     DoAppendKeyPairL( EIMPSSharedKeysPECClientLoginLogoutStateData,
       
   399                       KIMPSSharedKeysPECClientLoginLogoutStateData );
       
   400     DoAppendKeyPairL( EIMPSSharedKeysPECLoginLogoutEventData,
       
   401                       KIMPSSharedKeysPECLoginLogoutEventData );
       
   402     DoAppendKeyPairL( EIMPSSharedKeysPECSSClientReqistrationData,
       
   403                       KIMPSSharedKeysPECSSClientReqistrationData );
       
   404     DoAppendKeyPairL( EIMPSSharedKeysPECGlobalOperationSignalData,
       
   405                       KIMPSSharedKeysPECGlobalOperationSignalData );
       
   406     DoAppendKeyPairL( EIMPSSharedKeysPECRemoteUiNotificationsData,
       
   407                       KIMPSSharedKeysPECRemoteUiNotificationsData );
       
   408 
       
   409     DoAppendKeyPairL( EIMPSSharedKeysCommonClientLoginLogoutStateData,
       
   410                       KIMPSSharedKeysCommonClientLoginLogoutStateData );
       
   411     DoAppendKeyPairL( EIMPSSharedKeysCommonLoginLogoutEventData,
       
   412                       KIMPSSharedKeysCommonLoginLogoutEventData );
       
   413     DoAppendKeyPairL( EIMPSSharedKeysCommonSSClientReqistrationData,
       
   414                       KIMPSSharedKeysCommonSSClientReqistrationData );
       
   415     DoAppendKeyPairL( EIMPSSharedKeysCommonGlobalOperationSignalData,
       
   416                       KIMPSSharedKeysCommonGlobalOperationSignalData );
       
   417     DoAppendKeyPairL( EIMPSSharedKeysCommonRemoteUiNotificationsData,
       
   418                       KIMPSSharedKeysCommonRemoteUiNotificationsData );
       
   419 
       
   420     // Connection UI Global channel keys
       
   421     DoAppendKeyPairL( EIMPSSharedKeysIMGlobalChannel,
       
   422                       KIMPSSharedKeysIMGlobalChannel );
       
   423     DoAppendKeyPairL( EIMPSSharedKeysPECGlobalChannel,
       
   424                       KIMPSSharedKeysPECGlobalChannel );
       
   425 
       
   426     // Connection UI Global data keys
       
   427     DoAppendKeyPairL( EIMPSSharedKeysIMGlobalData,
       
   428                       KIMPSSharedKeysIMGlobalData );
       
   429     DoAppendKeyPairL( EIMPSSharedKeysPECGlobalData,
       
   430                       KIMPSSharedKeysPECGlobalData );
       
   431 
       
   432     // Connection UI Permanent global data key
       
   433     DoAppendKeyPairL( EIMPSSharedKeysPermanentGlobalChannel,
       
   434                       KIMPSSharedKeysPermanentGlobalChannel );
       
   435     DoAppendKeyPairL( EIMPSSharedKeysPermanentGlobalData,
       
   436                       KIMPSSharedKeysPermanentGlobalData );
       
   437 
       
   438     DoAppendKeyPairL( EIMPSSharedKeysIMPresenceAuthSettingKey,
       
   439                       KIPMSSharedKeysIMPresenceAuthSettingKey );
       
   440 
       
   441     // Profile engines key
       
   442     DoAppendKeyPairL( EIMPSSharedKeysProEngAllowUpdatePresence,
       
   443                       KIMPSSharedKeysProEngAllowUpdatePresence );
       
   444 
       
   445     // Presence UI keys
       
   446     DoAppendKeyPairL( EIMPSSharedKeysPECAppKeyNamePublishing,
       
   447                       KIMPSSharedKeysPECAppKeyNamePublishing );
       
   448     }
       
   449 
       
   450 
       
   451 //  End of File