presadap12/impsplugin/src/presencepublishing/csubscribepresentitypresencerequest.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     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:  IMPS Protocol implementation for Presence Framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ximpprotocolconnectionhost.h>
       
    20 #include "CSubscribePresentityPresenceRequest.h"
       
    21 #include "impsconnectionmanagercontrolif.h"
       
    22 #include "impsdebugprint.h"
       
    23 #include "CImpsPluginAccessHandler.h"
       
    24 #include "CImpsPluginPureDataHandler.h"
       
    25 
       
    26 
       
    27 #include "CPEngXMLParser.h"
       
    28 #include "MPEngXMLParser.h"
       
    29 #include "CPEngXmlSerializer.h"
       
    30 #include "MPEngXmlSerializer.h"
       
    31 #include "CImpsPluginConnectionManager.h"
       
    32 #include "PEngXMLTags.h"
       
    33 
       
    34 #include <ximpobjectfactory.h>
       
    35 #include <ximpobjectcollection.h>
       
    36 #include <protocolpresentitygroupsdatahost.h>
       
    37 #include <presentitygroupinfo.h>
       
    38 #include <presentitygroupmemberinfo.h>
       
    39 #include <ximpidentity.h>
       
    40 #include <presenceinfofilter.h>
       
    41 #include "PImpsAdapXMLTools.h"
       
    42 #include "CPresenceNotificationHandler.h"
       
    43 
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CSubscribePresentityPresenceRequest::CSubscribePresentityPresenceRequest
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CSubscribePresentityPresenceRequest::CSubscribePresentityPresenceRequest( MImpsPrtPluginConnectionManager& aConnMan,
       
    52                                                                           TXIMPRequestId aRequestId ) :
       
    53         CActive( EPriorityNormal ),
       
    54         iRequestId( aRequestId ),
       
    55         iConnMan( aConnMan )
       
    56     {
       
    57     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::CSubscribePresentityPresenceRequest Start" ) );
       
    58     CActiveScheduler::Add( this );
       
    59 
       
    60     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::CSubscribePresentityPresenceRequest End" ) );
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CSubscribePresentityPresenceRequest::ConstructL
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CSubscribePresentityPresenceRequest::ConstructL()
       
    69     {
       
    70     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::ConstructL Start-End" ) );
       
    71 
       
    72     iParser = CreateXMLParserL();
       
    73     iConnMan.PresNotifier()->StartListeningL();
       
    74 
       
    75 
       
    76     }
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CSubscribePresentityPresenceRequest::NewL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CSubscribePresentityPresenceRequest* CSubscribePresentityPresenceRequest::NewL(
       
    84     MImpsPrtPluginConnectionManager& aConnMan,
       
    85     TXIMPRequestId aRequestId )
       
    86     {
       
    87     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::NewL Start" ) );
       
    88 
       
    89     CSubscribePresentityPresenceRequest* self = new( ELeave )
       
    90     CSubscribePresentityPresenceRequest( aConnMan, aRequestId );
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL();
       
    93     CleanupStack::Pop( self );
       
    94 
       
    95     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::NewL End" ) );
       
    96     return self;
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CSubscribePresentityPresenceRequest::NewLC
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CSubscribePresentityPresenceRequest* CSubscribePresentityPresenceRequest::NewLC(
       
   105     MImpsPrtPluginConnectionManager& aConnMan,
       
   106     TXIMPRequestId aRequestId )
       
   107     {
       
   108     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::NewLC Start" ) );
       
   109 
       
   110     CSubscribePresentityPresenceRequest* self = new( ELeave )
       
   111     CSubscribePresentityPresenceRequest( aConnMan, aRequestId );
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114 
       
   115     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::NewLC End" ) );
       
   116     return self;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CSubscribePresentityPresenceRequest::~CSubscribePresentityPresenceRequest
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 CSubscribePresentityPresenceRequest::~CSubscribePresentityPresenceRequest()
       
   124     {
       
   125     IMPS_DP( D_IMPS_LIT( "::~CSubscribePresentityPresenceRequest Start" ) );
       
   126 
       
   127     delete iResponse;
       
   128     CActive::Cancel();
       
   129     iConnMan.Remove( this );
       
   130     delete iParser;
       
   131 
       
   132     IMPS_DP( D_IMPS_LIT( "::~CSubscribePresentityPresenceRequest End" ) );
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CSubscribePresentityPresenceRequest::DoCancel()
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CSubscribePresentityPresenceRequest::DoCancel()
       
   141     {
       
   142     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::DoCancel Start" ) );
       
   143 
       
   144     iConnMan.DataHandler().CancelSending( iSendId );
       
   145 
       
   146     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::DoCancel End" ) );
       
   147     }
       
   148 
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CSubscribePresentityPresenceRequest::RunL()
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CSubscribePresentityPresenceRequest::RunL()
       
   155     {
       
   156     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::RunL Start" ) );
       
   157 
       
   158     User::LeaveIfError( iStatus.Int() );
       
   159 
       
   160     iResponse = iConnMan.DataHandler().ResponseL( iSendId );
       
   161 
       
   162     TPtrC8 resultBlock( NULL, 0 );
       
   163     TInt wvErrorCode = KErrNone;
       
   164 
       
   165     // Check if we got 200
       
   166     if ( iParser->DecodeL( *iResponse, KResultXMLTag, ETrue ) )
       
   167         {
       
   168         resultBlock.Set( iParser->ResultL() );
       
   169         if ( iParser->DecodeL( resultBlock, KCodeXMLTag, EFalse ) )
       
   170             {
       
   171             TPtrC8 cspStatusCodeBlock( iParser->ResultL() );
       
   172             TInt cspStatusInt;
       
   173             TLex8 lexer( cspStatusCodeBlock );
       
   174             lexer.SkipSpace();
       
   175             TInt lexErr = lexer.Val( cspStatusInt );
       
   176             if ( lexErr == KErrNone )
       
   177                 {
       
   178                 wvErrorCode = cspStatusInt;
       
   179                 }
       
   180             }
       
   181         }
       
   182 
       
   183     // we have to process notifications for this from the server
       
   184 
       
   185     IMPS_DP( D_IMPS_LIT( " SubscribePresentityPresenceL::wvErrorCode %d" ), wvErrorCode );
       
   186 
       
   187     // Make request complete over here.
       
   188     if ( wvErrorCode == 200 )
       
   189         {
       
   190         wvErrorCode = KErrNone;
       
   191         }
       
   192     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, wvErrorCode );
       
   193 
       
   194     delete this;
       
   195     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::RunL End" ) );
       
   196     }
       
   197 
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CSubscribePresentityPresenceRequest::RunError
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 TInt CSubscribePresentityPresenceRequest::RunError( TInt  aError )
       
   204     {
       
   205     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::RunError Start" ) );
       
   206 
       
   207     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError );
       
   208 
       
   209     delete this;
       
   210     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::RunError End" ) );
       
   211     return KErrNone;
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CSubscribePresentityPresenceRequest::SubscribePresentityPresenceL
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CSubscribePresentityPresenceRequest::SubscribePresentityPresenceL(
       
   219     const MXIMPIdentity& aIdentity,
       
   220     const MPresenceInfoFilter& aPif )
       
   221     {
       
   222     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::SubscribePresentityPresenceL Start" ) );
       
   223 
       
   224     TPtr8 ptrbuffer( iConnMan.DataHandler().TransferBufferL() );
       
   225     MPEngXMLSerializer* serializer = CreateXmlSerializerLC( ptrbuffer );
       
   226 
       
   227     IMPSPRTPLUGIN_UNUSED_PARAM( aPif );
       
   228 
       
   229     IMPS_DP( D_IMPS_LIT( "SubscribePresentityPresenceL Manufacture XML " ) );
       
   230 
       
   231     //serializer->StartTagL(KTransactionContent);
       
   232     //serializer->AttributeL( KXmlXmlns, KTransactionContentNS_CSP12 );
       
   233     NImpsAdapXMLTools::AppendTransactionContentTagXmlL( *serializer, iConnMan.GetVersion() );
       
   234 
       
   235     serializer->StartTagL( KSubscribePresence );
       
   236     //<User>
       
   237     // <UserID>
       
   238     // Contact ID
       
   239     // </UserID>
       
   240     //</User>
       
   241     // userId or contactlist Id or both are allowed
       
   242     serializer->StartTagL( KUser );
       
   243     serializer->StartTagL( KUserIDXMLTag
       
   244                          ).NarrowTextL( KWVXMLTag
       
   245                                       ).WvAddressL( aIdentity.Identity()
       
   246                                                   ).EndTagL( KUserIDXMLTag );
       
   247     serializer->EndTagL( KUser );
       
   248     // if attribute list is not present all attributes are requested
       
   249     serializer->StartTagL( KAutoSubscribe ).NarrowTextL( KXMLValueTrue ).EndTagL( KAutoSubscribe );
       
   250 
       
   251     serializer->EndTagL( KSubscribePresence );
       
   252     serializer->EndTagL( KTransactionContent );
       
   253 
       
   254     CleanupStack::PopAndDestroy(); //serializer
       
   255 
       
   256 
       
   257     iSendId = iConnMan.DataHandler().SendDataL( iStatus );
       
   258 
       
   259     IMPS_DP( D_IMPS_LIT( " SendData Request id %d " ), iSendId );
       
   260     // signal the scheduler
       
   261     SetActive();
       
   262 
       
   263     IMPS_DP( D_IMPS_LIT( "CSubscribePresentityPresenceRequest::SubscribePresentityPresenceL End" ) );
       
   264     }
       
   265 
       
   266 // End of file