usbmgmt/usbmgr/host/fdf/production/server/src/fdfserver.cpp
branchRCL_3
changeset 16 012cc2ee6408
parent 15 f92a4f87e424
equal deleted inserted replaced
15:f92a4f87e424 16:012cc2ee6408
     1 /*
     1 /*
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2009 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".
    24 #include "fdfsession.h"
    24 #include "fdfsession.h"
    25 #include <usb/usblogger.h>
    25 #include <usb/usblogger.h>
    26 #include "utils.h"
    26 #include "utils.h"
    27 #include "fdfapi.h"
    27 #include "fdfapi.h"
    28 #include "fdf.h"
    28 #include "fdf.h"
    29 #include "OstTraceDefinitions.h"
    29 
    30 #ifdef OST_TRACE_COMPILER_IN_USE
    30 #ifdef __FLOG_ACTIVE
    31 #include "fdfserverTraces.h"
    31 _LIT8(KLogComponent, "fdf      ");
    32 #endif
    32 #endif
    33 
    33 
    34 #ifdef _DEBUG
    34 #ifdef _DEBUG
    35 _LIT(KPanicCategory, "fdfsrv");
    35 PANICCATEGORY("fdfsrv");
    36 #endif
    36 #endif
    37 
       
    38 
    37 
    39 void CFdfServer::NewLC()
    38 void CFdfServer::NewLC()
    40 	{
    39 	{
    41 	OstTraceFunctionEntry0( CFDFSERVER_NEWLC_ENTRY );
    40 	LOG_STATIC_FUNC_ENTRY
    42 	
    41 
    43 	CFdfServer* self = new(ELeave) CFdfServer;
    42 	CFdfServer* self = new(ELeave) CFdfServer;
    44 	CleanupStack::PushL(self);
    43 	CleanupStack::PushL(self);
    45 	// StartL is where the kernel checks that there isn't already an instance
    44 	// StartL is where the kernel checks that there isn't already an instance
    46 	// of the same server running, so do it before ConstructL.
    45 	// of the same server running, so do it before ConstructL.
    47 	self->StartL(KUsbFdfServerName);
    46 	self->StartL(KUsbFdfServerName);
    48 	self->ConstructL();
    47 	self->ConstructL();
    49 	OstTraceFunctionExit0( CFDFSERVER_NEWLC_EXIT );
       
    50 	}
    48 	}
    51 
    49 
    52 CFdfServer::~CFdfServer()
    50 CFdfServer::~CFdfServer()
    53 	{
    51 	{
    54 	OstTraceFunctionEntry0( CFDFSERVER_CFDFSERVER_DES_ENTRY );
    52 	LOG_FUNC
    55 	
       
    56 
    53 
    57 	delete iFdf;
    54 	delete iFdf;
    58 	OstTraceFunctionExit0( CFDFSERVER_CFDFSERVER_DES_EXIT );
       
    59 	}
    55 	}
    60 
    56 
    61 CFdfServer::CFdfServer()
    57 CFdfServer::CFdfServer()
    62  :	CServer2(CActive::EPriorityHigh)
    58  :	CServer2(CActive::EPriorityHigh)
    63 	{
    59 	{
    64 	}
    60 	}
    65 
    61 
    66 void CFdfServer::ConstructL()
    62 void CFdfServer::ConstructL()
    67 	{
    63 	{
    68 	OstTraceFunctionEntry0( CFDFSERVER_CONSTRUCTL_ENTRY );
    64 	LOG_FUNC
    69 	
    65 
    70 	iFdf = CFdf::NewL();
    66 	iFdf = CFdf::NewL();
    71 	OstTraceFunctionExit0( CFDFSERVER_CONSTRUCTL_EXIT );
       
    72 	}
    67 	}
    73 
    68 
    74 CSession2* CFdfServer::NewSessionL(const TVersion& aVersion,
    69 CSession2* CFdfServer::NewSessionL(const TVersion& aVersion,
    75 	const RMessage2& aMessage) const
    70 	const RMessage2& aMessage) const
    76 	{
    71 	{
    77 	OstTraceFunctionEntry0( CFDFSERVER_NEWSESSIONL_ENTRY );
    72 	LOG_LINE
    78 	OstTraceExt3( TRACE_NORMAL, CFDFSERVER_NEWSESSIONL, "aVersion = (%d,%d,%d)", aVersion.iMajor, aVersion.iMinor, aVersion.iBuild );
    73 	LOG_FUNC;
       
    74 	LOGTEXT4(_L8("\taVersion = (%d,%d,%d)"), aVersion.iMajor, aVersion.iMinor, aVersion.iBuild);
    79 	(void)aMessage;
    75 	(void)aMessage;
    80 
    76 
    81 	// Check if we already have a session open.
    77 	// Check if we already have a session open.
    82 	if ( iSession )
    78 	if ( iSession )
    83 		{
    79 		{
    84 		OstTrace0( TRACE_NORMAL, CFDFSERVER_NEWSESSIONL_DUP1, 
    80 		LEAVEL(KErrInUse);
    85 		        "Session in use");
       
    86 		User::Leave(KErrInUse);
       
    87 		}
    81 		}
    88 
    82 
    89 	// In the production system, check the secure ID of the prospective
    83 	// In the production system, check the secure ID of the prospective
    90 	// client. It should be that of USBSVR.
    84 	// client. It should be that of USBSVR.
    91 	// For unit testing, don't check the SID of the connecting client (it will
    85 	// For unit testing, don't check the SID of the connecting client (it will
   100 	// use a _LIT_SECURITY_POLICY_S0 here. This is because (a) we emit our own
    94 	// use a _LIT_SECURITY_POLICY_S0 here. This is because (a) we emit our own
   101 	// diagnostic messages, and (b) we don't want configuring this security
    95 	// diagnostic messages, and (b) we don't want configuring this security
   102 	// check OFF to allow any client to pass and thereby break our
    96 	// check OFF to allow any client to pass and thereby break our
   103 	// architecture.
    97 	// architecture.
   104 	TInt error = ( aMessage.SecureId() == KUsbsvrSecureId ) ? KErrNone : KErrPermissionDenied;
    98 	TInt error = ( aMessage.SecureId() == KUsbsvrSecureId ) ? KErrNone : KErrPermissionDenied;
   105 	LEAVEIFERRORL(error,OstTrace0( TRACE_NORMAL, CFDFSERVER_NEWSESSIONL_DUP2, 
    99 	LEAVEIFERRORL(error);
   106             "SecureId error"););
       
   107 #endif // __TEST_FDF__
   100 #endif // __TEST_FDF__
   108 
   101 
   109 #endif // __OVER_DUMMYUSBDI__
   102 #endif // __OVER_DUMMYUSBDI__
   110 
   103 
   111 	// Version number check...
   104 	// Version number check...
   113 		KUsbFdfSrvMinorVersionNumber,
   106 		KUsbFdfSrvMinorVersionNumber,
   114 		KUsbFdfSrvBuildNumber);
   107 		KUsbFdfSrvBuildNumber);
   115 
   108 
   116 	if ( !User::QueryVersionSupported(v, aVersion) )
   109 	if ( !User::QueryVersionSupported(v, aVersion) )
   117 		{
   110 		{
   118 		OstTrace0( TRACE_NORMAL, CFDFSERVER_NEWSESSIONL_DUP3, 
   111 		LEAVEL(KErrNotSupported);
   119                 "Version not supported");
       
   120 		User::Leave(KErrNotSupported);
       
   121 		}
   112 		}
   122 
   113 
   123 	CFdfServer* ncThis = const_cast<CFdfServer*>(this);
   114 	CFdfServer* ncThis = const_cast<CFdfServer*>(this);
   124 	ncThis->iSession = new(ELeave) CFdfSession(*iFdf, *ncThis);
   115 	ncThis->iSession = new(ELeave) CFdfSession(*iFdf, *ncThis);
   125 	if(!ncThis->iFdf)
   116 	ASSERT_DEBUG(ncThis->iFdf);
   126 	    {
       
   127         OstTrace0( TRACE_FATAL, CFDFSERVER_NEWSESSIONL_DUP4,"ncThis->iFdf is empty"); 
       
   128         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   129 	    }
       
   130             
       
   131 	ncThis->iFdf->SetSession(iSession);
   117 	ncThis->iFdf->SetSession(iSession);
   132 
   118 
   133 	OstTrace1( TRACE_NORMAL, CFDFSERVER_NEWSESSIONL_DUP5, "iSession = 0x%08x", iSession );
   119 	LOGTEXT2(_L8("\tiSession = 0x%08x"), iSession);
   134 	OstTraceFunctionExit0( CFDFSERVER_NEWSESSIONL_EXIT );
       
   135 	return iSession;
   120 	return iSession;
   136 	}
   121 	}
   137 
   122 
   138 void CFdfServer::SessionClosed()
   123 void CFdfServer::SessionClosed()
   139 	{
   124 	{
   140     OstTraceFunctionEntry0( CFDFSERVER_SESSIONCLOSED_ENTRY );
   125 	LOG_FUNC
   141 
   126 
   142 	if(!iSession)
   127 	ASSERT_DEBUG(iSession);
   143 	    {
       
   144         OstTrace0( TRACE_FATAL, CFDFSERVER_SESSIONCLOSED,"Empty iSession" ); 
       
   145         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   146 	    }
       
   147 	        
       
   148 	iSession = NULL;
   128 	iSession = NULL;
   149 	iFdf->SetSession(NULL);
   129 	iFdf->SetSession(NULL);
   150 
   130 
   151 	OstTrace0( TRACE_NORMAL, CFDFSERVER_SESSIONCLOSED_DUP1, "no remaining sessions- shutting down" );
   131 	LOGTEXT(_L8("\tno remaining sessions- shutting down"));
   152 	
       
   153 	// This returns control to the server boilerplate in main.cpp. This
   132 	// This returns control to the server boilerplate in main.cpp. This
   154 	// destroys all the objects, which includes signalling device detachment
   133 	// destroys all the objects, which includes signalling device detachment
   155 	// to any extant FDCs.
   134 	// to any extant FDCs.
   156 	// The session object could perfectly well do this in its destructor but
   135 	// The session object could perfectly well do this in its destructor but
   157 	// it's arguably more clear for the server to do it as it's the server
   136 	// it's arguably more clear for the server to do it as it's the server
   158 	// that's created immediately before calling CActiveScheduler::Start in
   137 	// that's created immediately before calling CActiveScheduler::Start in
   159 	// main.cpp.
   138 	// main.cpp.
   160 	CActiveScheduler::Stop();
   139 	CActiveScheduler::Stop();
   161 	OstTraceFunctionExit0( CFDFSERVER_SESSIONCLOSED_EXIT );
       
   162 	}
   140 	}