commonappservices/alarmserver/Test/unit/src/TEAlarmTestMANEventObserver.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2005-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 "TEAlarmTestMANEventObserver.h"
       
    17 #include "consoleantestclient.h"
       
    18 
       
    19 
       
    20 // //
       
    21 //
       
    22 // CMANEventObserver : public CActive
       
    23 //
       
    24 // //
       
    25 
       
    26 CMANEventObserver::CMANEventObserver(const TEventEntry& aEventEntry, RANTestClient& aANTestClient,
       
    27 								MMANEventHandler& aEventHandler) : CActive(EPriorityStandard),
       
    28 		iCAASClient(aANTestClient), iEventHandler(aEventHandler), iObserveEvent(aEventEntry)
       
    29 	{
       
    30 	CActiveScheduler::Add(this);	
       
    31 	}
       
    32 
       
    33 
       
    34 CMANEventObserver::~CMANEventObserver()
       
    35 	{
       
    36 	Deque();	
       
    37 	}
       
    38 
       
    39 
       
    40 CMANEventObserver* CMANEventObserver::NewL(const TEventEntry& aEventEntry, 
       
    41 		RANTestClient& aANTestClient, MMANEventHandler& aEventHandler)
       
    42 	{
       
    43 	__ASSERT_ALWAYS( aEventEntry.iType<=EEventDelete, \
       
    44 						User::Leave(KErrArgument));
       
    45 	CMANEventObserver* self = 
       
    46 			new (ELeave) CMANEventObserver(aEventEntry, aANTestClient, aEventHandler);
       
    47 
       
    48 	self->RegisterForNextEventL();
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 
       
    53 void CMANEventObserver::RegisterForNextEventL()
       
    54 	{
       
    55 	switch (iObserveEvent.iType)
       
    56 		{
       
    57 		case EEventSetAlarm:
       
    58 				iCAASClient.NotifyOnAlarm(iASShdAlarm, iStatus);
       
    59 				break;
       
    60 		case EEventSetState: 
       
    61 				iCAASClient.NotifyOnState(iObserveEvent.iAlarmId, 
       
    62 								iObserveEvent.iAltSFlags, iStatus);
       
    63 				break;
       
    64 		case EEventVisible:
       
    65 				iCAASClient.NotifyOnVisible(iObserveEvent.iAlarmId,
       
    66 								iObserveEvent.iVisible, iStatus);
       
    67 				break;
       
    68 		case EEventSoundStart:
       
    69 				iCAASClient.NotifyOnSoundStart(iObserveEvent.iAlarmId,
       
    70 								iSoundFileName,	iStatus);
       
    71 				break;
       
    72 		case EEventSoundStop:
       
    73 				iCAASClient.NotifyOnSoundStop(iObserveEvent.iAlarmId, iStatus);
       
    74 				break;
       
    75 		case EEventDelete:
       
    76 				iCAASClient.NotifyOnDelete(iObserveEvent.iAlarmId, iStatus);
       
    77 				break;
       
    78 		default: 
       
    79 				User::Leave(KErrArgument);
       
    80 		}
       
    81 	SetActive();
       
    82 	}
       
    83 
       
    84 
       
    85 void CMANEventObserver::RunL()
       
    86 	{
       
    87 	if (iStatus!=KErrNone)
       
    88 		{
       
    89 		TEventEntry errorEvent(EException, iStatus.Int());
       
    90 		iEventHandler.HandleEventL(errorEvent);
       
    91 		return;
       
    92 		}
       
    93 
       
    94 	RegisterForNextEventL();
       
    95 
       
    96 	if (iObserveEvent.iType==EEventSetAlarm)
       
    97 		{
       
    98 		iObserveEvent.iAlarmId = iASShdAlarm.Id();
       
    99 		}
       
   100 
       
   101 	iEventHandler.HandleEventL(iObserveEvent);
       
   102 	}
       
   103 	
       
   104 	
       
   105 
       
   106 // //
       
   107 //
       
   108 // CMANDelayedActionHandler : public CTimer
       
   109 //
       
   110 // //
       
   111 
       
   112 CMANDelayedActionHandler::CMANDelayedActionHandler(const TEventEntry& anAction,
       
   113 					MMANEventHandler& aEventHandler) : CTimer(EPriorityStandard),
       
   114 					iEventHandler(aEventHandler), iDelayedAction(anAction)
       
   115 	{
       
   116 	CActiveScheduler::Add(this);
       
   117 	}
       
   118 
       
   119 
       
   120 CMANDelayedActionHandler::~CMANDelayedActionHandler()
       
   121 	{
       
   122 	Deque();	
       
   123 	}
       
   124 
       
   125 
       
   126 CMANDelayedActionHandler* CMANDelayedActionHandler::NewL(const TEventEntry& anAction, 
       
   127 								MMANEventHandler& aEventHandler)
       
   128 	{
       
   129 	__ASSERT_ALWAYS( (anAction.iType==EActionAddAlarm \
       
   130 							|| anAction.iType==EActionUserWait \
       
   131 								|| anAction.iType==EActionReconnectToAS), \
       
   132 						User::Leave(KErrArgument));
       
   133 	CMANDelayedActionHandler* self = new (ELeave) CMANDelayedActionHandler(anAction, aEventHandler);
       
   134 	CleanupStack::PushL(self);
       
   135 	self->ConstructL();						// CTimer::ConstructL();
       
   136 	CleanupStack::Pop();
       
   137 	
       
   138 	self->After(1000000 * anAction.iPeriod);
       
   139 	
       
   140 	return self;
       
   141 	}
       
   142 
       
   143 
       
   144 void CMANDelayedActionHandler::RunL()
       
   145 	{
       
   146 	if (iStatus==KErrNone)
       
   147 		{
       
   148 		iEventHandler.HandleEventL(iDelayedAction);
       
   149 		}
       
   150 	else
       
   151 		{
       
   152 		TEventEntry errorEvent(EException, iStatus.Int());
       
   153 		iEventHandler.HandleEventL(errorEvent);
       
   154 		}
       
   155 	}
       
   156