sysstatemgmt/systemstatemgr/sus/src/susrtcadaptation.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2008-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 <e32debug.h>
       
    17 #include <ssm/ssmadaptation.h>
       
    18 #include "susrtcadaptation.h"
       
    19 
       
    20 /**
       
    21 @publishedPartner
       
    22 */
       
    23 void CRtcAdaptation::SubmitOrQueueL(const RMessage2 &aMessage)
       
    24 	{
       
    25 	CAdaptationMessage *messageCopy = new(ELeave) CAdaptationMessage(aMessage);
       
    26 	
       
    27 	if(!IsActive())
       
    28 		{
       
    29 		SubmitL(messageCopy);
       
    30 		}
       
    31 	else 
       
    32 		{
       
    33 		CleanupStack::PushL(messageCopy);
       
    34 		DEBUGPRINT2A("CRtcAdaptationRequests queuing request with function id: %d", aMessage.Function());
       
    35 		User::LeaveIfError(iPendingRequestsQueue.Queue(messageCopy));
       
    36 		CleanupStack::Pop(messageCopy);
       
    37 		}	
       
    38 	}
       
    39 
       
    40 void CRtcAdaptation::SubmitL(CAdaptationMessage*& aMessage)
       
    41 	{
       
    42 		DEBUGPRINT2A("CRtcAdaptationRequests immediate submission of request with function id: %d", aMessage->Function());
       
    43 		iCurrentMessage = aMessage;
       
    44 		switch(aMessage->Function())
       
    45 			{
       
    46 			case EValidateRtc :
       
    47 				{
       
    48 				iRtcAdaptation.ValidateRtc(iValidityPckg, iStatus);
       
    49 				break;
       
    50 				}
       
    51 			case ESetWakeupAlarm :
       
    52 				{
       
    53 				iParam = HBufC8::NewL(aMessage->GetDesLength(0));
       
    54 				aMessage->ReadL(0,iParam->Des());
       
    55  				iRtcAdaptation.SetWakeupAlarm(*iParam, iStatus);
       
    56 				break;
       
    57 				}
       
    58 			case EUnsetWakeupAlarm :
       
    59 				{
       
    60 				iRtcAdaptation.UnsetWakeupAlarm(iStatus);
       
    61 				break;
       
    62 				}
       
    63 			default :
       
    64 				{
       
    65 				break;
       
    66 				}
       
    67 			}
       
    68 		SetActive();
       
    69 	}
       
    70 
       
    71 
       
    72 /**
       
    73 CRtcAdaptation implements RTC Adaptation related functionality as part of CSsmAdaptationServer.
       
    74 CSsmAdaptationServer loads RTC Adaptation plugin and creates CRtcAdaptation using the NewL.
       
    75 From then the loaded RTC Adaptation plugin will be owned by CRtcAdaptation.
       
    76 
       
    77 @internalComponent
       
    78 */
       
    79 
       
    80 CRtcAdaptation* CRtcAdaptation::NewL(MRtcAdaptation& aAdaptation)
       
    81 	{
       
    82 	CRtcAdaptation* self = new(ELeave) CRtcAdaptation(aAdaptation);
       
    83 	return self;	
       
    84 	}
       
    85 
       
    86 CRtcAdaptation::~CRtcAdaptation()
       
    87 	{
       
    88 	iPendingRequestsQueue.NotifyAndRemoveAll();
       
    89 	Cancel();
       
    90 	iPendingRequestsQueue.Close();
       
    91 	Release();
       
    92 	}
       
    93 
       
    94 CRtcAdaptation::CRtcAdaptation(MRtcAdaptation& aAdaptation) : CActive(EPriorityStandard), iRtcAdaptation(aAdaptation)
       
    95 	{
       
    96 	CActiveScheduler::Add(this);
       
    97 	}
       
    98 
       
    99 void CRtcAdaptation::Release()
       
   100 	{
       
   101 	iRtcAdaptation.Release();
       
   102 	}
       
   103 
       
   104 
       
   105 
       
   106 void CRtcAdaptation::DoValidateRtcL(const RMessage2& aMessage)
       
   107 	{
       
   108 	SubmitOrQueueL(aMessage);
       
   109 	}
       
   110 
       
   111 void CRtcAdaptation::DoSetWakeupAlarmL(const RMessage2& aMessage)
       
   112 	{
       
   113 	SubmitOrQueueL(aMessage);
       
   114 	}
       
   115 
       
   116 void CRtcAdaptation::DoUnsetWakeupAlarmL(const RMessage2& aMessage)
       
   117 	{
       
   118 	SubmitOrQueueL(aMessage);
       
   119 	}
       
   120 
       
   121 
       
   122 
       
   123 void CRtcAdaptation::DoRtcCancelL(const RMessage2& aMessage)
       
   124 	{
       
   125 	
       
   126 	if(iCurrentMessage != NULL)	
       
   127 		{
       
   128 		if(aMessage.Session() == iCurrentMessage->Session())
       
   129 			{
       
   130 			DEBUGPRINT1A("CRtcAdaptationRequests cancelling current request as requested");
       
   131 			iRtcAdaptation.Cancel();
       
   132 			}
       
   133 		iPendingRequestsQueue.RemoveFromQueueAndComplete(aMessage);  	
       
   134 		aMessage.Complete(KErrNone);
       
   135 		}
       
   136 	else
       
   137 		{
       
   138 		DEBUGPRINT1A("CRtcAdaptationRequests nothing to cancel, but cancel requested");
       
   139 		aMessage.Complete(KErrNone);				
       
   140 		}
       
   141 				
       
   142 	}
       
   143 
       
   144 void CRtcAdaptation::RunL()
       
   145 	{
       
   146 	
       
   147 	WriteResponseDataToClientMessageL();
       
   148 
       
   149 	DEBUGPRINT2A("CRtcAdaptation processed the request with funtion id: %d", iCurrentMessage->Function());
       
   150 	iCurrentMessage->Complete(iStatus.Int());
       
   151 	delete iCurrentMessage;
       
   152 	delete iParam;
       
   153 	iCurrentMessage = NULL;  
       
   154 	iParam = NULL;
       
   155 
       
   156 	if( (iPendingRequestsQueue.IsEmpty()) == EFalse )
       
   157 		{
       
   158 		CAdaptationMessage *messageCopy = NULL;
       
   159 		iPendingRequestsQueue.Dequeue(messageCopy);
       
   160 		SubmitL(messageCopy);
       
   161 		} 
       
   162 	}
       
   163 
       
   164 void CRtcAdaptation::WriteResponseDataToClientMessageL()
       
   165 	{
       
   166 	switch(iCurrentMessage->Function())
       
   167 		{
       
   168 			case EValidateRtc:
       
   169 				{
       
   170 				iCurrentMessage->WriteL(0,iValidityPckg);
       
   171 				break;					
       
   172 				}
       
   173 			default:
       
   174 				{
       
   175 				break;					
       
   176 				}				
       
   177 		}
       
   178 	}
       
   179 
       
   180 
       
   181 TInt CRtcAdaptation::RunError( TInt aError )
       
   182 	{
       
   183 	
       
   184 	if(iCurrentMessage != NULL)	
       
   185 		{
       
   186 		iCurrentMessage->Complete(aError);
       
   187 		delete iCurrentMessage;
       
   188 		iCurrentMessage = NULL;
       
   189 		}
       
   190 	
       
   191 	while( (iPendingRequestsQueue.IsEmpty()) == EFalse )
       
   192 		{
       
   193 		iPendingRequestsQueue.Dequeue(iCurrentMessage);
       
   194 		iCurrentMessage->Complete(aError);
       
   195 		delete iCurrentMessage;
       
   196 		iCurrentMessage = NULL;
       
   197 		}
       
   198 	
       
   199 	return KErrNone;
       
   200 			
       
   201 	}
       
   202 
       
   203 void CRtcAdaptation::DoCancel()
       
   204 	{
       
   205 	if(iCurrentMessage != NULL)	
       
   206 		{
       
   207 		iCurrentMessage->Complete(KErrCancel);
       
   208 		delete iCurrentMessage;
       
   209 		iCurrentMessage = NULL;
       
   210 		}
       
   211 		
       
   212 	while( (iPendingRequestsQueue.IsEmpty()) == EFalse )
       
   213 		{
       
   214 		iPendingRequestsQueue.Dequeue(iCurrentMessage);
       
   215 		iCurrentMessage->Complete(KErrCancel);
       
   216 		delete iCurrentMessage;
       
   217 		iCurrentMessage = NULL;
       
   218 		}
       
   219 	}
       
   220