hwrmhaptics/hapticsserver/src/hwrmhapticsserver.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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:  Haptic server implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hwrmhapticsserver.h"
       
    20 #include "hwrmhapticssession.h"
       
    21 #include "hwrmhapticsconfiguration.h"
       
    22 #include "hwrmhapticspluginmanager.h"  
       
    23 #include "hwrmhapticscommondata.h"
       
    24 #include "hwrmhapticsreservationhandler.h"
       
    25 #include "hwrmhapticscommands.h"
       
    26 #include "hwrmhapticsshutdown.h"
       
    27 #include "hwrmhapticstrace.h"
       
    28 
       
    29 const TInt KDefaultPluginTimeout = 3000000; // ms
       
    30 
       
    31 // HWRMHaptics policy
       
    32 _LIT( KHapticsPolicyFilename, "hwrmhapticspolicy.ini" );
       
    33 
       
    34 /**
       
    35  * Plat sec policy configuration
       
    36  */
       
    37 const TInt hapticsSecRanges[] = {0,11};
       
    38 const TUint hapticsSecRangeCount = sizeof(hapticsSecRanges)/sizeof(hapticsSecRanges[0]);
       
    39 const TUint8 hapticsSecElementsIndex[hapticsSecRangeCount] =
       
    40     {
       
    41     CPolicyServer::EAlwaysPass,
       
    42     CPolicyServer::EAlwaysPass
       
    43     };
       
    44 const CPolicyServer::TPolicyElement hapticsSecElements[] =
       
    45     {_INIT_SECURITY_POLICY_PASS};
       
    46 const CPolicyServer::TPolicy hapticsSecPolicy =
       
    47     {
       
    48     CPolicyServer::EAlwaysPass,
       
    49     hapticsSecRangeCount,
       
    50     hapticsSecRanges,
       
    51     hapticsSecElementsIndex,
       
    52     hapticsSecElements,
       
    53     };
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // C++ constructor
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CHWRMHapticsServer::CHWRMHapticsServer( TInt aPriority ) 
       
    60     : CPolicyServer( aPriority, hapticsSecPolicy, EUnsharableSessions )
       
    61     {
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Symbian 2nd phase constructor.
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CHWRMHapticsServer::ConstructL()
       
    69     {
       
    70     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::ConstructL()" ) ) );
       
    71 
       
    72     // construct the shutdown timer
       
    73     iShutdown = CHWRMHapticsShutdown::NewL();
       
    74     
       
    75     // Add server to active scheduler
       
    76     StartL( KServerProcessName );
       
    77     
       
    78     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::ConstructL - return" ) ) );
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Two-phased constructor.
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CHWRMHapticsServer* CHWRMHapticsServer::NewL( TInt aPriority )
       
    86     {
       
    87     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::NewL(0x%x)" ), aPriority ) );
       
    88 
       
    89     CHWRMHapticsServer* self = CHWRMHapticsServer::NewLC( aPriority );
       
    90     CleanupStack::Pop( self );
       
    91 
       
    92     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::NewL - return 0x%x" ), self ) );
       
    93 
       
    94     return self;
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Two-phased constructor.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 CHWRMHapticsServer* CHWRMHapticsServer::NewLC( TInt aPriority )
       
   102     {
       
   103     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::NewLC(0x%x)" ), aPriority ) );
       
   104 
       
   105     CHWRMHapticsServer* self = 
       
   106         new( ELeave ) CHWRMHapticsServer( aPriority );
       
   107     
       
   108     CleanupStack::PushL( self );
       
   109     self->ConstructL();
       
   110     
       
   111     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::NewLC - return 0x%x" ), self ) );
       
   112 
       
   113     return self;
       
   114     }
       
   115     
       
   116 // ---------------------------------------------------------------------------
       
   117 // Destructor
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 CHWRMHapticsServer::~CHWRMHapticsServer()
       
   121     {
       
   122     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::~CHWRMHapticsServer()" ) ) );
       
   123 
       
   124     // Delete plugin manager
       
   125     delete iHapticsPluginManager;
       
   126 
       
   127     // Delete reservation handler
       
   128     delete iHapticsReservationHandler;
       
   129 
       
   130     // Delete common data
       
   131     delete iHapticsCommonData;
       
   132     
       
   133     // Delete the shutdown timer
       
   134     delete iShutdown;
       
   135 
       
   136     // Signal final closure of ecom session
       
   137     REComSession::FinalClose();
       
   138 
       
   139     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::~CHWRMHapticsServer - return") ) );
       
   140     }
       
   141 
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // Creates a new CSession2
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 CSession2* CHWRMHapticsServer::NewSessionL( 
       
   148                                         const TVersion& aVersion,
       
   149                                         const RMessage2& /*aMessage*/ ) const
       
   150     {
       
   151     // check version
       
   152     if ( !User::QueryVersionSupported( TVersion( KServerVersionMajor, 
       
   153                                                  KServerVersionMinor, 
       
   154                                                  KServerVersionBuild ), 
       
   155                                                  aVersion ) )
       
   156         {
       
   157         // given version not supported
       
   158         User::Leave( KErrNotSupported );
       
   159         }
       
   160     
       
   161     // create session instance
       
   162     CSession2* session = CHWRMHapticsSession::NewL();
       
   163 
       
   164 
       
   165     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::NewSessionL - return 0x%x" ), session ) );
       
   166 
       
   167     return session;
       
   168     }
       
   169    
       
   170 // ---------------------------------------------------------------------------
       
   171 // Returns pointer to correct plugin handler.
       
   172 // In case resource is not supported, returns NULL
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 CHWRMHapticsPluginManager* CHWRMHapticsServer::PluginManager() const
       
   176     {
       
   177     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::PluginManager - return 0x%x" ), iHapticsPluginManager ) );
       
   178     return iHapticsPluginManager;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // Returns pointer to correct reservation handler.
       
   183 // In case resource is not supported, returns NULL
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 CHWRMHapticsReservationHandler* CHWRMHapticsServer::ReservationHandler() const
       
   187     {
       
   188     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::ReservationHandler - return 0x%x" ), iHapticsReservationHandler ) );
       
   189 
       
   190     return iHapticsReservationHandler;
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // Returns pointer to Haptics common data
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 CHWRMHapticsCommonData* CHWRMHapticsServer::HapticsCommonData() const
       
   198     {
       
   199     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::HapticsCommonData - return 0x%x" ), iHapticsCommonData ) );
       
   200     return iHapticsCommonData;
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // Initialises Haptics
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CHWRMHapticsServer::InitHaptics()
       
   208     {
       
   209     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::InitHaptics()" ) ) );
       
   210 
       
   211     // Initialize, if not already initialized
       
   212     if ( !iHapticsInitiated )
       
   213         {
       
   214         delete iHapticsReservationHandler;
       
   215         delete iHapticsPluginManager;
       
   216         delete iHapticsCommonData;
       
   217         iHapticsReservationHandler = NULL;
       
   218         iHapticsPluginManager = NULL;
       
   219         iHapticsCommonData = NULL;
       
   220 
       
   221         // create reservation handler
       
   222         TRAPD( err, iHapticsReservationHandler = 
       
   223                     CHWRMHapticsReservationHandler::NewL( 
       
   224                                                 KHapticsPolicyFilename ) );
       
   225         
       
   226         COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::InitHaptics() - iHapticsReservationHandler creation: %d" ), err ) );
       
   227 
       
   228         // if reservation handler creation succeeded, create common data
       
   229         if ( !err && iHapticsReservationHandler )
       
   230             {
       
   231             // create haptics common data
       
   232             TRAP( err, iHapticsCommonData = 
       
   233                            CHWRMHapticsCommonData::NewL() );
       
   234             
       
   235             COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::InitHaptics() - iHapticsPluginManager creation: %d" ), err ) );
       
   236 
       
   237             // if above creations succeeded, create plugin manager
       
   238             if ( !err && iHapticsCommonData )
       
   239                 {
       
   240                 // create plugin manager
       
   241                 TRAP( err, iHapticsPluginManager = 
       
   242                            CHWRMHapticsPluginManager::NewL( *iHapticsCommonData,
       
   243                                                             KDefaultPluginTimeout ) );
       
   244                 if ( !err  && iHapticsPluginManager )
       
   245                     {
       
   246                     iHapticsInitiated = ETrue;
       
   247                     }
       
   248 
       
   249                 COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::InitHaptics() - iHapticsCommonData creation: %d" ), err ) );
       
   250                 }
       
   251             }
       
   252         }
       
   253 
       
   254     COMPONENT_TRACE( ( _L( "CHWRMHapticsServer::InitHaptics() - return" ) ) );
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // Increases the amount of sessions connected to this server.
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 void CHWRMHapticsServer::AddSession()
       
   262     {
       
   263     // increase session count
       
   264     ++iSessionCount;
       
   265     
       
   266     // Cancel the shutdown timer if it was running
       
   267     iShutdown->Cancel();
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // Decreases the amount of sessions connected to this server.
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 void CHWRMHapticsServer::DropSession()
       
   275     {
       
   276     // decrease session count
       
   277     --iSessionCount;
       
   278 
       
   279     // Start the shutdown timer there are no more sessions
       
   280     if ( iSessionCount == 0 && !iShutdown->IsActive() )
       
   281         {
       
   282         iShutdown->Start();
       
   283         }
       
   284     }
       
   285 
       
   286 //  End of File