imservices/ossprotocoladaptation/src/presentitygroups/cremovepresentitygroupmemberrequest.cpp
branchRCL_3
changeset 14 7797b2f86d2b
parent 13 b6f2a363adf7
child 16 cfe5eb8bb9ca
equal deleted inserted replaced
13:b6f2a363adf7 14:7797b2f86d2b
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Remove presentity group member request to the network server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ximpprotocolconnectionhost.h>
       
    20 #include "cremovepresentitygroupmemberrequest.h"
       
    21 #include "mossprotocolconnectionmanager.h"
       
    22 #include "cossprotocolconnectionmanager.h"
       
    23 #include "ossprotocolpluginlogger.h"
       
    24 
       
    25 #include <ximpobjectfactory.h>
       
    26 #include <protocolpresencedatahost.h>
       
    27 #include <ximpobjectcollection.h>
       
    28 #include <protocolpresentitygroupsdatahost.h>
       
    29 #include <presentitygroupinfo.h>
       
    30 #include <presentitygroupmemberinfo.h>
       
    31 #include <ximpidentity.h>
       
    32 #include <ximpdatasubscriptionstate.h>
       
    33 
       
    34 #include <glib/gstrfuncs.h>
       
    35 #include <gtypes.h>
       
    36 #include <stdlib.h>
       
    37 #include "stringutils.h"
       
    38 #include <string.h>
       
    39 #include <sys/types.h>
       
    40 #include <stdio.h>
       
    41 #include <glib/gprintf.h>
       
    42 #include "msgliterals.h"
       
    43 #include "msg_enums.h"
       
    44 #include "ossprotocoladaptutils.h"
       
    45 
       
    46 // ======== MEMBER FUNCTIONS ========
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CRemovePresentityGroupMemberRequest::CRemovePresentityGroupMemberRequest
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CRemovePresentityGroupMemberRequest::CRemovePresentityGroupMemberRequest( 
       
    53 					MOSSProtocolConnectionManager& aConnMan,
       
    54 					TXIMPRequestId aRequestId ) :
       
    55     CActive( EPriorityNormal ),
       
    56     iRequestId( aRequestId ),
       
    57     iConnMan( aConnMan )
       
    58     {
       
    59     LOGGER ( TXT("::CRemovePresentityGroupMemberRequest Start") );
       
    60     CActiveScheduler::Add( this );
       
    61     
       
    62     LOGGER ( TXT("::CRemovePresentityGroupMemberRequest End") );
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CRemovePresentityGroupMemberRequest::ConstructL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CRemovePresentityGroupMemberRequest::ConstructL()
       
    71     {
       
    72     LOGGER ( TXT("CRemovePresentityGroupMemberRequest::ConstructL Start") );
       
    73     iUserId = NULL;
       
    74 	LOGGER ( TXT("CRemovePresentityGroupMemberRequest::ConstructL End") );
       
    75     }
       
    76 
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CRemovePresentityGroupMemberRequest::NewLC
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CRemovePresentityGroupMemberRequest* CRemovePresentityGroupMemberRequest::NewLC(
       
    84     MOSSProtocolConnectionManager& aConnMan,
       
    85     TXIMPRequestId aRequestId )
       
    86     {
       
    87     LOGGER ( TXT("CRemovePresentityGroupMemberRequest::NewLC Start") );
       
    88     
       
    89     CRemovePresentityGroupMemberRequest* self = new( ELeave ) 
       
    90     			CRemovePresentityGroupMemberRequest( aConnMan, aRequestId );
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL();
       
    93   
       
    94        
       
    95     LOGGER ( TXT("CRemovePresentityGroupMemberRequest::NewLC End") );
       
    96     return self;
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CRemovePresentityGroupMemberRequest::~CRemovePresentityGroupMemberRequest
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 CRemovePresentityGroupMemberRequest::~CRemovePresentityGroupMemberRequest()
       
   104     {
       
   105     LOGGER ( TXT("::~CRemovePresentityGroupMemberRequest Start") );
       
   106    
       
   107 	CActive::Cancel();
       
   108     delete iUserId;
       
   109     LOGGER ( TXT("::~CRemovePresentityGroupMemberRequest End") );
       
   110     }
       
   111 
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CRemovePresentityGroupMemberRequest::DoCancel()
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CRemovePresentityGroupMemberRequest::DoCancel()
       
   118     {
       
   119     LOGGER ( TXT("CRemovePresentityGroupMemberRequest::DoCancel Start") );
       
   120   
       
   121     LOGGER ( TXT("CRemovePresentityGroupMemberRequest::DoCancel End") );
       
   122     }
       
   123 
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CRemovePresentityGroupMemberRequest::RunL()
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CRemovePresentityGroupMemberRequest::RunL()
       
   130     {
       
   131     LOGGER ( TXT("CRemovePresentityGroupMemberRequest::RunL Start") );
       
   132     message_hdr_resp* msg_struct = NULL;
       
   133     char* pResponse = NULL;  
       
   134 	User::LeaveIfError( iStatus.Int() );
       
   135    
       
   136 	pResponse = iConnMan.DataHandler().ResponseL ( iSendId );
       
   137 	
       
   138 	msg_struct = ( message_hdr_resp* )pResponse ;
       
   139 	if( !( msg_struct->response ))
       
   140 	{
       
   141 		switch( msg_struct->error_type )
       
   142 		{
       
   143 	
       
   144 		default:  //for all other error codes like ssl related are mapped to general error
       
   145 			   iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KXIMPErrServiceGeneralError );
       
   146 		       break;       
       
   147 		}	
       
   148 	}
       
   149 	else
       
   150 	{
       
   151          if( iUserId )
       
   152              {
       
   153              HBufC* sxpId = HBufC::NewLC( iConnMan.ServiceName().Length() + iUserId->Length() +1 );
       
   154              TPtr sxpIdPtr( sxpId->Des() );
       
   155         
       
   156              sxpIdPtr.Zero();
       
   157              sxpIdPtr.Append( iConnMan.ServiceName() );
       
   158              sxpIdPtr.Append(KColon);
       
   159              sxpIdPtr.Append( *iUserId );
       
   160              MPresenceCacheWriter2* presenceCacheWriter = MPresenceCacheWriter2::CreateWriterL();
       
   161              TInt cacheerror = presenceCacheWriter->DeletePresenceL( sxpIdPtr );
       
   162              User::LeaveIfError ( cacheerror);
       
   163              CleanupStack::PopAndDestroy(); // sxpId
       
   164              delete presenceCacheWriter;
       
   165              presenceCacheWriter = NULL;
       
   166              delete iUserId;
       
   167              iUserId = NULL;
       
   168              }
       
   169          iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KErrNone );
       
   170         }
       
   171 
       
   172 	free( pResponse );
       
   173 	delete this;
       
   174 	LOGGER ( TXT("CRemovePresentityGroupMemberRequest::RunL End") );
       
   175     }
       
   176 
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CRemovePresentityGroupMemberRequest::RunError
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 TInt CRemovePresentityGroupMemberRequest::RunError( TInt  aError )
       
   183     {
       
   184     LOGGER ( TXT("CRemovePresentityGroupMemberRequest::RunError Start") );
       
   185     
       
   186     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError );
       
   187     
       
   188     delete this;
       
   189 	LOGGER ( TXT("CRemovePresentityGroupMemberRequest::RunError End") );
       
   190     return KErrNone;
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // CRemovePresentityGroupMemberRequest::RemovePresentityGroupMemberL
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 void CRemovePresentityGroupMemberRequest::RemovePresentityGroupMemberL(
       
   198     const MXIMPIdentity& /*aGroupId*/,
       
   199     const MXIMPIdentity& aMemberId)
       
   200     {   
       
   201    
       
   202     LOGGER ( TXT("CRemovePresentityGroupMemberRequest::RemovePresentityGroupMemberL Start") );
       
   203 
       
   204 	int userLen=0;
       
   205 	int totalLen = 0;
       
   206 	iUserId = aMemberId.Identity().AllocL();
       
   207 
       
   208 	message_hdr_req msgHdr = {0,};	
       
   209     msgHdr.message_type = EDelete_Contact_Request;	
       
   210     
       
   211     TInt headerLength = sizeof( message_hdr_req );
       
   212 	totalLen += headerLength;
       
   213 	
       
   214 	// adding add contact
       
   215 	charFormatData tmpmsgData = OssProtocolAdapUtils::ConvertTUint16ToCharLC ( aMemberId.Identity() );
       
   216     char *tmpmsg = tmpmsgData.data;
       
   217     userLen = tmpmsgData.dataSize;
       
   218 	totalLen += userLen;
       
   219 	 
       
   220 	User::LeaveIfError ( totalLen > MAX_MSG_SIZE );
       
   221 
       
   222 	//now allocate memory.
       
   223 	char* smsg = ( char* ) User::AllocLC( totalLen );
       
   224 	memcpy( smsg, &msgHdr, headerLength );
       
   225 	memcpy ( smsg + headerLength, tmpmsg, userLen );
       
   226   
       
   227 	iSendId = iConnMan.DataHandler().SendDataL ( iStatus, smsg, totalLen );
       
   228 
       
   229 	// signal the scheduler
       
   230 	SetActive();
       
   231 
       
   232 	CleanupStack::PopAndDestroy ( 2 );//smsg, tmpmsg.
       
   233   	
       
   234 	LOGGER ( TXT("::RemovePresentityGroupMemberL End") );
       
   235     }
       
   236 
       
   237 
       
   238 // End of file