usbmgmt/usbmgr/host/functiondrivers/ms/msmm/server/src/msmmserver.cpp
branchRCL_3
changeset 15 f92a4f87e424
parent 0 c9bc50fca66e
child 16 012cc2ee6408
equal deleted inserted replaced
14:d3e8e7d462dd 15:f92a4f87e424
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19  @file
    19  @file
    20  @internalComponent
    20  @internalComponent
    21 */
    21 */
    22 
    22 
    23 #include "msmmserver.h"
    23 #include "msmmserver.h"
    24 #include <usb/hostms/msmmpolicypluginbase.h>
       
    25 #include "msmm_internal_def.h"
    24 #include "msmm_internal_def.h"
    26 #include "msmmsession.h"
    25 #include "msmmsession.h"
    27 #include "msmmengine.h"
    26 #include "msmmengine.h"
    28 #include "eventqueue.h"
    27 #include "eventqueue.h"
    29 #include "msmmterminator.h"
    28 #include "msmmterminator.h"
    30 
    29 #include "msmmdismountusbdrives.h"
       
    30 
       
    31 #include <usb/hostms/msmmpolicypluginbase.h>
    31 #include <usb/usblogger.h>
    32 #include <usb/usblogger.h>
    32 
    33 #include "OstTraceDefinitions.h"
    33 #ifdef __FLOG_ACTIVE
    34 #ifdef OST_TRACE_COMPILER_IN_USE
    34 _LIT8(KLogComponent, "UsbHostMsmmServer");
    35 #include "msmmserverTraces.h"
    35 #endif
    36 #endif
       
    37 
    36 
    38 
    37 //  Static public functions
    39 //  Static public functions
    38 TInt CMsmmServer::ThreadFunction()
    40 TInt CMsmmServer::ThreadFunction()
    39     {
    41     {
    40     TInt ret = KErrNone;
    42     TInt ret = KErrNone;
    42     __UHEAP_MARK;
    44     __UHEAP_MARK;
    43     // Create the cleanup stack
    45     // Create the cleanup stack
    44     CTrapCleanup* cleanupStack = CTrapCleanup::New();
    46     CTrapCleanup* cleanupStack = CTrapCleanup::New();
    45     if (cleanupStack)
    47     if (cleanupStack)
    46         {
    48         {
    47 #ifdef __FLOG_ACTIVE
       
    48         (void)CUsbLog::Connect();
       
    49 #endif
       
    50 
       
    51         TRAP(ret, ThreadFunctionL());
    49         TRAP(ret, ThreadFunctionL());
    52 
       
    53 #ifdef __FLOG_ACTIVE
       
    54         CUsbLog::Close();
       
    55 #endif
       
    56         
    50         
    57         delete cleanupStack;
    51         delete cleanupStack;
    58         }
    52         }
    59     else
    53     else
    60         {
    54         {
    65     return ret;
    59     return ret;
    66     }
    60     }
    67 
    61 
    68 void CMsmmServer::ThreadFunctionL()
    62 void CMsmmServer::ThreadFunctionL()
    69     {
    63     {
    70     LOG_STATIC_FUNC_ENTRY
    64     OstTraceFunctionEntry0( CMSMMSERVER_THREADFUNCTIONL_ENTRY );
    71     
    65     
    72     TSecureId creatorSID = User::CreatorSecureId();
    66     TSecureId creatorSID = User::CreatorSecureId();
    73     if (KFDFWSecureId != creatorSID)
    67     if (KFDFWSecureId != creatorSID)
    74         {
    68         {
    75         // Only FDF process can be the creator of the MSMM server
    69         // Only FDF process can be the creator of the MSMM server
    93     // request messages from clients.
    87     // request messages from clients.
    94     CActiveScheduler::Start();
    88     CActiveScheduler::Start();
    95 
    89 
    96     // Free the server and active scheduler.
    90     // Free the server and active scheduler.
    97     CleanupStack::PopAndDestroy(2, scheduler);
    91     CleanupStack::PopAndDestroy(2, scheduler);
    98     }
    92     OstTraceFunctionExit0( CMSMMSERVER_THREADFUNCTIONL_EXIT );
       
    93     }
       
    94 
       
    95 CPolicyServer::TCustomResult CMsmmServer::CustomSecurityCheckL(
       
    96     const RMessage2&  aMsg,
       
    97      TInt&  /*aAction*/,
       
    98      TSecurityInfo&  /*aMissing*/)
       
    99  {
       
   100      CPolicyServer::TCustomResult returnValue = CPolicyServer::EFail;    
       
   101      
       
   102      TSecureId ClientSID = aMsg.SecureId();
       
   103  
       
   104      if (KFDFWSecureId == ClientSID)
       
   105          {
       
   106          returnValue = CPolicyServer::EPass;
       
   107          }     
       
   108      else if ((KSidHbDeviceDialogAppServer == ClientSID) && SessionNumber() > 0)
       
   109          {
       
   110          returnValue = CPolicyServer::EPass;
       
   111          }
       
   112      return returnValue;
       
   113  }
    99 
   114 
   100 // Public functions
   115 // Public functions
   101 // Construction and destruction
   116 // Construction and destruction
   102 CMsmmServer* CMsmmServer::NewLC()
   117 CMsmmServer* CMsmmServer::NewLC()
   103     {
   118     {
   104     LOG_STATIC_FUNC_ENTRY
   119     OstTraceFunctionEntry0( CMSMMSERVER_NEWLC_ENTRY );
       
   120     
   105     CMsmmServer* self = new (ELeave) CMsmmServer(EPriorityHigh);
   121     CMsmmServer* self = new (ELeave) CMsmmServer(EPriorityHigh);
   106     CleanupStack::PushL(self);
   122     CleanupStack::PushL(self);
   107     
   123     
   108     // Create a server with unique server name
   124     // Create a server with unique server name
   109     self->StartL(KMsmmServerName);
   125     self->StartL(KMsmmServerName);
   110     self->ConstructL();
   126     self->ConstructL();
   111     
   127     
       
   128     OstTraceFunctionExit0( CMSMMSERVER_NEWLC_EXIT );
   112     return self;
   129     return self;
   113     }
   130     }
   114 
   131 
   115 CMsmmServer::~CMsmmServer()
   132 CMsmmServer::~CMsmmServer()
   116     {
   133     {
   117     LOG_FUNC
   134     OstTraceFunctionEntry0( CMSMMSERVER_CMSMMSERVER_DES_ENTRY );
       
   135     
   118     delete iPolicyPlugin;
   136     delete iPolicyPlugin;
   119     delete iEventQueue;
   137     delete iEventQueue;
   120     delete iEngine;
   138     delete iEngine;
   121     delete iTerminator;
   139     delete iTerminator;
       
   140     delete iDismountErrData;
       
   141     delete iDismountManager;
   122     REComSession::FinalClose();
   142     REComSession::FinalClose();
   123 
   143 
   124 #ifndef __OVER_DUMMYCOMPONENT__
   144 #ifndef __OVER_DUMMYCOMPONENT__
   125     iFs.RemoveProxyDrive(KPROXYDRIVENAME);
   145     iFs.RemoveProxyDrive(KPROXYDRIVENAME);
   126     iFs.Close();
   146     iFs.Close();
   127 #endif
   147 #endif
       
   148     OstTraceFunctionExit0( CMSMMSERVER_CMSMMSERVER_DES_EXIT );
   128     }
   149     }
   129     
   150     
   130     // CMsmmServer APIs
   151     // CMsmmServer APIs
   131 CSession2* CMsmmServer::NewSessionL(const TVersion& aVersion, 
   152 CSession2* CMsmmServer::NewSessionL(const TVersion& aVersion, 
   132         const RMessage2& aMessage) const
   153         const RMessage2& aMessage) const
   133     {
   154     {
   134     LOG_FUNC
   155     OstTraceFunctionEntry0( CMSMMSERVER_NEWSESSIONL_ENTRY );
   135     
   156     
   136     if (KMaxClientCount <= SessionNumber())
   157     if (KMaxClientCount <= SessionNumber())
   137         {
   158         {
   138         // There is a connection to MSMM server already.
   159         // There is a connection to MSMM server already.
   139         // Currently design of MSMM allows only one activated client 
   160         // Currently design of MSMM can have two clients, one FDF and the other Indicator UI
   140         // at any time.
   161         // at any time.
   141         User::Leave(KErrInUse);
   162         User::Leave(KErrInUse);
   142         }
   163         }
   143     
   164     
   144     // Check the client-side API version number against the server version 
   165     // Check the client-side API version number against the server version 
   157     return CMsmmSession::NewL(*(const_cast<CMsmmServer*>(this)), *iEventQueue);
   178     return CMsmmSession::NewL(*(const_cast<CMsmmServer*>(this)), *iEventQueue);
   158     }
   179     }
   159 
   180 
   160 TInt CMsmmServer::SessionNumber() const
   181 TInt CMsmmServer::SessionNumber() const
   161     {
   182     {
   162     LOG_FUNC
   183     OstTraceFunctionEntry0( CMSMMSERVER_SESSIONNUMBER_ENTRY );
   163     
       
   164     return iNumSessions;
   184     return iNumSessions;
   165     }
   185     }
   166 
   186 
   167 void CMsmmServer::AddSession()
   187 void CMsmmServer::AddSession()
   168     {
   188     {
   169     LOG_FUNC
   189     OstTraceFunctionEntry0( CMSMMSERVER_ADDSESSION_ENTRY );
   170     
   190      
   171     ++iNumSessions;
   191     ++iNumSessions;
   172     iTerminator->Cancel();
   192     iTerminator->Cancel();
       
   193     OstTraceFunctionExit0( CMSMMSERVER_ADDSESSION_EXIT );
   173     }
   194     }
   174 
   195 
   175 void CMsmmServer::RemoveSession()
   196 void CMsmmServer::RemoveSession()
   176     {
   197     {
   177     LOG_FUNC
   198     OstTraceFunctionEntry0( CMSMMSERVER_REMOVESESSION_ENTRY );
   178     
   199     
   179     --iNumSessions;
   200     --iNumSessions;
   180     if (iNumSessions == 0)
   201     if (iNumSessions == 0)
   181         {
   202         {
   182         // Discard all pending adding interface events from queue
   203         // Discard all pending adding interface events from queue
   184         // handled in it.
   205         // handled in it.
   185         iEventQueue->Finalize();
   206         iEventQueue->Finalize();
   186         iTerminator->Cancel();
   207         iTerminator->Cancel();
   187         iTerminator->Start();
   208         iTerminator->Start();
   188         }
   209         }
   189     }
   210 		
       
   211     OstTraceFunctionExit0( CMSMMSERVER_REMOVESESSION_EXIT );
       
   212     }
       
   213 	
       
   214 	void CMsmmServer::DismountUsbDrivesL(TUSBMSDeviceDescription& aDevice)
       
   215     {
       
   216     OstTraceFunctionEntry0( CMSMMSERVER_DISMOUNTUSBDRIVERSL_ENTRY );
       
   217     delete iDismountManager;
       
   218     iDismountManager = NULL;
       
   219     iDismountManager= CMsmmDismountUsbDrives::NewL();
       
   220     
       
   221     //Also notify the MSMM plugin of beginning of dismounting     
       
   222     iDismountErrData->iError = EHostMsEjectInProgress;
       
   223     iDismountErrData->iE32Error = KErrNone;
       
   224     iDismountErrData->iManufacturerString = aDevice.iManufacturerString;
       
   225     iDismountErrData->iProductString = aDevice.iProductString;
       
   226     iDismountErrData->iDriveName = 0x0;
       
   227    
       
   228     TRAP_IGNORE(iPolicyPlugin->SendErrorNotificationL(*iDismountErrData));
       
   229 
       
   230     // Start dismounting
       
   231     iDismountManager->DismountUsbDrives(*iPolicyPlugin, aDevice);
       
   232 	OstTraceFunctionExit0( CMSMMSERVER_DISMOUNTUSBDRIVERSL_EXIT );
       
   233     }
       
   234 
   190 
   235 
   191 //  Private functions 
   236 //  Private functions 
   192 // CMsmmServer Construction
   237 // CMsmmServer Construction
   193 CMsmmServer::CMsmmServer(TInt aPriority)
   238 CMsmmServer::CMsmmServer(TInt aPriority)
   194     :CPolicyServer(aPriority, KMsmmServerSecurityPolicy, EUnsharableSessions)
   239     :CPolicyServer(aPriority, KMsmmServerSecurityPolicy, EUnsharableSessions)
   195     {
   240     {
   196     LOG_FUNC
   241     OstTraceFunctionEntry0( CMSMMSERVER_CMSMMSERVER_CONS_ENTRY );
   197     //
       
   198     }
   242     }
   199 
   243 
   200 void CMsmmServer::ConstructL()
   244 void CMsmmServer::ConstructL()
   201     {
   245     {
   202     LOG_FUNC
   246     OstTraceFunctionEntry0( CMSMMSERVER_CONSTRUCTL_ENTRY );
   203     
   247     
   204     iEngine = CMsmmEngine::NewL();
   248     iEngine = CMsmmEngine::NewL();
   205     iEventQueue = CDeviceEventQueue::NewL(*this);
   249     iEventQueue = CDeviceEventQueue::NewL(*this);
   206     iTerminator = CMsmmTerminator::NewL(*iEventQueue);
   250     iTerminator = CMsmmTerminator::NewL(*iEventQueue);
   207     iPolicyPlugin = CMsmmPolicyPluginBase::NewL();
   251     iPolicyPlugin = CMsmmPolicyPluginBase::NewL();
       
   252     iDismountErrData = new (ELeave) THostMsErrData;
   208     if (!iPolicyPlugin)
   253     if (!iPolicyPlugin)
   209         {
   254         {
   210         // Not any policy plugin implementation available
   255         // Not any policy plugin implementation available
   211         PanicServer(ENoPolicyPlugin);
   256         PanicServer(ENoPolicyPlugin);
   212         }
   257         }
   223         }
   268         }
   224 #endif
   269 #endif
   225     
   270     
   226     // Start automatic shutdown timer
   271     // Start automatic shutdown timer
   227     iTerminator->Start();
   272     iTerminator->Start();
       
   273     OstTraceFunctionExit0( CMSMMSERVER_CONSTRUCTL_EXIT );
   228     }
   274     }
   229 
   275 
   230 // End of file
   276 // End of file