presadap12/impsplugin/src/presentitygroups/cremovepresentitygroupmemberrequest.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 "CRemovePresentityGroupMemberRequest.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 <protocolpresencedatahost.h>
       
    36 #include <ximpobjectcollection.h>
       
    37 #include <protocolpresentitygroupsdatahost.h>
       
    38 #include <presentitygroupinfo.h>
       
    39 #include <presentitygroupmemberinfo.h>
       
    40 #include <ximpidentity.h>
       
    41 #include <ximpdatasubscriptionstate.h>
       
    42 #include "PImpsAdapXMLTools.h"
       
    43 
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CRemovePresentityGroupMemberRequest::CRemovePresentityGroupMemberRequest
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CRemovePresentityGroupMemberRequest::CRemovePresentityGroupMemberRequest(
       
    52     MImpsPrtPluginConnectionManager& aConnMan,
       
    53     TXIMPRequestId aRequestId ) :
       
    54         CActive( EPriorityNormal ),
       
    55         iRequestId( aRequestId ),
       
    56         iConnMan( aConnMan )
       
    57     {
       
    58     IMPS_DP( D_IMPS_LIT( "::CRemovePresentityGroupMemberRequest Start" ) );
       
    59     CActiveScheduler::Add( this );
       
    60 
       
    61     IMPS_DP( D_IMPS_LIT( "::CRemovePresentityGroupMemberRequest End" ) );
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CRemovePresentityGroupMemberRequest::ConstructL
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CRemovePresentityGroupMemberRequest::ConstructL()
       
    70     {
       
    71     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::ConstructL Start" ) );
       
    72 
       
    73     iParser = CreateXMLParserL();
       
    74     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::ConstructL End" ) );
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CRemovePresentityGroupMemberRequest::NewL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CRemovePresentityGroupMemberRequest* CRemovePresentityGroupMemberRequest::NewL(
       
    83     MImpsPrtPluginConnectionManager& aConnMan,
       
    84     TXIMPRequestId aRequestId )
       
    85     {
       
    86     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::NewL Start" ) );
       
    87 
       
    88     CRemovePresentityGroupMemberRequest* self = new( ELeave )
       
    89     CRemovePresentityGroupMemberRequest( aConnMan, aRequestId );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL();
       
    92     CleanupStack::Pop( self );
       
    93 
       
    94     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::NewL End" ) );
       
    95     return self;
       
    96     }
       
    97 
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CRemovePresentityGroupMemberRequest::NewLC
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 CRemovePresentityGroupMemberRequest* CRemovePresentityGroupMemberRequest::NewLC(
       
   104     MImpsPrtPluginConnectionManager& aConnMan,
       
   105     TXIMPRequestId aRequestId )
       
   106     {
       
   107     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::NewLC Start" ) );
       
   108 
       
   109     CRemovePresentityGroupMemberRequest* self =
       
   110         CRemovePresentityGroupMemberRequest::NewL( aConnMan, aRequestId );
       
   111     CleanupStack::PushL( self );
       
   112 
       
   113     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::NewLC End" ) );
       
   114     return self;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CRemovePresentityGroupMemberRequest::~CRemovePresentityGroupMemberRequest
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 CRemovePresentityGroupMemberRequest::~CRemovePresentityGroupMemberRequest()
       
   122     {
       
   123     IMPS_DP( D_IMPS_LIT( "::~CRemovePresentityGroupMemberRequest Start" ) );
       
   124 
       
   125     delete iResponse;
       
   126     CActive::Cancel();
       
   127     iConnMan.Remove( this );
       
   128 
       
   129     delete iGroupName;
       
   130     delete iMemberName;
       
   131     delete iParser;
       
   132 
       
   133     IMPS_DP( D_IMPS_LIT( "::~CRemovePresentityGroupMemberRequest End" ) );
       
   134     }
       
   135 
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CRemovePresentityGroupMemberRequest::DoCancel()
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CRemovePresentityGroupMemberRequest::DoCancel()
       
   142     {
       
   143     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::DoCancel Start" ) );
       
   144 
       
   145     iConnMan.DataHandler().CancelSending( iSendId );
       
   146 
       
   147     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::DoCancel End" ) );
       
   148     }
       
   149 
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CRemovePresentityGroupMemberRequest::RunL()
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CRemovePresentityGroupMemberRequest::RunL()
       
   156     {
       
   157     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RunL Start" ) );
       
   158 
       
   159     User::LeaveIfError( iStatus.Int() );
       
   160 
       
   161     iResponse = iConnMan.DataHandler().ResponseL( iSendId );
       
   162 
       
   163     TPtrC8 resultBlock( NULL, 0 );
       
   164     TInt wvErrorCode = KErrNone;
       
   165 
       
   166     //Look for mandatory parts
       
   167     if ( iParser->DecodeL( *iResponse, KResultXMLTag, ETrue ) )
       
   168         {
       
   169         resultBlock.Set( iParser->ResultL() );
       
   170         if ( iParser->DecodeL( resultBlock, KCodeXMLTag, EFalse ) )
       
   171             {
       
   172             TPtrC8 cspStatusCodeBlock( iParser->ResultL() );
       
   173             TInt cspStatusInt;
       
   174             TLex8 lexer( cspStatusCodeBlock );
       
   175             lexer.SkipSpace();
       
   176             TInt lexErr = lexer.Val( cspStatusInt );
       
   177             if ( lexErr == KErrNone )
       
   178                 {
       
   179                 wvErrorCode = cspStatusInt;
       
   180                 }
       
   181             }
       
   182         }
       
   183 
       
   184     IMPS_DP( D_IMPS_LIT( " RemovePresentityGroupMemberRequest wvErrorCode %d " ), wvErrorCode );
       
   185 
       
   186 
       
   187     // issue request to prfw to update datacache so that
       
   188     // client can receive the event
       
   189     if ( KWVRequestResponseResultCode == wvErrorCode )
       
   190         {
       
   191         MXIMPObjectFactory& prfwObjFact = iConnMan.HandleToHost().ObjectFactory();
       
   192         MXIMPIdentity* groupName = prfwObjFact.NewIdentityLC();
       
   193         MXIMPIdentity* memberName = prfwObjFact.NewIdentityLC();
       
   194 
       
   195         groupName->SetIdentityL( *iGroupName );
       
   196         memberName->SetIdentityL( *iMemberName );
       
   197 
       
   198         IMPS_DP( D_IMPS_LIT( "------------------------------------------------------------------" ) );
       
   199 
       
   200         IMPS_DP( D_IMPS_LIT( "---------------------Data from presadap1.2 to PresenceFramework-----------" ) );
       
   201 
       
   202         IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RunL:GroupId:%S " ), iGroupName );
       
   203 
       
   204         IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RunL:GroupMemberName:%S " ), iMemberName );
       
   205 
       
   206         IMPS_DP( D_IMPS_LIT( "------------------------------------------------------------------" ) );
       
   207 
       
   208         iConnMan.HandleToHost().ProtocolPresenceDataHost().GroupsDataHost().HandlePresentityGroupMemberRemovedL(
       
   209             groupName, memberName );
       
   210         CleanupStack::Pop( 2 ); // groupName, memberName
       
   211         }
       
   212 
       
   213     // issue request complete to prfw
       
   214     if ( wvErrorCode == KWVRequestResponseResultCode )
       
   215         {
       
   216         wvErrorCode = KErrNone;
       
   217         }
       
   218     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, wvErrorCode );
       
   219 
       
   220     delete this;
       
   221     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RunL End" ) );
       
   222     }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CRemovePresentityGroupMemberRequest::RunError
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 TInt CRemovePresentityGroupMemberRequest::RunError( TInt  aError )
       
   230     {
       
   231     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RunError Start" ) );
       
   232 
       
   233     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError );
       
   234 
       
   235     delete this;
       
   236     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RunError End" ) );
       
   237     return KErrNone;
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // CRemovePresentityGroupMemberRequest::RemovePresentityGroupMemberL
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CRemovePresentityGroupMemberRequest::RemovePresentityGroupMemberL(
       
   245     const MXIMPIdentity& aGroupId,
       
   246     const MXIMPIdentity& aMemberId )
       
   247     {
       
   248 
       
   249     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RemovePresentityGroupMemberL Start" ) );
       
   250 
       
   251     IMPS_DP( D_IMPS_LIT( "------------------------------------------------------------------" ) );
       
   252 
       
   253     IMPS_DP( D_IMPS_LIT( "---------------------Data from framework to presadap1.2-----------" ) );
       
   254 
       
   255     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RemovePresentityGroupMemberL:GroupId:%S " ), & aGroupId.Identity() );
       
   256 
       
   257     IMPS_DP( D_IMPS_LIT( "CRemovePresentityGroupMemberRequest::RemovePresentityGroupMemberL:MemberId:%S " ), & aMemberId.Identity() );
       
   258 
       
   259     TPtr8 ptrbuffer( iConnMan.DataHandler().TransferBufferL() );
       
   260     MPEngXMLSerializer* serializer = CreateXmlSerializerLC( ptrbuffer );
       
   261 
       
   262     iGroupName = aGroupId.Identity().AllocL();
       
   263     iMemberName = aMemberId.Identity().AllocL();
       
   264 
       
   265     NImpsAdapXMLTools::AppendTransactionContentTagXmlL( *serializer, iConnMan.GetVersion() );
       
   266 
       
   267     serializer->StartTagL( KListMnageRequest );
       
   268     if ( KErrNone == iGroupName->Left( KPEngAttrWVIdPrefixLength ).CompareF( KPengWVIDPrefix ) )
       
   269         {
       
   270         serializer->StartTagL( KContactList
       
   271                              ).WvAddressL( aGroupId.Identity()
       
   272                                          ).EndTagL( KContactList );
       
   273         }
       
   274 
       
   275 
       
   276     else
       
   277         {
       
   278         serializer->StartTagL( KContactList
       
   279                              ).NarrowTextL( KWVXMLTag
       
   280                                           ).WvAddressL( aGroupId.Identity()
       
   281                                                       ).EndTagL( KContactList );
       
   282         }
       
   283 
       
   284     serializer->StartTagL( KRemoveNickList );
       
   285 
       
   286     // <UserID>
       
   287     // contact Id
       
   288     // </UserID>
       
   289     // </NickName>
       
   290     if ( KErrNone == iMemberName->Left( KPEngAttrWVIdPrefixLength ).CompareF( KPengWVIDPrefix ) )
       
   291         {
       
   292         serializer->StartTagL( KUserIDXMLTag
       
   293                              ).WvAddressL( aMemberId.Identity()
       
   294                                          ).EndTagL( KUserIDXMLTag
       
   295                                                   );
       
   296         }
       
   297 
       
   298 
       
   299     else
       
   300         {
       
   301         serializer->StartTagL( KUserIDXMLTag
       
   302                              ).NarrowTextL( KWVXMLTag
       
   303                                           ).WvAddressL( aMemberId.Identity()
       
   304                                                       ).EndTagL( KUserIDXMLTag
       
   305                                                                );
       
   306         }
       
   307 
       
   308 
       
   309     serializer->EndTagL( KRemoveNickList );
       
   310 
       
   311     serializer->StartTagL( KReceiveList ).NarrowTextL( KXMLValueFalse ).EndTagL( KReceiveList );
       
   312 
       
   313     serializer->EndTagL( KListMnageRequest );
       
   314     serializer->EndTagL( KTransactionContent );
       
   315 
       
   316     CleanupStack::PopAndDestroy(); //serializer
       
   317 
       
   318     iSendId = iConnMan.DataHandler().SendDataL( iStatus );
       
   319 
       
   320     IMPS_DP( D_IMPS_LIT( " SendData Request id %d " ), iSendId );
       
   321 
       
   322     // signal the scheduler
       
   323     SetActive();
       
   324 
       
   325     IMPS_DP( D_IMPS_LIT( "::RemovePresentityGroupMemberL End" ) );
       
   326     }
       
   327 
       
   328 // End of file