imservices/instantmessagingcache/imcacheclient/src/cimcacheclient.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 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:  client class implementation to connect to server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  INCLUDE FILES
       
    21 #include "cimcacheclient.h"
       
    22 
       
    23 #include "imcacheprocessstarter.h"
       
    24 #include <imcachedefs.h>
       
    25 #include "mimcacheclient.h"
       
    26 // logs
       
    27 #include "imcachedebugtrace.h"
       
    28 #include "cimcacheeventhandler.h"
       
    29 
       
    30 #include "cimcacheaccesseventhandler.h"
       
    31 
       
    32 // ==============================================================
       
    33 // ======================== CLIENT ==============================
       
    34 // ==============================================================
       
    35 
       
    36 // Destructor
       
    37 CIMCacheClient::~CIMCacheClient()
       
    38 	{
       
    39 	TRACE( T_LIT("CIMCacheClient::~CIMCacheClient() begin") );
       
    40 	if( iUpdateObserver )
       
    41 		{
       
    42 		delete iUpdateObserver;
       
    43 		}
       
    44 	
       
    45 	if( iAccessObserver )
       
    46 		{
       
    47 		delete iAccessObserver;
       
    48 		}
       
    49     if( iChatBuffer )
       
    50         {
       
    51         delete iChatBuffer;
       
    52         }
       
    53     //finally close the session.
       
    54     RSessionBase::Close();
       
    55 	#if _BullseyeCoverage
       
    56 	cov_write();
       
    57 	#endif
       
    58 	TRACE( T_LIT("CIMCacheClient::~CIMCacheClient() end") );
       
    59 	}
       
    60 // -----------------------------------------------------------------------------
       
    61 // CIMCacheClient::CIMCacheClient()
       
    62 // C++ default constructor can NOT contain any code, that
       
    63 // might leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CIMCacheClient::CIMCacheClient( )
       
    67 	{
       
    68     TRACE( T_LIT("CIMCacheClient::CIMCacheClient()") );
       
    69     }
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CIMCacheClient::Connect()
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 TInt CIMCacheClient::Connect()
       
    77     {
       
    78     TRACE( T_LIT("CIMCacheClient::Connect() begin") );
       
    79     TFileName fullExePath;
       
    80     IMCacheProcessStarter::FullExePathForClientLocation( EIMCacheServerExe,
       
    81                                                  fullExePath );
       
    82 
       
    83 	TRACE( T_LIT("CIMCacheClient::Connect() end") );
       
    84     return IMCacheProcessStarter::ConnectToServer( fullExePath,
       
    85                                             KNullDesC,
       
    86                                             *this,
       
    87                                             KIMCacheServerName,
       
    88                                             TVersion( KIMCacheVersionMajor,
       
    89                                                       KIMCacheVersionMinor,
       
    90                                                       KIMCacheVersionBuild ),
       
    91                                             KIMCacheMsgSlotCount );
       
    92     
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CIMCacheClient::RegisterObserverL()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CIMCacheClient::RegisterUpdateObserverL( MIMCacheEventHandler& aObserver )
       
   100 	{
       
   101 	TRACE( T_LIT("CIMCacheClient::RegisterUpdateObserverL() begin") );
       
   102 
       
   103 	CIMCacheEventHandler* tempObserver = CIMCacheEventHandler::NewL(  *this , aObserver );
       
   104 
       
   105 	if( iUpdateObserver )
       
   106 		{
       
   107 		delete iUpdateObserver;
       
   108 		iUpdateObserver = NULL;
       
   109 		}
       
   110 
       
   111 	iUpdateObserver = tempObserver;
       
   112 	TRACE( T_LIT("CIMCacheClient::RegisterUpdateObserverL() end") );
       
   113 	}
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CIMCacheClient::UnRegisterUpdateObserver()
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CIMCacheClient::UnRegisterUpdateObserver( MIMCacheEventHandler& /*aObserver*/)
       
   120 	{
       
   121 	TRACE( T_LIT("CIMCacheClient::UnRegisterUpdateObserver() begin") );
       
   122 	
       
   123 	iUpdateObserver->UnRegisterObserver();
       
   124 
       
   125     TRACE( T_LIT("CIMCacheClient::UnRegisterUpdateObserver() end") );
       
   126 	}
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CIMCacheClient::RegisterAccessObserverL()
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CIMCacheClient::RegisterAccessObserverL( MIMCacheEventHandler& aObserver )
       
   133 	{
       
   134 	TRACE( T_LIT("CIMCacheClient::RegisterUpdateObserverL() begin") );
       
   135 
       
   136 	CIMCacheAccessEventHandler* tempObserver = CIMCacheAccessEventHandler::NewL(  *this , aObserver );
       
   137 
       
   138 	if( iAccessObserver )
       
   139 		{
       
   140 		delete iAccessObserver;
       
   141 		iAccessObserver = NULL;
       
   142 		}
       
   143 
       
   144 	iAccessObserver = tempObserver;
       
   145 	TRACE( T_LIT("CIMCacheClient::RegisterUpdateObserverL() end") );
       
   146 	}
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CIMCacheClient::UnRegisterAccessObserver()
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CIMCacheClient::UnRegisterAccessObserver( MIMCacheEventHandler& /*aObserver*/)
       
   153 	{
       
   154 	TRACE( T_LIT("CIMCacheClient::UnRegisterUpdateObserver() begin") );
       
   155 	
       
   156 	iAccessObserver->UnRegisterObserver();
       
   157 
       
   158     TRACE( T_LIT("CIMCacheClient::UnRegisterUpdateObserver() end") );
       
   159 	}
       
   160 // -----------------------------------------------------------------------------
       
   161 // CIMCacheClient::RegisterObserverToServerL()
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CIMCacheClient::RegisterObserverToServerL( TRequestStatus& aStatus , EIMCacheOperations aRight)
       
   165 	{
       
   166 	TRACE( T_LIT("CIMCacheClient::RegisterObserverToServerL() begin") );
       
   167 	TIpcArgs args;
       
   168 	SendReceive( aRight, args, aStatus );
       
   169 	TRACE( T_LIT("CIMCacheClient::RegisterObserverToServerL() end") );
       
   170 	}
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CIMCacheClient::UnRegisterObserverToServerL()
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CIMCacheClient::UnRegisterObserverToServerL( TRequestStatus& aStatus, EIMCacheOperations aRight)
       
   177 	{
       
   178 	TRACE( T_LIT("CIMCacheClient::UnRegisterObserverToServerL() begin") );
       
   179 	TIpcArgs args;
       
   180 	TInt err = SendReceive( aRight, args );
       
   181 	User::LeaveIfError( err );
       
   182 	TRACE( T_LIT("CIMCacheClient::UnRegisterObserverToServerL() end") );
       
   183 	}
       
   184 // -----------------------------------------------------------------------------
       
   185 // CIMCacheClient::CancelRequestL()
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CIMCacheClient::CancelRequestL( TRequestStatus& aStatus, EIMCacheOperations aRight)
       
   189     {
       
   190     TRACE( T_LIT("CIMCacheClient::CancelRequestL() begin") );
       
   191     TIpcArgs args;
       
   192     TInt err = SendReceive( aRight, args );
       
   193     User::LeaveIfError( err );
       
   194     TRACE( T_LIT("CIMCacheClient::CancelRequestL() end") );
       
   195     }
       
   196 // -----------------------------------------------------------------------------
       
   197 // CIMCacheClient::StartTransactionL()
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CIMCacheClient::StartTransactionL( EIMCacheOperations aOperationType,
       
   201 									   TInt aServiceId ,
       
   202 									   const TDesC& aText
       
   203 									   )
       
   204 	{
       
   205 	TRACE( T_LIT("CIMCacheClient::StartTransactionL() begin") );
       
   206 	TIpcArgs args = CreateArgumentsL( aServiceId, aText );
       
   207  	TInt err = SendReceive( aOperationType, args );
       
   208     User::LeaveIfError( err );
       
   209     TRACE( T_LIT("CIMCacheClient::StartTransactionL() end") );
       
   210 	}
       
   211 
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CIMCacheClient::StartTransactionL()
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CIMCacheClient::StartTransactionL(EIMCacheOperations aOperationType,
       
   218 										const TDesC& aText
       
   219 									   )
       
   220 	{
       
   221 	TRACE( T_LIT("CIMCacheClient::StartTransactionL() begin") );
       
   222 	TIpcArgs args;
       
   223     args.Set( 0,  &aText );
       
   224    	TInt err = SendReceive( aOperationType, args );
       
   225     User::LeaveIfError( err );
       
   226     TRACE( T_LIT("CIMCacheClient::StartTransactionL() end") );
       
   227 	}
       
   228 // -----------------------------------------------------------------------------
       
   229 // CIMCacheClient::StartTransactionL()
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CIMCacheClient::StartTransactionL(	EIMCacheOperations aOperationType,
       
   233 										TInt aServiceId,
       
   234 										const TDesC& aText1 ,
       
   235 										const TDesC& aText2 
       
   236 									   	)
       
   237 	{
       
   238 	TRACE( T_LIT("CIMCacheClient::StartTransactionL() begin") );
       
   239 	TIpcArgs args = CreateArgumentsL(aServiceId, aText1, aText2 );
       
   240  	TInt err = SendReceive( aOperationType, args );
       
   241     User::LeaveIfError( err );
       
   242     TRACE( T_LIT("CIMCacheClient::StartTransactionL() end") );
       
   243 	}
       
   244 	
       
   245 // -----------------------------------------------------------------------------
       
   246 // CIMCacheClient::StopTransactionL()
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 TInt CIMCacheClient::StartTransactionL(EIMCacheOperations aOperationType )
       
   250 	{
       
   251 	TRACE( T_LIT("CIMCacheClient::StopTransactionL() begin") );
       
   252 	TRACE( T_LIT(" aOperationType = %d  "),aOperationType );
       
   253 	TInt err = SendReceive( aOperationType );
       
   254     TRACE( T_LIT("CIMCacheClient::StopTransactionL() end") );
       
   255 	return err;
       
   256 	}
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CIMCacheClient::CreateArgumentsL()
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 TIpcArgs CIMCacheClient::CreateArgumentsL( TInt aServiceId ,
       
   263 									   const TDesC& aText  )
       
   264 	{
       
   265 	TRACE( T_LIT("CIMCacheClient::CreateArgumentsL() begin") );
       
   266 	// set the arguments for the message
       
   267 	TIpcArgs args;
       
   268     args.Set( 0,  aServiceId );
       
   269     args.Set( 1,  &aText );
       
   270     TRACE( T_LIT("CIMCacheClient::CreateArgumentsL() end") );
       
   271     return args;
       
   272 	}
       
   273 
       
   274  // -----------------------------------------------------------------------------
       
   275 // CIMCacheClient::CreateArgumentsL()
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 TIpcArgs CIMCacheClient::CreateArgumentsL(TInt aServiceId, 
       
   279 										const TDesC& aText1  ,
       
   280 									   const TDesC& aText2  )
       
   281 	{
       
   282 	TRACE( T_LIT("CIMCacheClient::CreateArgumentsL() begin") );
       
   283 	// set the arguments for the message
       
   284 	TIpcArgs args(aServiceId);
       
   285     args.Set( 1,  &aText1 );
       
   286     args.Set( 2,  &aText2 );
       
   287     TRACE( T_LIT("CIMCacheClient::CreateArgumentsL() end") );
       
   288     return args;
       
   289 	}
       
   290 
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CIMCacheClient::GetInformationL()
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 TInt CIMCacheClient::GetInformationL(EIMCacheOperations aOperationType, TInt aServiceId,const TDesC& aBuddyId )
       
   297 	{
       
   298 	TRACE( T_LIT("CIMCacheClient::GetInformationL start") );
       
   299 	TInt returnValue = 0;
       
   300 	TIpcArgs args(aServiceId);
       
   301 	args.Set( 1,  &aBuddyId );
       
   302     TPckg<TInt> pack( returnValue );
       
   303     args.Set(2, &pack );
       
   304     TInt err = SendReceive( aOperationType, args );
       
   305     User::LeaveIfError( err );
       
   306     TRACE( T_LIT("CIMCacheClient::GetInformationL() end") );
       
   307 	return returnValue;
       
   308 	}
       
   309 
       
   310  // -----------------------------------------------------------------------------
       
   311 // CIMCacheClient::GetCountL()
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 TInt CIMCacheClient::GetInformationL(EIMCacheOperations aOperationType, TInt aServiceId )
       
   315 	{
       
   316 	TRACE( T_LIT("CIMCacheClient::GetInformationL") );
       
   317 	TInt returnValue = 0;
       
   318 	TIpcArgs args(aServiceId);
       
   319         
       
   320     TPckg<TInt> pack( returnValue );
       
   321     args.Set(1, &pack );
       
   322     TInt err = SendReceive( aOperationType, args );
       
   323     User::LeaveIfError( err );
       
   324     TRACE( T_LIT("CIMCacheClient::GetInformationL() end") );
       
   325 	return returnValue;
       
   326 	}	
       
   327 // -----------------------------------------------------------------------------
       
   328 // CIMCacheClient::GetContactBufferL()
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 TPtr8 CIMCacheClient::GetBufferedDataL(EIMCacheOperations aOperationType )
       
   332     {
       
   333     TRACE( T_LIT("CIMCacheClient::GetContactBufferL() begin") );
       
   334     
       
   335     if(!iChatBuffer)//if not allocated allocate.
       
   336         {
       
   337         iChatBuffer = HBufC8::NewL(KMaxSize);
       
   338         }
       
   339     TPtr8 chatBufferPtr = iChatBuffer->Des();
       
   340     TIpcArgs msgArgs;
       
   341     msgArgs.Set( 0, &chatBufferPtr );
       
   342     
       
   343     TInt err = SendReceive( aOperationType, msgArgs );
       
   344     User::LeaveIfError( err );
       
   345   
       
   346     TRACE( T_LIT("CIMCacheClient::GetContactBufferL() end") );
       
   347     
       
   348     return iChatBuffer->Des();
       
   349     }
       
   350     
       
   351 // -----------------------------------------------------------------------------
       
   352 // CIMCacheClient::GetChatListL()
       
   353 // -----------------------------------------------------------------------------    
       
   354 TPtr8 CIMCacheClient::GetChatListL( const TInt& aServiceId /*= -1*/ )
       
   355     {
       
   356     
       
   357     if(!iChatBuffer)//if not allocated allocate.
       
   358         {
       
   359         iChatBuffer = HBufC8::NewL(KMaxSize);
       
   360         }
       
   361     TPtr8 ptr = iChatBuffer->Des();
       
   362      
       
   363     TIpcArgs msgArgs( aServiceId );//at 0.
       
   364     msgArgs.Set( 1, &ptr  );
       
   365     
       
   366     TInt err = SendReceive( EIMCacheGetChatList, msgArgs );
       
   367     User::LeaveIfError( err );
       
   368   
       
   369   	return iChatBuffer->Des();
       
   370     }
       
   371     
       
   372 // end of file
       
   373