sysstatemgmt/systemstarter/test/sysmondemo/src/sysmondemoserv.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 #include "sysmondemo.h"
       
    17 #include "sysmonclisess.h"
       
    18 #include "dscstore.h"
       
    19 #include "dscitem.h"
       
    20 
       
    21 
       
    22 
       
    23 _LIT(KHelloWorld, "Z:\\sys\\bin\\helloworld.exe") ;
       
    24 /************************************************************************************/
       
    25 
       
    26 CDemoSSess* CDemoSSess::NewL()
       
    27 {
       
    28 	CDemoSSess* sess = new(ELeave) CDemoSSess ;
       
    29 	return sess ;
       
    30 }
       
    31 
       
    32 CDemoSSess::~CDemoSSess()
       
    33 {
       
    34 	
       
    35 }
       
    36 
       
    37 void CDemoSSess::ServiceL(const RMessage2 &aMessage)
       
    38 {
       
    39 	iMessage = const_cast<RMessage2&> (aMessage) ;
       
    40 	
       
    41 	switch (iMessage.Function())
       
    42 	{
       
    43 		case EServerPoke:
       
    44 			CmdPokeL() ;
       
    45 			break ;
       
    46 		
       
    47 		case EServerKill:
       
    48 			CmdKillL() ;
       
    49 			break ;
       
    50 		
       
    51 		case EServerDone:
       
    52 			CmdDoneL() ;
       
    53 			break ;			
       
    54 		default:
       
    55 			break ;
       
    56 				
       
    57 	}	
       
    58 	
       
    59 	iMessage.Complete(KErrNone) ;	
       
    60 }
       
    61 
       
    62 
       
    63 void CDemoSSess::CmdPokeL()
       
    64 {
       
    65 
       
    66 	TPckg<TTime> package(DemoServer()->GetLoadTime()) ;		
       
    67 	iMessage.WriteL(0, package) ;
       
    68 }
       
    69 		
       
    70 void CDemoSSess::CmdKillL()
       
    71 {
       
    72 	TTime time1 ;
       
    73 	time1.HomeTime() ; /* returning the time of death */
       
    74 	
       
    75 
       
    76 	TPckg<TTime> package(time1) ;		
       
    77 	iMessage.WriteL(0, package) ;
       
    78 	
       
    79 	CActiveScheduler::Stop() ;	
       
    80 }
       
    81 		
       
    82 void CDemoSSess::CmdDoneL()
       
    83 {
       
    84 	TTime time1 ;
       
    85 	time1.HomeTime() ; /* returning the time of death */
       
    86 	
       
    87 	TPckg<TTime> package(time1) ;		
       
    88 	iMessage.WriteL(0, package) ;
       
    89 
       
    90 	/* connect to monitor and cancel monitoring */
       
    91 	
       
    92 	RSysMonSession sysMon ;
       
    93 	
       
    94 	sysMon.OpenL() ;
       
    95 	
       
    96 	sysMon.CancelMonitorSelfL() ;
       
    97 	
       
    98 	sysMon.Close() ;
       
    99 	
       
   100 	CActiveScheduler::Stop() ;	// going to kill this server also
       
   101 	
       
   102 }
       
   103 
       
   104 
       
   105 
       
   106 CDemoServ* CDemoSSess::DemoServer()
       
   107 {
       
   108 	return static_cast<CDemoServ*> (const_cast<CServer2*> (Server())) ;
       
   109 }
       
   110 
       
   111 
       
   112 
       
   113 /************************************************************************************/
       
   114 /**************************************************************************************/
       
   115 
       
   116 CDemoServ* CDemoServ::NewLC()
       
   117 {
       
   118 	CDemoServ* serv = new(ELeave) CDemoServ() ;
       
   119 	CleanupStack::PushL(serv) ;
       
   120 	
       
   121 	
       
   122 	serv->StartL(KDemoServerName) ;	
       
   123 	
       
   124 	return serv ;	
       
   125 }
       
   126 
       
   127 CDemoServ::CDemoServ():CServer2(EPriorityHigh)
       
   128 {
       
   129 	iLoadTime.HomeTime() ;
       
   130 }
       
   131 
       
   132 CDemoServ::~CDemoServ()
       
   133 {
       
   134 	
       
   135 }
       
   136 		
       
   137 
       
   138 TTime CDemoServ::GetLoadTime()
       
   139 {
       
   140 	return iLoadTime ;
       
   141 }
       
   142 
       
   143 
       
   144 CSession2* CDemoServ::NewSessionL(const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const
       
   145 {
       
   146 	return CDemoSSess::NewL() ;	
       
   147 }
       
   148 
       
   149 
       
   150 /**************************************************************************************/
       
   151 
       
   152 static void AddToDscL()
       
   153 {
       
   154 	RDscStore store ;
       
   155 	
       
   156 	store.OpenL() ;
       
   157 	CleanupClosePushL(store) ;
       
   158 	
       
   159 	TInt err ;
       
   160 	
       
   161 	TRAP(err, store.DeleteDscL(TUid::Uid(KDefaultSymbianDsc))) ;
       
   162 		
       
   163 	TRAP(err, store.CreateDscL()) ;
       
   164 	
       
   165 	
       
   166 	CDscItem *item = CDscItem::NewL() ;
       
   167 	CleanupStack::PushL(item) ;
       
   168 	
       
   169 	item->SetFileParamsL(KHelloWorld, KNullDesC) ;
       
   170 	item->SetMonitored(ETrue) ;
       
   171 	
       
   172 		
       
   173 	TRAP(err, store.AddItemL(*item)) ;
       
   174 	
       
   175 	
       
   176 	if (err != KErrNone)
       
   177 		{
       
   178 		store.DeleteItemL(*item) ;
       
   179 		store.AddItemL(*item) ;
       
   180 		}
       
   181 	
       
   182 	CleanupStack::PopAndDestroy(item) ;
       
   183 	CleanupStack::PopAndDestroy(&store) ;
       
   184 	
       
   185 }
       
   186 
       
   187 
       
   188 static void RunServerL()
       
   189 //
       
   190 // Perform all server initialisation, in particular creation of the
       
   191 // scheduler and server and then run the scheduler
       
   192 //
       
   193 	{
       
   194 	// naming the server thread after the server helps to debug panics
       
   195 
       
   196 	User::LeaveIfError(RThread::RenameMe(KDemoServerName))  ;
       
   197 	
       
   198 	AddToDscL() ;
       
   199 		
       
   200 	//
       
   201 	// create and install the active scheduler we need
       
   202 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
   203 	CleanupStack::PushL(s);
       
   204 	CActiveScheduler::Install(s);
       
   205 	//
       
   206 	// create the server (leave it on the cleanup stack)
       
   207 	CDemoServ::NewLC();
       
   208 	//
       
   209 	// Initialisation complete, now signal the client
       
   210 	RProcess::Rendezvous(KErrNone);
       
   211 	//
       
   212 	// Ready to run
       
   213 	CActiveScheduler::Start();
       
   214 	//
       
   215 	// Cleanup the server and scheduler
       
   216 	CleanupStack::PopAndDestroy(2);
       
   217 	}
       
   218 
       
   219 TInt E32Main()
       
   220 //
       
   221 // Server process entry-point
       
   222 //
       
   223 	{
       
   224 	__UHEAP_MARK;
       
   225 	//
       
   226 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   227 	TInt r=KErrNoMemory;
       
   228 	if (cleanup)
       
   229 		{
       
   230 		TRAP(r,RunServerL());
       
   231 		delete cleanup;
       
   232 		}
       
   233 	//
       
   234 	__UHEAP_MARKEND;
       
   235 	return r;
       
   236 	}