usbmgmt/usbmgr/host/fdf/production/server/src/fdfserver.cpp
changeset 0 c9bc50fca66e
child 29 59aa7d6e3e0f
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2007-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 "fdfserver.h"
       
    24 #include "fdfsession.h"
       
    25 #include <usb/usblogger.h>
       
    26 #include "utils.h"
       
    27 #include "fdfapi.h"
       
    28 #include "fdf.h"
       
    29 
       
    30 #ifdef __FLOG_ACTIVE
       
    31 _LIT8(KLogComponent, "fdf      ");
       
    32 #endif
       
    33 
       
    34 #ifdef _DEBUG
       
    35 PANICCATEGORY("fdfsrv");
       
    36 #endif
       
    37 
       
    38 void CFdfServer::NewLC()
       
    39 	{
       
    40 	LOG_STATIC_FUNC_ENTRY
       
    41 
       
    42 	CFdfServer* self = new(ELeave) CFdfServer;
       
    43 	CleanupStack::PushL(self);
       
    44 	// StartL is where the kernel checks that there isn't already an instance
       
    45 	// of the same server running, so do it before ConstructL.
       
    46 	self->StartL(KUsbFdfServerName);
       
    47 	self->ConstructL();
       
    48 	}
       
    49 
       
    50 CFdfServer::~CFdfServer()
       
    51 	{
       
    52 	LOG_FUNC
       
    53 
       
    54 	delete iFdf;
       
    55 	}
       
    56 
       
    57 CFdfServer::CFdfServer()
       
    58  :	CServer2(CActive::EPriorityHigh)
       
    59 	{
       
    60 	}
       
    61 
       
    62 void CFdfServer::ConstructL()
       
    63 	{
       
    64 	LOG_FUNC
       
    65 
       
    66 	iFdf = CFdf::NewL();
       
    67 	}
       
    68 
       
    69 CSession2* CFdfServer::NewSessionL(const TVersion& aVersion,
       
    70 	const RMessage2& aMessage) const
       
    71 	{
       
    72 	LOG_LINE
       
    73 	LOG_FUNC;
       
    74 	LOGTEXT4(_L8("\taVersion = (%d,%d,%d)"), aVersion.iMajor, aVersion.iMinor, aVersion.iBuild);
       
    75 	(void)aMessage;
       
    76 
       
    77 	// Check if we already have a session open.
       
    78 	if ( iSession )
       
    79 		{
       
    80 		LEAVEL(KErrInUse);
       
    81 		}
       
    82 
       
    83 	// In the production system, check the secure ID of the prospective
       
    84 	// client. It should be that of USBSVR.
       
    85 	// For unit testing, don't check the SID of the connecting client (it will
       
    86 	// not be USBSVR but the FDF Unit Test server).
       
    87 #ifndef __OVER_DUMMYUSBDI__
       
    88 
       
    89 #ifndef __TEST_FDF__
       
    90 	// NB When using t_fdf, this SID check needs disabling- t_fdf has yet
       
    91 	// another SID.
       
    92 	_LIT_SECURE_ID(KUsbsvrSecureId, 0x101fe1db);
       
    93 	// Contrary to what the sysdoc says on SecureId, we specifically *don't*
       
    94 	// use a _LIT_SECURITY_POLICY_S0 here. This is because (a) we emit our own
       
    95 	// diagnostic messages, and (b) we don't want configuring this security
       
    96 	// check OFF to allow any client to pass and thereby break our
       
    97 	// architecture.
       
    98 	TInt error = ( aMessage.SecureId() == KUsbsvrSecureId ) ? KErrNone : KErrPermissionDenied;
       
    99 	LEAVEIFERRORL(error);
       
   100 #endif // __TEST_FDF__
       
   101 
       
   102 #endif // __OVER_DUMMYUSBDI__
       
   103 
       
   104 	// Version number check...
       
   105 	TVersion v(KUsbFdfSrvMajorVersionNumber,
       
   106 		KUsbFdfSrvMinorVersionNumber,
       
   107 		KUsbFdfSrvBuildNumber);
       
   108 
       
   109 	if ( !User::QueryVersionSupported(v, aVersion) )
       
   110 		{
       
   111 		LEAVEL(KErrNotSupported);
       
   112 		}
       
   113 
       
   114 	CFdfServer* ncThis = const_cast<CFdfServer*>(this);
       
   115 	ncThis->iSession = new(ELeave) CFdfSession(*iFdf, *ncThis);
       
   116 	ASSERT_DEBUG(ncThis->iFdf);
       
   117 	ncThis->iFdf->SetSession(iSession);
       
   118 
       
   119 	LOGTEXT2(_L8("\tiSession = 0x%08x"), iSession);
       
   120 	return iSession;
       
   121 	}
       
   122 
       
   123 void CFdfServer::SessionClosed()
       
   124 	{
       
   125 	LOG_FUNC
       
   126 
       
   127 	ASSERT_DEBUG(iSession);
       
   128 	iSession = NULL;
       
   129 	iFdf->SetSession(NULL);
       
   130 
       
   131 	LOGTEXT(_L8("\tno remaining sessions- shutting down"));
       
   132 	// This returns control to the server boilerplate in main.cpp. This
       
   133 	// destroys all the objects, which includes signalling device detachment
       
   134 	// to any extant FDCs.
       
   135 	// The session object could perfectly well do this in its destructor but
       
   136 	// it's arguably more clear for the server to do it as it's the server
       
   137 	// that's created immediately before calling CActiveScheduler::Start in
       
   138 	// main.cpp.
       
   139 	CActiveScheduler::Stop();
       
   140 	}