sysstatemgmt/systemstateplugins/adptplugin/src/stateadaptationref.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 0 4e1aa6a622a0
child 22 8cb079868133
--- a/sysstatemgmt/systemstateplugins/adptplugin/src/stateadaptationref.cpp	Thu Aug 19 11:09:10 2010 +0300
+++ b/sysstatemgmt/systemstateplugins/adptplugin/src/stateadaptationref.cpp	Tue Aug 31 16:29:05 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -10,10 +10,21 @@
 //
 // Contributors:
 //
-// Description:
+// Description: This adaptation plugin implementation is for test/reference purposes.   
+// The loading of this plugin is controlled through test macro defined in the iby file "ssmcompatibility.iby".
+// If the macro "TEST_SSM_MACRO" is not defined, original plugins are loaded and this plugin is not loaded.
+// If the test P & S key is set in the test code, the calls are routed to the reference or dummy implementations.
+// Else the actual plugins are loaded and the calls are routed to the actual implementations.
+// The test P & S key which it looks for is KStateAdaptationPluginPropertyKey (0x2000D76A)
 //
 
+#include <e32property.h>
+#include <ssm/ssmstate.h>
 #include "stateadaptationref.h"
+#include "ssmdebug.h"
+
+const TUint32 KStateAdaptationPluginPropertyKey = 0x2000D76A;
+const TUid KPropertyCategory={0x2000D75B};
 
 /**
 Static method to create new State Adaptation Plugin.
@@ -40,6 +51,7 @@
 CStateAdaptationRef::~CStateAdaptationRef()
 	{
 	delete iTimer;
+	iSaaStateAdaptationLib.Close();
 	}
 
 CStateAdaptationRef::CStateAdaptationRef()
@@ -48,6 +60,10 @@
 
 void CStateAdaptationRef::ConstructL()
 	{
+    DEBUGPRINT1A("Loading Actual plugins");
+    _LIT(KSaaStateAdaptationDLL, "saastateadaptation.dll");
+    User::LeaveIfError(iSaaStateAdaptationLib.Load(KSaaStateAdaptationDLL));
+    iSaaStateAdaptationDll = (MStateAdaptation *)(iSaaStateAdaptationLib.Lookup(1)()); 
 	iTimer = CStateRefAdaptationTimer::NewL();
 	}
 
@@ -57,39 +73,84 @@
 	delete this;
 	}
 
-void CStateAdaptationRef::RequestCoopSysStateChange(TSsmState /*aState*/, TRequestStatus& aStatus)
+void CStateAdaptationRef::RequestCoopSysStateChange(TSsmState aState, TRequestStatus& aStatus)
 	{
-	aStatus = KRequestPending;
-	TRequestStatus* status = &aStatus;
-	User::RequestComplete(status, KErrNone);
+	if(!IsTestPsKeyDefined())
+	    {
+	    DEBUGPRINT1A("RequestCoopSysStateChange:: Calling Actual plugins functions (saastateadaptation.dll)");
+	    iSaaStateAdaptationDll->RequestCoopSysStateChange(aState, aStatus);
+	    }
+	else
+	    {
+	    DEBUGPRINT1A("RequestCoopSysStateChange:: Calling ref plugins functions (stateadaptationref.dll)");
+	    aStatus = KRequestPending;
+	    TRequestStatus* status = &aStatus;
+	    User::RequestComplete(status, KErrNone);
+	    }
 	}
 
 void CStateAdaptationRef::RequestCoopSysSelfTest(TRequestStatus& aStatus)
 	{
-	aStatus = KRequestPending;
-	TRequestStatus* status = &aStatus;
-	User::RequestComplete(status, KErrNone);
+	if(!IsTestPsKeyDefined())
+        {
+        DEBUGPRINT1A("RequestCoopSysSelfTest:: Calling Actual plugins functions (saastateadaptation.dll)");
+        iSaaStateAdaptationDll->RequestCoopSysSelfTest(aStatus);
+        }
+    else
+        {
+        DEBUGPRINT1A("RequestCoopSysSelfTest:: Calling ref plugins functions (stateadaptationref.dll)");
+        aStatus = KRequestPending;
+        TRequestStatus* status = &aStatus;
+        User::RequestComplete(status, KErrNone);
+        }
 	}
 
-void CStateAdaptationRef::RequestCoopSysPerformRestartActions(TInt /*aReason*/, TRequestStatus& aStatus)
+void CStateAdaptationRef::RequestCoopSysPerformRestartActions(TInt aReason, TRequestStatus& aStatus)
 	{
-	aStatus = KRequestPending;
-	TRequestStatus* status = &aStatus;
-	User::RequestComplete(status, KErrNone);
+	if(!IsTestPsKeyDefined())
+        {
+        DEBUGPRINT1A("RequestCoopSysPerformRestartActions:: Calling Actual plugins functions (saastateadaptation.dll)");
+        iSaaStateAdaptationDll->RequestCoopSysPerformRestartActions(aReason, aStatus);
+        }
+    else
+        {
+        DEBUGPRINT1A("RequestCoopSysPerformRestartActions:: Calling ref plugins functions (stateadaptationref.dll)");
+        aStatus = KRequestPending;
+        TRequestStatus* status = &aStatus;
+        User::RequestComplete(status, KErrNone);
+        }
 	}
 
