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