presencefwsimpleadpt/src/simplepluginwatcher.cpp
branchGCC_SURGE
changeset 28 d9861ae9169c
parent 23 77cb48a03620
parent 26 04ca1926b01c
equal deleted inserted replaced
23:77cb48a03620 28:d9861ae9169c
     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 #include <utf.h>
       
    23 
       
    24 #include <personpresenceinfo.h>
       
    25 
       
    26 #include <presenceinfo.h>
       
    27 #include <presenceinfofieldcollection.h>
       
    28 #include <presenceinfofield.h>
       
    29 #include <presenceinfofieldvaluetext.h>
       
    30 #include <presenceinfofieldvalueenum.h>
       
    31 #include <presenceobjectfactory.h>
       
    32 #include <presenceerrors.hrh>
       
    33 
       
    34 #include <presentitygroupmemberinfo.h>
       
    35 
       
    36 #include <protocolpresencedatahost.h>
       
    37 #include <protocolpresentitygroupsdatahost.h>
       
    38 #include <protocolpresencewatchingdatahost.h>
       
    39 
       
    40 #include <ximpdatasubscriptionstate.h>
       
    41 #include <ximperrors.hrh>
       
    42 #include <ximpidentity.h>
       
    43 #include <ximpobjectcollection.h>
       
    44 #include <ximpobjectfactory.h>
       
    45 #include <ximpprotocolconnectionhost.h>
       
    46 #include <ximpstatus.h>
       
    47 
       
    48 #include <simplefactory.h>
       
    49 #include <simpleerrors.h>
       
    50 #include <msimplewinfo.h>
       
    51 #include <msimplewatcher.h>
       
    52 #include <msimpledocument.h>
       
    53 #include <msimpleelement.h>
       
    54 
       
    55 #include "simpleplugincommon.h"
       
    56 #include "simplepluginwatcher.h"
       
    57 #include "simplepluginentitywatcher.h"
       
    58 #include "simpleplugindebugutils.h"
       
    59 #include "simpleutils.h"
       
    60 #include "simplepluginxdmutils.h"
       
    61 #include "simpleplugindata.h"
       
    62 #include "simplepluginconnection.h"
       
    63 
       
    64 
       
    65 
       
    66 // ======== MEMBER FUNCTIONS ========
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CSimplePluginWatcher::CSimplePluginWatcher
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CSimplePluginWatcher::CSimplePluginWatcher(
       
    73     MSimplePluginSettings& aConnSets,
       
    74     MSimplePluginConnectionObs& aObs,
       
    75     MSimpleConnection& aConn )
       
    76 : CActive( CActive::EPriorityStandard ),
       
    77   iConnSets( aConnSets), iConnObs(aObs), iConnection(aConn), iCompleted( ETrue ),
       
    78   iOperation( EPluginUndef ), iXdmState( EPluginIdle )
       
    79     {
       
    80     CActiveScheduler::Add( this );
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CSimplePluginWatcher::ConstructL
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 void CSimplePluginWatcher::ConstructL( )
       
    88     {
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CSimplePluginWatcher::NewL
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 CSimplePluginWatcher* CSimplePluginWatcher::NewL(
       
    96     MSimplePluginSettings& aConnSets,
       
    97     MSimplePluginConnectionObs& aObs,
       
    98     MSimpleConnection& aConn )
       
    99     {
       
   100     CSimplePluginWatcher* self =
       
   101         new( ELeave ) CSimplePluginWatcher( aConnSets, aObs, aConn );
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL(  );
       
   104     CleanupStack::Pop( self );
       
   105     return self;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CSimplePluginWatcher::~CSimplePluginWatcher
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 CSimplePluginWatcher::~CSimplePluginWatcher()
       
   113     {
       
   114     iWatchers.ResetAndDestroy();
       
   115     iWatchers.Close();
       
   116     delete iPresIdentity;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CSimplePluginWatcher::DoSubscribePresentityPresenceL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CSimplePluginWatcher::DoSubscribePresentityPresenceL(
       
   124     const MXIMPIdentity& aPresentityId,
       
   125     const MPresenceInfoFilter& /*aPif*/,   // notice: aPif filter not supported
       
   126     TXIMPRequestId aReqId )
       
   127     {
       
   128 #ifdef _DEBUG
       
   129     PluginLogger::Log(_L("PluginWatcher: DoSubscribePresentityPresenceL"));
       
   130 #endif
       
   131 
       
   132     TRAPD( err, DoDoSubscribePresentityPresenceL(aPresentityId, aReqId ));
       
   133     if ( err )
       
   134         {
       
   135         User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   136         }
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CSimplePluginWatcher::DoDoSubscribePresentityPresenceL
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CSimplePluginWatcher::DoDoSubscribePresentityPresenceL(
       
   144     const MXIMPIdentity& aPresentityId,
       
   145     TXIMPRequestId aReqId )
       
   146     {
       
   147     iOperation = EPluginUndef;
       
   148     iXdmState = EPluginIdle;
       
   149 
       
   150     SetPresIdentityL( aPresentityId );
       
   151     iPrFwId = aReqId;
       
   152     iCompleted = EFalse;
       
   153 
       
   154   HBufC8* pres8 = NULL;
       
   155     pres8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( iPresIdentity->Des() );
       
   156     CleanupStack::PushL( pres8 ); // << pres8
       
   157 
       
   158     CSimplePluginEntityWatcher* watcher = MatchWatcher2L( pres8->Des(), ETrue );
       
   159     watcher->StartSubscribeL( pres8->Des() );
       
   160     CleanupStack::PopAndDestroy( pres8 );  // >> pres8
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CSimplePluginWatcher::DoUpdatePresentityPresenceSubscriptionPifL
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CSimplePluginWatcher::DoUpdatePresentityPresenceSubscriptionPifL(
       
   168     const MXIMPIdentity& /*aPresentityId*/,
       
   169     const MPresenceInfoFilter& /*aPif*/,
       
   170     TXIMPRequestId /*aReqId*/ )
       
   171     {
       
   172 #ifdef _DEBUG
       
   173     PluginLogger::Log(
       
   174         _L("PluginWatcher: DoUpdatePresentityPresenceSubscriptionPifL"));
       
   175 #endif
       
   176 
       
   177     iOperation = EPluginUndef;
       
   178 
       
   179     // notice: aPif filter not supported
       
   180     User::Leave( KErrNotSupported );
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CSimplePluginWatcher::DoUnsubscribePresentityPresenceL
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void CSimplePluginWatcher::DoUnsubscribePresentityPresenceL(
       
   188     const MXIMPIdentity& aPresentityId,
       
   189     TXIMPRequestId aReqId )
       
   190     {
       
   191 #ifdef _DEBUG
       
   192     PluginLogger::Log(_L("PluginWatcher: DoUnsubscribePresentityPresenceL"));
       
   193 #endif
       
   194 
       
   195     TRAPD( err, DoDoUnsubscribePresentityPresenceL( aPresentityId, aReqId ) );
       
   196     if ( err )
       
   197         {
       
   198         User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   199         }
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CSimplePluginWatcher::DoDoUnsubscribePresentityPresenceL
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CSimplePluginWatcher::DoDoUnsubscribePresentityPresenceL(
       
   207     const MXIMPIdentity& aPresentityId,
       
   208     TXIMPRequestId aReqId )
       
   209     {
       
   210 
       
   211     iOperation = EPluginUndef;
       
   212     iXdmState = EPluginIdle;
       
   213 
       
   214     SetPresIdentityL( aPresentityId );
       
   215     iPrFwId = aReqId;
       
   216     iCompleted = EFalse;
       
   217 
       
   218   HBufC8* pres8 = NULL;
       
   219     pres8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( iPresIdentity->Des() );
       
   220     CleanupStack::PushL( pres8 ); // << pres8
       
   221 
       
   222     CSimplePluginEntityWatcher* watcher = MatchWatcher2L( pres8->Des(), EFalse );
       
   223     if ( !watcher )
       
   224         {
       
   225         User::Leave( KErrNotFound ); // Notice: error code
       
   226         }
       
   227     else
       
   228         {
       
   229 #ifdef _DEBUG
       
   230         PluginLogger::Log(_L("PluginWatcher: -> StopSubscribeL"));
       
   231 #endif
       
   232         watcher->StopSubscribeL();
       
   233         }
       
   234     CleanupStack::PopAndDestroy( pres8 );  // >> pres8
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CSimplePluginWatcher::DoSubscribePresentityGroupMembersPresenceL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CSimplePluginWatcher::DoSubscribePresentityGroupMembersPresenceL(
       
   242     const MXIMPIdentity& aGroupId,
       
   243     const MPresenceInfoFilter& /*aPif*/,   // notice: aPif filter not supported
       
   244     TXIMPRequestId aReqId )
       
   245     {
       
   246 #ifdef _DEBUG
       
   247     PluginLogger::Log(
       
   248         _L("PluginWatcher: DoSubscribePresentityGroupMembersPresenceL"));
       
   249 #endif
       
   250 
       
   251     iOperation = EPluginSubscribeGroup;
       
   252     iXdmState = EPluginIdle;
       
   253 
       
   254     SetPresIdentityL( aGroupId );
       
   255     iPrFwId = aReqId;
       
   256     iCompleted = EFalse;
       
   257 
       
   258     // Get Shared XDM lists first and create RLS service first
       
   259     StartXdmOperationL();
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // CSimplePluginWatcher::DoUpdatePresentityGroupMembersPresenceSubscriptionPifL
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 void CSimplePluginWatcher::DoUpdatePresentityGroupMembersPresenceSubscriptionPifL(
       
   267     const MXIMPIdentity& /*aGroupId*/,
       
   268     const MPresenceInfoFilter& /*aPif*/,
       
   269     TXIMPRequestId /*aReqId*/ )
       
   270     {
       
   271 #ifdef _DEBUG
       
   272     PluginLogger::Log(
       
   273   _L("PluginWatcher: DoUpdatePresentityGroupMembersPresenceSubscriptionPifL"));
       
   274 #endif
       
   275     // notice: aPif filter not supported
       
   276     User::Leave( KErrNotSupported );
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // CSimplePluginWatcher::DoUnsubscribePresentityGroupMembersPresenceL
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 void CSimplePluginWatcher::DoUnsubscribePresentityGroupMembersPresenceL(
       
   284     const MXIMPIdentity& aGroupId,
       
   285     TXIMPRequestId aReqId )
       
   286     {
       
   287 #ifdef _DEBUG
       
   288     PluginLogger::Log(
       
   289         _L("PluginWatcher: DoUnsubscribePresentityGroupMembersPresenceL"));
       
   290 #endif
       
   291     TRAPD( err, DoDoUnsubscribePresentityGroupMembersPresenceL( aGroupId, aReqId ));
       
   292     if ( err )
       
   293         {
       
   294         User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   295         }
       
   296     }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // CSimplePluginWatcher::DoDoUnsubscribePresentityGroupMembersPresenceL
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 void CSimplePluginWatcher::DoDoUnsubscribePresentityGroupMembersPresenceL(
       
   303     const MXIMPIdentity& aGroupId,
       
   304     TXIMPRequestId aReqId )
       
   305     {
       
   306     iOperation = EPluginUnsubscribeGroup;
       
   307     iXdmState = EPluginIdle;
       
   308 
       
   309     SetPresIdentityL( aGroupId );
       
   310     iPrFwId = aReqId;
       
   311     iCompleted = EFalse;
       
   312 
       
   313     HBufC* buf16 = iXdmUtils->RlsServiceByResourceListLC( iPresIdentity->Des() ); // << buf16
       
   314 
       
   315     HBufC8* buf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( buf16->Des() );
       
   316     CleanupStack::PushL( buf );  // << buf
       
   317 
       
   318     CSimplePluginEntityWatcher* watcher = MatchWatcher2L( buf->Des(), EFalse );
       
   319 
       
   320     CleanupStack::PopAndDestroy( buf );  // >> buf
       
   321     CleanupStack::PopAndDestroy( buf16 );  // >> buf16
       
   322 
       
   323     if ( !watcher )
       
   324         {
       
   325         User::Leave( KErrNotFound ); // Notice: error code
       
   326         }
       
   327     else
       
   328         {
       
   329         watcher->StopSubscribeL();
       
   330         }
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CSimplePluginWatcher::GetInterface
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 TAny* CSimplePluginWatcher::GetInterface(
       
   338         TInt32 aInterfaceId,
       
   339         TIfGetOps aOptions )
       
   340     {
       
   341     if ( aInterfaceId == GetInterfaceId() )
       
   342         {
       
   343         // caller wants this interface
       
   344         MProtocolPresenceWatching* myIf = this;
       
   345         return myIf;
       
   346         }
       
   347     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   348         {
       
   349         User::Panic( _L("CSimplePlugin"), KErrExtensionNotSupported );
       
   350         }
       
   351     return NULL;
       
   352     }
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // CSimplePluginWatcher::GetInterface
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 const TAny* CSimplePluginWatcher::GetInterface(
       
   359     TInt32 aInterfaceId,
       
   360     TIfGetOps aOptions ) const
       
   361     {
       
   362     if ( aInterfaceId == GetInterfaceId() )
       
   363         {
       
   364         // caller wants this interface
       
   365         const MProtocolPresenceWatching* myIf = this;
       
   366         return myIf;
       
   367         }
       
   368     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   369         {
       
   370         User::Panic( _L("CSimplePlugin"), KErrExtensionNotSupported );
       
   371         }
       
   372     return NULL;
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // CSimplePluginWatcher::GetInterfaceId
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 TInt32 CSimplePluginWatcher::GetInterfaceId() const
       
   380     {
       
   381     return MProtocolPresenceWatching::KInterfaceId;
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // CSimplePluginWatcher::MatchWatcher2L
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 CSimplePluginEntityWatcher* CSimplePluginWatcher::MatchWatcher2L(
       
   389     const TDesC8& aPresentityid, TBool aCreate )
       
   390     {
       
   391     TInt count = iWatchers.Count();
       
   392     for ( TInt i = 0; i < count; i++ )
       
   393         {
       
   394         CSimplePluginEntityWatcher* temp = (iWatchers[i]);
       
   395         if ( !temp->PresentityId().CompareF( aPresentityid ))
       
   396             {
       
   397             return temp;
       
   398             }
       
   399         }
       
   400 
       
   401     // If watcher was not found, crete it when wanted so.
       
   402     if ( !aCreate )
       
   403         {
       
   404         return NULL;
       
   405         }
       
   406     else
       
   407         {
       
   408         CSimplePluginEntityWatcher* watcher = CSimplePluginEntityWatcher::NewL(
       
   409             iConnObs, iConnection, *this );
       
   410         iWatchers.Append( watcher );
       
   411         return watcher;
       
   412         }
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------------------------
       
   416 // CSimplePluginWatcher::DeleteWatcher
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 void CSimplePluginWatcher::DeleteWatcher(
       
   420     const TDesC8& aPresentityid )
       
   421     {
       
   422 
       
   423 #ifdef _DEBUG
       
   424     PluginLogger::Log( _L("PluginWatcher: DeleteWatcher **"));
       
   425 #endif
       
   426 
       
   427     TInt count = iWatchers.Count();
       
   428     for ( TInt i = 0; i < count; i++ )
       
   429         {
       
   430         CSimplePluginEntityWatcher* temp = (iWatchers[i]);
       
   431         if ( !temp->PresentityId().CompareF( aPresentityid ) )
       
   432             {
       
   433             iWatchers.Remove( i );
       
   434             iWatchers.GranularCompress();
       
   435             delete temp;
       
   436             break;
       
   437             }
       
   438         else
       
   439             {
       
   440             }
       
   441         }
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // CSimplePluginWatcher::GetEntitiesInListL
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 void CSimplePluginWatcher::GetEntitiesInListL(
       
   449     const TDesC& aList, MXIMPObjectCollection& aMembers )
       
   450     {
       
   451     __ASSERT_DEBUG( iXdmUtils, User::Leave( KErrCorrupt ) );
       
   452 
       
   453     const TInt KMyGran = 10;
       
   454     CPtrCArray* ids = new (ELeave) CPtrCArray( KMyGran );
       
   455     CleanupStack::PushL( ids );      // << ids
       
   456 
       
   457     CPtrCArray* dispNames = new (ELeave) CPtrCArray( KMyGran );
       
   458     CleanupStack::PushL( dispNames  );      // << dispNames
       
   459 
       
   460     iXdmUtils->GetEntitiesInListL( aList, *ids, *dispNames );
       
   461 
       
   462     CopyGroupMembersToCollectionL( *ids, *dispNames, aMembers );
       
   463 
       
   464     CleanupStack::PopAndDestroy( dispNames );
       
   465     CleanupStack::PopAndDestroy( ids );
       
   466     }
       
   467 
       
   468 // ---------------------------------------------------------------------------
       
   469 // CSimplePluginWatcher::StartWatchingRlsL
       
   470 // ---------------------------------------------------------------------------
       
   471 //
       
   472 void CSimplePluginWatcher::StartWatchingRlsL()
       
   473     {
       
   474     HBufC* buf = iXdmUtils->RlsServiceByResourceListLC( iPresIdentity->Des() );  // << buf
       
   475 
       
   476     HBufC8* buf2 = NULL;
       
   477     buf2 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( buf->Des() );
       
   478     CleanupStack::PushL( buf2 ); // << buf2
       
   479 
       
   480     CSimplePluginEntityWatcher* watcher = MatchWatcher2L( buf2->Des(), ETrue );
       
   481 
       
   482     watcher->StartSubscribeListL( buf2->Des() );
       
   483 
       
   484     watcher->SetSimpleNameL( buf2->Des() );
       
   485 
       
   486     CleanupStack::PopAndDestroy( buf2 );  // >> buf2
       
   487     CleanupStack::PopAndDestroy( buf );  // >> buf
       
   488     }
       
   489 
       
   490 // ---------------------------------------------------------------------------
       
   491 // CSimplePluginWatcher::SetPresIdentityL()
       
   492 // ---------------------------------------------------------------------------
       
   493 //
       
   494 void CSimplePluginWatcher::SetPresIdentityL(
       
   495      const MXIMPIdentity& aPresentityId )
       
   496      {
       
   497      delete iPresIdentity;
       
   498      iPresIdentity = NULL;
       
   499      iPresIdentity = aPresentityId.Identity().AllocL();
       
   500      }
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // CSimplePluginWatcher::CompletePrFwReq
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 void CSimplePluginWatcher::CompletePrFwReq( TInt aStatus )
       
   507     {
       
   508 #ifdef _DEBUG
       
   509     PluginLogger::Log(_L("PluginWatcher: CompletePrFwReq status=%d"), aStatus );
       
   510 #endif
       
   511     iXdmState = EPluginIdle;
       
   512 
       
   513     if ( !iCompleted )
       
   514         {
       
   515         iCompleted = ETrue;
       
   516         // Convert error code when needed
       
   517         if ( aStatus == KSimpleErrNotFound &&
       
   518              ( iOperation == EPluginSubscribeGroup ||
       
   519                iOperation == EPluginUnsubscribeGroup ))
       
   520             {
       
   521             aStatus = KPresenceErrUnknownPresentityGroup;
       
   522             }
       
   523         else if ( aStatus == KSimpleErrNotFound )
       
   524             {
       
   525             aStatus = KPresenceErrUnknownPresentity;
       
   526             }
       
   527         else
       
   528             {
       
   529             }
       
   530         iConnObs.CompleteReq( iPrFwId, aStatus );
       
   531         iPrFwId = TXIMPRequestId();
       
   532         iOperation = EPluginUndef;
       
   533         }
       
   534     else
       
   535         {
       
   536         }
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // CSimplePluginWatcher::CompleteWatcher
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 void CSimplePluginWatcher::CompleteWatcher( TInt aStatus )
       
   544     {
       
   545 #ifdef _DEBUG
       
   546     PluginLogger::Log(_L("PluginWatcher: CompleteWatcher status=%d"), aStatus );
       
   547 #endif
       
   548     // start to remove RLS service when needed.
       
   549     if ( iOperation == EPluginUnsubscribeGroup && iXdmState == EPluginIdle )
       
   550         {
       
   551         TRAPD( err, iXdmUtils->FetchRlsL( iStatus ));
       
   552         if ( err )
       
   553             {
       
   554             CompletePrFwReq( err );
       
   555             }
       
   556         else
       
   557             {
       
   558             iXdmState = EPluginFetchRls;
       
   559             SetActive();
       
   560             }
       
   561         }
       
   562     else
       
   563         {
       
   564         CompletePrFwReq( aStatus );
       
   565         }
       
   566     }
       
   567 
       
   568 // ---------------------------------------------------------------------------
       
   569 // CSimplePluginWatcher::StartXdmOperationL
       
   570 // ---------------------------------------------------------------------------
       
   571 //
       
   572 void CSimplePluginWatcher::StartXdmOperationL()
       
   573     {
       
   574     TRAPD( err, DoStartXdmOperationL() );
       
   575     if ( err )
       
   576         {
       
   577         User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   578         }
       
   579     }
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // CSimplePluginWatcher::DoStartXdmOperationL
       
   583 // ---------------------------------------------------------------------------
       
   584 //
       
   585 void CSimplePluginWatcher::DoStartXdmOperationL()
       
   586     {
       
   587     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   588     if ( !iXdmUtils )
       
   589         {
       
   590         iXdmUtils = iConnObs.XdmUtilsL();
       
   591         }
       
   592     iXdmUtils->InitializeXdmsOnlyL( iStatus );
       
   593 
       
   594     iXdmState = EPluginInitXdm;
       
   595 
       
   596     SetActive();
       
   597     }
       
   598 
       
   599 // ---------------------------------------------------------------------------
       
   600 // CSimplePluginWatcher::DoCancel
       
   601 // ---------------------------------------------------------------------------
       
   602 //
       
   603 void CSimplePluginWatcher::DoCancel(  )
       
   604     {
       
   605     iXdmUtils->Cancel();
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------------------------
       
   609 // CSimplePluginWatcher::RunL
       
   610 // ---------------------------------------------------------------------------
       
   611 //
       
   612 void CSimplePluginWatcher::RunL(  )
       
   613     {
       
   614 
       
   615     TInt status = iStatus.Int();
       
   616 
       
   617 #ifdef _DEBUG
       
   618     PluginLogger::Log(_L("PluginWatcher: RunL %d"), status );
       
   619 #endif
       
   620     if ( !status )
       
   621         {
       
   622         // create RLS service first here
       
   623         if ( iOperation == EPluginSubscribeGroup )
       
   624             {
       
   625             DoRunForSubscriptionL();
       
   626             }
       
   627         // remove RLS service when needed.
       
   628         else if ( iOperation == EPluginUnsubscribeGroup )
       
   629             {
       
   630             DoRunForUnsubscriptionL();
       
   631             }
       
   632         else
       
   633             {
       
   634             // Idle state should not be completed. We should not come here
       
   635             // because of PrFw core makes one request at a time.
       
   636             }
       
   637         }
       
   638     else
       
   639         {
       
   640         CompletePrFwReq( status );
       
   641         }
       
   642     }
       
   643 
       
   644 // ---------------------------------------------------------------------------
       
   645 // CSimplePluginWatcher::RunError
       
   646 // ---------------------------------------------------------------------------
       
   647 //
       
   648 TInt CSimplePluginWatcher::RunError( TInt aError )
       
   649     {
       
   650     CompletePrFwReq( aError );
       
   651     return KErrNone;
       
   652     }
       
   653 
       
   654 // ---------------------------------------------------------------------------
       
   655 // CSimplePluginWatcher::GetListContentL
       
   656 // ---------------------------------------------------------------------------
       
   657 //
       
   658 void CSimplePluginWatcher::GetListContentL()
       
   659     {
       
   660     MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory();
       
   661     MProtocolPresentityGroupsDataHost& dataHost =
       
   662         iConnObs.Host()->ProtocolPresenceDataHost().GroupsDataHost();
       
   663 
       
   664     MXIMPObjectCollection* entities =
       
   665         myFactory.NewObjectCollectionLC();          // << entities
       
   666     GetEntitiesInListL( iPresIdentity->Des(), *entities );
       
   667 
       
   668     // callback for data
       
   669     MXIMPIdentity* id = myFactory.NewIdentityLC();  // << id
       
   670     id->SetIdentityL( iPresIdentity->Des() );
       
   671 #ifdef _DEBUG
       
   672     PluginLogger::Log(
       
   673         _L("PluginWatcher: callback HandlePresentityGroupContentL"));
       
   674 #endif
       
   675     dataHost.HandlePresentityGroupContentL( id, entities );
       
   676     CleanupStack::Pop();                            // >> id
       
   677     CleanupStack::Pop();                            // >> entities
       
   678 
       
   679     }
       
   680 
       
   681 // ---------------------------------------------------------------------------
       
   682 // CSimplePluginWatcher::CopyGroupMembersToCollectionL
       
   683 // ---------------------------------------------------------------------------
       
   684 //
       
   685 void CSimplePluginWatcher::CopyGroupMembersToCollectionL(
       
   686     CPtrCArray& aIds, CPtrCArray& aNames, MXIMPObjectCollection& aCollection)
       
   687     {
       
   688     MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory();
       
   689     MPresenceObjectFactory& myPresenceFactory = iConnObs.PresenceObjectFactory();
       
   690     TInt count = aIds.Count();
       
   691     for ( TInt i=0; i < count; i++ )
       
   692         {
       
   693         // create here MPresentityGroupMemberInfo
       
   694         MPresentityGroupMemberInfo* info = myPresenceFactory.NewPresentityGroupMemberInfoLC(); // << info
       
   695         MXIMPIdentity* id = myFactory.NewIdentityLC();  // << id
       
   696         id->SetIdentityL( aIds[i] );
       
   697         info->SetGroupMemberIdL( id );
       
   698         CleanupStack::Pop(); // >> id
       
   699 
       
   700         info->SetGroupMemberDisplayNameL( aNames[i] );
       
   701         aCollection.AddObjectL( info );
       
   702         CleanupStack::Pop(); // >> info
       
   703         }
       
   704     }
       
   705 
       
   706 // ---------------------------------------------------------------------------
       
   707 // CSimplePluginWatcher::DoRunForSubscriptionL
       
   708 // ---------------------------------------------------------------------------
       
   709 //
       
   710 void CSimplePluginWatcher::DoRunForSubscriptionL( )
       
   711     {
       
   712     if ( iXdmState == EPluginInitXdm )
       
   713         {
       
   714         // get members of the list first
       
   715         GetListContentL();
       
   716 
       
   717         // Fetch RLS document first before modifying the data.
       
   718         TRAPD( err, iXdmUtils->FetchRlsL( iStatus ));
       
   719         if ( err )
       
   720             {
       
   721             CompletePrFwReq( err );
       
   722             }
       
   723         else
       
   724             {
       
   725             iXdmState = EPluginFetchRls;
       
   726             SetActive();
       
   727             }
       
   728         }
       
   729     else if ( iXdmState == EPluginFetchRls )
       
   730         {
       
   731         // Create RLS document service
       
   732         iXdmUtils->AddRlsGroupL( iPresIdentity->Des() );
       
   733         iXdmState = EPluginAddGroupMember;
       
   734         iXdmUtils->CommitRlsL( iStatus );
       
   735         SetActive();
       
   736         }
       
   737     else
       
   738         {
       
   739         StartWatchingRlsL();
       
   740         }
       
   741     }
       
   742 
       
   743 // ---------------------------------------------------------------------------
       
   744 // CSimplePluginWatcher::DoRunForUnsubscriptionL
       
   745 // ---------------------------------------------------------------------------
       
   746 //
       
   747 void CSimplePluginWatcher::DoRunForUnsubscriptionL( )
       
   748     {
       
   749     TInt status = iStatus.Int();
       
   750     if ( iXdmState == EPluginIdle )
       
   751         {
       
   752         TRAPD( err, iXdmUtils->FetchRlsL( iStatus ));
       
   753         if ( err )
       
   754             {
       
   755             CompletePrFwReq( err );
       
   756             }
       
   757         else
       
   758             {
       
   759             iXdmState = EPluginFetchRls;
       
   760             SetActive();
       
   761             }
       
   762         }
       
   763     else if ( iXdmState == EPluginFetchRls )
       
   764         {
       
   765         TRAPD( err, iXdmUtils->RemoveRlsServiceByResourceListL( iPresIdentity->Des(), iStatus ));
       
   766         if ( err )
       
   767             {
       
   768             CompletePrFwReq( err );
       
   769             }
       
   770         else
       
   771             {
       
   772             iXdmState = EPluginRemoveGroupMember;
       
   773             SetActive();
       
   774             }
       
   775         }
       
   776     else
       
   777         {
       
   778         CompletePrFwReq( status );
       
   779         }
       
   780     }
       
   781 
       
   782 
       
   783 
       
   784 // End of file