-void CStateAdaptationRef::RequestCoopSysPerformShutdownActions(TInt /*aReason*/, TRequestStatus& aStatus)
+void CStateAdaptationRef::RequestCoopSysPerformShutdownActions(TInt aReason, TRequestStatus& aStatus)
 	{
-	aStatus = KRequestPending;
-	TRequestStatus* status = &aStatus;
-	User::RequestComplete(status, KErrNone);
+	if(!IsTestPsKeyDefined())
+        {
+        DEBUGPRINT1A("RequestCoopSysPerformShutdownActions:: Calling Actual plugins functions (saastateadaptation.dll)");
+        iSaaStateAdaptationDll->RequestCoopSysPerformShutdownActions(aReason, aStatus);
+        }
+    else
+        {
+        DEBUGPRINT1A("RequestCoopSysPerformShutdownActions:: Calling ref plugins functions (stateadaptationref.dll)");
+        aStatus = KRequestPending;
+        TRequestStatus* status = &aStatus;
+        User::RequestComplete(status, KErrNone);
+        }
 	}
 
-void CStateAdaptationRef::RequestCoopSysPerformRfsActions(TSsmRfsType /*aRfsType*/, TRequestStatus& aStatus)
+void CStateAdaptationRef::RequestCoopSysPerformRfsActions(TSsmRfsType aRfsType, TRequestStatus& aStatus)
 	{
-	aStatus = KRequestPending;
-	TRequestStatus* status = &aStatus;
-	User::RequestComplete(status, KErrNone);
+	if(!IsTestPsKeyDefined())
+        {
+        DEBUGPRINT1A("RequestCoopSysPerformRfsActions:: Calling Actual plugins functions (saastateadaptation.dll)");
+        iSaaStateAdaptationDll->RequestCoopSysPerformRfsActions(aRfsType, aStatus);
+        }
+    else
+        {
+        DEBUGPRINT1A("RequestCoopSysPerformRfsActions:: Calling ref plugins functions (stateadaptationref.dll)");
+        aStatus = KRequestPending;
+        TRequestStatus* status = &aStatus;
+        User::RequestComplete(status, KErrNone);
+        }
 	}
 
 /**
@@ -98,10 +159,16 @@
 */
 void CStateAdaptationRef::RequestCancel()
 	{
+	if(!IsTestPsKeyDefined())
+        {
+        DEBUGPRINT1A("RequestCancel:: Calling Actual plugins functions (saastateadaptation.dll)");
+        iSaaStateAdaptationDll->RequestCancel();
+        }
 	}
 
 /**
-  The reference implementation completes with KErrNotSupported since there isn't a Cooperating System on HRP/Techview.
+  The reference implementation completes with KErrNotSupported. This is required for automated testing.
+  Actual plugins return expected values and this can be verified by manual testing
   On a device, State Adaptation Plug-in would request for notification from the Cooperating System for 'aEvent'.
   
   The above mentioned implementation is modified to facilitate testing and increase the code coverage of the Adaptation 
@@ -120,8 +187,22 @@
 */
 void CStateAdaptationRef::NotifyCoopSysEvent(TDes8& /*aEvent*/, TRequestStatus& aStatus)
 	{
-	aStatus = KRequestPending;
-	iTimer->After(2000000,aStatus);
+	if(!IsTestPsKeyDefined())
+        {
+        /* Only ssmpowersup.dll has an outstanding request. If this is passed to the actual plugin, the
+        request will never complete till a power event happens. This would add the test code requests in a queue
+        and the test code waits indefinitely. Hence, complete the request with KErrServerTerminated. This would free 
+        the queue for test code to be executed. It has not impact on the test environment */
+        aStatus = KRequestPending;
+        TRequestStatus* status = &aStatus;
+        User::RequestComplete(status, KErrServerTerminated);
+        }
+    else
+        {
+        DEBUGPRINT1A("NotifyCoopSysEvent:: Calling ref plugins functions (stateadaptationref.dll)");
+        aStatus = KRequestPending;
+        iTimer->After(2000000,aStatus);
+        }
 	}
 
 /**
@@ -130,13 +211,36 @@
 */
 void CStateAdaptationRef::NotifyCancel()
 	{
-	if(iTimer->IsActive())
-		{
-		iTimer->Cancel();			
-		}	
+	if(!IsTestPsKeyDefined())
+        {
+        DEBUGPRINT1A("NotifyCancel:: Calling Actual plugins functions (saastateadaptation.dll)");
+        iSaaStateAdaptationDll->NotifyCancel();
+        }
+    else
+        {
+        DEBUGPRINT1A("NotifyCancel:: Calling ref plugins functions (stateadaptationref.dll)");
+        if(iTimer->IsActive())
+            {
+            iTimer->Cancel();
+            }
+        }
 	}
 
-
+/**
+    Helper function to check for P&S Key
+*/
+TBool CStateAdaptationRef::IsTestPsKeyDefined()
+    {
+    TBool testPsKeyDefined = EFalse;
+    TInt result = RProperty::Get(KPropertyCategory, KStateAdaptationPluginPropertyKey, testPsKeyDefined);
+    DEBUGPRINT3(_L("KStateAdaptationPluginPropertyKey %d Error %d"), testPsKeyDefined, result);
+    if ((KErrNone != result) && (KErrNotFound != result))
+        {
+        //Could not retrieve property value. Tests might fail 
+        DEBUGPRINT1A("IsTestPsKeyDefined ERROR :: Could not retrieve property value)");
+        }
+    return testPsKeyDefined;
+    }
 
 CStateRefAdaptationTimer::CStateRefAdaptationTimer():CTimer(CActive::EPriorityUserInput)
 	{