commonuisupport/uikon/test/tmultiplealarm/TRemoteFactory.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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 /**
       
    17  @file
       
    18  @internalComponent - Internal Symbian test code
       
    19 */
       
    20 
       
    21 #include "TRemoteFactory.h"
       
    22 
       
    23 #include <asaltdefs.h>
       
    24 #include "eikalsup.h"
       
    25 #include <uikon/eikalsrv.h>
       
    26 
       
    27 CTRemoteFactory* CTRemoteFactory::NewL()
       
    28 	{
       
    29 	CTRemoteFactory *self = new (ELeave) CTRemoteFactory;
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 	CleanupStack::Pop();
       
    33 	return self;
       
    34 	}
       
    35 	
       
    36 CTRemoteFactory::CTRemoteFactory() :
       
    37 	iMaxAlarms(1),
       
    38 	iResponse(EFalse),
       
    39 	iId(-1),
       
    40 	iResponseCode(-1),
       
    41 	iCount(0),
       
    42 	iSnoozeTime(0)
       
    43 	{
       
    44 	}
       
    45 	
       
    46 void CTRemoteFactory::ConstructL()
       
    47 	{
       
    48 	User::LeaveIfError(iMsgQ.OpenGlobal(KRemoteQName, EOwnerThread));
       
    49 	iMaxAlarms = ReadInt();
       
    50 	iState = ReadInt();
       
    51 	iResponse = ReadBool();
       
    52 	
       
    53 	if(iResponse) 
       
    54 		{
       
    55 		iId = ReadInt();
       
    56 		iResponseCode = ReadInt();
       
    57 		
       
    58 		iSnoozeTime = ReadInt();
       
    59 		iUpdateSnooze = ReadBool();
       
    60 			
       
    61 		iQuietPeriod = TTime(MAKE_TUINT64(ReadInt(), ReadInt()));
       
    62 		}
       
    63 	}
       
    64 	
       
    65 CTRemoteFactory::~CTRemoteFactory()
       
    66 	{
       
    67 	}
       
    68 	
       
    69 MEikServAlarm* CTRemoteFactory::NewAlarmL(CEikAlmControlSupervisor& aSupervisor)
       
    70 	{
       
    71 	return CTRemoteAlarm::NewL(aSupervisor, this, iState);
       
    72 	}
       
    73 
       
    74 TInt CTRemoteFactory::ReadInt()
       
    75 	{
       
    76 	TRemoteMsg msg;
       
    77 	iMsgQ.ReceiveBlocking(msg);
       
    78 	return msg.Int();
       
    79 	}
       
    80 
       
    81 TBool CTRemoteFactory::ReadBool()
       
    82 	{
       
    83 	TRemoteMsg msg;
       
    84 	iMsgQ.ReceiveBlocking(msg);
       
    85 	
       
    86 	return msg.Bool();
       
    87 	}
       
    88 	
       
    89 void CTRemoteFactory::SendInt(const TInt aValue)
       
    90 	{
       
    91 	TRemoteMsg msg(aValue);
       
    92 	iMsgQ.SendBlocking(msg);
       
    93 	}
       
    94 	
       
    95 void CTRemoteFactory::SendData(const TDesC8& aData)
       
    96 	{
       
    97 	for(TInt i = 0; i < aData.Size(); i += KRemoteQMaxDataSize)
       
    98 		{
       
    99 		TPtrC8 mid = aData.Mid(i);
       
   100 		
       
   101 		TRemoteMsg msg(mid.Ptr(), KRemoteQMaxDataSize);		
       
   102 		iMsgQ.SendBlocking(msg);
       
   103 		}
       
   104 	}
       
   105 
       
   106 CTRemoteAlarm* CTRemoteAlarm::NewL(CEikAlmControlSupervisor& aSupervisor, CTRemoteFactory* aFactory, TInt aState)
       
   107 	{
       
   108 	return new (ELeave) CTRemoteAlarm(aSupervisor, aFactory, aState);
       
   109 	}
       
   110 
       
   111 CTRemoteAlarm::CTRemoteAlarm(CEikAlmControlSupervisor& aSupervisor, CTRemoteFactory* aFactory, TInt aState) :
       
   112 	iSupervisor(aSupervisor), iFactory(aFactory), iAlarmId(KNullAlarmId), iState(aState)
       
   113 	{
       
   114 	}
       
   115 
       
   116 CTRemoteAlarm::~CTRemoteAlarm()
       
   117 	{
       
   118 	iFactory->SendInt(iAlarmId);
       
   119 	}
       
   120 	
       
   121 void CTRemoteAlarm::Release()
       
   122 	{
       
   123 	delete this;
       
   124 	}
       
   125 	
       
   126 void CTRemoteAlarm::ShowAlarm()
       
   127 	{
       
   128 	iFactory->SendInt(EASAltOpCodeVisible);
       
   129 	iFactory->SendInt(iAlarmId);
       
   130 
       
   131 	if(iFactory->Server()->AlarmAlertIsVisible() == EFalse) // Already showing
       
   132 		{
       
   133 		iFactory->SendInt(ETrue);
       
   134 		}
       
   135 
       
   136 	else // Will be updated on completion.
       
   137 		{
       
   138 		iFactory->SendInt(!iFactory->Server()->AlarmAlertIsVisible());
       
   139 		}
       
   140 	
       
   141 	// If we are testing TaskKeyPressedL do this here since we will only be notified for visible alarms.
       
   142 	if (iFactory->Response() && 
       
   143 		iFactory->ResponseId() == iAlarmId &&
       
   144 		iFactory->ResponseCode() == ETestActionTaskKey) // We are in response mode
       
   145 		{
       
   146 		TRAP_IGNORE(iFactory->Server()->TaskKeyPressedL());
       
   147 		}	
       
   148 	}
       
   149 	
       
   150 void CTRemoteAlarm::HideAlarm()
       
   151 	{
       
   152 	iFactory->SendInt(EASAltOpCodeVisible);
       
   153 	iFactory->SendInt(iAlarmId);
       
   154 
       
   155 	if(iFactory->Server()->AlarmAlertIsVisible() == EFalse) // Already hidden
       
   156 		{
       
   157 		iFactory->SendInt(EFalse);
       
   158 		}
       
   159 
       
   160 	else // Will be updated on completion.
       
   161 		{
       
   162 		iFactory->SendInt(!iFactory->Server()->AlarmAlertIsVisible());
       
   163 		}
       
   164 	}
       
   165 	
       
   166 TInt CTRemoteAlarm::CurrentServerState() const
       
   167 	{
       
   168 	return iState;
       
   169 	}
       
   170 	
       
   171 void CTRemoteAlarm::UpdateSoundPauseTimeInterval(TInt aMinutes)
       
   172 	{
       
   173 	if (iFactory->Response())
       
   174 		{
       
   175 		switch(iFactory->ResponseCode())
       
   176 			{
       
   177 		case ETestActionHandleSwitch: // If we are testing HandleSwitchOnEvent
       
   178 		case ETestActionHandleSwitchAndPause: // or we are testing ETestActionHandleSwitchAndPause tell test step we got the update
       
   179 			iFactory->SendInt(iFactory->ResponseCode());
       
   180 			iFactory->SendInt(aMinutes);
       
   181 			break;
       
   182 		case EASAltAlertServerResponseSnooze: // Send update snooze interval in case someone is waiting
       
   183 			if(aMinutes != iFactory->SnoozeTime() && iFactory->UpdateSnooze())  // Only send if it has been updated
       
   184 				{
       
   185 				iFactory->SendInt(aMinutes);
       
   186 				}
       
   187 			break;
       
   188 		default:
       
   189 			break;
       
   190 			}
       
   191 		}
       
   192 	}
       
   193 	
       
   194 void CTRemoteAlarm::UpdateForAlarmServerState(TInt aNewAlarmServerState)
       
   195 	{
       
   196 	iState = aNewAlarmServerState;
       
   197 	iFactory->SendInt(EASAltOpCodeSetState);
       
   198 	iFactory->SendInt(aNewAlarmServerState);
       
   199 	iFactory->SendInt(iAlarmId);
       
   200 	
       
   201 	if (iFactory->Response() && iFactory->ResponseId() == iAlarmId) // We are in response mode
       
   202 		{
       
   203 		switch(iFactory->ResponseCode())
       
   204 			{
       
   205 		case EASAltAlertServerResponseSnooze:
       
   206 			if(iFactory->SnoozeTime() >= 0)
       
   207 				{
       
   208 				TRAP_IGNORE(iSupervisor.CmdTaskAwayFromAlarmL(iFactory->SnoozeTime()));
       
   209 				}
       
   210 			else 
       
   211 				{
       
   212 				TRAP_IGNORE(iSupervisor.CmdTaskAwayFromAlarmL());
       
   213 				}
       
   214 			
       
   215 			break;
       
   216 				
       
   217 		case EASAltAlertServerResponseClear:
       
   218 			iSupervisor.CmdAcknowledgeAlarm();
       
   219 			break;
       
   220 			
       
   221 		case EASAltAlertServerResponsePauseSound:
       
   222 			TRAP_IGNORE(iSupervisor.CmdPauseAlarmSoundL(iFactory->SnoozeTime()));
       
   223 			break;
       
   224 		case EASAltAlertServerResponseClearAll:
       
   225 			TRAP_IGNORE(iFactory->Server()->ClearAllAlarmsL());
       
   226 			break;
       
   227 			
       
   228 		case ETestActionSetQuietPeriod:
       
   229 			TRAP_IGNORE(iFactory->Server()->SetQuietPeriodL(iFactory->QuietPeriod()));
       
   230 			break;			
       
   231 		case EASAltAlertServerResponseSilence:
       
   232 			iSupervisor.CmdSilenceAlarmSound();
       
   233 			break;
       
   234 			
       
   235 		case ETestActionHandleSwitch:
       
   236 			iFactory->Server()->HandleSwitchOnEvent();
       
   237 			break;
       
   238 			
       
   239 
       
   240 			
       
   241 		case ETestActionDie:
       
   242 			CActiveScheduler::Stop();
       
   243 			break;
       
   244 			
       
   245 		case ETestActionHandleSwitchAndPause:
       
   246 			TRAP_IGNORE(iSupervisor.CmdPauseAlarmSoundL(iFactory->SnoozeTime()));
       
   247 			iFactory->Server()->HandleSwitchOnEvent();
       
   248 			break;
       
   249 		
       
   250 		default:
       
   251 			break;
       
   252 			}
       
   253 		}
       
   254 	}
       
   255 	
       
   256 void CTRemoteAlarm::UpdateAlarmInfo(const TASShdAlarm& aAlarm,const TFullName& /*aOwner*/)
       
   257 	{
       
   258 	iAlarmId = aAlarm.Id();
       
   259 	
       
   260 	iFactory->SendInt(EASAltOpCodeSetAlarm);
       
   261 	iFactory->SendInt(iAlarmId);
       
   262 
       
   263 	const TDesC8& data = iSupervisor.AlarmData();
       
   264 	
       
   265 	iFactory->SendInt(data.Size());	
       
   266 	iFactory->SendData(data);
       
   267 	
       
   268 	}
       
   269 	
       
   270 void CTRemoteAlarm::StartPlayAlarmL(const TDesC& aAlarmName)
       
   271 	{
       
   272 	iFactory->SendInt(EASAltOpCodeStartPlayingSound);
       
   273 	iFactory->SendInt(iAlarmId);
       
   274 	
       
   275 	TBuf8<KMaxAlarmSoundNameLength> buf;
       
   276 	buf.Copy(aAlarmName);
       
   277 	iFactory->SendData(buf);
       
   278 	}
       
   279 	
       
   280 void CTRemoteAlarm::StopPlayAlarm()
       
   281 	{
       
   282 	iFactory->SendInt(EASAltOpCodeStopPlayingSound);
       
   283 	iFactory->SendInt(iAlarmId); 
       
   284 	}