presencefwsimpleadpt/src/simplepluginpublisher.cpp
branchRCL_3
changeset 34 2669f8761a99
parent 31 2580314736af
child 35 fbd2e7cec7ef
equal deleted inserted replaced
31:2580314736af 34:2669f8761a99
     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 #include <presenceinfo.h>
       
    26 #include <presenceinfofield.h>
       
    27 #include <presenceinfofieldcollection.h>
       
    28 #include <presenceinfofieldvaluetext.h>
       
    29 #include <presenceinfofieldvalueenum.h>
       
    30 #include <presenceinfofieldvaluebinary.h>
       
    31 #include <presenceobjectfactory.h>
       
    32 #include <presencewatcherinfo.h>
       
    33 #include <presenceerrors.hrh>
       
    34 
       
    35 #include <servicepresenceinfo.h>
       
    36 #include <devicepresenceinfo.h>
       
    37 
       
    38 #include <protocolpresencedatahost.h>
       
    39 #include <protocolpresencepublishingdatahost.h>
       
    40 
       
    41 #include <ximpdatasubscriptionstate.h>
       
    42 #include <ximperrors.hrh>
       
    43 #include <ximpidentity.h>
       
    44 #include <ximpobjectcollection.h>
       
    45 #include <ximpobjectfactory.h>
       
    46 #include <ximpprotocolconnectionhost.h>
       
    47 #include <ximpstatus.h>
       
    48 
       
    49 #include <simplefactory.h>
       
    50 
       
    51 #include <msimplewinfo.h>
       
    52 #include <msimplepublisher.h>
       
    53 #include <msimplewatcher.h>
       
    54 #include <msimpledocument.h>
       
    55 #include <msimpleelement.h>
       
    56 #include <msimplecontent.h>
       
    57 
       
    58 #include "simpleplugincommon.h"
       
    59 #include "simplepluginpublisher.h"
       
    60 #include "simpleplugindebugutils.h"
       
    61 #include "simpleutils.h"
       
    62 #include "simplepluginwinfo.h"
       
    63 #include "simpleplugindata.h"
       
    64 #include "simplepluginxdmutils.h"
       
    65 #include "simplepluginconnection.h"
       
    66 
       
    67 
       
    68 // ======== MEMBER FUNCTIONS ========
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CSimplePluginWatcherInfo::CSimplePluginWatcherInfo
       
    73 // -----------------------------------------------------------------------------
       
    74 CSimplePluginWatcherInfo::CSimplePluginWatcherInfo( )
       
    75         {}
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CSimplePluginWatcherInfo::~CSimplePluginWatcherInfo
       
    79 // -----------------------------------------------------------------------------
       
    80 CSimplePluginWatcherInfo::~CSimplePluginWatcherInfo()
       
    81     {
       
    82     delete iId;
       
    83     delete iSipId;
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------
       
    87 // CSimplePluginWatcherInfo::NewL
       
    88 // ----------------------------------------------------------
       
    89 //
       
    90 CSimplePluginWatcherInfo* CSimplePluginWatcherInfo::NewL(
       
    91    const TDesC8& aId, const TDesC& aSipId )
       
    92     {
       
    93     CSimplePluginWatcherInfo* self = new (ELeave) CSimplePluginWatcherInfo( );
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL( aId, aSipId );
       
    96     CleanupStack::Pop( self );
       
    97     return self;
       
    98     }
       
    99 
       
   100 // ----------------------------------------------------------
       
   101 // CSimplePluginWatcherInfo::ConstructL
       
   102 // ----------------------------------------------------------
       
   103 //
       
   104 void CSimplePluginWatcherInfo::ConstructL(
       
   105     const TDesC8& aId, const TDesC& aSipId  )
       
   106     {
       
   107     iId = aId.AllocL();
       
   108     iSipId = aSipId.AllocL();
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CSimplePluginWatcherInfo::Destroy
       
   113 // -----------------------------------------------------------------------------
       
   114 void CSimplePluginWatcherInfo::Destroy()
       
   115     {
       
   116     iLink.Deque();
       
   117     delete this;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CSimplePluginWatcherInfo::Match
       
   122 // -----------------------------------------------------------------------------
       
   123 TBool CSimplePluginWatcherInfo::Match( const TDesC8& aId, const TDesC& aSipId )
       
   124     {
       
   125     if ( (!iId->Des().CompareF( aId )) && (!iSipId->Des().CompareF( aSipId)) )
       
   126         {
       
   127         return ETrue;
       
   128         }
       
   129     else
       
   130         {
       
   131         return EFalse;
       
   132         }
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CSimplePluginWatcherInfo::SipId
       
   137 // -----------------------------------------------------------------------------
       
   138 TPtrC CSimplePluginWatcherInfo::SipId( )
       
   139     {
       
   140     return iSipId ? iSipId->Des() : TPtrC();
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CSimplePluginPublisher::CSimplePluginPublisher
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 CSimplePluginPublisher::CSimplePluginPublisher(
       
   148     MSimplePluginSettings& aConnSets,
       
   149     MSimplePluginConnectionObs& aObs,
       
   150     MSimpleConnection& aConn )
       
   151 : CActive( CActive::EPriorityStandard ),
       
   152   iConnObs(aObs), iConnSets( aConnSets), iConnection(aConn),
       
   153   iSubscribed(EFalse), iSubscribedOwn(EFalse), iPublished(EFalse),
       
   154   iWatcherList( CSimplePluginWatcherInfo::LinkOffset())
       
   155     {
       
   156     CActiveScheduler::Add(this);
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CSimplePluginPublisher::ConstructL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CSimplePluginPublisher::ConstructL( )
       
   164     {
       
   165     iPublisher = TSimpleFactory::NewPublisherL( iConnection, *this );
       
   166     iWatcher = TSimpleFactory::NewWatcherL( iConnection, *this );
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // CSimplePluginPublisher::NewL
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 CSimplePluginPublisher* CSimplePluginPublisher::NewL(
       
   174     MSimplePluginSettings& aConnSets,
       
   175     MSimplePluginConnectionObs& aObs,
       
   176     MSimpleConnection& aConn )
       
   177     {
       
   178     CSimplePluginPublisher* self =
       
   179         new( ELeave ) CSimplePluginPublisher( aConnSets, aObs, aConn );
       
   180     CleanupStack::PushL( self );
       
   181     self->ConstructL(  );
       
   182     CleanupStack::Pop( self );
       
   183     return self;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CSimplePluginPublisher::~CSimplePluginPublisher
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CSimplePluginPublisher::~CSimplePluginPublisher()
       
   191     {
       
   192     if ( iDocument )
       
   193         {
       
   194         iDocument->Close();
       
   195         }
       
   196 
       
   197     if ( iPublisher )
       
   198         {
       
   199         iPublisher->Close();
       
   200         }
       
   201 
       
   202     if ( iWatcher )
       
   203         {
       
   204         iWatcher->Close();
       
   205         }
       
   206 
       
   207     // delete iWatchers;
       
   208     DeleteWatchers();
       
   209 
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CSimplePluginPublisher::DeleteWatchers
       
   214 // -----------------------------------------------------------------------------
       
   215 void CSimplePluginPublisher::DeleteWatchers()
       
   216     {
       
   217 #ifdef _DEBUG
       
   218     PluginLogger::Log(_L("PluginPublisher: DeleteWatchers" ) );
       
   219 #endif
       
   220     // Delete all buffered transaction requests
       
   221     TDblQueIter<CSimplePluginWatcherInfo> rIter( iWatcherList );
       
   222     rIter.SetToFirst();
       
   223 
       
   224     while ( rIter )
       
   225         {
       
   226         CSimplePluginWatcherInfo* w = rIter;
       
   227         rIter++;
       
   228         // delete wathcer info
       
   229         w->Destroy();
       
   230         }
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CSimplePluginPublisher::AddWatcherIfNotExistsL
       
   235 // -----------------------------------------------------------------------------
       
   236 void CSimplePluginPublisher::AddWatcherIfNotExistsL( const TDesC8& aId, const TDesC& aSipId )
       
   237     {
       
   238 #ifdef _DEBUG
       
   239     PluginLogger::Log(_L("PluginPublisher: AddWatcherIfNotExistsL" ) );
       
   240 #endif
       
   241     TDblQueIter<CSimplePluginWatcherInfo> rIter( iWatcherList );
       
   242     rIter.SetToFirst();
       
   243 
       
   244     TBool found(EFalse);
       
   245 
       
   246     while ( rIter )
       
   247         {
       
   248         CSimplePluginWatcherInfo* w = rIter;
       
   249         rIter++;
       
   250         found = w->Match( aId, aSipId );
       
   251         if ( found )
       
   252             {
       
   253             break;
       
   254             }
       
   255         else
       
   256             {
       
   257             // continue searching
       
   258             }
       
   259         }
       
   260     if ( !found )
       
   261         {
       
   262 #ifdef _DEBUG
       
   263         PluginLogger::Log(_L("PluginPublisher: AddWatcherIfNotExistsL adds a watcher" ) );
       
   264 #endif
       
   265         CSimplePluginWatcherInfo* w = CSimplePluginWatcherInfo::NewL( aId, aSipId );
       
   266         iWatcherList.AddLast( *w );
       
   267         }
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CSimplePluginPublisher::RemoveWatcherIfExistsL
       
   272 // -----------------------------------------------------------------------------
       
   273 void CSimplePluginPublisher::RemoveWatcherIfExistsL( const TDesC8& aId, const TDesC& aSipId )
       
   274     {
       
   275 #ifdef _DEBUG
       
   276     PluginLogger::Log(_L("PluginPublisher: RemoveWatcherIfExistsL" ) );
       
   277 #endif
       
   278     TDblQueIter<CSimplePluginWatcherInfo> rIter( iWatcherList );
       
   279     rIter.SetToFirst();
       
   280 
       
   281     TBool found(EFalse);
       
   282 
       
   283     while ( rIter )
       
   284         {
       
   285         CSimplePluginWatcherInfo* w = rIter;
       
   286         rIter++;
       
   287         // delete wathcer info
       
   288         found = w->Match( aId, aSipId );
       
   289         if ( found )
       
   290             {
       
   291 #ifdef _DEBUG
       
   292             PluginLogger::Log(_L("PluginPublisher: RemoveWatcherIfExistsL removes a watcher" ) );
       
   293 #endif
       
   294             w->Destroy();
       
   295             break;
       
   296             }
       
   297         else
       
   298             {
       
   299             // continue searching
       
   300             }
       
   301         }
       
   302     }
       
   303 // -----------------------------------------------------------------------------
       
   304 // CSimplePluginPublisher::MakeCurrentWatcherListLC
       
   305 // -----------------------------------------------------------------------------
       
   306 CDesCArrayFlat* CSimplePluginPublisher::MakeCurrentWatcherListLC()
       
   307     {
       
   308 #ifdef _DEBUG
       
   309     PluginLogger::Log(_L("PluginPublisher: MakeCurrentWatcherListL" ) );
       
   310 #endif
       
   311     // No one should be added more than once
       
   312     const TInt KMyGran = 10;
       
   313     CDesCArrayFlat* watchers = new (ELeave) CDesCArrayFlat( KMyGran );
       
   314     CleanupStack::PushL( watchers );      // << watchers
       
   315 
       
   316     // add user only once here.
       
   317     TDblQueIter<CSimplePluginWatcherInfo> rIter( iWatcherList );
       
   318     rIter.SetToFirst();
       
   319 
       
   320     while ( rIter )
       
   321         {
       
   322         CSimplePluginWatcherInfo* w = rIter;
       
   323         rIter++;
       
   324 
       
   325         TInt dummy = 0;
       
   326         if ( watchers->Find( w->SipId(), dummy ))
       
   327             {
       
   328             watchers->AppendL( w->SipId() );
       
   329             }
       
   330         else
       
   331             {
       
   332             // continue searching
       
   333             }
       
   334         }
       
   335 
       
   336     return watchers;
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // CSimplePluginPublisher::DoPublishOwnPresenceL
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 void CSimplePluginPublisher::DoPublishOwnPresenceL(
       
   344     const MPresenceInfo& aOwnPresence,
       
   345     TXIMPRequestId aReqId )
       
   346     {
       
   347 #ifdef _DEBUG
       
   348     PluginLogger::Log(_L("PluginPublisher: DoPublishOwnPresenceL"));
       
   349 #endif
       
   350 
       
   351     const MPersonPresenceInfo* persInfo = aOwnPresence.PersonPresence();
       
   352 
       
   353     // convert data format from PrFW to internal
       
   354     if ( !persInfo )
       
   355         {
       
   356         // Notice: error codes
       
   357         CompletePrFwReq( KErrArgument );
       
   358         return;
       
   359         }
       
   360     InitializeSimpleDocumentL( );
       
   361     AddSimpleDocumentPersL( persInfo );
       
   362 
       
   363     TInt myCount = aOwnPresence.ServicePresenceCount();
       
   364     for ( TInt i=0; i < myCount; i++ )
       
   365         {
       
   366         const MServicePresenceInfo& servInfo = aOwnPresence.ServicePresenceAt(i);
       
   367         AddSimpleDocumentServiceL( servInfo );
       
   368         }
       
   369     myCount = aOwnPresence.DevicePresenceCount();
       
   370     for ( TInt i=0; i < myCount; i++ )
       
   371         {
       
   372         const MDevicePresenceInfo& devInfo = aOwnPresence.DevicePresenceAt(i);
       
   373         AddSimpleDocumentDeviceL( devInfo );
       
   374         }
       
   375 
       
   376     // Ensure that XDM rules exists, the show continues in RunL
       
   377     StartXdmOperationL(aReqId );
       
   378     iOperation = EPublishOwn;
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // CSimplePluginPublisher::DoSubscribeOwnPresenceL
       
   383 // ---------------------------------------------------------------------------
       
   384 //
       
   385 void CSimplePluginPublisher::DoSubscribeOwnPresenceL(
       
   386     const MPresenceInfoFilter& /*aPif*/,   // notice: aPif filter not supported
       
   387     TXIMPRequestId aReqId )
       
   388     {
       
   389 #ifdef _DEBUG
       
   390     PluginLogger::Log(_L("PluginPublisher: DoSubscribeOwnPresenceL"));
       
   391 #endif
       
   392 
       
   393     StartXdmOperationL( aReqId );
       
   394 
       
   395     iOperation = ESubscribeOwn;
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------------------------
       
   399 // CSimplePluginPublisher::DoUpdateOwnPresenceSubscriptionPifL
       
   400 // ---------------------------------------------------------------------------
       
   401 //
       
   402 void CSimplePluginPublisher::DoUpdateOwnPresenceSubscriptionPifL(
       
   403     const MPresenceInfoFilter& /*aPif*/,
       
   404     TXIMPRequestId /*aReqId*/ )
       
   405     {
       
   406 #ifdef _DEBUG
       
   407     PluginLogger::Log(_L("PluginPublisher: DoUpdateOwnPresenceSubscriptionPifL"));
       
   408 #endif
       
   409     // Notice: aPif filter not supported
       
   410     User::Leave( KErrNotSupported );
       
   411     }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // CSimplePluginPublisher::DoUnsubscribeOwnPresenceL
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 void CSimplePluginPublisher::DoUnsubscribeOwnPresenceL(
       
   418     TXIMPRequestId aReqId )
       
   419     {
       
   420 #ifdef _DEBUG
       
   421     PluginLogger::Log(_L("PluginPublisher: DoUnsubscribeOwnPresenceL"));
       
   422 #endif
       
   423     iSubscribedOwn = EFalse;
       
   424     TRAPD( err, iSimpleId = iWatcher->UnsubscribeL());
       
   425     if ( err )
       
   426         {
       
   427         User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   428         }
       
   429     iPrFwId = aReqId;
       
   430     iOperation = EUnsubscribeOwn;
       
   431     }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // CSimplePluginPublisher::DoSubscribePresenceWatcherListL
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 void CSimplePluginPublisher::DoSubscribePresenceWatcherListL(
       
   438     TXIMPRequestId aReqId )
       
   439     {
       
   440 #ifdef _DEBUG
       
   441     PluginLogger::Log(_L("PluginPublisher: DoSubscribePresenceWatcherListL"));
       
   442 #endif
       
   443 
       
   444     if ( !iSubscribed )
       
   445         {
       
   446         TRAPD( err, iConnObs.WinfoHandlerL()->SubscribeWinfoListL( aReqId ));
       
   447         if ( err )
       
   448             {
       
   449             User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   450             }
       
   451         iSubscribed = ETrue;
       
   452         iPrFwId = aReqId;
       
   453         iOperation = ESubscribeWinfo;
       
   454         }
       
   455     else
       
   456         {
       
   457         iPrFwId = aReqId;
       
   458         CompletePrFwReq( KErrNone );
       
   459         }
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------------------------
       
   463 // CSimplePluginPublisher::DoUnsubscribePresenceWatcherListL
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 void CSimplePluginPublisher::DoUnsubscribePresenceWatcherListL(
       
   467     TXIMPRequestId aReqId )
       
   468     {
       
   469 #ifdef _DEBUG
       
   470     PluginLogger::Log(_L("PluginPublisher: DoUnsubscribePresenceWatcherListL"));
       
   471 #endif
       
   472     if ( iSubscribed )
       
   473         {
       
   474         TRAPD( err, iConnObs.WinfoHandlerL()->UnsubscribeWinfoListL( aReqId ));
       
   475         if ( err )
       
   476             {
       
   477             User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   478             }
       
   479         iSubscribed = EFalse;
       
   480         iPrFwId = aReqId;
       
   481         iOperation = EUnsubscribeWinfo;
       
   482         }
       
   483     else
       
   484         {
       
   485         iPrFwId = aReqId;
       
   486         CompletePrFwReq( KErrNone );
       
   487         }
       
   488     }
       
   489 
       
   490 // ---------------------------------------------------------------------------
       
   491 // CSimplePluginPublisher::PublishReqCompleteL
       
   492 // ---------------------------------------------------------------------------
       
   493 //
       
   494 void CSimplePluginPublisher::PublishReqCompleteL( TInt /*aOpid*/, TInt aStatus )
       
   495     {
       
   496 #ifdef _DEBUG
       
   497     PluginLogger::Log(_L("PluginPublisher: PublishReqCompleteL("));
       
   498 #endif
       
   499     if ( !aStatus )
       
   500         {
       
   501         iPublished = ETrue;
       
   502         }
       
   503     else
       
   504         {
       
   505         }
       
   506 
       
   507     CompletePrFwReq( aStatus );
       
   508     }
       
   509 
       
   510 // ---------------------------------------------------------------------------
       
   511 // CSimplePluginPublisher::PublishTerminatedL
       
   512 // ---------------------------------------------------------------------------
       
   513 //
       
   514 void CSimplePluginPublisher::PublishTerminatedL( TInt /*aOpid*/ )
       
   515     {
       
   516 #ifdef _DEBUG
       
   517     PluginLogger::Log(_L("PluginPublisher: PublishTerminatedL"));
       
   518 #endif
       
   519     // Notice: nothing to do now in Host APi.
       
   520     iPublished = EFalse;
       
   521     }
       
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 // CSimplePluginPublisher::WatcherReqCompleteL
       
   525 // ---------------------------------------------------------------------------
       
   526 //
       
   527 void CSimplePluginPublisher::WatcherReqCompleteL( TInt /*aOpid*/, TInt aStatus )
       
   528     {
       
   529 #ifdef _DEBUG
       
   530     PluginLogger::Log(_L("PluginPublisher: WatcherReqCompleteL"));
       
   531 #endif
       
   532     if ( !aStatus )
       
   533         {
       
   534         iSubscribedOwn = ETrue;
       
   535         }
       
   536     else
       
   537         {
       
   538         }
       
   539     CompletePrFwReq( aStatus );
       
   540     }
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // CSimplePluginPublisher::WatcherNotificationL
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 void CSimplePluginPublisher::WatcherNotificationL( MSimpleDocument& aDocument )
       
   547     {
       
   548 #ifdef _DEBUG
       
   549     PluginLogger::Log(_L("PluginPublisher: WatcherNotificationL"));
       
   550 #endif
       
   551 
       
   552     // Notice: Do not need to check the expiration here since WatcherTerminatedL
       
   553     // is called then too.
       
   554 
       
   555     MProtocolPresencePublishingDataHost& publishHost =
       
   556         iConnObs.Host()->ProtocolPresenceDataHost().PublishingDataHost();
       
   557     MPresenceInfo* prInfo = iConnObs.PresenceObjectFactory().NewPresenceInfoLC();  // << prInfo
       
   558     CSimplePluginData::NotifyToPrInfoL( iConnObs.PresenceObjectFactory(), aDocument, *prInfo );
       
   559 
       
   560 #ifdef _DEBUG
       
   561     // ---------------------------------------------------------
       
   562     const MPersonPresenceInfo* pers_debug = prInfo->PersonPresence();
       
   563     const MPresenceInfoFieldCollection& coll_debug = pers_debug->Fields();
       
   564     TInt count_debug = coll_debug.FieldCount();
       
   565     PluginLogger::Log(_L("PluginPublisher: nbr of fields received =%d"), count_debug );
       
   566     // ---------------------------------------------------------
       
   567 #endif
       
   568 
       
   569     // PrFw Host API callbacks
       
   570 
       
   571 #ifdef _DEBUG
       
   572     PluginLogger::Log(_L("PluginPublisher: callback HandleSubscribedOwnPresenceL"));
       
   573 #endif
       
   574     publishHost.HandleSubscribedOwnPresenceL( prInfo );
       
   575     CleanupStack::Pop();  // >> prInfo
       
   576 
       
   577     }
       
   578 
       
   579 // ---------------------------------------------------------------------------
       
   580 // CSimplePluginPublisher::WatcherListNotificationL
       
   581 // ---------------------------------------------------------------------------
       
   582 //
       
   583 void CSimplePluginPublisher::WatcherListNotificationL( MSimplePresenceList& /*aList*/ )
       
   584     {
       
   585     // Notice: not needed.
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // CSimplePluginPublisher::WatcherTerminatedL
       
   590 // ---------------------------------------------------------------------------
       
   591 //
       
   592 void CSimplePluginPublisher::WatcherTerminatedL(
       
   593     TInt /*aOpId*/, TInt /*aReason*/ )
       
   594     {
       
   595 #ifdef _DEBUG
       
   596     PluginLogger::Log(_L("PluginPublisher: WatcherTerminatedL"));
       
   597 #endif
       
   598     iSubscribedOwn = EFalse;
       
   599 
       
   600     MProtocolPresencePublishingDataHost& publishHost =
       
   601         iConnObs.Host()->ProtocolPresenceDataHost().PublishingDataHost();
       
   602     MXIMPDataSubscriptionState *state = iConnObs.ObjectFactory().NewDataSubscriptionStateLC();
       
   603     MXIMPStatus* status = iConnObs.ObjectFactory().NewStatusLC();
       
   604     state->SetSubscriptionStateL( MXIMPDataSubscriptionState::ESubscriptionInactive );
       
   605     status->SetResultCode( KErrCompletion );
       
   606 #ifdef _DEBUG
       
   607     PluginLogger::Log(_L("PluginPublisher: callback SetOwnPresenceDataSubscriptionStateL"));
       
   608 #endif
       
   609     publishHost.SetOwnPresenceDataSubscriptionStateL( state, status );
       
   610     CleanupStack::Pop( 2 ); // status, state
       
   611     }
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // CSimplePluginPublisher::CompletePrFwReq
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 void CSimplePluginPublisher::CompletePrFwReq( TInt aStatus )
       
   618     {
       
   619 #ifdef _DEBUG
       
   620     PluginLogger::Log(_L("PluginPublisher: CompletePrFwReq status=%d"), aStatus );
       
   621 #endif
       
   622     if ( iOperation != ENoOperation )
       
   623         {
       
   624         iOperation = ENoOperation;
       
   625         iConnObs.CompleteReq( iPrFwId, aStatus );
       
   626         iPrFwId = TXIMPRequestId();
       
   627         }
       
   628     else
       
   629         {
       
   630         }
       
   631     return;
       
   632     }
       
   633 
       
   634 // ---------------------------------------------------------------------------
       
   635 // CSimplePluginPublisher::DoCancel
       
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 void CSimplePluginPublisher::DoCancel(  )
       
   639     {
       
   640     iXdmUtils->Cancel();
       
   641     }
       
   642 
       
   643 // ---------------------------------------------------------------------------
       
   644 // CSimplePluginPublisher::RunL
       
   645 // ---------------------------------------------------------------------------
       
   646 //
       
   647 void CSimplePluginPublisher::RunL(  )
       
   648     {
       
   649 
       
   650     TInt status = iStatus.Int();
       
   651 
       
   652 #ifdef _DEBUG
       
   653     PluginLogger::Log(_L("PluginPublisher: RunL %d"), status );
       
   654 #endif
       
   655 
       
   656     if ( !status )
       
   657         {
       
   658         if ( iOperation == ESubscribeOwn )
       
   659             {
       
   660             iSimpleId = iWatcher->SubscribeL(
       
   661                 iConnSets.CurrentSipPresentity8(),
       
   662                 NULL,  // aFilter <-> aPif
       
   663                 ETrue, EFalse );
       
   664             }
       
   665         else
       
   666             {
       
   667             MakePublishReqL();
       
   668             }
       
   669         }
       
   670     else
       
   671         {
       
   672         CompletePrFwReq( status );
       
   673         }
       
   674     }
       
   675 
       
   676 // ---------------------------------------------------------------------------
       
   677 // CSimplePluginPublisher::RunError
       
   678 // ---------------------------------------------------------------------------
       
   679 //
       
   680 TInt CSimplePluginPublisher::RunError( TInt aError )
       
   681     {
       
   682     CompletePrFwReq( aError );
       
   683     return KErrNone;
       
   684     }
       
   685 
       
   686 // ---------------------------------------------------------------------------
       
   687 // CSimplePluginPublisher::GetInterface
       
   688 // ---------------------------------------------------------------------------
       
   689 //
       
   690 TAny* CSimplePluginPublisher::GetInterface(
       
   691         TInt32 aInterfaceId,
       
   692         TIfGetOps aOptions )
       
   693     {
       
   694     if ( aInterfaceId == GetInterfaceId() )
       
   695         {
       
   696         // caller wants this interface
       
   697         MProtocolPresencePublishing* myIf = this;
       
   698         return myIf;
       
   699         }
       
   700     else if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   701         {
       
   702         User::Panic( _L("CSimplePlugin"), KErrExtensionNotSupported );
       
   703         }
       
   704     return NULL;
       
   705     }
       
   706 
       
   707 // ---------------------------------------------------------------------------
       
   708 // CSimplePluginPublisher::GetInterface
       
   709 // ---------------------------------------------------------------------------
       
   710 //
       
   711 const TAny* CSimplePluginPublisher::GetInterface(
       
   712     TInt32 aInterfaceId,
       
   713     TIfGetOps aOptions ) const
       
   714     {
       
   715     if ( aInterfaceId == GetInterfaceId() )
       
   716         {
       
   717         // caller wants this interface
       
   718         const MProtocolPresencePublishing* myIf = this;
       
   719         return myIf;
       
   720         }
       
   721     else if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   722         {
       
   723         User::Panic( _L("CSimplePlugin"), KErrExtensionNotSupported );
       
   724         }
       
   725     return NULL;
       
   726     }
       
   727 
       
   728 // ---------------------------------------------------------------------------
       
   729 // CSimplePluginPublisher::GetInterfaceId
       
   730 // ---------------------------------------------------------------------------
       
   731 //
       
   732 TInt32 CSimplePluginPublisher::GetInterfaceId() const
       
   733     {
       
   734     return MProtocolPresencePublishing::KInterfaceId;
       
   735     }
       
   736 
       
   737 
       
   738 // ---------------------------------------------------------------------------
       
   739 // CSimplePluginPublisher::InitializeSimpleDocumentL
       
   740 // ---------------------------------------------------------------------------
       
   741 //
       
   742 void CSimplePluginPublisher::InitializeSimpleDocumentL( )
       
   743     {
       
   744     if ( iDocument )
       
   745         {
       
   746         iDocument->Close();
       
   747         iDocument = NULL;
       
   748         }
       
   749     iDocument = TSimpleFactory::NewDocumentL();
       
   750     iDocument->AddNamespaceL( KSimplePDM, KSimpleNsPDM );
       
   751     iDocument->AddNamespaceL( KSimpleRPID, KSimpleNsRPID );
       
   752     iDocument->AddNamespaceL( KSimpleOP, KSimpleNsOP );
       
   753     }
       
   754 
       
   755 // ---------------------------------------------------------------------------
       
   756 // CSimplePluginPublisher::AddSimpleDocumentPersL
       
   757 // ---------------------------------------------------------------------------
       
   758 //
       
   759 void CSimplePluginPublisher::AddSimpleDocumentPersL(
       
   760     const MPersonPresenceInfo* aInfo )
       
   761     {
       
   762     CSimplePluginData::AddPrPersToSimpleDocumentL(
       
   763         aInfo, *iDocument, iConnSets.CurrentSipPresentity8() );
       
   764     }
       
   765 
       
   766 // ---------------------------------------------------------------------------
       
   767 // CSimplePluginPublisher::AddSimpleDocumentServiceL
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 void CSimplePluginPublisher::AddSimpleDocumentServiceL(
       
   771     const MServicePresenceInfo& aInfo )
       
   772     {
       
   773     if ( aInfo.Fields().FieldCount() > 0 || aInfo.ServiceType().Length() )
       
   774         {
       
   775         // Notice: currently all the fields in the namespace are supported,
       
   776         // but this ensures that if namespace is extended later, it is
       
   777         // handled right way in the adaptation
       
   778         User::Leave( KPresenceErrPresenceInfoFieldTypeNotSupported );
       
   779         }
       
   780     else
       
   781         {
       
   782         }
       
   783     }
       
   784 
       
   785 // ---------------------------------------------------------------------------
       
   786 // CSimplePluginPublisher::AddSimpleDocumentDeviceL
       
   787 // ---------------------------------------------------------------------------
       
   788 //
       
   789 void CSimplePluginPublisher::AddSimpleDocumentDeviceL(
       
   790     const MDevicePresenceInfo& aInfo )
       
   791     {
       
   792     if ( aInfo.Fields().FieldCount() > 0 || aInfo.DeviceName().Length() )
       
   793         {
       
   794         // Notice: currently all the fields in the namespace are supported,
       
   795         // but this ensures that if namespace is extended later, it is
       
   796         // handled right way in the adaptation
       
   797         User::Leave( KPresenceErrPresenceInfoFieldTypeNotSupported );
       
   798         }
       
   799     else
       
   800         {
       
   801         }
       
   802     }
       
   803 
       
   804 // ---------------------------------------------------------------------------
       
   805 // CSimplePluginPublisher::MakePublishReqL
       
   806 // ---------------------------------------------------------------------------
       
   807 //
       
   808 void CSimplePluginPublisher::MakePublishReqL( )
       
   809     {
       
   810 #ifdef _DEBUG
       
   811     PluginLogger::Log(_L("PluginPublisher: -> MakePublishReqL"));
       
   812 #endif
       
   813     // Send the iDocument
       
   814     if ( !iPublished )
       
   815         {
       
   816         iSimpleId = iPublisher->StartPublishL( *iDocument, ETrue );
       
   817         }
       
   818     else
       
   819         {
       
   820         iSimpleId = iPublisher->ModifyPublishL( *iDocument);
       
   821         }
       
   822     }
       
   823 
       
   824 // ---------------------------------------------------------------------------
       
   825 // CSimplePluginPublisher::StartXdmOperationL
       
   826 // ---------------------------------------------------------------------------
       
   827 //
       
   828 void CSimplePluginPublisher::StartXdmOperationL(
       
   829     TXIMPRequestId aReqId )
       
   830     {
       
   831     TRAPD( err, DoStartXdmOperationL( aReqId ));
       
   832     if ( err )
       
   833         {
       
   834         User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   835         }
       
   836     }
       
   837 
       
   838 // ---------------------------------------------------------------------------
       
   839 // CSimplePluginPublisher::DoStartXdmOperationL
       
   840 // ---------------------------------------------------------------------------
       
   841 //
       
   842 void CSimplePluginPublisher::DoStartXdmOperationL(
       
   843     TXIMPRequestId aReqId )
       
   844     {
       
   845     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   846     iPrFwId = aReqId;
       
   847     if ( !iXdmUtils )
       
   848         {
       
   849         iXdmUtils = iConnObs.XdmUtilsL();
       
   850         }
       
   851     iXdmUtils->InitializeXdmL( iStatus );
       
   852     SetActive();
       
   853     }
       
   854 
       
   855 
       
   856 
       
   857 // ---------------------------------------------------------------------------
       
   858 // CSimplePluginPublisher::WinfoNotificationL
       
   859 // ---------------------------------------------------------------------------
       
   860 //
       
   861 void CSimplePluginPublisher::WinfoNotificationL(
       
   862     MSimpleWinfo& aWinfo )
       
   863     {
       
   864     // ignore if not subscribed
       
   865     if ( !iSubscribed )
       
   866         {
       
   867         return;
       
   868         }
       
   869 
       
   870 #ifdef _DEBUG
       
   871     PluginLogger::Log(_L("PluginPublisher: WinfoNotificationL"));
       
   872 #endif
       
   873 
       
   874     // Handle full-state and partial state notifications
       
   875     // - If terminated -> remove from iWatcherList
       
   876     // - If active -> add into iWatcherList if does not already exist
       
   877     // WinfoTerminatedL handles termination of subscription.
       
   878 
       
   879     // Notice: CSimplePluginWinfo has completed the open request if needed before this.
       
   880 
       
   881 
       
   882     /* example:
       
   883 
       
   884     // active/pending/terminated
       
   885 
       
   886    <?xml version="1.0"?>
       
   887      <watcherinfo xmlns="urn:ietf:params:xml:ns:watcherinfo"
       
   888    version="0" state="full">
       
   889      <watcher-list resource="sip:presentity@example.com"
       
   890                    package="presence">
       
   891          <watcher status="active"
       
   892             id="sr8fdsj"
       
   893             duration-subscribed="509"
       
   894             expiration="20"
       
   895             event="approved">sip:watcherA@example.com"
       
   896           </watcher>
       
   897      */
       
   898 
       
   899     RPointerArray<MSimpleElement> elems;
       
   900     CleanupClosePushL( elems );         // << elems
       
   901     TInt err = aWinfo.SimpleElementsL( elems );
       
   902     User::LeaveIfError( err );
       
   903     TInt count = elems.Count();
       
   904 
       
   905     __ASSERT_DEBUG( count == 1, User::Leave( KErrCorrupt ) );
       
   906 
       
   907     using namespace NSimplePlugin::NSimpleOma;
       
   908 
       
   909     const TDesC8* stateVal = aWinfo.AttrValue( KSimpleState8 );
       
   910     if ( stateVal && !stateVal->CompareF( KSimpleFull8 ))
       
   911         {
       
   912 #ifdef _DEBUG
       
   913         PluginLogger::Log(_L("PluginPublisher: fullstate = TRUE") );
       
   914 #endif
       
   915         // full winfo-list is received
       
   916         DeleteWatchers();
       
   917         }
       
   918   else
       
   919         {
       
   920 #ifdef _DEBUG
       
   921         PluginLogger::Log(_L("PluginPublisher: fullstate = FALSE") );
       
   922 #endif
       
   923     }
       
   924 
       
   925     MSimpleElement* elem = elems[0];
       
   926     TPtrC8 p8 = elem->LocalName();
       
   927     err = p8.CompareF( KSimpleWatcherList8 );
       
   928     User::LeaveIfError( err );
       
   929 
       
   930     err = elem->SimpleElementsL( elems );
       
   931     User::LeaveIfError( err );
       
   932 
       
   933     // Collect the active watchers only.
       
   934     UpdateActiveWatchersListL( elems );
       
   935 
       
   936     CDesCArrayFlat* watchers = MakeCurrentWatcherListLC();  // << watchers
       
   937     MXIMPObjectCollection *actives =
       
   938         iConnObs.ObjectFactory().NewObjectCollectionLC();                  // << actives
       
   939 
       
   940     // Create MPresenceWatcherInfo entities for
       
   941     // all active watchers and add to actives.
       
   942     TInt wCount = watchers->MdcaCount();
       
   943     for ( TInt j = 0; j < wCount; j++ )
       
   944         {
       
   945         // create MPresenceWatcherInfo object
       
   946         MPresenceWatcherInfo* wInfo =
       
   947             iConnObs.PresenceObjectFactory().NewPresenceWatcherInfoLC();           // << wInfo
       
   948 
       
   949         MXIMPIdentity* identity = iConnObs.ObjectFactory().NewIdentityLC();  // << identity
       
   950 #ifdef _DEBUG
       
   951         TBuf<200> debug_buffer;
       
   952         debug_buffer = watchers->MdcaPoint( j );
       
   953         PluginLogger::Log(_L("PluginPublisher: add watcher into collection: %S"), &debug_buffer);
       
   954 #endif
       
   955         identity->SetIdentityL( watchers->MdcaPoint( j ) );
       
   956         wInfo->SetWatcherIdL( identity );
       
   957         CleanupStack::Pop( );                               // >> identity
       
   958 
       
   959         wInfo->SetWatcherDisplayNameL( watchers->MdcaPoint( j ) );
       
   960         wInfo->SetWatcherTypeL( MPresenceWatcherInfo::EPresenceSubscriber );
       
   961 
       
   962         actives->AddObjectL( wInfo );
       
   963         CleanupStack::Pop( );                           // >> wInfo
       
   964         }
       
   965 
       
   966     MProtocolPresencePublishingDataHost& publishHost =
       
   967         iConnObs.Host()->ProtocolPresenceDataHost().PublishingDataHost();
       
   968 
       
   969 #ifdef _DEBUG
       
   970     PluginLogger::Log(_L("PluginPublisher: callback HandlePresenceWatcherListL"));
       
   971 #endif
       
   972     publishHost.HandlePresenceWatcherListL( actives );
       
   973     CleanupStack::Pop();                            // >> actives
       
   974     CleanupStack::PopAndDestroy( watchers );        // >> watchers
       
   975     CleanupStack::PopAndDestroy( &elems );          // >> elems
       
   976 
       
   977     }
       
   978 
       
   979 // ---------------------------------------------------------------------------
       
   980 // CSimplePluginPublisher::WinfoTerminatedL
       
   981 // ---------------------------------------------------------------------------
       
   982 //
       
   983 void CSimplePluginPublisher::WinfoTerminatedL( TInt /*aReason*/ )
       
   984     {
       
   985 #ifdef _DEBUG
       
   986     PluginLogger::Log(_L("PluginPublisher: WinfoTerminatedL") );
       
   987 #endif
       
   988 
       
   989     if ( !iSubscribed )
       
   990         {
       
   991         return;
       
   992         }
       
   993 
       
   994     // call SetPresenceWatcherListDataSubscriptionStateL
       
   995     iSubscribed = EFalse;
       
   996 
       
   997     MProtocolPresencePublishingDataHost& publishHost =
       
   998         iConnObs.Host()->ProtocolPresenceDataHost().PublishingDataHost();
       
   999     MXIMPDataSubscriptionState *state = iConnObs.ObjectFactory().NewDataSubscriptionStateLC();
       
  1000     MXIMPStatus* status = iConnObs.ObjectFactory().NewStatusLC();
       
  1001     state->SetSubscriptionStateL( MXIMPDataSubscriptionState::ESubscriptionInactive );
       
  1002     state->SetDataStateL( MXIMPDataSubscriptionState::EDataUnavailable );
       
  1003     status->SetResultCode( KErrCompletion );
       
  1004 #ifdef _DEBUG
       
  1005     PluginLogger::Log(_L("PluginPublisher: callback SetPresenceWatcherListDataSubscriptionStateL"));
       
  1006 #endif
       
  1007     publishHost.SetPresenceWatcherListDataSubscriptionStateL( state, status );
       
  1008     CleanupStack::Pop( 2 ); // status, state
       
  1009     }
       
  1010 
       
  1011 
       
  1012 // ---------------------------------------------------------------------------
       
  1013 // CSimplePluginPublisher::UpdateActiveWatchersListL
       
  1014 // ---------------------------------------------------------------------------
       
  1015 //
       
  1016 void CSimplePluginPublisher::UpdateActiveWatchersListL(
       
  1017     RPointerArray<MSimpleElement>& aElems )
       
  1018     {
       
  1019     // Collect active users.
       
  1020     using namespace NSimplePlugin::NSimpleOma;
       
  1021 
       
  1022     HBufC* nodeContent = NULL;
       
  1023 
       
  1024     TInt count = aElems.Count();
       
  1025 
       
  1026     for ( TInt i = 0; i < count; i++ )
       
  1027         {
       
  1028         MSimpleElement* elem = aElems[i];
       
  1029         TPtrC8 p8( elem->LocalName());
       
  1030         if (!( p8.CompareF( KSimpleWatcher8 )))
       
  1031             {
       
  1032             const TDesC8* pp8 = elem->AttrValue( KSimpleStatus8 );
       
  1033             // Active wathers here
       
  1034             if ( pp8 && !pp8->CompareF( KSimpleActive8 ))
       
  1035                 {
       
  1036 
       
  1037                 // save id since there may be multiple subscriptions
       
  1038                 // from a single watcher SIP identity.
       
  1039                 const TDesC8* pId8 = elem->AttrValue( KSimpleId8 );
       
  1040 
       
  1041                 // Build collection of grant requests
       
  1042                 // Find the child node containing the SIP entity
       
  1043                 nodeContent = elem->ContentUnicodeL();
       
  1044                 CleanupStack::PushL( nodeContent );         // << nodeContent
       
  1045 
       
  1046                 AddWatcherIfNotExistsL( pId8 ? *pId8 : KNullDesC8, nodeContent->Des() );
       
  1047 
       
  1048                 CleanupStack::PopAndDestroy( nodeContent ); // >> nodeContent
       
  1049                 }
       
  1050             // Terminated wathers here, remove them from active list
       
  1051             else if ( pp8 && !pp8->CompareF( KSimpleTerminated8 ))
       
  1052                 {
       
  1053 
       
  1054                 const TDesC8* pId8 = elem->AttrValue( KSimpleId8 );
       
  1055 
       
  1056                 // Remove terminated from iWatcherList
       
  1057                 nodeContent = elem->ContentUnicodeL();
       
  1058                 CleanupStack::PushL( nodeContent );             // << nodeContent
       
  1059 
       
  1060                 RemoveWatcherIfExistsL( pId8 ? *pId8 : KNullDesC8, nodeContent->Des() );
       
  1061 
       
  1062                 CleanupStack::PopAndDestroy( nodeContent );     // >> nodeContent
       
  1063                 }
       
  1064             }
       
  1065         }
       
  1066 
       
  1067     }
       
  1068 
       
  1069 
       
  1070 
       
  1071 // End of file