presencefwsimpleadpt/src/simpleplugingroups.cpp
branchRCL_3
changeset 35 fbd2e7cec7ef
parent 0 c8caa15ef882
equal deleted inserted replaced
34:2669f8761a99 35:fbd2e7cec7ef
       
     1 /*
       
     2 * Copyright (c) 2006 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:    SIMPLE Protocol implementation for Presence Framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 
       
    23 #include <presentitygroupinfo.h>
       
    24 #include <presenceobjectfactory.h>
       
    25 #include <presentitygroupmemberinfo.h>
       
    26 #include <protocolpresencedatahost.h>
       
    27 #include <protocolpresentitygroupsdatahost.h>
       
    28 #include <ximpdatasubscriptionstate.h>
       
    29 #include <ximpidentity.h>
       
    30 #include <ximpobjectfactory.h>
       
    31 #include <ximpobjectcollection.h>
       
    32 #include <ximpprotocolconnectionhost.h>
       
    33 #include <ximpstatus.h>
       
    34 
       
    35 #include <simplefactory.h>
       
    36 #include <msimpleconnection.h>
       
    37 
       
    38 #include <pressettingsapi.h>
       
    39 #include <cpresencexdm.h>
       
    40 #include <rlspresxdmconsts.h>
       
    41 #include <XdmErrors.h>
       
    42 #include <presenceerrors.hrh>
       
    43 
       
    44 #include "simpleplugingroups.h"
       
    45 #include "simpleplugindebugutils.h"
       
    46 #include "simplepluginxdmutils.h"
       
    47 #include "simpleplugincommon.h"
       
    48 #include "simplepluginconnection.h"
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CSimplePluginGroups::CSimplePluginGroups
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CSimplePluginGroups::CSimplePluginGroups(
       
    57     MSimplePluginConnectionObs& aObs  )
       
    58 : CActive( CActive::EPriorityStandard ),
       
    59   iConnObs(aObs), iSubscribed(KSimplePluginSubsNone),
       
    60   iOperation( ENoOperation),
       
    61   iState( EPluginIdle ), iCompleted( ETrue )
       
    62     {
       
    63     CActiveScheduler::Add( this );
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CSimplePluginGroups::ConstructL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CSimplePluginGroups::ConstructL( )
       
    71     {
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CSimplePluginGroups::NewL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CSimplePluginGroups* CSimplePluginGroups::NewL(
       
    79     MSimplePluginConnectionObs& aObs )
       
    80     {
       
    81     CSimplePluginGroups* self =
       
    82         new( ELeave ) CSimplePluginGroups( aObs );
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL(  );
       
    85     CleanupStack::Pop( self );
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CSimplePluginGroups::~CSimplePluginGroups
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CSimplePluginGroups::~CSimplePluginGroups()
       
    94     {
       
    95     delete iPresIdentity;
       
    96     delete iPresIdentity2;
       
    97     delete iDisplayName;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CSimplePluginGroups::DoSubscribePresentityGroupListL
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CSimplePluginGroups::DoSubscribePresentityGroupListL(
       
   105     TXIMPRequestId aReqId )
       
   106     {
       
   107 #ifdef _DEBUG
       
   108     PluginLogger::Log(_L("PluginGroups: DoSubscribePresentityGroupListL"));
       
   109 #endif
       
   110 
       
   111     iCompleted = EFalse;
       
   112 
       
   113     // List of lists under OMa buddylist
       
   114     StartXdmOperationL( aReqId, EGetListOfLists );
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CSimplePluginGroups::DoUnsubscribePresentityGroupListL
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CSimplePluginGroups::DoUnsubscribePresentityGroupListL(
       
   122     TXIMPRequestId aReqId )
       
   123     {
       
   124 #ifdef _DEBUG
       
   125     PluginLogger::Log(_L("PluginGroups: DoUnsubscribePresentityGroupListL"));
       
   126 #endif
       
   127     iPrFwId = aReqId;
       
   128     iCompleted = EFalse;
       
   129     CompletePrFwReq( KErrNone );
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CSimplePluginGroups::DoCreatePresentityGroupL
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CSimplePluginGroups::DoCreatePresentityGroupL(
       
   137     const MXIMPIdentity& aGroupId,
       
   138     const TDesC16& aDisplayName,
       
   139     TXIMPRequestId aReqId )
       
   140     {
       
   141 #ifdef _DEBUG
       
   142     PluginLogger::Log(_L("PluginGroups: DoCreatePresentityGroupL"));
       
   143 #endif
       
   144     iCompleted = EFalse;
       
   145     StartXdmOperationL(
       
   146         aGroupId, aDisplayName, aReqId, ECreatePresentityGroup );
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CSimplePluginGroups::DoDeletePresentityGroupL
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CSimplePluginGroups::DoDeletePresentityGroupL(
       
   154     const MXIMPIdentity& aGroupId,
       
   155     TXIMPRequestId aReqId )
       
   156     {
       
   157 #ifdef _DEBUG
       
   158     PluginLogger::Log(_L("PluginGroups: DoDeletePresentityGroupL"));
       
   159 #endif
       
   160     iCompleted = EFalse;
       
   161     StartXdmOperationL( aGroupId, aReqId, EDeletePresentityGroup );
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CSimplePluginGroups::DoUpdatePresentityGroupDisplayNameL
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CSimplePluginGroups::DoUpdatePresentityGroupDisplayNameL(
       
   169     const MXIMPIdentity& /*aGroupId*/,
       
   170     const TDesC16& /*aDisplayName*/,
       
   171     TXIMPRequestId /*aReqId*/ )
       
   172     {
       
   173 #ifdef _DEBUG
       
   174     PluginLogger::Log(_L("PluginGroups: DoUpdatePresentityGroupDisplayNameL"));
       
   175 #endif
       
   176     // Notice: not supported.
       
   177     User::Leave( KErrNotSupported );
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CSimplePluginGroups::DoSubscribePresentityGroupContentL
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CSimplePluginGroups::DoSubscribePresentityGroupContentL(
       
   185     const MXIMPIdentity& aGroupId,
       
   186     TXIMPRequestId aReqId )
       
   187     {
       
   188 #ifdef _DEBUG
       
   189     PluginLogger::Log(_L("PluginGroups: DoSubscribePresentityGroupContentL"));
       
   190 #endif
       
   191     iCompleted = EFalse;
       
   192 
       
   193     // List of lists under OMa buddylist
       
   194     StartXdmOperationL( aGroupId, aReqId, EGetListContent );
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CSimplePluginGroups::DoUnsubscribePresentityGroupContentL
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CSimplePluginGroups::DoUnsubscribePresentityGroupContentL(
       
   202     const MXIMPIdentity& /*aGroupId*/,
       
   203     TXIMPRequestId aReqId )
       
   204     {
       
   205 #ifdef _DEBUG
       
   206     PluginLogger::Log(_L("PluginGroups: DoUnsubscribePresentityGroupContentL"));
       
   207 #endif
       
   208     iCompleted = EFalse;
       
   209     iPrFwId = aReqId;
       
   210     CompletePrFwReq( KErrNone );
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CSimplePluginGroups::DoAddPresentityGroupMemberL
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CSimplePluginGroups::DoAddPresentityGroupMemberL(
       
   218     const MXIMPIdentity& aGroupId,
       
   219     const MXIMPIdentity& aMemberId,
       
   220     const TDesC16& aMemberDisplayName,
       
   221     TXIMPRequestId aReqId )
       
   222     {
       
   223 #ifdef _DEBUG
       
   224     PluginLogger::Log(_L("PluginGroups: DoAddPresentityGroupMemberL"));
       
   225 #endif
       
   226     iCompleted = EFalse;
       
   227     StartXdmOperationL(
       
   228         aGroupId, aMemberId, aMemberDisplayName,
       
   229         aReqId, EAddPresentityGroupMember );
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // CSimplePluginGroups::DoRemovePresentityGroupMemberL
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 void CSimplePluginGroups::DoRemovePresentityGroupMemberL(
       
   237     const MXIMPIdentity& aGroupId,
       
   238     const MXIMPIdentity& aMemberId,
       
   239     TXIMPRequestId aReqId )
       
   240     {
       
   241 #ifdef _DEBUG
       
   242     PluginLogger::Log(_L("PluginGroups: DoRemovePresentityGroupMemberL"));
       
   243 #endif
       
   244     iCompleted = EFalse;
       
   245     StartXdmOperationL(
       
   246         aGroupId, aMemberId,
       
   247         aReqId, ERemovePresentityGroupMember );
       
   248     }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CSimplePluginGroups::DoUpdatePresentityGroupMemberDisplayNameL
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 void CSimplePluginGroups::DoUpdatePresentityGroupMemberDisplayNameL(
       
   255     const MXIMPIdentity& /*aGroupId*/,
       
   256     const MXIMPIdentity& /*aMemberId*/,
       
   257     const TDesC16& /*aMemberDisplayName*/,
       
   258     TXIMPRequestId /*aReqId*/ )
       
   259     {
       
   260 #ifdef _DEBUG
       
   261     PluginLogger::Log(
       
   262         _L("PluginGroups: DoUpdatePresentityGroupMemberDisplayNameL"));
       
   263 #endif
       
   264     // Notice: Not supported.
       
   265     User::Leave( KErrNotSupported );
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CSimplePluginGroups::DoCancel()
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CSimplePluginGroups::DoCancel(  )
       
   273     {
       
   274 #ifdef _DEBUG
       
   275     PluginLogger::Log(_L("PluginGroups: DoCancel"));
       
   276 #endif
       
   277     if ( iOperation != ENoOperation )
       
   278         {
       
   279         iXdmUtils->Cancel();
       
   280         }
       
   281     else
       
   282         {
       
   283         }
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CSimplePluginGroups::RunL()
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CSimplePluginGroups::RunL(  )
       
   291     {
       
   292     TInt myStatus = iStatus.Int();
       
   293 
       
   294 #ifdef _DEBUG
       
   295     PluginLogger::Log(_L("PluginGroups: RunL status=%d active=%d"), myStatus, IsActive() );
       
   296 #endif
       
   297 
       
   298     if ( !myStatus )
       
   299         {
       
   300         // OK resposne
       
   301         CallActualXdmOperationL();
       
   302         }
       
   303     else
       
   304         {
       
   305         if ( iOperation == EDeletePresentityGroup && iState == EPluginCommitRls )
       
   306             {
       
   307             // Igonere RLS deletion failure and contine Shared XDM deletion
       
   308             CallActualXdmOperationL();
       
   309             }
       
   310         else
       
   311             {
       
   312             // Other errors terminated the show
       
   313             CompletePrFwReq( myStatus );
       
   314             }
       
   315         }
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CSimplePluginGroups::CallActualXdmOperationL
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CSimplePluginGroups::CallActualXdmOperationL()
       
   323     {
       
   324 #ifdef _DEBUG
       
   325     PluginLogger::Log(_L("PluginGroups: CallActualXdmOperationL operation=%d"), iOperation );
       
   326 #endif
       
   327 
       
   328     switch ( iOperation )
       
   329         {
       
   330         case ECreatePresentityGroup:
       
   331             HandleCreatePresentityGroupL( iPresIdentity->Des(), iDisplayName->Des() );
       
   332             break;
       
   333         case EDeletePresentityGroup:
       
   334             HandleDeletePresentityGroupL( iPresIdentity->Des() );
       
   335             break;
       
   336         case EAddPresentityGroupMember:
       
   337             HandleAddPresentityGroupMemberL();
       
   338             break;
       
   339         case ERemovePresentityGroupMember:
       
   340             HandleRemovePresentityGroupMemberL();
       
   341             break;
       
   342         case EGetListOfLists:
       
   343             GetListOfListsL();
       
   344             break;
       
   345         case EGetListContent:
       
   346             GetListContentL();
       
   347             break;
       
   348         default:
       
   349             User::Leave( KErrNotSupported );
       
   350             break;
       
   351         }
       
   352     }
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // CSimplePluginGroups::RunError
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 TInt CSimplePluginGroups::RunError( TInt aError )
       
   359     {
       
   360 #ifdef _DEBUG
       
   361     PluginLogger::Log(_L("PluginGroups: RunError %d active=%d"), aError, IsActive());
       
   362 #endif
       
   363     // complete the open request
       
   364     CompletePrFwReq( aError );
       
   365     return KErrNone;
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------------------------
       
   369 // CSimplePluginGroups::GetInterface()
       
   370 // ---------------------------------------------------------------------------
       
   371 //
       
   372 TAny* CSimplePluginGroups::GetInterface(
       
   373         TInt32 aInterfaceId,
       
   374         TIfGetOps aOptions )
       
   375     {
       
   376     if ( aInterfaceId == GetInterfaceId() )
       
   377         {
       
   378         // caller wants this interface
       
   379         MProtocolPresentityGroups* myIf = this;
       
   380         return myIf;
       
   381         }
       
   382     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   383         {
       
   384         User::Panic( _L("CSimplePlugin"), KErrExtensionNotSupported );
       
   385         }
       
   386     return NULL;
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CSimplePluginGroups::GetInterface()
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 const TAny* CSimplePluginGroups::GetInterface(
       
   394     TInt32 aInterfaceId,
       
   395     TIfGetOps aOptions ) const
       
   396     {
       
   397     if ( aInterfaceId == GetInterfaceId() )
       
   398         {
       
   399         // caller wants this interface
       
   400         const MProtocolPresentityGroups* myIf = this;
       
   401         return myIf;
       
   402         }
       
   403     else if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   404         {
       
   405         User::Panic( _L("CSimplePlugin"), KErrExtensionNotSupported );
       
   406         }
       
   407     return NULL;
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // CSimplePluginGroups::GetInterfaceId()
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 TInt32 CSimplePluginGroups::GetInterfaceId() const
       
   415     {
       
   416     return MProtocolPresentityGroups::KInterfaceId;
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // CSimplePluginGroups::SetPresIdentityL()
       
   421 // ---------------------------------------------------------------------------
       
   422 //
       
   423 void CSimplePluginGroups::SetPresIdentityL(
       
   424     const MXIMPIdentity& aPresentityId )
       
   425     {
       
   426     delete iPresIdentity;
       
   427     iPresIdentity = NULL;
       
   428     iPresIdentity = aPresentityId.Identity().AllocL();
       
   429     }
       
   430 
       
   431 // ---------------------------------------------------------------------------
       
   432 // CSimplePluginGroups::SetPresIdentity2L()
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 void CSimplePluginGroups::SetPresIdentity2L(
       
   436     const MXIMPIdentity& aPresentityId )
       
   437     {
       
   438     delete iPresIdentity2;
       
   439     iPresIdentity2 = NULL;
       
   440     iPresIdentity2 = aPresentityId.Identity().AllocL();
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // CSimplePluginGroups::StartXdmOperationL
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 void CSimplePluginGroups::StartXdmOperationL(
       
   448     TXIMPRequestId aReqId,
       
   449     TPluginGroupsOperation aOperation )
       
   450     {
       
   451     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   452     iPrFwId = aReqId;
       
   453     iOperation = aOperation;
       
   454     StartXdmOperationL();
       
   455     }
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 // CSimplePluginGroups::StartXdmOperationL
       
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 void CSimplePluginGroups::StartXdmOperationL(
       
   462     const MXIMPIdentity& aId,
       
   463     TXIMPRequestId aReqId,
       
   464     TPluginGroupsOperation aOperation )
       
   465     {
       
   466     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   467     SetPresIdentityL( aId );
       
   468     iPrFwId = aReqId;
       
   469     iOperation = aOperation;
       
   470     StartXdmOperationL();
       
   471     }
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // CSimplePluginGroups::StartXdmOperationL
       
   475 // ---------------------------------------------------------------------------
       
   476 //
       
   477 void CSimplePluginGroups::StartXdmOperationL(
       
   478         const MXIMPIdentity& aId,
       
   479         const TDesC16& aDisplayName,
       
   480         TXIMPRequestId aReqId,
       
   481         TPluginGroupsOperation aOperation )
       
   482     {
       
   483     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   484     SetPresIdentityL( aId );
       
   485 
       
   486     delete iDisplayName;
       
   487     iDisplayName = NULL;
       
   488     iDisplayName = aDisplayName.AllocL();
       
   489 
       
   490     iPrFwId = aReqId;
       
   491     iOperation = aOperation;
       
   492     StartXdmOperationL();
       
   493     }
       
   494 
       
   495 // ---------------------------------------------------------------------------
       
   496 // CSimplePluginGroups::StartXdmOperationL
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 void CSimplePluginGroups::StartXdmOperationL(
       
   500         const MXIMPIdentity& aId,
       
   501         const MXIMPIdentity& aMemberId,
       
   502         TXIMPRequestId aReqId,
       
   503         TPluginGroupsOperation aOperation )
       
   504     {
       
   505     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   506     SetPresIdentityL( aId );
       
   507     SetPresIdentity2L( aMemberId );
       
   508     iPrFwId = aReqId;
       
   509     iOperation = aOperation;
       
   510     StartXdmOperationL();
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 // CSimplePluginGroups::StartXdmOperationL
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 void CSimplePluginGroups::StartXdmOperationL(
       
   518         const MXIMPIdentity& aId,
       
   519         const MXIMPIdentity& aMemberId,
       
   520         const TDesC16& aDisplayName,
       
   521         TXIMPRequestId aReqId,
       
   522         TPluginGroupsOperation aOperation )
       
   523     {
       
   524     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   525     SetPresIdentityL( aId );
       
   526     SetPresIdentity2L( aMemberId );
       
   527 
       
   528     delete iDisplayName;
       
   529     iDisplayName = NULL;
       
   530     iDisplayName = aDisplayName.AllocL();
       
   531 
       
   532     iPrFwId = aReqId;
       
   533     iOperation = aOperation;
       
   534     StartXdmOperationL();
       
   535     }
       
   536 
       
   537 // ---------------------------------------------------------------------------
       
   538 // CSimplePluginGroups::StartXdmOperationL
       
   539 // ---------------------------------------------------------------------------
       
   540 //
       
   541 void CSimplePluginGroups::StartXdmOperationL()
       
   542     {
       
   543     TRAPD( err, DoStartXdmOperationL() );
       
   544     if ( err )
       
   545         {
       
   546         User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   547         }
       
   548     else
       
   549         {
       
   550         }
       
   551     }
       
   552 
       
   553 // ---------------------------------------------------------------------------
       
   554 // CSimplePluginGroups::DoStartXdmOperationL
       
   555 // ---------------------------------------------------------------------------
       
   556 //
       
   557 void CSimplePluginGroups::DoStartXdmOperationL()
       
   558     {
       
   559     if ( !iXdmUtils )
       
   560         {
       
   561         iXdmUtils = iConnObs.XdmUtilsL();
       
   562         }
       
   563     else
       
   564         {
       
   565         }
       
   566 
       
   567     // Delete Group is the only method that access XDM rules,
       
   568     // others access shared lists only.
       
   569     if ( iOperation != EDeletePresentityGroup )
       
   570         {
       
   571         iXdmUtils->InitializeXdmsOnlyL( iStatus );
       
   572         }
       
   573     else
       
   574         {
       
   575         iXdmUtils->InitializeXdmL( iStatus );
       
   576         }
       
   577 
       
   578     iState = EPluginInitXdm;
       
   579     SetActive();
       
   580     }
       
   581 
       
   582 // ---------------------------------------------------------------------------
       
   583 // CSimplePluginGroups::GetListOfListsL
       
   584 // ---------------------------------------------------------------------------
       
   585 //
       
   586 void CSimplePluginGroups::GetListOfListsL()
       
   587     {
       
   588     MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory();
       
   589     MProtocolPresentityGroupsDataHost& dataHost =
       
   590         iConnObs.Host()->ProtocolPresenceDataHost().GroupsDataHost();
       
   591 
       
   592     // This searches data from the local cache only.
       
   593     MXIMPObjectCollection* userLists =
       
   594         myFactory.NewObjectCollectionLC();          // << userLists
       
   595 
       
   596     const TInt KMyGran = 10;
       
   597     CDesCArrayFlat* lists = new (ELeave) CDesCArrayFlat( KMyGran );
       
   598     CleanupStack::PushL( lists );      // << lists
       
   599 
       
   600     CDesCArrayFlat* dNames = new (ELeave) CDesCArrayFlat( KMyGran );
       
   601     CleanupStack::PushL( dNames );      // << dNames
       
   602 
       
   603     iXdmUtils->GetUserListsL( *lists, *dNames );
       
   604 
       
   605     CopyGroupArraysToCollectionL( *lists, *dNames, *userLists );
       
   606 
       
   607     CleanupStack::PopAndDestroy( dNames );  // >> dNames
       
   608     CleanupStack::PopAndDestroy( lists );   // >> lists
       
   609 
       
   610     CompletePrFwReq( KErrNone );
       
   611 
       
   612     // Callback for subscription state (terminated).
       
   613     MXIMPDataSubscriptionState* myState =
       
   614         myFactory.NewDataSubscriptionStateLC();
       
   615     MXIMPStatus* myStatus = myFactory.NewStatusLC();
       
   616     // Notice: consider error codes
       
   617     myStatus->SetResultCode( KErrNone );
       
   618     myState->SetSubscriptionStateL(
       
   619         MXIMPDataSubscriptionState::ESubscriptionInactive );
       
   620     myState->SetDataStateL( MXIMPDataSubscriptionState::EDataUnavailable );
       
   621 #ifdef _DEBUG
       
   622     PluginLogger::Log(
       
   623     _L("PluginGroups: callback SetPresentityGroupListDataSubscriptionStateL"));
       
   624 #endif
       
   625     dataHost.SetPresentityGroupListDataSubscriptionStateL(
       
   626         myState, myStatus );
       
   627 
       
   628 
       
   629     CleanupStack::Pop( 2 ); // >> myState, myStatus
       
   630 
       
   631     // callback for data
       
   632 #ifdef _DEBUG
       
   633     PluginLogger::Log(_L("PluginGroups: callback HandlePresentityGroupListL"));
       
   634 #endif
       
   635     dataHost.HandlePresentityGroupListL( userLists );
       
   636     CleanupStack::Pop();     // >> userLists
       
   637     }
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 // CSimplePluginGroups::GetListContentL
       
   641 // ---------------------------------------------------------------------------
       
   642 //
       
   643 void CSimplePluginGroups::GetListContentL()
       
   644     {
       
   645     MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory();
       
   646     MProtocolPresentityGroupsDataHost& dataHost =
       
   647         iConnObs.Host()->ProtocolPresenceDataHost().GroupsDataHost();
       
   648 
       
   649     MXIMPObjectCollection* entities =
       
   650         myFactory.NewObjectCollectionLC();          // << entities
       
   651 
       
   652     const TInt KMyGran = 10;
       
   653     CPtrCArray* ids = new (ELeave) CPtrCArray( KMyGran );
       
   654     CleanupStack::PushL( ids );      // << ids
       
   655 
       
   656     CPtrCArray* dispNames = new (ELeave) CPtrCArray( KMyGran );
       
   657     CleanupStack::PushL( dispNames  );      // << dispNames
       
   658 
       
   659 
       
   660     iXdmUtils->GetEntitiesInListL( iPresIdentity->Des(), *ids, *dispNames );
       
   661 
       
   662     CopyGroupMembersToCollectionL( *ids, *dispNames, *entities );
       
   663 
       
   664     CleanupStack::PopAndDestroy( dispNames );
       
   665     CleanupStack::PopAndDestroy( ids );
       
   666 
       
   667     // Complete the PrFw request
       
   668     CompletePrFwReq( KErrNone );
       
   669 
       
   670     // callback for data
       
   671     MXIMPIdentity* id = myFactory.NewIdentityLC();  // << id
       
   672     id->SetIdentityL( iPresIdentity->Des() );
       
   673 #ifdef _DEBUG
       
   674     PluginLogger::Log(
       
   675         _L("PluginGroups: callback HandlePresentityGroupContentL ."));
       
   676 #endif
       
   677     dataHost.HandlePresentityGroupContentL( id, entities );
       
   678     CleanupStack::Pop();                  // >> id
       
   679     CleanupStack::Pop();                  // >> entities
       
   680 
       
   681     // Callback for subscription state (terminated).
       
   682     id = myFactory.NewIdentityLC();                     // << id
       
   683     id->SetIdentityL( iPresIdentity->Des() );
       
   684     MXIMPDataSubscriptionState* myState =
       
   685         myFactory.NewDataSubscriptionStateLC();         // << myState
       
   686     MXIMPStatus* myStatus = myFactory.NewStatusLC();    // << myStatus
       
   687     // Notice: consider error codes
       
   688     myStatus->SetResultCode( KErrNone );
       
   689     myState->SetSubscriptionStateL(
       
   690         MXIMPDataSubscriptionState::ESubscriptionInactive );
       
   691 #ifdef _DEBUG
       
   692     PluginLogger::Log(
       
   693         _L("PluginGroups: callback SetPresentityGroupContentDataSubscriptionStateL"));
       
   694 #endif
       
   695     dataHost.SetPresentityGroupContentDataSubscriptionStateL(
       
   696         id, myState, myStatus );
       
   697     CleanupStack::Pop( 3 ); // >> myStatus, myState, id
       
   698     }
       
   699 
       
   700 // ---------------------------------------------------------------------------
       
   701 // CSimplePluginGroups::CompletePrFwReq
       
   702 // ---------------------------------------------------------------------------
       
   703 //
       
   704 void CSimplePluginGroups::CompletePrFwReq( TInt aStatus )
       
   705     {
       
   706 #ifdef _DEBUG
       
   707     PluginLogger::Log(_L("PluginGroups: CompletePrFwReq status=%d"), aStatus );
       
   708 #endif
       
   709 
       
   710     if ( iCompleted  )
       
   711         {
       
   712         return;
       
   713         }
       
   714 
       
   715     iCompleted = ETrue;
       
   716     iOperation = ENoOperation;
       
   717     iConnObs.CompleteReq( iPrFwId, aStatus );
       
   718     iPrFwId = TXIMPRequestId();
       
   719     }
       
   720 
       
   721 // ---------------------------------------------------------------------------
       
   722 // CSimplePluginGroups::CompleteMe
       
   723 // ---------------------------------------------------------------------------
       
   724 //
       
   725 void CSimplePluginGroups::CompleteMe( TInt aStatus )
       
   726     {
       
   727 #ifdef _DEBUG
       
   728     PluginLogger::Log(_L("PluginGroups: CompleteMe status=%d"), aStatus );
       
   729 #endif
       
   730 
       
   731     iStatus = KRequestPending;
       
   732     TRequestStatus* s= &iStatus;
       
   733     User::RequestComplete( s, aStatus );
       
   734     }
       
   735 
       
   736 // ---------------------------------------------------------------------------
       
   737 // CSimplePluginGroups::CopyGroupArraysToCollectionL
       
   738 // ---------------------------------------------------------------------------
       
   739 //
       
   740 void CSimplePluginGroups::CopyGroupArraysToCollectionL(
       
   741     CDesCArrayFlat& aLists, CDesCArrayFlat& aNames, MXIMPObjectCollection& aCollection )
       
   742     {
       
   743     TInt count = aLists.Count();
       
   744     for ( TInt i=0; i < count; i++ )
       
   745         {
       
   746         // create here the PrFW group info
       
   747         MPresentityGroupInfo* info =
       
   748             iConnObs.PresenceObjectFactory().NewPresentityGroupInfoLC(); // << info
       
   749         MXIMPIdentity* id = iConnObs.ObjectFactory().NewIdentityLC();  // << id
       
   750         id->SetIdentityL( aLists[i] );
       
   751         info->SetGroupIdL( id );
       
   752         CleanupStack::Pop(); // >> id
       
   753 
       
   754         info->SetGroupDisplayNameL( aNames[i] );
       
   755         aCollection.AddObjectL( info );
       
   756         CleanupStack::Pop(); // >> info
       
   757         }
       
   758     }
       
   759 
       
   760 // ---------------------------------------------------------------------------
       
   761 // CSimplePluginGroups::CopyGroupMembersToCollectionL
       
   762 // ---------------------------------------------------------------------------
       
   763 //
       
   764 void CSimplePluginGroups::CopyGroupMembersToCollectionL(
       
   765     CPtrCArray& aIds, CPtrCArray& aNames, MXIMPObjectCollection& aCollection)
       
   766     {
       
   767     TInt count = aIds.Count();
       
   768     for ( TInt i=0; i < count; i++ )
       
   769         {
       
   770         // create here MPresentityGroupMemberInfo
       
   771         MPresentityGroupMemberInfo* info =
       
   772             iConnObs.PresenceObjectFactory().NewPresentityGroupMemberInfoLC(); // << info
       
   773         MXIMPIdentity* id = iConnObs.ObjectFactory().NewIdentityLC();  // << id
       
   774         id->SetIdentityL( aIds[i] );
       
   775         info->SetGroupMemberIdL( id );
       
   776         CleanupStack::Pop(); // >> id
       
   777 
       
   778         info->SetGroupMemberDisplayNameL( aNames[i] );
       
   779         aCollection.AddObjectL( info );
       
   780         CleanupStack::Pop(); // >> info
       
   781         }
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------------------------
       
   785 // CSimplePluginGroups::HandleCreatePresentityGroupL
       
   786 // ---------------------------------------------------------------------------
       
   787 //
       
   788 void CSimplePluginGroups::HandleCreatePresentityGroupL(
       
   789     const TDesC& aGroupId, const TDesC& aDispName )
       
   790     {
       
   791     if ( iState == EPluginInitXdm )
       
   792         {
       
   793         iState = EPluginCommitXdm;
       
   794         iXdmUtils->CreateEntityGroupL( aGroupId, aDispName );
       
   795         iXdmUtils->CommitXdmL( iStatus );
       
   796         SetActive();
       
   797         }
       
   798     else
       
   799         {
       
   800         // We are ready
       
   801         CompletePrFwReq( KErrNone );
       
   802         }
       
   803     }
       
   804 
       
   805 // ---------------------------------------------------------------------------
       
   806 // CSimplePluginGroups::HandleDeletePresentityGroupL
       
   807 // ---------------------------------------------------------------------------
       
   808 //
       
   809 void CSimplePluginGroups::HandleDeletePresentityGroupL( const TDesC& aGroupId )
       
   810     {
       
   811     if ( iState == EPluginInitXdm )
       
   812         {
       
   813         iState = EPluginFetchRls;
       
   814         iXdmUtils->FetchRlsL( iStatus );
       
   815         SetActive();
       
   816         }
       
   817     else if ( iState == EPluginFetchRls )
       
   818         {
       
   819         iState = EPluginCommitRls;
       
   820         // Remove RLS service
       
   821         iXdmUtils->RemoveRlsServiceByResourceListL( aGroupId, iStatus );
       
   822         SetActive();
       
   823         }
       
   824     else if ( iState == EPluginCommitRls )
       
   825         {
       
   826         iState = EPluginCommitXdm;
       
   827         iXdmUtils->DeleteEntityGroupL( aGroupId );
       
   828         iXdmUtils->CommitXdmL( iStatus );
       
   829         SetActive();
       
   830         }
       
   831     else if ( iState == EPluginCommitXdm )
       
   832         {
       
   833         // Delete the group from a granted rule. The following won't leave if
       
   834         // it does not locate under the rule.
       
   835 #ifdef _DEBUG
       
   836         PluginLogger::Log(
       
   837                 _L("PluginWatcher: TEST COVERS 2 **"));
       
   838 #endif
       
   839         iState = ERemoveGroupFromGranted;
       
   840         iXdmUtils->RemoveGroupFromGrantedL( aGroupId, iStatus );
       
   841         SetActive();
       
   842         }
       
   843     else
       
   844         {
       
   845         // We are ready
       
   846         CompletePrFwReq( KErrNone );
       
   847         }
       
   848     }
       
   849 
       
   850 // ---------------------------------------------------------------------------
       
   851 // CSimplePluginGroups::HandleAddPresentityGroupMemberL
       
   852 // ---------------------------------------------------------------------------
       
   853 //
       
   854 void CSimplePluginGroups::HandleAddPresentityGroupMemberL( )
       
   855     {
       
   856     if ( iState == EPluginInitXdm )
       
   857         {
       
   858         iXdmUtils->AddPresentityGroupMemberL(
       
   859             iPresIdentity->Des(), iPresIdentity2->Des(),
       
   860             iDisplayName->Des(), iStatus );
       
   861         iState = EPluginAddGroupMember;
       
   862         SetActive();
       
   863         }
       
   864     else
       
   865         {
       
   866         // We are ready
       
   867         CompletePrFwReq( KErrNone );
       
   868         }
       
   869     }
       
   870 
       
   871 // ---------------------------------------------------------------------------
       
   872 // CSimplePluginGroups::HandleRemovePresentityGroupMemberL
       
   873 // ---------------------------------------------------------------------------
       
   874 //
       
   875 void CSimplePluginGroups::HandleRemovePresentityGroupMemberL()
       
   876     {
       
   877     if ( iState == EPluginInitXdm )
       
   878         {
       
   879         iXdmUtils->RemovePresentityGroupMemberL(
       
   880             iPresIdentity->Des(), iPresIdentity2->Des(), iStatus );
       
   881         iState = EPluginRemoveGroupMember;
       
   882         SetActive();
       
   883         }
       
   884     else
       
   885         {
       
   886         // We are ready
       
   887         CompletePrFwReq( KErrNone );
       
   888         }
       
   889     }
       
   890 
       
   891 
       
   892 // End of file
       
   893