presadap12/impsplugin/src/presencepublishing/csubscribeownpresencerequest.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 "CSubscribeOwnPresenceRequest.h"
       
    21 #include "impsconnectionmanagercontrolif.h"
       
    22 #include "impsdebugprint.h"
       
    23 #include "CImpsPluginAccessHandler.h"
       
    24 #include "CImpsPluginPureDataHandler.h"
       
    25 #include <presenceinfo.h>
       
    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 <servicepresenceinfo.h>
       
    42 #include <personpresenceinfo.h>
       
    43 #include <presenceinfofield.h>
       
    44 #include <presenceinfofieldcollection.h>
       
    45 #include <presenceinfofieldvalueenum.h>
       
    46 #include <presenceinfofieldvaluetext.h>
       
    47 #include <servicepresenceinfo.h>
       
    48 #include <personpresenceinfo.h>
       
    49 #include "CPresenceNotificationHandler.h"
       
    50 
       
    51 
       
    52 #include "PImpsAdapXMLTools.h"
       
    53 
       
    54 // ======== MEMBER FUNCTIONS ========
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CSubscribeOwnPresenceRequest::CSubscribeOwnPresenceRequest
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CSubscribeOwnPresenceRequest::CSubscribeOwnPresenceRequest(
       
    61     MImpsPrtPluginConnectionManager& aConnMan,
       
    62     TXIMPRequestId aRequestId ) :
       
    63         CActive( EPriorityNormal ),
       
    64         iRequestId( aRequestId ),
       
    65         iConnMan( aConnMan )
       
    66     {
       
    67     IMPS_DP( D_IMPS_LIT( "::CSubscribeOwnPresenceRequest Start" ) );
       
    68     CActiveScheduler::Add( this );
       
    69 
       
    70     IMPS_DP( D_IMPS_LIT( "::CSubscribeOwnPresenceRequest End" ) );
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CSubscribeOwnPresenceRequest::ConstructL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CSubscribeOwnPresenceRequest::ConstructL()
       
    79     {
       
    80     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::ConstructL Start-End" ) );
       
    81 
       
    82     iParser = CreateXMLParserL();
       
    83 
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CSubscribeOwnPresenceRequest::NewL
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 CSubscribeOwnPresenceRequest* CSubscribeOwnPresenceRequest::NewL(
       
    92     MImpsPrtPluginConnectionManager& aConnMan,
       
    93     TXIMPRequestId aRequestId )
       
    94     {
       
    95     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::NewL Start" ) );
       
    96 
       
    97     CSubscribeOwnPresenceRequest* self = new( ELeave )
       
    98     CSubscribeOwnPresenceRequest( aConnMan, aRequestId );
       
    99     CleanupStack::PushL( self );
       
   100     self->ConstructL();
       
   101     CleanupStack::Pop( self );
       
   102 
       
   103     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::NewL End" ) );
       
   104     return self;
       
   105     }
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CSubscribeOwnPresenceRequest::NewLC
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 CSubscribeOwnPresenceRequest* CSubscribeOwnPresenceRequest::NewLC(
       
   113     MImpsPrtPluginConnectionManager& aConnMan,
       
   114     TXIMPRequestId aRequestId )
       
   115     {
       
   116     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::NewLC Start" ) );
       
   117 
       
   118     CSubscribeOwnPresenceRequest* self =
       
   119         CSubscribeOwnPresenceRequest::NewL( aConnMan, aRequestId );
       
   120     CleanupStack::PushL( self );
       
   121 
       
   122     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::NewLC End" ) );
       
   123     return self;
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CSubscribeOwnPresenceRequest::~CSubscribeOwnPresenceRequest
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 CSubscribeOwnPresenceRequest::~CSubscribeOwnPresenceRequest()
       
   131     {
       
   132     IMPS_DP( D_IMPS_LIT( "::~CSubscribeOwnPresenceRequest Start" ) );
       
   133 
       
   134     CActive::Cancel();
       
   135     iConnMan.Remove( this );
       
   136     delete iParser;
       
   137 
       
   138     IMPS_DP( D_IMPS_LIT( "::~CSubscribeOwnPresenceRequest End" ) );
       
   139     }
       
   140 
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CSubscribeOwnPresenceRequest::DoCancel()
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CSubscribeOwnPresenceRequest::DoCancel()
       
   147     {
       
   148     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::DoCancel Start" ) );
       
   149 
       
   150     iConnMan.DataHandler().CancelSending( iSendId );
       
   151 
       
   152     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::DoCancel End" ) );
       
   153     }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CSubscribeOwnPresenceRequest::RunL()
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void CSubscribeOwnPresenceRequest::RunL()
       
   161     {
       
   162     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::RunL Start" ) );
       
   163 
       
   164     User::LeaveIfError( iStatus.Int() );
       
   165 
       
   166 //	iResponse = iConnMan.DataHandler().ResponseL( iSendId );
       
   167     HBufC8* response = iConnMan.DataHandler().ResponseL( iSendId );
       
   168     CleanupStack::PushL( response );
       
   169     TPtrC8 resultBlock( NULL, 0 );
       
   170     TInt wvErrorCode = KErrNone;
       
   171 
       
   172     // Check if we got 200
       
   173     if ( iParser->DecodeL( *response, KResultXMLTag, ETrue ) )
       
   174         {
       
   175         resultBlock.Set( iParser->ResultL() );
       
   176         if ( iParser->DecodeL( resultBlock, KCodeXMLTag, EFalse ) )
       
   177             {
       
   178             TPtrC8 cspStatusCodeBlock( iParser->ResultL() );
       
   179             TInt cspStatusInt;
       
   180             TLex8 lexer( cspStatusCodeBlock );
       
   181             lexer.SkipSpace();
       
   182             TInt lexErr = lexer.Val( cspStatusInt );
       
   183             if ( lexErr == KErrNone )
       
   184                 {
       
   185                 wvErrorCode = cspStatusInt;
       
   186                 }
       
   187             }
       
   188         }
       
   189 
       
   190     CleanupStack::PopAndDestroy( response );
       
   191 
       
   192     IMPS_DP( D_IMPS_LIT( " SubscribeOwnPresenceL::wvErrorCode %d" ), wvErrorCode );
       
   193 
       
   194     // Make request complete over here.
       
   195     if ( wvErrorCode == KWVRequestResponseResultCode )
       
   196         {
       
   197         wvErrorCode = KErrNone;
       
   198         }
       
   199     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, wvErrorCode );
       
   200 
       
   201     delete this;
       
   202     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::RunL End" ) );
       
   203     }
       
   204 
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CSubscribeOwnPresenceRequest::RunError
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 TInt CSubscribeOwnPresenceRequest::RunError( TInt  aError )
       
   211     {
       
   212     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::RunError Start" ) );
       
   213 
       
   214     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError );
       
   215 
       
   216     delete this;
       
   217     IMPS_DP( D_IMPS_LIT( "CSubscribeOwnPresenceRequest::RunError End" ) );
       
   218     return KErrNone;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CSubscribeOwnPresenceRequest::SubscribeOwnPresenceL
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CSubscribeOwnPresenceRequest::SubscribeOwnPresenceL( const MPresenceInfoFilter& aPif )
       
   226     {
       
   227     IMPS_DP( D_IMPS_LIT( "::SubscribeOwnPresenceL Start" ) );
       
   228 
       
   229     TPtr8 ptrbuffer( iConnMan.DataHandler().TransferBufferL() );
       
   230     MPEngXMLSerializer* serializer = CreateXmlSerializerLC( ptrbuffer );
       
   231 
       
   232     NImpsAdapXMLTools::AppendTransactionContentTagXmlL( *serializer, iConnMan.GetVersion() );
       
   233 
       
   234     serializer->StartTagL( KSubscribePresence );
       
   235     //<User>
       
   236     // <UserID>
       
   237     // Contact ID
       
   238     // </UserID>
       
   239     //</User>
       
   240     // userId or contactlist Id or both are allowed
       
   241     serializer->StartTagL( KUser );
       
   242     serializer->StartTagL( KUserIDXMLTag
       
   243                          ).NarrowTextL( KWVXMLTag
       
   244                                       ).WvAddressL( iConnMan.UserName()
       
   245                                                   ).EndTagL( KUserIDXMLTag );
       
   246     serializer->EndTagL( KUser );
       
   247     serializer->StartTagL( KPresenceSubList );
       
   248     serializer->AttributeL( KXmlXmlns, KPresenceSubListAttributesNS_CSP12 );
       
   249 
       
   250     // fetch attributes from the pif and send it over to the server
       
   251     TBool statusmessage = aPif.MatchPersonFilter( NPresenceInfo::NFieldType::KStatusMessage );
       
   252     TBool availability = aPif.MatchPersonFilter( NPresenceInfo::NFieldType::KAvailability );
       
   253     TBool allattributes = aPif.MatchPersonFilter( NPresenceInfo::NFieldType::KAcceptAll );
       
   254 
       
   255     if ( !allattributes )
       
   256         {
       
   257         if ( statusmessage )
       
   258             {
       
   259             serializer->StartTagL( KStatusMood ).EndTagL( KStatusMood );
       
   260             serializer->StartTagL( KOnlineStatusXMLTag ).EndTagL( KOnlineStatusXMLTag );
       
   261             serializer->StartTagL( KStatusTextXMLTag ).EndTagL( KStatusTextXMLTag );
       
   262             serializer->StartTagL( KStatusContentXMLTag ).EndTagL( KStatusContentXMLTag );
       
   263             }
       
   264         if ( availability )
       
   265             {
       
   266             serializer->StartTagL( KUserAvailabilityXMLTag ).EndTagL( KUserAvailabilityXMLTag );
       
   267             }
       
   268         }
       
   269 
       
   270     serializer->EndTagL( KPresenceSubList );
       
   271 
       
   272     serializer->StartTagL( KAutoSubscribe ).NarrowTextL( KXMLValueTrue ).EndTagL( KAutoSubscribe );
       
   273 
       
   274     serializer->EndTagL( KSubscribePresence );
       
   275     serializer->EndTagL( KTransactionContent );
       
   276 
       
   277     CleanupStack::PopAndDestroy(); //serializer
       
   278 
       
   279 
       
   280     iSendId = iConnMan.DataHandler().SendDataL( iStatus );
       
   281 
       
   282     IMPS_DP( D_IMPS_LIT( " SendData Request id %d " ), iSendId );
       
   283     // signal the scheduler
       
   284     SetActive();
       
   285 
       
   286     IMPS_DP( D_IMPS_LIT( "::SubscribeOwnPresenceL End" ) );
       
   287     }
       
   288 
       
   289 // End of file