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