omadrm/drmengine/server/src/DRMServerStarter.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002 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:  This file is used only if RDRMRightsClient starts the
       
    15 *                DRM Rights Database server. 
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include   <e32std.h>
       
    21 #include    <e32uid.h>
       
    22 #include <f32file.h>
       
    23 
       
    24 #ifdef RD_MULTIPLE_DRIVE
       
    25 #include <DriveInfo.h>
       
    26 #endif
       
    27 
       
    28 #include "drmengineclientserver.h"
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 // EXTERNAL FUNCTION PROTOTYPES  
       
    32 // CONSTANTS
       
    33 #ifdef __WINS__
       
    34 LOCAL_C const TUint KServerMinHeapSize =  0x1000;  
       
    35 LOCAL_C const TUint KServerMaxHeapSize = 0x300000; 
       
    36 _LIT( KRightsServerFile, "RightsServer" );
       
    37 #else
       
    38 
       
    39 #ifdef RD_MULTIPLE_DRIVE
       
    40 _LIT( KRightsServerFile, "%c:\\RightsServer.exe" );
       
    41 #else
       
    42 _LIT( KRightsServerFile, "e:\\RightsServer.exe" );
       
    43 #endif
       
    44 #endif
       
    45 
       
    46 // MACROS
       
    47 // LOCAL CONSTANTS AND MACROS
       
    48 // MODULE DATA STRUCTURES
       
    49 // LOCAL FUNCTION PROTOTYPES
       
    50 LOCAL_C TInt CreateServer( void );
       
    51 
       
    52 // FORWARD DECLARATIONS
       
    53 
       
    54 // ============================= LOCAL FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CreateServer launches the DRM Rights server [process (THUMB/ARMI)|thread (WINS)]. 
       
    58 // Returns: KErrNone: No errors.
       
    59 //          <KErrNone: Symbian wide error code.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 LOCAL_C TInt CreateServer( void )
       
    63     {
       
    64     TInt error = KErrNone;
       
    65     
       
    66         RProcess server;
       
    67         
       
    68 #ifndef RD_MULTIPLE_DRIVE
       
    69     
       
    70         error = server.Create( KRightsServerFile, 
       
    71                                KNullDesC );
       
    72     
       
    73 #else //RD_MULTIPLE_DRIVE
       
    74         
       
    75         RFs fs;
       
    76         TInt driveNumber( -1 );
       
    77         TChar driveLetter;
       
    78         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, driveNumber );
       
    79         
       
    80         error = fs.Connect();
       
    81         if( error != KErrNone )
       
    82             {
       
    83             fs.Close();
       
    84             return error;
       
    85             }
       
    86         
       
    87         fs.DriveToChar( driveNumber, driveLetter );
       
    88         fs.Close();
       
    89 	
       
    90         TFileName rightsServerFile;
       
    91         rightsServerFile.Format( KRightsServerFile, (TUint)driveLetter );
       
    92     
       
    93         error = server.Create( rightsServerFile, 
       
    94                                KNullDesC );
       
    95     
       
    96 #endif
       
    97         
       
    98         if ( !error )
       
    99             {
       
   100             // Give some time to the process to start.
       
   101             User::After( 1000 );
       
   102             
       
   103         // Kick the server up & running.
       
   104         server.Resume();
       
   105             
       
   106         // Local handle not needed anymore.
       
   107         server.Close();
       
   108         }
       
   109         
       
   110     return error;
       
   111     }
       
   112     
       
   113 // ============================ MEMBER FUNCTIONS ===============================
       
   114     
       
   115 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   116     
       
   117 // -----------------------------------------------------------------------------
       
   118 // DRMServerStarter starts the actual server.
       
   119 // Returns: KErrNone: All went OK, no errors.
       
   120 //          <KErrNone: Symbian wide error code.
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C TInt DRMServerStarter()
       
   124     {
       
   125     RSemaphore semaphore;
       
   126     TFindServer server( DRMEngine::KServerName );
       
   127     TFullName name;
       
   128     
       
   129     // Check if the server is already running.
       
   130     TInt error = server.Next( name );
       
   131     
       
   132     if ( !error )
       
   133         {
       
   134         // Yep, it's already running.
       
   135         return KErrNone;
       
   136         }
       
   137 
       
   138     error = semaphore.CreateGlobal( DRMEngine::KDRMSemaphore,   // name
       
   139                                     0 ,              // count
       
   140                                     EOwnerThread ); // owner
       
   141     
       
   142     if ( error == KErrAlreadyExists )
       
   143         {
       
   144         error = semaphore.OpenGlobal( DRMEngine::KDRMSemaphore );
       
   145         }
       
   146         
       
   147     if ( !error )
       
   148         {
       
   149         error = CreateServer();
       
   150         if ( !error )
       
   151             {
       
   152             // Wait until server has done all its things.
       
   153             semaphore.Wait();
       
   154             
       
   155             // Signal the (possible) next one waiting in line. Server
       
   156             // only signals the semaphore once but there might be several
       
   157             // clients waiting for this semaphore, in theory.
       
   158             semaphore.Signal();
       
   159             }
       
   160         
       
   161         // Semaphore can be destroyed.
       
   162         semaphore.Close();
       
   163         }
       
   164         
       
   165     return error; 
       
   166     }
       
   167 //  End of File