resourcemgmt/hwresourcesmgr/server/src/HWRMSession.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "HWRMSession.h"
       
    21 #include "HWRMServer.h"
       
    22 #include "HWRMClient.h"  // THWRMResourceType
       
    23 #include "HWRMClientServer.h"
       
    24 #include "HWRMService.h"
       
    25 #include "HWRMVibraService.h"
       
    26 #include "HWRMVibraCommonService.h"
       
    27 #include "HWRMLightService.h"
       
    28 #include "HWRMPowerService.h"
       
    29 #include "HWRMFmTxService.h"
       
    30 #include "HWRMtrace.h"
       
    31 
       
    32 
       
    33 // EXTERNAL DATA STRUCTURES
       
    34 // None
       
    35 
       
    36 // EXTERNAL FUNCTION PROTOTYPES  
       
    37 // None
       
    38 
       
    39 // CONSTANTS
       
    40 // None
       
    41 
       
    42 // MACROS
       
    43 // None
       
    44 
       
    45 // LOCAL CONSTANTS AND MACROS
       
    46 // None
       
    47 
       
    48 // MODULE DATA STRUCTURES
       
    49 // None
       
    50 
       
    51 // LOCAL FUNCTION PROTOTYPES
       
    52 // None
       
    53 
       
    54 // FORWARD DECLARATIONS
       
    55 // None
       
    56 
       
    57 // ============================= LOCAL FUNCTIONS ===============================
       
    58 
       
    59 // ============================ MEMBER FUNCTIONS ===============================
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CHWRMSession::CHWRMSession
       
    63 // C++ constructor
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CHWRMSession::CHWRMSession(CHWRMServer& aServer)
       
    67     : iHWRMServer(aServer),
       
    68     iService(NULL),
       
    69     iCompletionNeeded(EFalse)
       
    70     {
       
    71     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMSession::CHWRMSession()" ) );
       
    72     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMSession::CHWRMSession - return" ));
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CHWRMSession::NewL
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CHWRMSession* CHWRMSession::NewL(CHWRMServer& aServer)
       
    81     {
       
    82     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMSession::NewL()" ) );
       
    83 
       
    84     CHWRMSession* self = new( ELeave ) CHWRMSession(aServer);
       
    85     
       
    86     // No ConstructL as nothing to do there
       
    87 
       
    88     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMSession::NewL - return 0x%x" ), self );
       
    89 
       
    90     return self;
       
    91     }
       
    92    
       
    93 // ---------------------------------------------------------
       
    94 // Destructor
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 CHWRMSession::~CHWRMSession()
       
    98     {
       
    99     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMSession::~CHWRMSession()" ) );
       
   100 
       
   101     // iHWRMServer not owned and therefore not cleaned
       
   102 
       
   103 	delete iService;
       
   104 	iService = NULL;
       
   105 
       
   106     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMSession::~CHWRMSession - return" ) );
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CHWRMSession::ServiceL
       
   111 // Calls request handling functions. Also traps any leaves and signals client if
       
   112 // error occurs.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CHWRMSession::ServiceL( const RMessage2& aMessage )
       
   116     {
       
   117     COMPONENT_TRACE2(_L( "HWRM Server - CHWRMSession::ServiceL(0x%x)" ), aMessage.Handle() );
       
   118 
       
   119 #if defined(COMPONENT_TRACE_FLAG) && defined(_DEBUG)
       
   120     // check memory usage
       
   121     TInt biggestBlock;
       
   122     COMPONENT_TRACE2(_L( "HWRM Server - #### Memory Available in Heap: %6d ####" ), User::Heap().Available(biggestBlock) );
       
   123     COMPONENT_TRACE2(_L( "HWRM Server - #### Biggest block:            %6d ####" ), biggestBlock);
       
   124 #endif
       
   125 
       
   126 #ifdef HWRM_TEST_IGNORE_CLIENTS
       
   127     // Just complete calls that come from other parts of system than module test application
       
   128     TSecureId* sid = new (ELeave) TSecureId(0x33442255);
       
   129     if ( aMessage.SecureId().iId != sid->iId )
       
   130         {
       
   131         COMPONENT_TRACE2(_L( "HWRM Server - CHWRMSession::ServiceL - Ignoring call from 0x%x" ), aMessage.SecureId().iId);
       
   132         aMessage.Complete(KErrNone);
       
   133         delete sid;
       
   134         return;
       
   135         }
       
   136     delete sid;
       
   137 #endif
       
   138 
       
   139     // Reset completion need flag
       
   140     iCompletionNeeded = ETrue;
       
   141     
       
   142     TRAPD( error, DispatchMessageL( aMessage ));
       
   143 
       
   144     if ( error != KErrNone )
       
   145         {
       
   146         COMPONENT_TRACE2(_L("HWRM Server - CHWRMSession::ServiceL(): Error in DispatchMessageL: %d"), error );
       
   147         iCompletionNeeded = ETrue;
       
   148         }
       
   149 
       
   150     if ( iCompletionNeeded )
       
   151         {
       
   152         aMessage.Complete(error);
       
   153         }
       
   154 
       
   155     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMSession::ServiceL - return" ));
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CHWRMSession::DispatchMessageL
       
   160 // Calls matching function of CWalletTaskOrganizer for handling the request.
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CHWRMSession::DispatchMessageL( const RMessage2& aMessage )
       
   164     {
       
   165     COMPONENT_TRACE3(_L( "HWRM Server - CHWRMSession::DispatchMessageL(0x%x), client SID: 0x%x" ), aMessage.Function(), aMessage.SecureId().iId );
       
   166 
       
   167     // Check command code and call appropriate function
       
   168     switch ( aMessage.Function() )
       
   169         {
       
   170     	case EHWRMCreateVibraService:
       
   171     	    {
       
   172     	    if ( iService )
       
   173     	        {
       
   174     	        User::Leave(KErrAlreadyExists);
       
   175     	        }
       
   176     	    else
       
   177     	        {
       
   178     	        CHWRMPluginHandler* pluginHandler = iHWRMServer.GetPluginHandler(HWRMResourceTypeVibra);
       
   179     	        CHWRMReservationHandler* reservationHandler = iHWRMServer.GetReservationHandler(HWRMResourceTypeVibra);
       
   180     	        CHWRMVibraCommonService* commonService = iHWRMServer.GetVibraCommonService();
       
   181     	        CHWRMVibraCommonData* vibraCommonData = iHWRMServer.GetVibraCommonData();
       
   182     	        
       
   183         	    // if handler or common data is NULL, this resource is not supported by device
       
   184         	    if ( !pluginHandler || !reservationHandler || !vibraCommonData )
       
   185         	        {
       
   186         	        User::Leave(KErrNotSupported);
       
   187         	        }
       
   188         	    else
       
   189         	        {        	        
       
   190         	        iService = static_cast<CHWRMService*>
       
   191                         (CHWRMVibraService::NewL(pluginHandler, 
       
   192                         reservationHandler, *commonService, *vibraCommonData, 
       
   193                         vibraCommonData->IsPrivilegedSid(aMessage.SecureId())));
       
   194         	        }
       
   195     	        }
       
   196     		break;
       
   197     	    }
       
   198     	case EHWRMCreateLightService:
       
   199     	    {
       
   200     	    if ( iService )
       
   201     	        {
       
   202     	        User::Leave(KErrAlreadyExists);
       
   203     	        }
       
   204     	    else
       
   205     	        {
       
   206     	        CHWRMPluginHandler* pluginHandler = iHWRMServer.GetPluginHandler(HWRMResourceTypeLight);
       
   207     	        CHWRMReservationHandler* reservationHandler = iHWRMServer.GetReservationHandler(HWRMResourceTypeLight);
       
   208         	    
       
   209     	        CHWRMLightCommonData* lightCommonData = iHWRMServer.GetLightCommonData();
       
   210         	    
       
   211         	    // if handler is NULL, this resource is not supported by device
       
   212         	    if ( !pluginHandler|| !reservationHandler || !lightCommonData)
       
   213         	        {
       
   214         	        User::Leave(KErrNotSupported);
       
   215         	        }
       
   216         	    else
       
   217         	        {
       
   218         	        iService = static_cast<CHWRMService*>(CHWRMLightService::NewL(pluginHandler, reservationHandler, *lightCommonData));
       
   219         	        }
       
   220     	        }
       
   221     		break;
       
   222     	    }
       
   223     	    
       
   224     	case EHWRMCreatePowerService:
       
   225     	    {
       
   226     	    if ( iService )
       
   227     	        {
       
   228     	        User::Leave(KErrAlreadyExists);
       
   229     	        }
       
   230     	    else
       
   231     	        {
       
   232     	        CHWRMPluginHandler* pluginHandler = iHWRMServer.GetPluginHandler(HWRMResourceTypePower);
       
   233         	    
       
   234     	        CHWRMPowerCommonData* powerCommonData = iHWRMServer.GetPowerCommonData();
       
   235         	    
       
   236         	    // if handler is NULL, this resource is not supported by device
       
   237         	    if ( !pluginHandler || !powerCommonData)
       
   238         	        {
       
   239         	        User::Leave(KErrNotSupported);
       
   240         	        }
       
   241         	    else
       
   242         	        {
       
   243         	        iService = static_cast<CHWRMService*>(CHWRMPowerService::NewL(pluginHandler, *powerCommonData));
       
   244         	        }
       
   245     	        }
       
   246     		break;
       
   247     	    }
       
   248     	    
       
   249     	case EHWRMCreateFmTxService:
       
   250     	    {
       
   251     	    if ( iService )
       
   252     	        {
       
   253     	        User::Leave(KErrAlreadyExists);
       
   254     	        }
       
   255     	    else
       
   256     	        {
       
   257                 CHWRMPluginHandler* pluginHandler = iHWRMServer.GetPluginHandler( 
       
   258                                                                     HWRMResourceTypeFmTx );
       
   259                 CHWRMPluginHandler* watcherPluginHandler = iHWRMServer.GetPluginHandler( 
       
   260                                                                     HWRMResourceTypeFmTxWatcher );
       
   261       	        CHWRMReservationHandler* reservationHandler = iHWRMServer.GetReservationHandler( 
       
   262                                                                     HWRMResourceTypeFmTx);
       
   263   	        
       
   264     	        CHWRMFmTxCommonData* fmTxCommonData = iHWRMServer.GetFmTxCommonData();
       
   265     	      	        
       
   266         	    // if handler or common data is NULL, this resource is not supported by device
       
   267         	    if ( !pluginHandler|| !watcherPluginHandler || !reservationHandler || !fmTxCommonData)
       
   268         	        {
       
   269         	        User::Leave(KErrNotSupported);
       
   270         	        }
       
   271         	    else
       
   272         	        {
       
   273         	        iService = static_cast<CHWRMService*>(CHWRMFmTxService::NewL(pluginHandler,
       
   274         	        															 *watcherPluginHandler,
       
   275         	        															 reservationHandler,
       
   276         	        															 *fmTxCommonData,
       
   277         	        															 *(fmTxCommonData->GetRdsTextConverter())) );
       
   278         	        }
       
   279     	        }
       
   280     		break;
       
   281     	    }
       
   282 
       
   283         // Cannot identify the message, it must be for service.
       
   284         // If no service yet established, panic.
       
   285         default:
       
   286             {
       
   287             if ( iService )
       
   288                 {
       
   289                 iCompletionNeeded = iService->ExecuteMessageL(aMessage);
       
   290                 }
       
   291             else
       
   292                 {
       
   293                 User::Leave(KErrBadHandle);                
       
   294                 }
       
   295            
       
   296             break;
       
   297             }
       
   298         }
       
   299 
       
   300     COMPONENT_TRACE1(_L( "HWRM Server - CHWRMSession::DispatchMessageL - return" ));
       
   301     }
       
   302 
       
   303 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   304 
       
   305 //  End of File