imservices/instantmessagingcache/imcacheserver/src/cimcacheserver.cpp
changeset 0 e6b17d312c8b
child 1 b610b446cb01
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:  instantmessagingcache server class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #define __INCLUDE_CAPABILITY_NAMES__
       
    19 #define __INCLUDE_ALL_SUPPORTED_CAPABILITIES__
       
    20 
       
    21 //  INCLUDE FILES
       
    22 #include "cimcacheserver.h"
       
    23 
       
    24 #include "ccacheserveractivehelper.h"
       
    25 #include "cimcachesession.h"
       
    26 #include "mimcachemessageheader.h"
       
    27 #include "timcachemessagefactory.h"
       
    28 #include "cimcachemessageheader.h"
       
    29 #include "cimcachemessagebase.h"
       
    30 // logs
       
    31 #include "imcachedebugtrace.h" //logs
       
    32 
       
    33 // ==============================================================
       
    34 // =============== PLATSEC POLICY CONFIGURATION =================
       
    35 // ==============================================================
       
    36 
       
    37 static const TInt KIMCachePlatSecRangeCount = 2;
       
    38 
       
    39 //Ranges for the Request values
       
    40 static const TInt KIMCachePlatSecRanges[ KIMCachePlatSecRangeCount ] =
       
    41     {
       
    42     0,
       
    43     EIMCacheOperationLast
       
    44     };
       
    45 
       
    46 
       
    47 // Element indexes for the defined ranges
       
    48 static const TUint8 KIMCachePlatSecElementsIndex[ KIMCachePlatSecRangeCount ] =
       
    49     {
       
    50     0,
       
    51     CPolicyServer::ENotSupported
       
    52     };
       
    53 
       
    54 
       
    55 // Policy elements
       
    56 static const CPolicyServer::TPolicyElement KIMCachePlatSecElements[] =
       
    57     {
       
    58         {
       
    59         _INIT_SECURITY_POLICY_C2( ECapabilityReadUserData,
       
    60                                   ECapabilityWriteUserData ),
       
    61         -5 //CPolicyServer::EFailClient
       
    62         }
       
    63     };
       
    64 
       
    65 
       
    66 // The platsec policy
       
    67 static const CPolicyServer::TPolicy KIMCachePlatSecPolicy =
       
    68     {
       
    69     // Shortcut to the index into Elements,that is used to check a connection attempt
       
    70     0,
       
    71 
       
    72     // Number of ranges in the iRanges array
       
    73     KIMCachePlatSecRangeCount,
       
    74 
       
    75     // A pointer to an array of ordered ranges of request numbers
       
    76     KIMCachePlatSecRanges,
       
    77 
       
    78     // A pointer to an array of TUint8 values specifying
       
    79     // the appropriate action to take for each range in iRanges
       
    80     KIMCachePlatSecElementsIndex,
       
    81 
       
    82     // A pointer to an array of distinct policy elements
       
    83     KIMCachePlatSecElements
       
    84     };
       
    85 
       
    86 
       
    87 // ==============================================================
       
    88 // ======================= SERVER  ==============================
       
    89 // ==============================================================
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CIMCacheServer::ExecuteL
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CIMCacheServer::ExecuteL()
       
    96     {
       
    97     TRACE( T_LIT( "CIMCacheServer::ExecuteL() begin") );
       
    98     // start scheduler
       
    99     CActiveScheduler* pA = new( ELeave )CActiveScheduler;
       
   100     CleanupStack::PushL( pA );
       
   101     CActiveScheduler::Install( pA );
       
   102 
       
   103 
       
   104     // create server
       
   105     CIMCacheServer* server = new( ELeave ) CIMCacheServer();
       
   106     CleanupStack::PushL( server );
       
   107     server->InitializeL(*server);
       
   108     server->StartL( KIMCacheServerName );
       
   109 
       
   110 
       
   111     //Signal client that we are started
       
   112     RProcess().Rendezvous( KErrNone );
       
   113 
       
   114     // Execute the server
       
   115     // Codescanner warning: using CActiveScheduler::Start (id:3)
       
   116     // this has to be called for server starting.
       
   117     CActiveScheduler::Start(); // CSI: 3 # See above
       
   118 
       
   119     //Cleanup
       
   120     CleanupStack::PopAndDestroy( server );//server
       
   121     CleanupStack::PopAndDestroy( pA );
       
   122     CActiveScheduler::Install( NULL );
       
   123     TRACE( T_LIT( "CIMCacheServer::ExecuteL() end") );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CIMCacheServer::~CIMCacheServer
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 CIMCacheServer::~CIMCacheServer()
       
   131     {
       
   132     TRACE( T_LIT( "CIMCacheServer::~CIMCacheServer() begin") );
       
   133    
       
   134     iSessions.Close();
       
   135     
       
   136 	delete iActiveHelper;
       
   137 	
       
   138 	#if _BullseyeCoverage
       
   139     	cov_write();
       
   140 	#endif
       
   141     TRACE( T_LIT( "CIMCacheServer::~CIMCacheServer() end") );
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CIMCacheServer::CIMCacheServer
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 
       
   149 CIMCacheServer::CIMCacheServer()
       
   150     : CPolicyServer( CActive::EPriorityStandard,
       
   151                      KIMCachePlatSecPolicy )
       
   152     {
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CIMCacheServer::NewSessionL
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 CSession2* CIMCacheServer::NewSessionL( const TVersion &aVersion,
       
   160                                           const RMessage2& /*aMessage*/ ) const
       
   161     {
       
   162     TRACE( T_LIT( "CIMCacheServer::NewSessionL() begin") );
       
   163     TVersion srvVersion( KIMCacheVersionMajor,
       
   164                          KIMCacheVersionMinor,
       
   165                          KIMCacheVersionBuild );
       
   166 
       
   167 	if( !User::QueryVersionSupported( aVersion, srvVersion ) )
       
   168         {
       
   169         User::Leave( KErrNotSupported );
       
   170         }
       
   171 	CIMCacheSession* session = CIMCacheSession::NewL();	
       
   172      
       
   173     TRACE( T_LIT( "CIMCacheServer::NewSessionL() end session[%d] created"), session );
       
   174     return session;
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CIMCacheServer::SessionCreatedL
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CIMCacheServer::SessionCreatedL( CIMCacheSession* aSession )
       
   182     {
       
   183     TRACE( T_LIT( "CIMCacheServer::SessionCreatedL begin aSession[%d]"),aSession );
       
   184     iSessionCount++;
       
   185     TInt err = iSessions.Find( aSession );
       
   186     if(err == KErrNotFound )
       
   187 	    {
       
   188 	    iSessions.AppendL( aSession );
       
   189 	    }
       
   190     TRACE( T_LIT( "CIMCacheServer::SessionCreatedL() end") );
       
   191       }
       
   192 // -----------------------------------------------------------------------------
       
   193 // CIMCacheServer::SessionDied
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void CIMCacheServer::SessionDied( CIMCacheSession* aSession )
       
   197     {
       
   198     TRACE( T_LIT( "CIMCacheServer::SessionDied() begin") );
       
   199     TInt count = iSessions.Count();
       
   200       for( TInt i = 0; i < count; i++ )
       
   201 			{
       
   202 			if( iSessions[i] == aSession )
       
   203 				{
       
   204 				iSessions.Remove( i );
       
   205 				break;
       
   206 				}
       
   207 			}
       
   208 	iSessionCount--;
       
   209 	if( iSessionCount == 0 )
       
   210 		{
       
   211 		// Codescanner warning: using CActiveScheduler::Stop ( Id: 4)
       
   212 		// it is required to stop the server
       
   213 		CActiveScheduler::Stop(); // CSI: 4 # See above
       
   214 		}
       
   215 	TRACE( T_LIT( "CIMCacheServer::SessionDied() end") );
       
   216     }
       
   217 // -----------------------------------------------------------------------------
       
   218 // CIMCacheManager::GetActiveHelper
       
   219 // Pass pointer to toc array to client.
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 CCacheServerActiveHelper* CIMCacheServer::GetActiveHelper()
       
   223 	{
       
   224     return iActiveHelper;
       
   225 	}
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CIMCacheServer::InitializeL
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CIMCacheServer::InitializeL(CIMCacheServer& aServer)
       
   232     {
       
   233     TRACE( T_LIT( "CIMCacheServer::InitializeL begin") );
       
   234     
       
   235     iActiveHelper = CCacheServerActiveHelper::NewL( aServer );
       
   236     
       
   237     TRACE( T_LIT( "CIMCacheServer::InitializeL end") );
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CIMCacheServer::PackAndNotifyEventL
       
   242 // -----------------------------------------------------------------------------
       
   243 // send notication to all if registration is valid
       
   244  
       
   245 void CIMCacheServer::PackAndNotifyEventL(TIMCacheOperationsCode aChangeType,
       
   246                                          TInt aServiceId,
       
   247 										 MIMCacheMessageHeader* aChatHeader /*=NULL*/, 
       
   248 									 	 CIMCacheMessageBase* aMessage /*=NULL*/ ) 
       
   249 	{
       
   250 	TInt count = iSessions.Count();
       
   251 	for(TInt i = 0; i<count; i++ )
       
   252 		{
       
   253 		if( aServiceId == iSessions[i]->ServiceId() )
       
   254 		    {
       
   255 		    // send changes to only those session which are has same service Id
       
   256 		    iSessions[i]->PackAndNotifyEventL(aChangeType , aChatHeader, aMessage);	
       
   257 		    }
       
   258 		}
       
   259 	}
       
   260 
       
   261 
       
   262 // ==============================================================
       
   263 // ====================== ENTRY POINT ===========================
       
   264 // ==============================================================
       
   265 GLDEF_C TInt E32Main()
       
   266     {
       
   267     TRACE( T_LIT("E32Main - enter") );
       
   268 
       
   269     User::RenameThread( KIMCacheServerName );
       
   270 
       
   271     CTrapCleanup* tc = CTrapCleanup::New();
       
   272     if( !tc )
       
   273         {
       
   274         return KErrNoMemory;
       
   275         }
       
   276 
       
   277     TRAPD( err, CIMCacheServer::ExecuteL() );
       
   278     delete tc;
       
   279 
       
   280     TRACE( T_LIT("E32Main - exit: %d"), err );
       
   281     return err;
       
   282     }
       
   283 
       
   284 
       
   285 
       
   286 //  END OF FILE
       
   287 
       
   288