wvuing/IMPSConnectionUI/ClientPluginSrc/CCnUiClientPluginPEC.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:  PEC client plugin.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32std.h>
       
    20 
       
    21 #include "MIMPSSharedData.h"
       
    22 #include "CIMPSSharedDataFactory.h"
       
    23 #include "IMPSUIDDefs.h"
       
    24 
       
    25 //PEC attributes
       
    26 #include <CPEngAttributeTransaction2.h>
       
    27 #include <CPEngAttributeStore2.h>
       
    28 #include <MPEngPresenceAttrModel2.h>
       
    29 #include <MPEngPresenceAttrTypeProperties2.h>
       
    30 
       
    31 //PEC attribute lists
       
    32 #include <CPEngAttributeListStore2.h>
       
    33 #include <CPEngAttributeListTransaction2.h>
       
    34 #include <MPEngAttributeList2.h>
       
    35 
       
    36 //PEC contact lists
       
    37 #include <CPEngContactListStore2.h>
       
    38 #include <CPEngContactListTransaction2.h>
       
    39 #include <MPEngContactList2.h>
       
    40 
       
    41 // PEC
       
    42 #include <CPEngNWSessionSlotID2.h>
       
    43 #include <PEngWVServices2.h>
       
    44 
       
    45 #include <ImpsServices.h>
       
    46 #include <PEngWVPresenceErrors2.h>
       
    47 #include <PEngWVPresenceAttributes2.h>
       
    48 
       
    49 #include <WVSettingsSharedDataNG.h>
       
    50 #include "CCnUiClientPluginPEC.h"
       
    51 #include "IMPSPublishLevelPolicy.h"
       
    52 #include "impspresenceconnectionuiconstsng.h"
       
    53 
       
    54 
       
    55 // ================= MEMBER FUNCTIONS =======================
       
    56 // Two-phased constructor.
       
    57 CCnUiClientPluginPEC* CCnUiClientPluginPEC::NewL( CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    58     {
       
    59     CCnUiClientPluginPEC* self = new ( ELeave ) CCnUiClientPluginPEC();
       
    60 
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL( aNWSessionSlotID );
       
    63     CleanupStack::Pop( self ); //self
       
    64 
       
    65     return self;
       
    66     }
       
    67 
       
    68 
       
    69 // Destructor
       
    70 CCnUiClientPluginPEC::~CCnUiClientPluginPEC()
       
    71     {
       
    72     }
       
    73 
       
    74 
       
    75 // C++ default constructor can NOT contain any code, that
       
    76 // might leave.
       
    77 //
       
    78 CCnUiClientPluginPEC::CCnUiClientPluginPEC()
       
    79         : CCnUiClientPluginBase( EIMPSConnClientPEC )
       
    80     {
       
    81     }
       
    82 
       
    83 
       
    84 // Symbian OS default constructor can leave.
       
    85 void CCnUiClientPluginPEC::ConstructL( CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    86     {
       
    87     CCnUiClientPluginBase::ConstructL( aNWSessionSlotID );
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CCnUiClientPluginPEC::CurrentConnectionModeSettingL()
       
    93 // From MCnUiClientPlugin
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 TCnUiConnectionMode CCnUiClientPluginPEC::CurrentConnectionModeSettingL()
       
    97     {
       
    98     // dummy implementation
       
    99     TCnUiConnectionMode cMode( ECnUiCMAutomatic );
       
   100     return cMode;
       
   101     }
       
   102 
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CCnUiClientPluginPEC::ReWakeAutomaticConnectionModeL()
       
   106 // From MCnUiClientPlugin
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CCnUiClientPluginPEC::ReWakeAutomaticConnectionModeL()
       
   110     {
       
   111     // this is no longer needed
       
   112     }
       
   113 
       
   114 
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CCnUiClientPluginPEC::ConnectionOpenInitL()
       
   118 // From MCnUiClientPlugin - connection open related methods
       
   119 // Overloaded from CCnUiClientPluginBase
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CCnUiClientPluginPEC::ConnectionOpenInitL( TBool aSapConnectionOpen,
       
   123                                                 const CIMPSSAPSettings& aSap )
       
   124     {
       
   125     //let first the base class to do its things like disable synchronization
       
   126     //of unknown lists
       
   127     CCnUiClientPluginBase::ConnectionOpenInitL( aSapConnectionOpen, aSap );
       
   128 
       
   129     //if opening real NW connection, initialize the local
       
   130     //attribute lists and attributes here as needed
       
   131     //==>they will get synchronized with PEC engine login & synchronization
       
   132     if ( !aSapConnectionOpen )
       
   133         {
       
   134         IMPSPublishLevelPolicy::InitializePublishLevelL( *iNWSessionSlotID );
       
   135         }
       
   136     }
       
   137 
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CCnUiClientPluginPEC::DoPostLoginProsessingL()
       
   142 // From MCnUiClientPlugin - connection open related methods
       
   143 // Overloaded from CCnUiClientPluginBase
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CCnUiClientPluginPEC::DoPostLoginProsessingL( TRequestStatus& aStatus )
       
   147     {
       
   148 
       
   149     //do first the client specific things (enable profiles presence updates)
       
   150     MIMPSSharedData* sharedData = CIMPSSharedDataFactory::CreatePermanentKeyHandlerL(
       
   151                                       NULL,
       
   152                                       KIMPSProfileEngineKeyUid );
       
   153 
       
   154     //From SharedDataKeys.h
       
   155     //1 == allowed to update Presence attributes
       
   156     //ignore possible settings errors, all this is done with best effort way...
       
   157     sharedData->SetIntKey( EIMPSSharedKeysProEngAllowUpdatePresence, 1 );
       
   158 
       
   159     delete sharedData;
       
   160 
       
   161     //and the let the base class take the charge...
       
   162     //NOTE!! Order must be this becase the base might start something
       
   163     //asynhronous & and after that leaving isn't allowd...
       
   164 
       
   165     CCnUiClientPluginBase::DoPostLoginProsessingL( aStatus );
       
   166     }
       
   167 
       
   168 
       
   169 
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CCnUiClientPluginPEC::DoPreLogoutProsessingL()
       
   173 // From MCnUiClientPlugin - connection close related methods
       
   174 // Overloaded from CCnUiClientPluginBase
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CCnUiClientPluginPEC::DoPreLogoutProsessingL( TRequestStatus& aStatus )
       
   178     {
       
   179 
       
   180     //do first the client specific things (disable profiles presence updates)
       
   181     MIMPSSharedData* sharedData = CIMPSSharedDataFactory::CreatePermanentKeyHandlerL(
       
   182                                       NULL,
       
   183                                       KIMPSProfileEngineKeyUid );
       
   184 
       
   185     //From SharedDataKeys.h
       
   186     //0 == not allowed to update Presence attributes, default
       
   187     //ignore possible settings errors, all this is done with best effort way...
       
   188     sharedData->SetIntKey( EIMPSSharedKeysProEngAllowUpdatePresence, 0 );
       
   189 
       
   190     delete sharedData;
       
   191 
       
   192     //and the let the base class take the charge...
       
   193     //NOTE!! Order must be this becase the base might start something
       
   194     //asynhronous & and after that leaving isn't allowd...
       
   195     CCnUiClientPluginBase::DoPreLogoutProsessingL( aStatus );
       
   196     }
       
   197 
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CCnUiClientPluginPEC::DoVerifySapCapabilities()
       
   202 // From CCnUiClientPluginBase
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 TBool CCnUiClientPluginPEC::DoVerifySapCapabilities( TPEngWVCspServicesTree2 aCurrentNwServices )
       
   206     {
       
   207     // For PEC WV server must support all of these main features
       
   208     // Logical and is used
       
   209     //==> if any of these is EFalse, result will be EFalse
       
   210 
       
   211     TBool capabOK = aCurrentNwServices.iFundamentalFeat.FeatureSupported();
       
   212     capabOK &= aCurrentNwServices.iFundamentalFeat.SubFunctionSupported( KPEngFFSubFuncSRCH );
       
   213     capabOK &= aCurrentNwServices.iFundamentalFeat.SubFunctionSupported( KPEngFFSubFuncSTSRC );
       
   214 
       
   215     capabOK &= aCurrentNwServices.iPresenceFeat.FeatureSupported();
       
   216     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncGCLI );
       
   217     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncCCLI );
       
   218     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncDCLI );
       
   219     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncMCLS );
       
   220 
       
   221     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncGETWL );
       
   222     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncGETPR );
       
   223     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncUPDPR );
       
   224 
       
   225     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncCALI );
       
   226     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncDALI );
       
   227     capabOK &= aCurrentNwServices.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncGALS );
       
   228 
       
   229 
       
   230 
       
   231     return capabOK;
       
   232     }
       
   233 
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CCnUiClientPluginPEC::DoClientKnownCntListsLC()
       
   237 // Template method from CCnUiClientPluginBase
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 CDesCArray* CCnUiClientPluginPEC::DoClientKnownCntListsLC()
       
   241     {
       
   242     CDesCArrayFlat* lists = new ( ELeave ) CDesCArrayFlat( 4 ); //4 known lists
       
   243     CleanupStack::PushL( lists );
       
   244 
       
   245     //enumerate here those lists that are used by PEC & needs to be
       
   246     //synchronized when PEC is doing login
       
   247 
       
   248     CPEngContactListStore2* contactListStore = CPEngContactListStore2::NewLC( *iNWSessionSlotID );
       
   249 
       
   250     const MDesCArray& array = contactListStore->AllContactListsL();
       
   251 
       
   252     for ( TInt i = 1; i < array.MdcaCount(); i++ )
       
   253         {
       
   254         TPtrC list = array.MdcaPoint( i );
       
   255         if ( list.FindF( KIMPSPECContactListIdentifier() ) != KErrNotFound  )
       
   256             {
       
   257             // this seems to be PECUi's list
       
   258             lists->AppendL( list );
       
   259             }
       
   260         }
       
   261     CleanupStack::PopAndDestroy( contactListStore );
       
   262 
       
   263     return lists;
       
   264     }
       
   265 
       
   266 
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CCnUiClientPluginPEC::DoStartExplicitPostLoginSyncL()
       
   270 // From CCnUiClientPluginBase
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 void CCnUiClientPluginPEC::DoStartExplicitPostLoginSyncL()
       
   274     {
       
   275     // first do the base synchronization
       
   276     User::LeaveIfError( iPEngCntListPublisher->BaseSynchronizeContactLists( *this ) );
       
   277     SetStepProcessingActive();
       
   278     iStepId = EBaseCntListSynch;
       
   279     }
       
   280 
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CCnUiClientPluginPEC::DoHandleExplicitPostLoginSyncStepCompleteL()
       
   284 // From CCnUiClientPluginBase
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 void CCnUiClientPluginPEC::DoHandleExplicitPostLoginSyncStepCompleteL( TStepId aStepId,
       
   288                                                                        TInt& aStepStatus )
       
   289     {
       
   290     switch ( aStepId )
       
   291         {
       
   292         case EBaseCntListSynch:
       
   293             {
       
   294             if ( aStepStatus == KErrNone )
       
   295                 {
       
   296                 //initialize the local attribute lists as needed
       
   297                 IMPSPublishLevelPolicy::InitializePublishLevelL( *iNWSessionSlotID );
       
   298 
       
   299                 //and synchronize known PEC list explicitly with network server
       
   300                 MDesCArray* knownLists = DoClientKnownCntListsLC();
       
   301                 User::LeaveIfError( iPEngCntListPublisher->SynchronizeContactLists(
       
   302                                         *knownLists,
       
   303                                         *this ) );
       
   304                 CleanupStack::PopAndDestroy();  //knownLists
       
   305                 SetStepProcessingActive();
       
   306                 iStepId = ECntListPublish;
       
   307                 }
       
   308             break;
       
   309             }
       
   310 
       
   311         case ECntListPublish:
       
   312             {
       
   313             if ( ( aStepStatus == KErrNone ) ||
       
   314                  ( aStepStatus == KPEngNwErrPartiallySuccessful ) )
       
   315                 {
       
   316                 //Contact lists are now successfully synchronized
       
   317                 aStepStatus = KErrNone;
       
   318 
       
   319                 User::LeaveIfError( iPEngAttributeListPublisher->PublishAttributeLists( *this ) );
       
   320                 SetStepProcessingActive();
       
   321                 iStepId = EAttribListPublish;
       
   322                 }
       
   323             break;
       
   324             }
       
   325 
       
   326         case EAttribListPublish:
       
   327             {
       
   328             if ( ( aStepStatus == KErrNone ) ||
       
   329                  ( aStepStatus == KPEngNwErrPartiallySuccessful ) )
       
   330                 {
       
   331                 //Attribute lists are now successfully synchronized
       
   332 
       
   333 
       
   334                 aStepStatus = KErrNone;
       
   335                 UpdateAttributesL();
       
   336                 SetStepProcessingActive();
       
   337                 iStepId = EAttributePublish;
       
   338                 }
       
   339             break;
       
   340             }
       
   341 
       
   342 
       
   343         case EAttributePublish:
       
   344             {
       
   345             //ignore possibly from attribute publish propagating errors
       
   346             aStepStatus = KErrNone;
       
   347             break;
       
   348             }
       
   349 
       
   350 
       
   351         default:
       
   352             {
       
   353             //nothing to do
       
   354             break;
       
   355             }
       
   356         }
       
   357     }
       
   358 
       
   359 
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CCnUiClientPluginPEC::DoStartPreLogoutPublishL()
       
   363 // From CCnUiClientPluginBase
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CCnUiClientPluginPEC::DoStartPreLogoutPublishL()
       
   367     {
       
   368     }
       
   369 
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CCnUiClientPluginPEC::DoHandlePreLogoutPublishStepCompleteL()
       
   373 // From CCnUiClientPluginBase
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CCnUiClientPluginPEC::DoHandlePreLogoutPublishStepCompleteL( TStepId /*aStepId*/,
       
   377                                                                   TInt& /*aStepStatus*/ )
       
   378     {
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CCnUiClientPluginPEC::DoHandlePreLogoutPublishStepCompleteL()
       
   383 //
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 void CCnUiClientPluginPEC::UpdateAttributesL()
       
   387     {
       
   388     RPointerArray<MPEngPresenceAttrModel2> models;
       
   389     CleanupStack::PushL( TCleanupItem( DestroyCloseModelArray, &models ) );
       
   390 
       
   391     MPEngPresenceAttrModel2* userAvail = NULL;
       
   392     TInt err = iPEngAttributeStore->GetAndLockOwnAttribute( KUidPrAttrUserAvailability,
       
   393                                                             userAvail );
       
   394 
       
   395     // if the model was locked, the pointer is still null, but we want to continue with
       
   396     // the other attributes
       
   397     if ( ( err != KErrNone ) && ( err != KErrLocked  ) )
       
   398         {
       
   399         User::Leave( err );
       
   400         }
       
   401     else
       
   402         {
       
   403         CleanupClosePushL( *userAvail );
       
   404         models.AppendL( userAvail );
       
   405         CleanupStack::Pop(); // userAvail
       
   406         }
       
   407 
       
   408     MPEngPresenceAttrModel2* onlineStatus = NULL;
       
   409     err = iPEngAttributeStore->GetAndLockOwnAttribute( KUidPrAttrOnlineStatus, onlineStatus );
       
   410 
       
   411     // if the model was locked, the pointer is still null, but we want to continue with
       
   412     // the other attributes
       
   413     if ( ( err != KErrNone ) && ( err != KErrLocked  ) )
       
   414         {
       
   415         User::Leave( err );
       
   416         }
       
   417     else
       
   418         {
       
   419         CleanupClosePushL( *onlineStatus );
       
   420         onlineStatus->SetQualifier( ETrue );
       
   421         models.AppendL( onlineStatus );
       
   422         CleanupStack::Pop(); // onlineStatus
       
   423         }
       
   424 
       
   425     MPEngPresenceAttrModel2* clientInfo = NULL;
       
   426     err = iPEngAttributeStore->GetAndLockOwnAttribute( KUidPrAttrClientInfo, clientInfo );
       
   427 
       
   428     // if the model was locked, the pointer is still null, but we want to continue with
       
   429     // the other attributes
       
   430     if ( ( err != KErrNone ) && ( err != KErrLocked  ) )
       
   431         {
       
   432         User::Leave( err );
       
   433         }
       
   434     else
       
   435         {
       
   436         CleanupClosePushL( *clientInfo );
       
   437         models.AppendL( clientInfo );
       
   438         CleanupStack::Pop(); // clientInfo
       
   439         }
       
   440 
       
   441     MPEngPresenceAttrModel2* statusText = NULL;
       
   442     err = iPEngAttributeStore->GetAndLockOwnAttribute( KUidPrAttrStatusText, statusText );
       
   443 
       
   444     // if the model was locked, the pointer is still null, but we want to continue with
       
   445     // the other attributes
       
   446     if ( ( err != KErrNone ) && ( err != KErrLocked  ) )
       
   447         {
       
   448         User::Leave( err );
       
   449         }
       
   450     else
       
   451         {
       
   452         CleanupClosePushL( *statusText );
       
   453         models.AppendL( statusText );
       
   454         CleanupStack::Pop(); // statusText
       
   455         }
       
   456 
       
   457     MPEngPresenceAttrModel2* statusContent = NULL;
       
   458     err = iPEngAttributeStore->GetAndLockOwnAttribute( KUidPrAttrStatusContent, statusContent );
       
   459 
       
   460     // if the model was locked, the pointer is still null, but we want to continue with
       
   461     // the other attributes
       
   462     if ( ( err != KErrNone ) && ( err != KErrLocked  ) )
       
   463         {
       
   464         User::Leave( err );
       
   465         }
       
   466     else
       
   467         {
       
   468         CleanupClosePushL( *statusContent );
       
   469         models.AppendL( statusContent );
       
   470         CleanupStack::Pop(); // statusContent
       
   471         }
       
   472 
       
   473     User::LeaveIfError( iPEngAttributePublisher->PublishAndUnLockOwnAttributes( models, *this ) );
       
   474     CleanupStack::Pop(); // models
       
   475     }
       
   476 
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CCnUiClientPluginPEC::DestroyCloseModelArray()
       
   480 //
       
   481 // -----------------------------------------------------------------------------
       
   482 //
       
   483 void CCnUiClientPluginPEC::DestroyCloseModelArray( TAny* aObject )
       
   484     {
       
   485     reinterpret_cast<RPointerArray<MPEngPresenceAttrModel2>*>( aObject )->ResetAndDestroy();
       
   486     }
       
   487 
       
   488 //  End of File
       
   489 
       
   490 
       
   491 
       
   492