mpx/collectionframework/collectionserver/src/mpxcollectionserver.cpp
changeset 0 a2952bb97e68
child 34 e257e2b6459d
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:  Collection server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32svr.h>
       
    21 #include "mpxcollectionframeworkdefs.h"
       
    22 #include "mpxcollectionserverdefs.h"
       
    23 #include "mpxcollectionserversession.h"
       
    24 #include "mpxcollectionengine.h"
       
    25 #include "mpxcollectionserver.h"
       
    26 
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // Server Security Policy
       
    31 const TUint KMPXCollectionServerRangeCount = 2;
       
    32 const TInt KMPXCollectionServerRanges[KMPXCollectionServerRangeCount] = 
       
    33     {
       
    34     0,                  //range is [0-EMcsServerOpEnd)
       
    35     EMcsServerOpEnd,    //range is [EMcsServerOpEnd-KMaxTInt] 
       
    36     };
       
    37 const TUint8 KMPXCollectionSeverElementsIndex[KMPXCollectionServerRangeCount] = 
       
    38     {
       
    39     0,                            //applies to range [0-EMcsServerOpEnd)
       
    40     CPolicyServer::ENotSupported, //applies to range [EMcsServerOpEnd-KMaxTInt]
       
    41     };
       
    42     
       
    43 const CPolicyServer::TPolicyElement KMPXCollectionServerPolicyElements[] = 
       
    44     {
       
    45     {_INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData), 
       
    46                               CPolicyServer::EFailClient},
       
    47     };
       
    48     
       
    49 const CPolicyServer::TPolicy KMPXCollectionServerPolicy =
       
    50     {
       
    51     CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
       
    52     KMPXCollectionServerRangeCount,                   
       
    53     KMPXCollectionServerRanges,
       
    54     KMPXCollectionSeverElementsIndex,
       
    55     KMPXCollectionServerPolicyElements,
       
    56     };
       
    57 
       
    58 
       
    59 // ============================ LOCAL FUNCTIONS ==============================
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // Start collection server
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 LOCAL_C void StartServerL()
       
    66     {
       
    67     User::LeaveIfError(User::RenameThread(KMPXCollectionServerName));
       
    68     CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
    69     CleanupStack::PushL(scheduler);    
       
    70     CActiveScheduler::Install(scheduler);
       
    71     CMPXCollectionServer* server = CMPXCollectionServer::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 CMPXCollectionServer* CMPXCollectionServer::NewL()
       
    87     {
       
    88     CMPXCollectionServer *pS = new(ELeave) CMPXCollectionServer(
       
    89                                                 CActive::EPriorityStandard,
       
    90                                                 KMPXCollectionServerPolicy);
       
    91     CleanupStack::PushL(pS);
       
    92     pS->ConstructL();
       
    93     CleanupStack::Pop(pS);
       
    94     return pS;
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // C++ constructor can NOT contain any code that might leave.
       
    99 // ----------------------------------------------------------------------------
       
   100 //
       
   101 CMPXCollectionServer::CMPXCollectionServer(TInt aPriority, const TPolicy &aPolicy)
       
   102     : CPolicyServer(aPriority, aPolicy) 
       
   103     {}
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // Destructor
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 CMPXCollectionServer::~CMPXCollectionServer()
       
   110     {
       
   111     delete iEngine;
       
   112     }
       
   113     
       
   114 // ----------------------------------------------------------------------------
       
   115 // Symbian 2nd phase constructor can leave.
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 void CMPXCollectionServer::ConstructL()
       
   119     {
       
   120     iEngine = CMPXCollectionEngine::NewL();
       
   121     StartL(KMPXCollectionServerName);
       
   122     }
       
   123  
       
   124 // ----------------------------------------------------------------------------
       
   125 // Find the collection that has client aName, and remove it from that collection; 
       
   126 // if that collection has no clients, then delete that collection. If the server 
       
   127 // has no more client sessions, then stop the server.
       
   128 // ----------------------------------------------------------------------------
       
   129 //
       
   130 void CMPXCollectionServer::RemoveClient()
       
   131     { 
       
   132     iClients--; 
       
   133     MPX_ASSERT(iClients>=0); 
       
   134     if (iClients==0)
       
   135         {
       
   136         CActiveScheduler::Stop(); 
       
   137         }
       
   138     }
       
   139 
       
   140 // ----------------------------------------------------------------------------
       
   141 // Create a new session
       
   142 // ----------------------------------------------------------------------------
       
   143 //
       
   144 CSession2* CMPXCollectionServer::NewSessionL(const TVersion& aVersion,
       
   145                                              const RMessage2& /*aMessage*/) const
       
   146     {
       
   147     TVersion v(KMPXCollectionServerMajorVersionNumber,
       
   148                KMPXCollectionServerMinorVersionNumber,
       
   149                KMPXCollectionServerBuildVersionNumber);
       
   150     if (!User::QueryVersionSupported(v,aVersion))
       
   151         User::Leave(KErrNotSupported);
       
   152     CSession2* session = CMPXCollectionSession::NewL(*iEngine);
       
   153     const_cast<CMPXCollectionServer*>(this)->iClients++;;
       
   154     return session;
       
   155     }
       
   156 
       
   157 // ----------------------------------------------------------------------------
       
   158 // Server exe entry
       
   159 // ----------------------------------------------------------------------------
       
   160 //
       
   161 TInt E32Main()
       
   162     {
       
   163     __UHEAP_MARK;
       
   164     //
       
   165     CTrapCleanup* cleanup=CTrapCleanup::New();
       
   166     TInt r=KErrNoMemory;
       
   167     if (cleanup)
       
   168         {
       
   169         TRAP(r,StartServerL());
       
   170         }
       
   171         
       
   172     delete cleanup;
       
   173     __UHEAP_MARKEND;
       
   174     return r;
       
   175     }
       
   176 
       
   177 // End of file