sysstatemgmt/systemstateplugins/adptplugin/src/stateadaptationref.cpp
changeset 0 4e1aa6a622a0
child 21 ccb4f6b3db21
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 "stateadaptationref.h"
       
    17 
       
    18 /**
       
    19 Static method to create new State Adaptation Plugin.
       
    20 
       
    21 @return	a new plugin object for State Adaptation.
       
    22 */
       
    23 EXPORT_C MStateAdaptation* CreateStateAdaptationL()
       
    24 	{
       
    25 	CStateAdaptationRef* stateAdaptationRef = CStateAdaptationRef::NewL();
       
    26 	return (static_cast<MStateAdaptation*>(stateAdaptationRef));
       
    27 	}
       
    28 
       
    29 CStateAdaptationRef* CStateAdaptationRef::NewL()
       
    30 	{
       
    31 	CStateAdaptationRef* self = new(ELeave) CStateAdaptationRef;
       
    32 	
       
    33 	CleanupStack::PushL(self);
       
    34 	self->ConstructL();
       
    35 	CleanupStack::Pop();
       
    36 
       
    37 	return self;
       
    38 	}
       
    39 
       
    40 CStateAdaptationRef::~CStateAdaptationRef()
       
    41 	{
       
    42 	delete iTimer;
       
    43 	}
       
    44 
       
    45 CStateAdaptationRef::CStateAdaptationRef()
       
    46 	{
       
    47 	}
       
    48 
       
    49 void CStateAdaptationRef::ConstructL()
       
    50 	{
       
    51 	iTimer = CStateRefAdaptationTimer::NewL();
       
    52 	}
       
    53 
       
    54 //from MStateAdaptation
       
    55 void CStateAdaptationRef::Release()
       
    56 	{
       
    57 	delete this;
       
    58 	}
       
    59 
       
    60 void CStateAdaptationRef::RequestCoopSysStateChange(TSsmState /*aState*/, TRequestStatus& aStatus)
       
    61 	{
       
    62 	aStatus = KRequestPending;
       
    63 	TRequestStatus* status = &aStatus;
       
    64 	User::RequestComplete(status, KErrNone);
       
    65 	}
       
    66 
       
    67 void CStateAdaptationRef::RequestCoopSysSelfTest(TRequestStatus& aStatus)
       
    68 	{
       
    69 	aStatus = KRequestPending;
       
    70 	TRequestStatus* status = &aStatus;
       
    71 	User::RequestComplete(status, KErrNone);
       
    72 	}
       
    73 
       
    74 void CStateAdaptationRef::RequestCoopSysPerformRestartActions(TInt /*aReason*/, TRequestStatus& aStatus)
       
    75 	{
       
    76 	aStatus = KRequestPending;
       
    77 	TRequestStatus* status = &aStatus;
       
    78 	User::RequestComplete(status, KErrNone);
       
    79 	}
       
    80 
       
    81 void CStateAdaptationRef::RequestCoopSysPerformShutdownActions(TInt /*aReason*/, TRequestStatus& aStatus)
       
    82 	{
       
    83 	aStatus = KRequestPending;
       
    84 	TRequestStatus* status = &aStatus;
       
    85 	User::RequestComplete(status, KErrNone);
       
    86 	}
       
    87 
       
    88 void CStateAdaptationRef::RequestCoopSysPerformRfsActions(TSsmRfsType /*aRfsType*/, TRequestStatus& aStatus)
       
    89 	{
       
    90 	aStatus = KRequestPending;
       
    91 	TRequestStatus* status = &aStatus;
       
    92 	User::RequestComplete(status, KErrNone);
       
    93 	}
       
    94 
       
    95 /**
       
    96   Cancel the notification request. Reference implementation completes the requests immediately so there is nothing to Cancel.
       
    97   On a device, Cancel() needs an implementation as the Request might be outstanding and it needs to be cancelled.
       
    98 */
       
    99 void CStateAdaptationRef::RequestCancel()
       
   100 	{
       
   101 	}
       
   102 
       
   103 /**
       
   104   The reference implementation completes with KErrNotSupported since there isn't a Cooperating System on HRP/Techview.
       
   105   On a device, State Adaptation Plug-in would request for notification from the Cooperating System for 'aEvent'.
       
   106   
       
   107   The above mentioned implementation is modified to facilitate testing and increase the code coverage of the Adaptation 
       
   108   server code.The modified functionality is as follows.
       
   109   
       
   110   
       
   111   Instead of completing the notification request with KErrNotSupported the it is passed to 
       
   112   CStateAdaptationRefEventHandler which is an active object wiht lower priority compared to 
       
   113   the server active object.Because of this a delay will be introduced in completing the notification
       
   114   request so that other active objects can run avoiding infinite loop and starvation of other 
       
   115   active objects,which will be the case if the notification request is immediately completed.
       
   116   This is strictly for testing purposes.On a device this call will be replaced by a notification request
       
   117   to cooperative system.
       
   118   
       
   119   
       
   120 */
       
   121 void CStateAdaptationRef::NotifyCoopSysEvent(TDes8& /*aEvent*/, TRequestStatus& aStatus)
       
   122 	{
       
   123 	aStatus = KRequestPending;
       
   124 	iTimer->After(2000000,aStatus);
       
   125 	}
       
   126 
       
   127 /**
       
   128   Cancel the notification request. Reference implementation completes the requests immediately so there is nothing to Cancel.
       
   129   On a device, Cancel() needs an implementation as the Request might be outstanding and it needs to be cancelled.
       
   130 */
       
   131 void CStateAdaptationRef::NotifyCancel()
       
   132 	{
       
   133 	if(iTimer->IsActive())
       
   134 		{
       
   135 		iTimer->Cancel();			
       
   136 		}	
       
   137 	}
       
   138 
       
   139 
       
   140 
       
   141 CStateRefAdaptationTimer::CStateRefAdaptationTimer():CTimer(CActive::EPriorityUserInput)
       
   142 	{
       
   143    	CActiveScheduler::Add(this);
       
   144 	}
       
   145 
       
   146 CStateRefAdaptationTimer::~CStateRefAdaptationTimer()
       
   147 	{
       
   148 	Cancel();	
       
   149 	}
       
   150 
       
   151 CStateRefAdaptationTimer* CStateRefAdaptationTimer::NewL()
       
   152 	{
       
   153    	CStateRefAdaptationTimer* self=new (ELeave) CStateRefAdaptationTimer();
       
   154    	CleanupStack::PushL(self);
       
   155    	self->ConstructL();
       
   156    	CleanupStack::Pop();
       
   157     return self;		
       
   158 	}
       
   159 
       
   160 void CStateRefAdaptationTimer::After(TTimeIntervalMicroSeconds32 aCancelDelay, TRequestStatus& aStatus)
       
   161 	{
       
   162 	iReqStatus = &aStatus;
       
   163 	if(!IsActive())
       
   164 	CTimer::After(aCancelDelay);	
       
   165 	}
       
   166 
       
   167 
       
   168 
       
   169 void CStateRefAdaptationTimer::DoCancel()
       
   170 	{
       
   171 	User::RequestComplete(iReqStatus, KErrCancel);	
       
   172 	CTimer::DoCancel();	
       
   173 	}
       
   174 
       
   175 
       
   176 void CStateRefAdaptationTimer::RunL()
       
   177 	{
       
   178 	User::RequestComplete(iReqStatus, KErrNone);	
       
   179 	}
       
   180 
       
   181