DirectPrint/DirectPrintServer/src/directprintserver.cpp
changeset 15 2275db202402
parent 12 613a5ff70823
equal deleted inserted replaced
2:acc370d7f2f6 15:2275db202402
       
     1 /*
       
     2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "directprintserver.h"
       
    20 #include "directprintclientserver.h"
       
    21 #include "directprintsession.h"
       
    22 #include "clog.h"
       
    23 #include "directprintbody.h"
       
    24  
       
    25 namespace
       
    26 	{
       
    27 	// panic
       
    28 	_LIT( KDirectPrintServerPanic, "CIPSer" );
       
    29 	enum TDirectPrintServerPanic
       
    30 		{
       
    31 		EBadDescriptor
       
    32 		};
       
    33 	
       
    34 	void PanicClient( const RMessage2& aMessage, TDirectPrintServerPanic aCategory )
       
    35 		{
       
    36 		aMessage.Panic( KDirectPrintServerPanic, aCategory );
       
    37 		}
       
    38 	}
       
    39 
       
    40 
       
    41 CDirectPrintServer* CDirectPrintServer::NewLC()
       
    42     {
       
    43 	CDirectPrintServer* server = new (ELeave) CDirectPrintServer();
       
    44     CleanupStack::PushL( server ) ;
       
    45     server->ConstructL();
       
    46     return server;
       
    47     }
       
    48 
       
    49         
       
    50 CDirectPrintServer::CDirectPrintServer()
       
    51 	: CPolicyServer( 0, KDirectPrintPolicy, ESharableSessions )
       
    52 	{
       
    53 	}    
       
    54 
       
    55 CDirectPrintServer::~CDirectPrintServer()
       
    56     {
       
    57     LOG("CDirectPrintServer::~CDirectPrintServer begin");
       
    58     delete iEngine;
       
    59 	iFbs.Disconnect();
       
    60 	LOG("CDirectPrintServer::~CDirectPrintServer end");
       
    61     }
       
    62 
       
    63 void CDirectPrintServer::ConstructL()
       
    64     {  
       
    65     LOG("CDirectPrintServer::ConstructL begin");          
       
    66     StartL( KDirectPrintServerName );    
       
    67     User::LeaveIfError( iFbs.Connect() );        
       
    68     iEngine = CDirectPrintBody::NewL();
       
    69     LOG("CDirectPrintServer::ConstructL end");
       
    70     }
       
    71 
       
    72 void CDirectPrintServer::AddSession()
       
    73 	{
       
    74 	LOG("CDirectPrintServer::AddSession begin");
       
    75 	++iConnsCount;
       
    76 	LOG("CDirectPrintServer::AddSession end");
       
    77 	}
       
    78 
       
    79 void CDirectPrintServer::RemoveSession()
       
    80 	{
       
    81 	--iConnsCount;
       
    82 	LOG1("CDirectPrintServer::RemoveSession iConnsCount: %d", iConnsCount);
       
    83 	if( iConnsCount == 0 )
       
    84 		{
       
    85 		delete iEngine;
       
    86 		iEngine = NULL;
       
    87 		iFbs.Disconnect();
       
    88 		CActiveScheduler::Stop();
       
    89 		}
       
    90 	LOG("CDirectPrintServer::RemoveSession end");
       
    91 	}
       
    92 
       
    93 TInt CDirectPrintServer::SessionCount() const
       
    94 	{
       
    95 	LOG("CDirectPrintServer::SessionCount begin");
       
    96 	LOG1("CDirectPrintServer::SessionCount return: %d", iConnsCount);
       
    97 	return iConnsCount;
       
    98 	}
       
    99 
       
   100 TInt CDirectPrintServer::RunError( TInt aError )
       
   101     {
       
   102     LOG1("CDirectPrintServer::RunError aError: %d", aError);
       
   103 	if( aError == KErrBadDescriptor )
       
   104         {        
       
   105         PanicClient( Message(), EBadDescriptor );
       
   106         }
       
   107 	else
       
   108         {
       
   109 		Message().Complete( aError );
       
   110         }	
       
   111 	ReStart();
       
   112 	LOG("CDirectPrintServer::RunError end");
       
   113 	return KErrNone;
       
   114     }
       
   115 
       
   116     
       
   117 CSession2* CDirectPrintServer::NewSessionL( const TVersion& aVersion, const RMessage2& ) const
       
   118 	{
       
   119 	LOG("CDirectPrintServer::NewSessionL begin");
       
   120 	TBool supported = User::QueryVersionSupported( TVersion( KDirectPrintServerMajor,
       
   121 													KDirectPrintServerMinor,
       
   122 													KDirectPrintServerBuild ),
       
   123 													aVersion );	
       
   124 	if( !supported )
       
   125         {
       
   126 		User::Leave( KErrNotSupported );
       
   127         }
       
   128         
       
   129     LOG("CDirectPrintServer::NewSessionL end");	
       
   130 	return new (ELeave) CDirectPrintSession();
       
   131 	}
       
   132 	
       
   133 TInt CDirectPrintServer::ReserveEngine( const CSession2* aSession )
       
   134 	{
       
   135 	LOG("CDirectPrintServer::ReserveEngine begin");
       
   136 	TInt err( KErrInUse );
       
   137 	if( iEngineHolder == aSession || !iEngineHolder )
       
   138 		{
       
   139 		iEngineHolder = aSession;
       
   140 		err = KErrNone;
       
   141 		}
       
   142 	LOG1("CDirectPrintServer::ReserveEngine return: %d", err);
       
   143 	return err;	
       
   144 	}
       
   145 
       
   146 TInt CDirectPrintServer::ReleaseEngine( const CSession2* aSession )
       
   147 	{
       
   148 	LOG("CDirectPrintServer::ReleaseEngine begin");
       
   149 	TInt err( KErrInUse );
       
   150 	if( iEngineHolder == aSession || !iEngineHolder )
       
   151 		{
       
   152 		iEngineHolder = NULL;
       
   153 		err = KErrNone;
       
   154 		}
       
   155 	LOG1("CDirectPrintServer::ReleaseEngine return: %d", err);
       
   156 	return err;		
       
   157 	}
       
   158 
       
   159 CDirectPrintBody& CDirectPrintServer::Engine() const
       
   160 	{
       
   161 	LOG("CDirectPrintServer::Engine begin");
       
   162 	LOG("CDirectPrintServer::Engine end");
       
   163 	return *iEngine;
       
   164 	}
       
   165 
       
   166 //  End of File