mmappcomponents/harvester/server/src/mpxharvesterserver.cpp
changeset 0 a2952bb97e68
child 28 f56ec6ce2732
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Harvester Server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32svr.h>
       
    21 
       
    22 #include "mpxharvestercommon.h"
       
    23 #include "mpxharvesterserver.h"
       
    24 #include "mpxharvesterengine.h"
       
    25 #include "mpxharvestersession.h"
       
    26 #include "mpxharvesterserverdefs.h"
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // Server Security Policy
       
    31 const TUint KMPXHarvesterServerRangeCount = 2;
       
    32 const TInt KMPXHarvesterServerRanges[KMPXHarvesterServerRangeCount] = 
       
    33     {
       
    34     0,                  //range is [0-EHvsServerOpCount)
       
    35     EHvsServerOpCount   //range is [EHvsServerOpCount-KMaxTInt] 
       
    36     };
       
    37 const TUint8 KMPXHarvesterSeverElementsIndex[KMPXHarvesterServerRangeCount] = 
       
    38     {
       
    39     0,                            
       
    40     CPolicyServer::ENotSupported
       
    41     };
       
    42     
       
    43 const CPolicyServer::TPolicyElement KMPXHarvesterServerPolicyElements[] = 
       
    44     {
       
    45     {_INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData), 
       
    46                               CPolicyServer::EFailClient}
       
    47     };
       
    48     
       
    49 const CPolicyServer::TPolicy KMPXHarvesterServerPolicy =
       
    50     {
       
    51     CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
       
    52     KMPXHarvesterServerRangeCount,                   
       
    53     KMPXHarvesterServerRanges,
       
    54     KMPXHarvesterSeverElementsIndex,
       
    55     KMPXHarvesterServerPolicyElements
       
    56     };
       
    57 
       
    58 
       
    59 // ============================ LOCAL FUNCTIONS ==============================
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // Start Harvester Server
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 LOCAL_C void StartServerL()
       
    66     {
       
    67     User::LeaveIfError(User::RenameThread(KMPXHarvesterServerName));
       
    68     CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
    69     CleanupStack::PushL(scheduler);    
       
    70     CActiveScheduler::Install(scheduler);
       
    71     CMPXHarvesterServer* server = CMPXHarvesterServer::NewL();
       
    72     CleanupStack::PushL(server);    
       
    73     RProcess::Rendezvous(KErrNone);
       
    74     CActiveScheduler::Start();
       
    75     CActiveScheduler::Install(NULL);
       
    76     CleanupStack::PopAndDestroy(server);
       
    77     CleanupStack::PopAndDestroy(scheduler);
       
    78     }
       
    79 
       
    80 // ============================ MEMBER FUNCTIONS ==============================
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // Two-phased constructor.
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 CMPXHarvesterServer* CMPXHarvesterServer::NewL()
       
    87     {
       
    88     CMPXHarvesterServer *server = new(ELeave) CMPXHarvesterServer(
       
    89                                                 EMPXHarvesterServerPriority, 
       
    90                                                 KMPXHarvesterServerPolicy);
       
    91     CleanupStack::PushL(server);
       
    92     server->ConstructL();
       
    93     CleanupStack::Pop(server);
       
    94     return server;
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // C++ constructor can NOT contain any code that might leave.
       
    99 // ----------------------------------------------------------------------------
       
   100 //
       
   101 CMPXHarvesterServer::CMPXHarvesterServer(TInt aPriority, const TPolicy &aPolicy)
       
   102     : CPolicyServer(aPriority, aPolicy) 
       
   103     {}
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // Destructor
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 CMPXHarvesterServer::~CMPXHarvesterServer()
       
   110     {
       
   111     delete iEngine;
       
   112     }
       
   113     
       
   114 // ----------------------------------------------------------------------------
       
   115 // Symbian 2nd phase constructor can leave.
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 void CMPXHarvesterServer::ConstructL()
       
   119     {
       
   120     iEngine = CMPXHarvesterEngine::NewL();
       
   121     StartL(KMPXHarvesterServerName);
       
   122     RProcess().SetPriority(::EPriorityLow);
       
   123     }
       
   124     
       
   125 // ----------------------------------------------------------------------------
       
   126 // Increments number of sessions this server holds
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 void CMPXHarvesterServer::AddClient()
       
   130     {
       
   131     iClients++;
       
   132     }
       
   133     
       
   134  
       
   135 // ----------------------------------------------------------------------------
       
   136 // Decrement the number of clients currently connected to the harvester server
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void CMPXHarvesterServer::RemoveClient()
       
   140     { 
       
   141     iClients--; 
       
   142     ASSERT(iClients>=0); 
       
   143     }
       
   144 
       
   145 // ----------------------------------------------------------------------------
       
   146 // Create a new session
       
   147 // ----------------------------------------------------------------------------
       
   148 //
       
   149 CSession2* CMPXHarvesterServer::NewSessionL(const TVersion& aVersion,
       
   150                                            const RMessage2& /*aMessage*/) const
       
   151     {
       
   152     TVersion v(KMPXHarvesterServerMajorVersionNumber,
       
   153                KMPXHarvesterServerMinorVersionNumber,
       
   154                KMPXHarvesterServerBuildVersionNumber);
       
   155     if (!User::QueryVersionSupported(v,aVersion))
       
   156         {
       
   157         User::Leave(KErrNotSupported);
       
   158         }
       
   159     return CMPXHarvesterSession::NewL(*(const_cast<CMPXHarvesterServer*>(this)),
       
   160                                         *iEngine);
       
   161     }
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 // Server exe entry
       
   165 // ----------------------------------------------------------------------------
       
   166 //
       
   167 TInt E32Main()
       
   168     {
       
   169     __UHEAP_MARK;
       
   170     //
       
   171     CTrapCleanup* cleanup=CTrapCleanup::New();
       
   172     TInt r(KErrNoMemory);
       
   173     if (cleanup)
       
   174         {
       
   175         TRAP(r,StartServerL());
       
   176         }
       
   177         
       
   178     delete cleanup;
       
   179     __UHEAP_MARKEND;
       
   180     return r;
       
   181     }
       
   182