dbgsrv/coredumpserver/server/src/coredumpserver.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // core_dump_server.cpp
       
    15 //
       
    16 
       
    17 // System includes
       
    18 #include <e32cmn.h>
       
    19 #include <e32std.h>
       
    20 #include <e32svr.h>
       
    21 
       
    22 // Project includes
       
    23 #include "coredumpserver.h"
       
    24 #include "coredumpsession.h"
       
    25 #include "flashdatasource.h"
       
    26 
       
    27 /**
       
    28 This is the version of the security server that we have developed our code against
       
    29 and it comes from the interface definition of the DSS at the time of compilation.
       
    30 */
       
    31 const TVersion securityServerVersion( 
       
    32 				KDebugServMajorVersionNumber, 
       
    33 				KDebugServMinorVersionNumber, 
       
    34 				KDebugServPatchVersionNumber );
       
    35 
       
    36 /*
       
    37 * Called to panic the server (in event of partial construction or serious error)
       
    38 */
       
    39 void CCoreDumpServer::PanicServer(TCoreDumpServerPanic aPanic)
       
    40 	{
       
    41         //are we using this??
       
    42 	User::Panic(KCoreDumpServerName, aPanic);
       
    43 	}
       
    44 	
       
    45 CCoreDumpServer* CCoreDumpServer::NewL()
       
    46 {
       
    47 	CCoreDumpServer* self = CCoreDumpServer::NewLC();
       
    48     CleanupStack::Pop();
       
    49     return self;
       
    50 }
       
    51 	
       
    52 /*
       
    53 * Symbian OS 1st stage construction
       
    54 */
       
    55 CCoreDumpServer* CCoreDumpServer::NewLC()
       
    56 	{
       
    57 	//RDebug::Print( _L("CCoreDumpServer* CCoreDumpServer::NewLC()\n"));
       
    58 	CCoreDumpServer* self = new (ELeave) CCoreDumpServer();
       
    59 	CleanupStack::PushL(self);
       
    60 	self->ConstructL();
       
    61 	return self;
       
    62 	}
       
    63 	
       
    64 /*
       
    65 * Destructor
       
    66 */
       
    67 CCoreDumpServer::~CCoreDumpServer()
       
    68 	{
       
    69     //LOG_MSG("->CCoreDumpServer::~CCoreDumpServer\n");
       
    70     iSecSess.Close();
       
    71 	}
       
    72 
       
    73 /*
       
    74 * Called when a new session is to be created
       
    75 */
       
    76 CSession2* CCoreDumpServer::NewSessionL( const TVersion& aVersion, 
       
    77 									   const RMessage2& /*aMessage*/ ) const
       
    78 	{
       
    79 
       
    80 	//RDebug::Printf( "->CCoreDumpServer::NewSessionL()\n" );
       
    81     
       
    82     RSecuritySvrSession &session = const_cast<RSecuritySvrSession&>(iSecSess);
       
    83     
       
    84 	THandleInfo dssSessionInfo;
       
    85 	session.HandleInfo( & dssSessionInfo );
       
    86 
       
    87 	if( dssSessionInfo.iNumOpenInProcess > 1 )
       
    88 		{
       
    89         //if there is already a session with DSS this means that we started it already for someone else
       
    90 		RDebug::Print( _L("CCoreDumpServer::NewSessionL() : Error : Session to DSS already in use by CDS\n"));
       
    91 		User::Leave( KErrAlreadyExists );
       
    92 		}
       
    93 
       
    94 	// Check the client-side API version number against the server version number.
       
    95 	TVersion serverVersion(	KCoreDumpServMajorVersionNumber,
       
    96 							KCoreDumpServMinorVersionNumber,
       
    97 							KCoreDumpServBuildVersionNumber);
       
    98 
       
    99 	LOG_MSG4( "CCoreDumpServer::NewSessionL() : Server version: major=%d,minor=%d,build=%d\n",
       
   100 		KCoreDumpServMajorVersionNumber, KCoreDumpServMinorVersionNumber, KCoreDumpServBuildVersionNumber );
       
   101 
       
   102 	LOG_MSG4( "  Client API built against : major=%d,minor=%d,build=%d\n", 
       
   103 		aVersion.iBuild, aVersion.iMajor, aVersion.iMinor );
       
   104 
       
   105 	if( !User::QueryVersionSupported( serverVersion, aVersion ) )
       
   106 		{
       
   107 		// This server version is incompatible with the version of the server the 
       
   108 		// client-side API was built against
       
   109 		RDebug::Printf( "CCoreDumpServer::NewSessionL() : Leaving due to incompatible versions\n" );
       
   110 		User::Leave( KErrNotSupported );
       
   111 		}
       
   112 
       
   113 	//LOG_MSG("CCoreDumpServer::NewSessionL - creating new core dump session\n");
       
   114 	return CCoreDumpSession::NewL(session);
       
   115 	}
       
   116 
       
   117 /*
       
   118 * Called when a session is opened
       
   119 */
       
   120 void CCoreDumpServer::SessionOpened()
       
   121 	{
       
   122 	//LOG_MSG("->CCoreDumpServer::SessionOpened()\n");
       
   123 	++iNumSessions;
       
   124 	}
       
   125 
       
   126 
       
   127 /*
       
   128 * Called when a session is closed 
       
   129 */
       
   130 void CCoreDumpServer::SessionClosed()
       
   131 	{
       
   132 	//LOG_MSG("->CCoreDumpServer::SessionClosed()\n");
       
   133 	if(--iNumSessions < 1) // No more sessions connected to the server, shut down the server
       
   134 		{
       
   135 	    //LOG_MSG("CCoreDumpServer::SessionClosed() -> CActiveScheduler::Stop()\n");
       
   136 		CActiveScheduler::Stop();
       
   137 		}
       
   138 	}
       
   139    
       
   140 
       
   141 /*
       
   142 * Called when the server active object's RunL() leaves
       
   143 */
       
   144 TInt CCoreDumpServer::RunError(TInt aError)
       
   145 	{
       
   146 	Message().Complete(aError);
       
   147     
       
   148 	// Call Restart(), as RunL() left before server got chance to re-issue its request
       
   149 	ReStart();
       
   150 
       
   151 	return KErrNone;
       
   152 	}
       
   153 
       
   154 // PRIVATE MEMBER FUNCTIONS
       
   155 
       
   156 /*
       
   157 * C++ Constructor
       
   158 */
       
   159 CCoreDumpServer::CCoreDumpServer( TInt aPriority )
       
   160 	: CServer2( aPriority ), 
       
   161 	  iNumSessions( 0 )
       
   162 	{
       
   163 	// No implementation required
       
   164 	}
       
   165 	
       
   166 
       
   167 /*
       
   168 * Symbian OS 2nd stage construction. Called from CCoreDumpServer::NewLC()
       
   169 */	
       
   170 void CCoreDumpServer::ConstructL()
       
   171 	{
       
   172 	//LOG_MSG("->CCoreDumpServer::ConstructL()\n" );
       
   173 
       
   174 	TInt err = iSecSess.Connect( securityServerVersion );
       
   175 
       
   176 	if( KErrNone != err )
       
   177 		{
       
   178 		_LIT( KDssStartErrorMsg ,"Core Dump Server: Unable to Start/Connect to Debug Security Server");
       
   179 		User::InfoPrint( KDssStartErrorMsg );
       
   180 
       
   181 		LOG_MSG2("CCoreDumpServer::ConstructL() - unable to open security server session! err:%d\n", err);
       
   182 		User::Leave(err);
       
   183 		}
       
   184 
       
   185     err = iSecSess.ShareAuto();
       
   186     
       
   187 	StartL( KCoreDumpServerName );
       
   188 	}