commonappservices/alarmserver/Test/TServerSessionEngine.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1999-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 "TServerSessionEngine.h"
       
    17 
       
    18 // System includes
       
    19 #include <e32base.h>
       
    20 #include <e32test.h>
       
    21 #include <f32file.h>
       
    22 
       
    23 // User includes
       
    24 #include "ASSrvServerWideData.h"
       
    25 #include "ASSrvTimer.h"
       
    26 #include <consolealarmalertservermain.h>
       
    27 //
       
    28 
       
    29 // Constants
       
    30 const TUid KServerUid2={0x1000008D};
       
    31 const TUid KServerUid3={0x101F502A};
       
    32 const TUidType serverUid(KNullUid,KServerUid2,KServerUid3);
       
    33 
       
    34 
       
    35 
       
    36 
       
    37 //
       
    38 // ----> CTestServerSessionEngine (source)
       
    39 //
       
    40 
       
    41 //*************************************************************************************
       
    42 CTestServerSessionEngine::CTestServerSessionEngine()
       
    43 	{
       
    44 	iHomeTime.HomeTime();
       
    45 	}
       
    46 
       
    47 
       
    48 //*************************************************************************************
       
    49 CTestServerSessionEngine::~CTestServerSessionEngine()
       
    50 	{
       
    51 	delete iTimerObserver;	
       
    52 	delete iSessionEngine;
       
    53 	delete iServerWideData;
       
    54 	delete iSession;
       
    55 	delete iChangeObserver;
       
    56 
       
    57 	// delete the active scheduler
       
    58 	delete CActiveScheduler::Current();
       
    59 	}
       
    60 
       
    61 
       
    62 //*************************************************************************************
       
    63 void CTestServerSessionEngine::ConstructL()
       
    64 	{
       
    65 	CActiveScheduler* iScheduler = new(ELeave) CActiveScheduler();
       
    66 	CActiveScheduler::Install(iScheduler);
       
    67 
       
    68 	StartAlarmServerL();
       
    69 
       
    70 	//
       
    71 	iChangeObserver = new(ELeave) TASSrvAnyEventObserver();
       
    72 	iSession = new(ELeave) TASSrvSession();
       
    73 	iServerWideData = CASSrvServerWideData::NewL();
       
    74 	iSessionEngine = CASSrvSessionEngine::NewL(*iServerWideData, *iChangeObserver, *iSession);
       
    75 
       
    76 	iTimerObserver = new(ELeave) TASSrvAlarmTimerObserver();
       
    77 	}
       
    78 
       
    79 
       
    80 //*************************************************************************************
       
    81 CTestServerSessionEngine* CTestServerSessionEngine::NewLC()
       
    82 	{
       
    83 	CTestServerSessionEngine* self = new(ELeave) CTestServerSessionEngine();
       
    84 	CleanupStack::PushL(self);
       
    85 	self->ConstructL();
       
    86 	return self;
       
    87 	}
       
    88 
       
    89 
       
    90 //
       
    91 //
       
    92 //
       
    93 
       
    94 
       
    95 //*************************************************************************************
       
    96 void CTestServerSessionEngine::StartAlarmServerL()
       
    97 	{
       
    98 #ifdef __WINS__ 
       
    99 	// Have to start the alarm alert server otherwise the alarm
       
   100 	// server cannot start.
       
   101 	_LIT(KConsoleAlarmAlertServerImg,"ConsoleAlarmAlertServer");
       
   102 	RProcess server;
       
   103 	server.Create(KConsoleAlarmAlertServerImg, KNullDesC, serverUid);
       
   104 	TRequestStatus stat;
       
   105 	server.Rendezvous(stat);
       
   106 	if (stat != KRequestPending)
       
   107 		{
       
   108 		server.Kill(0);		// abort startup
       
   109 		}
       
   110 	else
       
   111 		{
       
   112 		server.Resume();	// logon OK - start the server
       
   113 		}
       
   114 		
       
   115 	User::WaitForRequest(stat);
       
   116 	TInt result = stat.Int();
       
   117 	if(result != KErrNone && result != KErrAlreadyExists)
       
   118 		{
       
   119 		User::LeaveIfError(result);	
       
   120 		}		
       
   121 #endif //  __WINS__ 
       
   122 	}
       
   123 
       
   124 
       
   125 //
       
   126 //
       
   127 //
       
   128 
       
   129 
       
   130 //*************************************************************************************
       
   131 TAlarmId CTestServerSessionEngine::AddAlarmWithSpecificTimeL(TInt aSecondsFromNow)
       
   132 	{
       
   133 	TASSrvAlarm alarm(ServerWideData());
       
   134 	alarm.Category()=KASCliCategoryClock;
       
   135 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatOnce;
       
   136 	TTime time = iHomeTime;
       
   137 	time += TTimeIntervalSeconds(aSecondsFromNow);
       
   138 	// convert time to UTC
       
   139 	time -= User::UTCOffset();
       
   140 	alarm.SetUtcNextDueTime(time);
       
   141 	iSessionEngine->AlarmAddL(alarm);
       
   142 
       
   143 	const TAlarmId id = alarm.Id();
       
   144 	if(id == KNullAlarmId)
       
   145 		User::Leave(KErrGeneral);
       
   146 
       
   147 	return id;
       
   148 	}
       
   149 
       
   150 
       
   151 //*************************************************************************************
       
   152 TAlarmId CTestServerSessionEngine::AddAlarmWithSpecificCategoryL(TAlarmCategory aCategory)
       
   153 	{
       
   154 	TASSrvAlarm alarm(ServerWideData());
       
   155 	alarm.Category()=aCategory;
       
   156 	alarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatOnce;
       
   157 	TTime time = iHomeTime;
       
   158 	// convert time to UTC
       
   159 	time -= User::UTCOffset();
       
   160 	time += TTimeIntervalSeconds(10);
       
   161 	alarm.SetUtcNextDueTime(time);
       
   162 	iSessionEngine->AlarmAddL(alarm);
       
   163 
       
   164 	const TAlarmId id = alarm.Id();
       
   165 	if(id == KNullAlarmId)
       
   166 		User::Leave(KErrGeneral);
       
   167 
       
   168 	return id;
       
   169 	}
       
   170 
       
   171 //*************************************************************************************
       
   172 void CTestServerSessionEngine::AwaitNotificationL()
       
   173 	{
       
   174 	iServerWideData->Timer().NotifyAlarmExpiredL(*iTimerObserver);
       
   175 	}
       
   176 
       
   177 //*************************************************************************************
       
   178 void CTestServerSessionEngine::ClearAlarmStoreL()
       
   179 	{
       
   180 	// Delete all alarms
       
   181 	RArray<TAlarmCategory>* categories = iSessionEngine->AlarmCategoryListLC();
       
   182 	TInt count = categories->Count();
       
   183 	for(TInt i=0; i<count; i++)
       
   184 		{
       
   185 		const TAlarmCategory category = (*categories)[i];
       
   186 		iSessionEngine->DeleteAllAlarmsByCategoryL(category, EFalse);
       
   187 		}
       
   188 	categories->Close();
       
   189 	CleanupStack::PopAndDestroy(categories);
       
   190 	}
       
   191 
       
   192 
       
   193 //
       
   194 //
       
   195 //
       
   196 
       
   197 //
       
   198 // ----> TASSrvAnyEventObserver (source)
       
   199 //
       
   200 
       
   201 void TASSrvAnyEventObserver::MASSrvAnyEventHandleChange(TAlarmChangeEvent /*aEvent*/, TAlarmId /*aAlarmId*/)
       
   202 	{
       
   203 	}
       
   204 
       
   205 //
       
   206 //
       
   207 //
       
   208 
       
   209 //
       
   210 // ----> TASSrvSession (source)
       
   211 //
       
   212 
       
   213 TASSrvSessionId TASSrvSession::MASSrvSessionId() const
       
   214 	{
       
   215 	return 0;
       
   216 	}
       
   217 
       
   218 void TASSrvSession::MASSrvSessionFullName(TDes& aDes) const
       
   219 	{
       
   220 	aDes = KNullDesC;
       
   221 	}
       
   222 
       
   223 //
       
   224 //
       
   225 //
       
   226 
       
   227 //
       
   228 // ----> TASSrvAlarmTimerObserver (source)
       
   229 //
       
   230 
       
   231 void TASSrvAlarmTimerObserver::MATimerHandleAlarmExpired(TAlarmTimerEvent aEvent, TAlarmId /*aAlarmId*/)
       
   232 	{
       
   233 	if (aEvent == EAlarmTimerEventAlarmExpired)
       
   234 		{
       
   235 		CActiveScheduler::Stop();
       
   236 		}
       
   237 	}