sysstatemgmt/systemstateplugins/adptplugin/src/stateadaptationref.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 0 4e1aa6a622a0
child 22 8cb079868133
equal deleted inserted replaced
20:1ddbe54d0645 21:ccb4f6b3db21
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description: This adaptation plugin implementation is for test/reference purposes.   
    14 //
    14 // The loading of this plugin is controlled through test macro defined in the iby file "ssmcompatibility.iby".
    15 
    15 // If the macro "TEST_SSM_MACRO" is not defined, original plugins are loaded and this plugin is not loaded.
       
    16 // If the test P & S key is set in the test code, the calls are routed to the reference or dummy implementations.
       
    17 // Else the actual plugins are loaded and the calls are routed to the actual implementations.
       
    18 // The test P & S key which it looks for is KStateAdaptationPluginPropertyKey (0x2000D76A)
       
    19 //
       
    20 
       
    21 #include <e32property.h>
       
    22 #include <ssm/ssmstate.h>
    16 #include "stateadaptationref.h"
    23 #include "stateadaptationref.h"
       
    24 #include "ssmdebug.h"
       
    25 
       
    26 const TUint32 KStateAdaptationPluginPropertyKey = 0x2000D76A;
       
    27 const TUid KPropertyCategory={0x2000D75B};
    17 
    28 
    18 /**
    29 /**
    19 Static method to create new State Adaptation Plugin.
    30 Static method to create new State Adaptation Plugin.
    20 
    31 
    21 @return	a new plugin object for State Adaptation.
    32 @return	a new plugin object for State Adaptation.
    38 	}
    49 	}
    39 
    50 
    40 CStateAdaptationRef::~CStateAdaptationRef()
    51 CStateAdaptationRef::~CStateAdaptationRef()
    41 	{
    52 	{
    42 	delete iTimer;
    53 	delete iTimer;
       
    54 	iSaaStateAdaptationLib.Close();
    43 	}
    55 	}
    44 
    56 
    45 CStateAdaptationRef::CStateAdaptationRef()
    57 CStateAdaptationRef::CStateAdaptationRef()
    46 	{
    58 	{
    47 	}
    59 	}
    48 
    60 
    49 void CStateAdaptationRef::ConstructL()
    61 void CStateAdaptationRef::ConstructL()
    50 	{
    62 	{
       
    63     DEBUGPRINT1A("Loading Actual plugins");
       
    64     _LIT(KSaaStateAdaptationDLL, "saastateadaptation.dll");
       
    65     User::LeaveIfError(iSaaStateAdaptationLib.Load(KSaaStateAdaptationDLL));
       
    66     iSaaStateAdaptationDll = (MStateAdaptation *)(iSaaStateAdaptationLib.Lookup(1)()); 
    51 	iTimer = CStateRefAdaptationTimer::NewL();
    67 	iTimer = CStateRefAdaptationTimer::NewL();
    52 	}
    68 	}
    53 
    69 
    54 //from MStateAdaptation
    70 //from MStateAdaptation
    55 void CStateAdaptationRef::Release()
    71 void CStateAdaptationRef::Release()
    56 	{
    72 	{
    57 	delete this;
    73 	delete this;
    58 	}
    74 	}
    59 
    75 
    60 void CStateAdaptationRef::RequestCoopSysStateChange(TSsmState /*aState*/, TRequestStatus& aStatus)
    76 void CStateAdaptationRef::RequestCoopSysStateChange(TSsmState aState, TRequestStatus& aStatus)
    61 	{
    77 	{
    62 	aStatus = KRequestPending;
    78 	if(!IsTestPsKeyDefined())
    63 	TRequestStatus* status = &aStatus;
    79 	    {
    64 	User::RequestComplete(status, KErrNone);
    80 	    DEBUGPRINT1A("RequestCoopSysStateChange:: Calling Actual plugins functions (saastateadaptation.dll)");
       
    81 	    iSaaStateAdaptationDll->RequestCoopSysStateChange(aState, aStatus);
       
    82 	    }
       
    83 	else
       
    84 	    {
       
    85 	    DEBUGPRINT1A("RequestCoopSysStateChange:: Calling ref plugins functions (stateadaptationref.dll)");
       
    86 	    aStatus = KRequestPending;
       
    87 	    TRequestStatus* status = &aStatus;
       
    88 	    User::RequestComplete(status, KErrNone);
       
    89 	    }
    65 	}
    90 	}
    66 
    91 
    67 void CStateAdaptationRef::RequestCoopSysSelfTest(TRequestStatus& aStatus)
    92 void CStateAdaptationRef::RequestCoopSysSelfTest(TRequestStatus& aStatus)
    68 	{
    93 	{
    69 	aStatus = KRequestPending;
    94 	if(!IsTestPsKeyDefined())
    70 	TRequestStatus* status = &aStatus;
    95         {
    71 	User::RequestComplete(status, KErrNone);
    96         DEBUGPRINT1A("RequestCoopSysSelfTest:: Calling Actual plugins functions (saastateadaptation.dll)");
    72 	}
    97         iSaaStateAdaptationDll->RequestCoopSysSelfTest(aStatus);
    73 
    98         }
    74 void CStateAdaptationRef::RequestCoopSysPerformRestartActions(TInt /*aReason*/, TRequestStatus& aStatus)
    99     else
    75 	{
   100         {
    76 	aStatus = KRequestPending;
   101         DEBUGPRINT1A("RequestCoopSysSelfTest:: Calling ref plugins functions (stateadaptationref.dll)");
    77 	TRequestStatus* status = &aStatus;
   102         aStatus = KRequestPending;
    78 	User::RequestComplete(status, KErrNone);
   103         TRequestStatus* status = &aStatus;
    79 	}
   104         User::RequestComplete(status, KErrNone);
    80 
   105         }
    81 void CStateAdaptationRef::RequestCoopSysPerformShutdownActions(TInt /*aReason*/, TRequestStatus& aStatus)
   106 	}
    82 	{
   107 
    83 	aStatus = KRequestPending;
   108 void CStateAdaptationRef::RequestCoopSysPerformRestartActions(TInt aReason, TRequestStatus& aStatus)
    84 	TRequestStatus* status = &aStatus;
   109 	{
    85 	User::RequestComplete(status, KErrNone);
   110 	if(!IsTestPsKeyDefined())
    86 	}
   111         {
    87 
   112         DEBUGPRINT1A("RequestCoopSysPerformRestartActions:: Calling Actual plugins functions (saastateadaptation.dll)");
    88 void CStateAdaptationRef::RequestCoopSysPerformRfsActions(TSsmRfsType /*aRfsType*/, TRequestStatus& aStatus)
   113         iSaaStateAdaptationDll->RequestCoopSysPerformRestartActions(aReason, aStatus);
    89 	{
   114         }
    90 	aStatus = KRequestPending;
   115     else
    91 	TRequestStatus* status = &aStatus;
   116         {
    92 	User::RequestComplete(status, KErrNone);
   117         DEBUGPRINT1A("RequestCoopSysPerformRestartActions:: Calling ref plugins functions (stateadaptationref.dll)");
       
   118         aStatus = KRequestPending;
       
   119         TRequestStatus* status = &aStatus;
       
   120         User::RequestComplete(status, KErrNone);
       
   121         }
       
   122 	}
       
   123 
       
   124 void CStateAdaptationRef::RequestCoopSysPerformShutdownActions(TInt aReason, TRequestStatus& aStatus)
       
   125 	{
       
   126 	if(!IsTestPsKeyDefined())
       
   127         {
       
   128         DEBUGPRINT1A("RequestCoopSysPerformShutdownActions:: Calling Actual plugins functions (saastateadaptation.dll)");
       
   129         iSaaStateAdaptationDll->RequestCoopSysPerformShutdownActions(aReason, aStatus);
       
   130         }
       
   131     else
       
   132         {
       
   133         DEBUGPRINT1A("RequestCoopSysPerformShutdownActions:: Calling ref plugins functions (stateadaptationref.dll)");
       
   134         aStatus = KRequestPending;
       
   135         TRequestStatus* status = &aStatus;
       
   136         User::RequestComplete(status, KErrNone);
       
   137         }
       
   138 	}
       
   139 
       
   140 void CStateAdaptationRef::RequestCoopSysPerformRfsActions(TSsmRfsType aRfsType, TRequestStatus& aStatus)
       
   141 	{
       
   142 	if(!IsTestPsKeyDefined())
       
   143         {
       
   144         DEBUGPRINT1A("RequestCoopSysPerformRfsActions:: Calling Actual plugins functions (saastateadaptation.dll)");
       
   145         iSaaStateAdaptationDll->RequestCoopSysPerformRfsActions(aRfsType, aStatus);
       
   146         }
       
   147     else
       
   148         {
       
   149         DEBUGPRINT1A("RequestCoopSysPerformRfsActions:: Calling ref plugins functions (stateadaptationref.dll)");
       
   150         aStatus = KRequestPending;
       
   151         TRequestStatus* status = &aStatus;
       
   152         User::RequestComplete(status, KErrNone);
       
   153         }
    93 	}
   154 	}
    94 
   155 
    95 /**
   156 /**
    96   Cancel the notification request. Reference implementation completes the requests immediately so there is nothing to Cancel.
   157   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.
   158   On a device, Cancel() needs an implementation as the Request might be outstanding and it needs to be cancelled.
    98 */
   159 */
    99 void CStateAdaptationRef::RequestCancel()
   160 void CStateAdaptationRef::RequestCancel()
   100 	{
   161 	{
   101 	}
   162 	if(!IsTestPsKeyDefined())
   102 
   163         {
   103 /**
   164         DEBUGPRINT1A("RequestCancel:: Calling Actual plugins functions (saastateadaptation.dll)");
   104   The reference implementation completes with KErrNotSupported since there isn't a Cooperating System on HRP/Techview.
   165         iSaaStateAdaptationDll->RequestCancel();
       
   166         }
       
   167 	}
       
   168 
       
   169 /**
       
   170   The reference implementation completes with KErrNotSupported. This is required for automated testing.
       
   171   Actual plugins return expected values and this can be verified by manual testing
   105   On a device, State Adaptation Plug-in would request for notification from the Cooperating System for 'aEvent'.
   172   On a device, State Adaptation Plug-in would request for notification from the Cooperating System for 'aEvent'.
   106   
   173   
   107   The above mentioned implementation is modified to facilitate testing and increase the code coverage of the Adaptation 
   174   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.
   175   server code.The modified functionality is as follows.
   109   
   176   
   118   
   185   
   119   
   186   
   120 */
   187 */
   121 void CStateAdaptationRef::NotifyCoopSysEvent(TDes8& /*aEvent*/, TRequestStatus& aStatus)
   188 void CStateAdaptationRef::NotifyCoopSysEvent(TDes8& /*aEvent*/, TRequestStatus& aStatus)
   122 	{
   189 	{
   123 	aStatus = KRequestPending;
   190 	if(!IsTestPsKeyDefined())
   124 	iTimer->After(2000000,aStatus);
   191         {
       
   192         /* Only ssmpowersup.dll has an outstanding request. If this is passed to the actual plugin, the
       
   193         request will never complete till a power event happens. This would add the test code requests in a queue
       
   194         and the test code waits indefinitely. Hence, complete the request with KErrServerTerminated. This would free 
       
   195         the queue for test code to be executed. It has not impact on the test environment */
       
   196         aStatus = KRequestPending;
       
   197         TRequestStatus* status = &aStatus;
       
   198         User::RequestComplete(status, KErrServerTerminated);
       
   199         }
       
   200     else
       
   201         {
       
   202         DEBUGPRINT1A("NotifyCoopSysEvent:: Calling ref plugins functions (stateadaptationref.dll)");
       
   203         aStatus = KRequestPending;
       
   204         iTimer->After(2000000,aStatus);
       
   205         }
   125 	}
   206 	}
   126 
   207 
   127 /**
   208 /**
   128   Cancel the notification request. Reference implementation completes the requests immediately so there is nothing to Cancel.
   209   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.
   210   On a device, Cancel() needs an implementation as the Request might be outstanding and it needs to be cancelled.
   130 */
   211 */
   131 void CStateAdaptationRef::NotifyCancel()
   212 void CStateAdaptationRef::NotifyCancel()
   132 	{
   213 	{
   133 	if(iTimer->IsActive())
   214 	if(!IsTestPsKeyDefined())
   134 		{
   215         {
   135 		iTimer->Cancel();			
   216         DEBUGPRINT1A("NotifyCancel:: Calling Actual plugins functions (saastateadaptation.dll)");
   136 		}	
   217         iSaaStateAdaptationDll->NotifyCancel();
   137 	}
   218         }
   138 
   219     else
   139 
   220         {
       
   221         DEBUGPRINT1A("NotifyCancel:: Calling ref plugins functions (stateadaptationref.dll)");
       
   222         if(iTimer->IsActive())
       
   223             {
       
   224             iTimer->Cancel();
       
   225             }
       
   226         }
       
   227 	}
       
   228 
       
   229 /**
       
   230     Helper function to check for P&S Key
       
   231 */
       
   232 TBool CStateAdaptationRef::IsTestPsKeyDefined()
       
   233     {
       
   234     TBool testPsKeyDefined = EFalse;
       
   235     TInt result = RProperty::Get(KPropertyCategory, KStateAdaptationPluginPropertyKey, testPsKeyDefined);
       
   236     DEBUGPRINT3(_L("KStateAdaptationPluginPropertyKey %d Error %d"), testPsKeyDefined, result);
       
   237     if ((KErrNone != result) && (KErrNotFound != result))
       
   238         {
       
   239         //Could not retrieve property value. Tests might fail 
       
   240         DEBUGPRINT1A("IsTestPsKeyDefined ERROR :: Could not retrieve property value)");
       
   241         }
       
   242     return testPsKeyDefined;
       
   243     }
   140 
   244 
   141 CStateRefAdaptationTimer::CStateRefAdaptationTimer():CTimer(CActive::EPriorityUserInput)
   245 CStateRefAdaptationTimer::CStateRefAdaptationTimer():CTimer(CActive::EPriorityUserInput)
   142 	{
   246 	{
   143    	CActiveScheduler::Add(this);
   247    	CActiveScheduler::Add(this);
   144 	}
   248 	}