usbmgmt/usbmgr/host/functiondrivers/ms/msmm/server/src/msmmserver.cpp
changeset 0 c9bc50fca66e
child 25 4ddb65515edd
child 42 f92a4f87e424
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include "msmmserver.h"
       
    24 #include <usb/hostms/msmmpolicypluginbase.h>
       
    25 #include "msmm_internal_def.h"
       
    26 #include "msmmsession.h"
       
    27 #include "msmmengine.h"
       
    28 #include "eventqueue.h"
       
    29 #include "msmmterminator.h"
       
    30 
       
    31 #include <usb/usblogger.h>
       
    32 
       
    33 #ifdef __FLOG_ACTIVE
       
    34 _LIT8(KLogComponent, "UsbHostMsmmServer");
       
    35 #endif
       
    36 
       
    37 //  Static public functions
       
    38 TInt CMsmmServer::ThreadFunction()
       
    39     {
       
    40     TInt ret = KErrNone;
       
    41     
       
    42     __UHEAP_MARK;
       
    43     // Create the cleanup stack
       
    44     CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
    45     if (cleanupStack)
       
    46         {
       
    47 #ifdef __FLOG_ACTIVE
       
    48         (void)CUsbLog::Connect();
       
    49 #endif
       
    50 
       
    51         TRAP(ret, ThreadFunctionL());
       
    52 
       
    53 #ifdef __FLOG_ACTIVE
       
    54         CUsbLog::Close();
       
    55 #endif
       
    56         
       
    57         delete cleanupStack;
       
    58         }
       
    59     else
       
    60         {
       
    61         ret = KErrNoMemory;
       
    62         }
       
    63     __UHEAP_MARKEND;
       
    64     
       
    65     return ret;
       
    66     }
       
    67 
       
    68 void CMsmmServer::ThreadFunctionL()
       
    69     {
       
    70     LOG_STATIC_FUNC_ENTRY
       
    71     
       
    72     TSecureId creatorSID = User::CreatorSecureId();
       
    73     if (KFDFWSecureId != creatorSID)
       
    74         {
       
    75         // Only FDF process can be the creator of the MSMM server
       
    76         User::Leave(KErrPermissionDenied);
       
    77         }
       
    78     
       
    79     // Create and install the active scheduler
       
    80     CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
       
    81     CleanupStack::PushL(scheduler);
       
    82     CActiveScheduler::Install(scheduler);
       
    83 
       
    84     // Create the server and leave it on cleanup stack
       
    85     CMsmmServer::NewLC();
       
    86 
       
    87     // Signal the client that the server is up and running
       
    88     RProcess::Rendezvous(KErrNone);
       
    89     
       
    90     RThread().SetPriority(EPriorityAbsoluteHigh);
       
    91 
       
    92     // Start the active scheduler, the server will now service 
       
    93     // request messages from clients.
       
    94     CActiveScheduler::Start();
       
    95 
       
    96     // Free the server and active scheduler.
       
    97     CleanupStack::PopAndDestroy(2, scheduler);
       
    98     }
       
    99 
       
   100 // Public functions
       
   101 // Construction and destruction
       
   102 CMsmmServer* CMsmmServer::NewLC()
       
   103     {
       
   104     LOG_STATIC_FUNC_ENTRY
       
   105     CMsmmServer* self = new (ELeave) CMsmmServer(EPriorityHigh);
       
   106     CleanupStack::PushL(self);
       
   107     
       
   108     // Create a server with unique server name
       
   109     self->StartL(KMsmmServerName);
       
   110     self->ConstructL();
       
   111     
       
   112     return self;
       
   113     }
       
   114 
       
   115 CMsmmServer::~CMsmmServer()
       
   116     {
       
   117     LOG_FUNC
       
   118     delete iPolicyPlugin;
       
   119     delete iEventQueue;
       
   120     delete iEngine;
       
   121     delete iTerminator;
       
   122     REComSession::FinalClose();
       
   123 
       
   124 #ifndef __OVER_DUMMYCOMPONENT__
       
   125     iFs.RemoveProxyDrive(KPROXYDRIVENAME);
       
   126     iFs.Close();
       
   127 #endif
       
   128     }
       
   129     
       
   130     // CMsmmServer APIs
       
   131 CSession2* CMsmmServer::NewSessionL(const TVersion& aVersion, 
       
   132         const RMessage2& aMessage) const
       
   133     {
       
   134     LOG_FUNC
       
   135     
       
   136     if (KMaxClientCount <= SessionNumber())
       
   137         {
       
   138         // There is a connection to MSMM server already.
       
   139         // Currently design of MSMM allows only one activated client 
       
   140         // at any time.
       
   141         User::Leave(KErrInUse);
       
   142         }
       
   143     
       
   144     // Check the client-side API version number against the server version 
       
   145     // number.
       
   146     TVersion serverVersion(KMsmmServMajorVersionNumber,
       
   147         KMsmmServMinorVersionNumber, KMsmmServBuildVersionNumber);
       
   148     
       
   149     if (!User::QueryVersionSupported(serverVersion, aVersion))
       
   150         {
       
   151         // Server version incompatible with client-side API
       
   152         PanicClient(aMessage, ENoSupportedVersion);
       
   153         User::Leave(KErrNotSupported);
       
   154         }
       
   155 
       
   156     // Version number is OK - create the session
       
   157     return CMsmmSession::NewL(*(const_cast<CMsmmServer*>(this)), *iEventQueue);
       
   158     }
       
   159 
       
   160 TInt CMsmmServer::SessionNumber() const
       
   161     {
       
   162     LOG_FUNC
       
   163     
       
   164     return iNumSessions;
       
   165     }
       
   166 
       
   167 void CMsmmServer::AddSession()
       
   168     {
       
   169     LOG_FUNC
       
   170     
       
   171     ++iNumSessions;
       
   172     iTerminator->Cancel();
       
   173     }
       
   174 
       
   175 void CMsmmServer::RemoveSession()
       
   176     {
       
   177     LOG_FUNC
       
   178     
       
   179     --iNumSessions;
       
   180     if (iNumSessions == 0)
       
   181         {
       
   182         // Discard all pending adding interface events from queue
       
   183         // and cancel event handler if a adding events is being 
       
   184         // handled in it.
       
   185         iEventQueue->Finalize();
       
   186         iTerminator->Cancel();
       
   187         iTerminator->Start();
       
   188         }
       
   189     }
       
   190 
       
   191 //  Private functions 
       
   192 // CMsmmServer Construction
       
   193 CMsmmServer::CMsmmServer(TInt aPriority)
       
   194     :CPolicyServer(aPriority, KMsmmServerSecurityPolicy, EUnsharableSessions)
       
   195     {
       
   196     LOG_FUNC
       
   197     //
       
   198     }
       
   199 
       
   200 void CMsmmServer::ConstructL()
       
   201     {
       
   202     LOG_FUNC
       
   203     
       
   204     iEngine = CMsmmEngine::NewL();
       
   205     iEventQueue = CDeviceEventQueue::NewL(*this);
       
   206     iTerminator = CMsmmTerminator::NewL(*iEventQueue);
       
   207     iPolicyPlugin = CMsmmPolicyPluginBase::NewL();
       
   208     if (!iPolicyPlugin)
       
   209         {
       
   210         // Not any policy plugin implementation available
       
   211         PanicServer(ENoPolicyPlugin);
       
   212         }
       
   213     
       
   214     // Initalize RFs connection and add the ELOCAL file system to file server
       
   215     User::LeaveIfError(iFs.Connect());
       
   216 
       
   217 #ifndef __OVER_DUMMYCOMPONENT__
       
   218     TInt ret(KErrNone);
       
   219     ret = iFs.AddProxyDrive(KFSEXTNAME);
       
   220     if ((KErrNone != ret) && (KErrAlreadyExists !=  ret))
       
   221         {
       
   222         User::Leave(ret);
       
   223         }
       
   224 #endif
       
   225     
       
   226     // Start automatic shutdown timer
       
   227     iTerminator->Start();
       
   228     }
       
   229 
       
   230 // End of file