sysstatemgmt/systemstateplugins/adptplugin/src/stateadaptationref.cpp
branchRCL_3
changeset 61 8cb079868133
parent 60 ccb4f6b3db21
equal deleted inserted replaced
60:ccb4f6b3db21 61:8cb079868133
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2009 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: This adaptation plugin implementation is for test/reference purposes.   
    13 // Description:
    14 // The loading of this plugin is controlled through test macro defined in the iby file "ssmcompatibility.iby".
       
    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 //
    14 //
    20 
    15 
    21 #include <e32property.h>
       
    22 #include <ssm/ssmstate.h>
       
    23 #include "stateadaptationref.h"
    16 #include "stateadaptationref.h"
    24 #include "ssmdebug.h"
       
    25 
       
    26 const TUint32 KStateAdaptationPluginPropertyKey = 0x2000D76A;
       
    27 const TUid KPropertyCategory={0x2000D75B};
       
    28 
    17 
    29 /**
    18 /**
    30 Static method to create new State Adaptation Plugin.
    19 Static method to create new State Adaptation Plugin.
    31 
    20 
    32 @return	a new plugin object for State Adaptation.
    21 @return	a new plugin object for State Adaptation.
    49 	}
    38 	}
    50 
    39 
    51 CStateAdaptationRef::~CStateAdaptationRef()
    40 CStateAdaptationRef::~CStateAdaptationRef()
    52 	{
    41 	{
    53 	delete iTimer;
    42 	delete iTimer;
    54 	iSaaStateAdaptationLib.Close();
       
    55 	}
    43 	}
    56 
    44 
    57 CStateAdaptationRef::CStateAdaptationRef()
    45 CStateAdaptationRef::CStateAdaptationRef()
    58 	{
    46 	{
    59 	}
    47 	}
    60 
    48 
    61 void CStateAdaptationRef::ConstructL()
    49 void CStateAdaptationRef::ConstructL()
    62 	{
    50 	{
    63     DEBUGPRINT1A("Loading Actual plugins");
       
    64     _LIT(KSaaStateAdaptationDLL, "saastateadaptation.dll");
       
    65     User::LeaveIfError(iSaaStateAdaptationLib.Load(KSaaStateAdaptationDLL));
       
    66     iSaaStateAdaptationDll = (MStateAdaptation *)(iSaaStateAdaptationLib.Lookup(1)()); 
       
    67 	iTimer = CStateRefAdaptationTimer::NewL();
    51 	iTimer = CStateRefAdaptationTimer::NewL();
    68 	}
    52 	}
    69 
    53 
    70 //from MStateAdaptation
    54 //from MStateAdaptation
    71 void CStateAdaptationRef::Release()
    55 void CStateAdaptationRef::Release()
    72 	{
    56 	{
    73 	delete this;
    57 	delete this;
    74 	}
    58 	}
    75 
    59 
    76 void CStateAdaptationRef::RequestCoopSysStateChange(TSsmState aState, TRequestStatus& aStatus)
    60 void CStateAdaptationRef::RequestCoopSysStateChange(TSsmState /*aState*/, TRequestStatus& aStatus)
    77 	{
    61 	{
    78 	if(!IsTestPsKeyDefined())
    62 	aStatus = KRequestPending;
    79 	    {
    63 	TRequestStatus* status = &aStatus;
    80 	    DEBUGPRINT1A("RequestCoopSysStateChange:: Calling Actual plugins functions (saastateadaptation.dll)");
    64 	User::RequestComplete(status, KErrNone);
    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 	    }
       
    90 	}
    65 	}
    91 
    66 
    92 void CStateAdaptationRef::RequestCoopSysSelfTest(TRequestStatus& aStatus)
    67 void CStateAdaptationRef::RequestCoopSysSelfTest(TRequestStatus& aStatus)
    93 	{
    68 	{
    94 	if(!IsTestPsKeyDefined())
    69 	aStatus = KRequestPending;
    95         {
    70 	TRequestStatus* status = &aStatus;
    96         DEBUGPRINT1A("RequestCoopSysSelfTest:: Calling Actual plugins functions (saastateadaptation.dll)");
    71 	User::RequestComplete(status, KErrNone);
    97         iSaaStateAdaptationDll->RequestCoopSysSelfTest(aStatus);
       
    98         }
       
    99     else
       
   100         {
       
   101         DEBUGPRINT1A("RequestCoopSysSelfTest:: Calling ref plugins functions (stateadaptationref.dll)");
       
   102         aStatus = KRequestPending;
       
   103         TRequestStatus* status = &aStatus;
       
   104         User::RequestComplete(status, KErrNone);
       
   105         }
       
   106 	}
    72 	}
   107 
    73 
   108 void CStateAdaptationRef::RequestCoopSysPerformRestartActions(TInt aReason, TRequestStatus& aStatus)
    74 void CStateAdaptationRef::RequestCoopSysPerformRestartActions(TInt /*aReason*/, TRequestStatus& aStatus)
   109 	{
    75 	{
   110 	if(!IsTestPsKeyDefined())
    76 	aStatus = KRequestPending;
   111         {
    77 	TRequestStatus* status = &aStatus;
   112         DEBUGPRINT1A("RequestCoopSysPerformRestartActions:: Calling Actual plugins functions (saastateadaptation.dll)");
    78 	User::RequestComplete(status, KErrNone);
   113         iSaaStateAdaptationDll->RequestCoopSysPerformRestartActions(aReason, aStatus);
       
   114         }
       
   115     else
       
   116         {
       
   117         DEBUGPRINT1A("RequestCoopSysPerformRestartActions:: Calling ref plugins functions (stateadaptationref.dll)");
       
   118         aStatus = KRequestPending;
       
   119         TRequestStatus* status = &aStatus;
       
   120         User::RequestComplete(status, KErrNone);
       
   121         }
       
   122 	}
    79 	}
   123 
    80 
   124 void CStateAdaptationRef::RequestCoopSysPerformShutdownActions(TInt aReason, TRequestStatus& aStatus)
    81 void CStateAdaptationRef::RequestCoopSysPerformShutdownActions(TInt /*aReason*/, TRequestStatus& aStatus)
   125 	{
    82 	{
   126 	if(!IsTestPsKeyDefined())
    83 	aStatus = KRequestPending;
   127         {
    84 	TRequestStatus* status = &aStatus;
   128         DEBUGPRINT1A("RequestCoopSysPerformShutdownActions:: Calling Actual plugins functions (saastateadaptation.dll)");
    85 	User::RequestComplete(status, KErrNone);
   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 	}
    86 	}
   139 
    87 
   140 void CStateAdaptationRef::RequestCoopSysPerformRfsActions(TSsmRfsType aRfsType, TRequestStatus& aStatus)
    88 void CStateAdaptationRef::RequestCoopSysPerformRfsActions(TSsmRfsType /*aRfsType*/, TRequestStatus& aStatus)
   141 	{
    89 	{
   142 	if(!IsTestPsKeyDefined())
    90 	aStatus = KRequestPending;
   143         {
    91 	TRequestStatus* status = &aStatus;
   144         DEBUGPRINT1A("RequestCoopSysPerformRfsActions:: Calling Actual plugins functions (saastateadaptation.dll)");
    92 	User::RequestComplete(status, KErrNone);
   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         }
       
   154 	}
    93 	}
   155 
    94 
   156 /**
    95 /**
   157   Cancel the notification request. Reference implementation completes the requests immediately so there is nothing to Cancel.
    96   Cancel the notification request. Reference implementation completes the requests immediately so there is nothing to Cancel.
   158   On a device, Cancel() needs an implementation as the Request might be outstanding and it needs to be cancelled.
    97   On a device, Cancel() needs an implementation as the Request might be outstanding and it needs to be cancelled.
   159 */
    98 */
   160 void CStateAdaptationRef::RequestCancel()
    99 void CStateAdaptationRef::RequestCancel()
   161 	{
   100 	{
   162 	if(!IsTestPsKeyDefined())
       
   163         {
       
   164         DEBUGPRINT1A("RequestCancel:: Calling Actual plugins functions (saastateadaptation.dll)");
       
   165         iSaaStateAdaptationDll->RequestCancel();
       
   166         }
       
   167 	}
   101 	}
   168 
   102 
   169 /**
   103 /**
   170   The reference implementation completes with KErrNotSupported. This is required for automated testing.
   104   The reference implementation completes with KErrNotSupported since there isn't a Cooperating System on HRP/Techview.
   171   Actual plugins return expected values and this can be verified by manual testing
       
   172   On a device, State Adaptation Plug-in would request for notification from the Cooperating System for 'aEvent'.
   105   On a device, State Adaptation Plug-in would request for notification from the Cooperating System for 'aEvent'.
   173   
   106   
   174   The above mentioned implementation is modified to facilitate testing and increase the code coverage of the Adaptation 
   107   The above mentioned implementation is modified to facilitate testing and increase the code coverage of the Adaptation 
   175   server code.The modified functionality is as follows.
   108   server code.The modified functionality is as follows.
   176   
   109   
   185   
   118   
   186   
   119   
   187 */
   120 */
   188 void CStateAdaptationRef::NotifyCoopSysEvent(TDes8& /*aEvent*/, TRequestStatus& aStatus)
   121 void CStateAdaptationRef::NotifyCoopSysEvent(TDes8& /*aEvent*/, TRequestStatus& aStatus)
   189 	{
   122 	{
   190 	if(!IsTestPsKeyDefined())
   123 	aStatus = KRequestPending;
   191         {
   124 	iTimer->After(2000000,aStatus);
   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         }
       
   206 	}
   125 	}
   207 
   126 
   208 /**
   127 /**
   209   Cancel the notification request. Reference implementation completes the requests immediately so there is nothing to Cancel.
   128   Cancel the notification request. Reference implementation completes the requests immediately so there is nothing to Cancel.
   210   On a device, Cancel() needs an implementation as the Request might be outstanding and it needs to be cancelled.
   129   On a device, Cancel() needs an implementation as the Request might be outstanding and it needs to be cancelled.
   211 */
   130 */
   212 void CStateAdaptationRef::NotifyCancel()
   131 void CStateAdaptationRef::NotifyCancel()
   213 	{
   132 	{
   214 	if(!IsTestPsKeyDefined())
   133 	if(iTimer->IsActive())
   215         {
   134 		{
   216         DEBUGPRINT1A("NotifyCancel:: Calling Actual plugins functions (saastateadaptation.dll)");
   135 		iTimer->Cancel();			
   217         iSaaStateAdaptationDll->NotifyCancel();
   136 		}	
   218         }
       
   219     else
       
   220         {
       
   221         DEBUGPRINT1A("NotifyCancel:: Calling ref plugins functions (stateadaptationref.dll)");
       
   222         if(iTimer->IsActive())
       
   223             {
       
   224             iTimer->Cancel();
       
   225             }
       
   226         }
       
   227 	}
   137 	}
   228 
   138 
   229 /**
   139 
   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     }
       
   244 
   140 
   245 CStateRefAdaptationTimer::CStateRefAdaptationTimer():CTimer(CActive::EPriorityUserInput)
   141 CStateRefAdaptationTimer::CStateRefAdaptationTimer():CTimer(CActive::EPriorityUserInput)
   246 	{
   142 	{
   247    	CActiveScheduler::Add(this);
   143    	CActiveScheduler::Add(this);
   248 	}
   144 	}