sysstatemgmt/systemstatereferenceplugins/clayer/src/saartcadaptation.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-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 "saartcadaptation.h"
       
    17 
       
    18 #include "startupadaptationadapter.h"
       
    19 #include "ssmdebug.h"
       
    20 #include "clayerpanic.h"
       
    21 /*
       
    22  * Creates a new object associated with the passed in CStartupAdaptationAdapter
       
    23  * 
       
    24  * @internalComponent
       
    25  */
       
    26 CSaaRtcAdaptation* CSaaRtcAdaptation::NewL(CStartupAdaptationAdapter* aAdapter)
       
    27 	{
       
    28 	CSaaRtcAdaptation* self = new (ELeave) CSaaRtcAdaptation(aAdapter);
       
    29 	return self;
       
    30 	}
       
    31 
       
    32 /*
       
    33  * Destructor for this object
       
    34  * 
       
    35  * @internalComponent
       
    36  */
       
    37 CSaaRtcAdaptation::~CSaaRtcAdaptation()
       
    38 	{
       
    39 
       
    40 	}
       
    41 
       
    42 /*
       
    43  * Decrements the reference count for this object, deleting it if necessary
       
    44  * 
       
    45  * @internalComponent
       
    46  */
       
    47 void CSaaRtcAdaptation::Release()
       
    48 	{
       
    49 	// This MClass is owned by the singleton CStartupAdaptationAdapter class so
       
    50 	// release should do nothing.
       
    51 	}
       
    52 
       
    53 /*
       
    54  * 
       
    55  * 
       
    56  * @internalComponent
       
    57  */
       
    58 void CSaaRtcAdaptation::ValidateRtc(TDes8& aValidityPckg, TRequestStatus& aStatus)
       
    59 	{
       
    60 	// If this adaptation is busy then complete with KErrInUse
       
    61 	if(Busy())
       
    62 		{
       
    63 		TRequestStatus* statusPtr = &aStatus;
       
    64 		User::RequestComplete(statusPtr, KErrInUse);
       
    65 		return;
       
    66 		}
       
    67 	// Set this request status
       
    68 	SetRequestStatus(&aStatus);
       
    69 	aStatus = KRequestPending;
       
    70 	// No outstand requests so set up command id
       
    71 	SetCommandId(StartupAdaptation::EValidateRTCTime);
       
    72 	// No parameters to set to pass in
       
    73 	
       
    74 	// Remember the package to pass data back into
       
    75 	iReturnDes = &aValidityPckg;
       
    76 	// Pass this to the adapter
       
    77 	TRAPD(err, iAdapter->QueueDispatchL(this));
       
    78 	if(err != KErrNone)
       
    79 		{
       
    80 		// Failed to queue adaptation, complete with error
       
    81 		SetRequestStatus(NULL);
       
    82 		TRequestStatus* statusPtr = &aStatus;
       
    83 		User::RequestComplete(statusPtr, err);
       
    84 		}
       
    85 	}
       
    86 
       
    87 /*
       
    88  * 
       
    89  * 
       
    90  * @internalComponent
       
    91  */
       
    92 void CSaaRtcAdaptation::SetWakeupAlarm(TDesC8& aAlarmTimePckg, TRequestStatus& aStatus)
       
    93 	{
       
    94 	// If this adaptation is busy then complete with KErrInUse
       
    95 	if(Busy())
       
    96 		{
       
    97 		TRequestStatus* statusPtr = &aStatus;
       
    98 		User::RequestComplete(statusPtr, KErrInUse);
       
    99 		return;
       
   100 		}
       
   101 	// Set this request status
       
   102 	SetRequestStatus(&aStatus);
       
   103 	aStatus = KRequestPending;
       
   104 	// No outstand requests so set up command id
       
   105 	SetCommandId(StartupAdaptation::ESetWakeupAlarm);
       
   106 	// Copy across the parameters into iWakeupAlarmPckg
       
   107 	TPckg<TTime> timePckg(iWakeupAlarmPckg().iTime);
       
   108 	timePckg.Copy(aAlarmTimePckg);
       
   109 	iWakeupAlarmPckg().iUniversalTimeOffset = 0;
       
   110 	iWakeupAlarmPckg().iDaylightSavingOffset = 0;
       
   111 	// Pass this to the adapter
       
   112 	TRAPD(err, iAdapter->QueueDispatchL(this));
       
   113 	if(err != KErrNone)
       
   114 		{
       
   115 		// Failed to queue adaptation, complete with error
       
   116 		SetRequestStatus(NULL);
       
   117 		TRequestStatus* statusPtr = &aStatus;
       
   118 		User::RequestComplete(statusPtr, err);
       
   119 		}
       
   120 
       
   121 	}
       
   122 
       
   123 /*
       
   124  * 
       
   125  * 
       
   126  * @internalComponent
       
   127  */
       
   128 void CSaaRtcAdaptation::UnsetWakeupAlarm(TRequestStatus& aStatus)
       
   129 	{
       
   130 	// If this adaptation is busy then complete with KErrInUse
       
   131 	if(Busy())
       
   132 		{
       
   133 		TRequestStatus* statusPtr = &aStatus;
       
   134 		User::RequestComplete(statusPtr, KErrInUse);
       
   135 		return;
       
   136 		}
       
   137 	// Set this request status
       
   138 	SetRequestStatus(&aStatus);
       
   139 	aStatus = KRequestPending;
       
   140 	// No outstand requests so set up command id
       
   141 	SetCommandId(StartupAdaptation::ECancelWakeupAlarm);
       
   142 	// No parameters to set to pass in
       
   143 	
       
   144 	// Pass this to the adapter
       
   145 	TRAPD(err, iAdapter->QueueDispatchL(this));
       
   146 	if(err != KErrNone)
       
   147 		{
       
   148 		// Failed to queue adaptation, complete with error
       
   149 		SetRequestStatus(NULL);
       
   150 		TRequestStatus* statusPtr = &aStatus;
       
   151 		User::RequestComplete(statusPtr, err);
       
   152 		}
       
   153 	}
       
   154 
       
   155 /*
       
   156  * 
       
   157  * 
       
   158  * @internalComponent
       
   159  */
       
   160 void CSaaRtcAdaptation::Cancel()
       
   161 	{
       
   162 	CancelRequest();
       
   163 	}
       
   164 	
       
   165 /*
       
   166  * Constructs a new state adaptation object and associates it with aAdapter
       
   167  * 
       
   168  * @internalComponent
       
   169  */
       
   170 CSaaRtcAdaptation::CSaaRtcAdaptation(CStartupAdaptationAdapter* aAdapter)
       
   171 : CAdaptationBase(aAdapter)
       
   172 	{
       
   173 
       
   174 	}
       
   175 
       
   176 /**
       
   177  * See CAdaptationBase for description of method.
       
   178  *  
       
   179  * @internalComponent
       
   180  */
       
   181 void CSaaRtcAdaptation::RequestComplete(const StartupAdaptation::TCommand __DEBUG_ONLY(aCommandId), TDesC8& aRetPckg)
       
   182 	{
       
   183 	DEBUGPRINT3A("SAA - Response received from adaptation with commandId: %d, expecting %d", aCommandId, CommandId());
       
   184 	__ASSERT_DEBUG(aCommandId == CommandId(), CLAYER_PANIC(ECLayerUnexpectedCommandResponse));
       
   185 	switch(CommandId())
       
   186 		{
       
   187 		case StartupAdaptation::EValidateRTCTime:
       
   188 			{
       
   189 			StartupAdaptation::TResponsePckg responsePckg;
       
   190 			responsePckg.Copy(aRetPckg);
       
   191 			// if responsePckg is KErrNone then the RTC is valid, otherwise it isn't valid, use this to set the value
       
   192 			TPckgBuf<TBool> booleanPckg(responsePckg() == KErrNone);
       
   193 			iReturnDes->Copy(booleanPckg);
       
   194 			// Null iReturnDes as it has no further use
       
   195 			iReturnDes = NULL;
       
   196 			CompleteRequestStatus(KErrNone);
       
   197 			break;
       
   198 			}
       
   199 		case StartupAdaptation::ESetWakeupAlarm:
       
   200 			{
       
   201 			StartupAdaptation::TResponsePckg responsePckg;
       
   202 			responsePckg.Copy(aRetPckg);
       
   203 			CompleteRequestStatus(responsePckg());
       
   204 			break;
       
   205 			}
       
   206 		case StartupAdaptation::ECancelWakeupAlarm:
       
   207 			// Always successful so nothing to check in aRetPckg
       
   208 			CompleteRequestStatus(KErrNone);
       
   209 			break;
       
   210 		default:
       
   211 			CLAYER_PANIC(ECLayerUnknownCommandResponse);
       
   212 			break;
       
   213 		}
       
   214 	}
       
   215 
       
   216 /**
       
   217  * See CAdaptationBase for description of method.
       
   218  *  
       
   219  * @internalComponent
       
   220  */
       
   221 TDesC8* CSaaRtcAdaptation::ParameterPckg()
       
   222 	{
       
   223 	TDesC8* ptr = NULL;
       
   224 	switch(CommandId())
       
   225 		{
       
   226 		case StartupAdaptation::EValidateRTCTime:
       
   227 			ptr = &iNullBuf;
       
   228 			break;
       
   229 		case StartupAdaptation::ESetWakeupAlarm:
       
   230 			ptr = &iWakeupAlarmPckg;
       
   231 			break;
       
   232 		case StartupAdaptation::ECancelWakeupAlarm:
       
   233 			ptr = &iNullBuf;
       
   234 			break;
       
   235 		default:
       
   236 			ptr = NULL;
       
   237 			break;
       
   238 		}
       
   239 	return ptr;
       
   240 	}