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