Update contrib.
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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\resourceman\d_rescontrol_cli.cpp
18 #include <kernel/kern_priv.h>
19 #include <drivers/resource_extend.h>
20 #include <drivers/resourceman.h>
21 #include "d_rescontrolcli.h"
22 #ifdef PRM_ENABLE_EXTENDED_VERSION
23 #include "dynamicresource.h"
25 #include "./resourceman_psl/rescontrol_psl.h"
27 #ifndef PRM_ENABLE_EXTENDED_VERSION
28 _LIT(KTestPowerRCName, "D_RESCONTROLCLI.LDD");
30 _LIT(KTestPowerRCName, "D_EXTENDEDRESCONTROLCLI.LDD");
33 const TInt KTestResManLddThreadPriority = 0x5;
34 _LIT(KTestResManLddThread, "TestResManLddThread");
36 #ifdef PRM_ENABLE_EXTENDED_VERSION
37 #define EXPECTED_POST_NOTI_COUNT 6 //Expected number of notifications as a result of post boot level setting.
39 #define EXPECTED_POST_NOTI_COUNT 5
41 #define MAX_DYNAMIC_RES_NUM 5
43 Structure for holding resource information
51 The logical device (factory class) for the resource manager client side test.
53 class DTestResManLddFactory : public DLogicalDevice
56 DTestResManLddFactory();
57 ~DTestResManLddFactory();
58 virtual TInt Install();
59 virtual void GetCaps(TDes8 &aDes) const;
60 virtual TInt Create(DLogicalChannelBase*& aChannel);
61 static void PostBootNotificationFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam);
62 void SetPostBootLevelAndRequestNotification(TUint aClientId, TUint aResId, TInt aPostBootLevel);
63 TDynamicDfcQue* iDfcQ;
64 DStaticPowerResource *iStaticRes;
65 DStaticPowerResource *iStaticResArray[3];
66 static SClientInfo iClient; //Need to be static to access them in PostBootNotificationFunc (callback function).
67 static TUint iPostBootNotiCount;
70 /** Logical channel class for Resource manager test LDD */
71 class DTestResManLdd : public DLogicalChannel
75 virtual ~DTestResManLdd();
76 // Inherited from DLogicalChannel
77 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
78 virtual void HandleMsg(TMessageBase* aMsg);
80 TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
81 TInt DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2);
82 TInt DoCancel(TUint aMask);
83 static void CallbackFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam);
84 static void CondNotificationFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam);
85 static void UnCondNotificationFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam);
87 DThread* iClientThreadPtr;
88 TPowerResourceCb iAsyncResourceCallback; //Callback object for handling long latency resources.
89 //Structure for storing the notification information
90 struct SNotificationList
95 DPowerResourceNotification *iNoti;
96 SNotificationList *iNext;
98 SNotificationList *iCondList; //List for maintaining conditional notification
99 SNotificationList *iUnCondList; //List for maintaining unconditional notification
100 TRequestStatus *iStatus; //Store the status and complete on callback function.
101 TBool iCallbackCancel;
102 TInt iClientId; //ID of the client that requested long latency operation, to compare in callback and notifications.
103 TUint iResourceId; //Id of the resource of long latency operation, to compare in callback and notifications.
104 //Below 2 variables are used only for asynchronous get resource state operation
105 TInt *iStatePtr; //Pointer to hold the address of state variable, where state is updated in callback function.
106 TInt *iLevelOwnerIdPtr; //Pointer to hold the address of level owner Id variable, where owner Id is updated in callback function.
107 HBuf *pBuf; //Buffer for testing caching of resource information for Idle power management
108 SClientInfo clientInfo[MAX_CLIENTS];
109 #ifdef PRM_ENABLE_EXTENDED_VERSION
110 TUint iTestParallelResourceId; //Variable to hold the long latency resource id, this is used only in test parallel execution of DFC's
111 static void TestParallelExecutionCallback(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam);
112 TBool iCallbackReceived;
113 TBool iValidateCallbackReceived;
114 TPowerResourceCb iAsyncTestParallelCallback; //Callback object for handling long latency resources change state while deregistering non-dependency resource.
115 RArray <DDynamicPowerResource*> iDynamicArray; //Array to hold dynamic resources. This includes dynamic dependent resource
119 //class definition for multilevel single instantaneous positive resource
120 class DLaterRegisterStaticResource : public DStaticPowerResource
123 DLaterRegisterStaticResource();
124 TInt DoRequest(TPowerRequest &req);
125 TInt GetInfo(TDes8* aInfo) const;
132 //Constructors of the resource
133 _LIT(KLaterRegisterStaticResource, "LaterRegisterStaticResource");
134 DLaterRegisterStaticResource::DLaterRegisterStaticResource() : DStaticPowerResource(KLaterRegisterStaticResource, E_OFF), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
139 TInt DLaterRegisterStaticResource::DoRequest(TPowerRequest& req)
141 Kern::Printf("DLaterRegisterStaticResource::DoRequest\n");
142 if(req.ReqType() == TPowerRequest::EGet)
144 req.Level() = iCurrentLevel;
146 else if(req.ReqType() == TPowerRequest::EChange)
148 iCurrentLevel = req.Level();
150 else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
152 req.Level() = iDefaultLevel;
153 iCurrentLevel = iDefaultLevel;
156 return KErrNotSupported;
160 TInt DLaterRegisterStaticResource::GetInfo(TDes8* info) const
162 DStaticPowerResource::GetInfo((TDes8*)info);
163 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
164 buf1->iDefaultLevel = iDefaultLevel;
165 buf1->iMinLevel = iMinLevel;
166 buf1->iMaxLevel = iMaxLevel;
170 //class definition for multilevel single instantaneous positive resource
171 class DLaterRegisterStaticResource1 : public DStaticPowerResource
174 DLaterRegisterStaticResource1();
175 TInt DoRequest(TPowerRequest &req);
176 TInt GetInfo(TDes8* aInfo) const;
183 //Constructors of the resource
184 _LIT(KLaterRegisterStaticResource1, "LaterRegisterStaticResource1");
185 DLaterRegisterStaticResource1::DLaterRegisterStaticResource1() : DStaticPowerResource(KLaterRegisterStaticResource1, E_OFF), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
190 TInt DLaterRegisterStaticResource1::DoRequest(TPowerRequest& req)
192 Kern::Printf("DLaterRegisterStaticResource1::DoRequest\n");
193 if(req.ReqType() == TPowerRequest::EGet)
195 req.Level() = iCurrentLevel;
197 else if(req.ReqType() == TPowerRequest::EChange)
199 iCurrentLevel = req.Level();
201 else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
203 req.Level() = iDefaultLevel;
204 iCurrentLevel = iDefaultLevel;
207 return KErrNotSupported;
211 TInt DLaterRegisterStaticResource1::GetInfo(TDes8* info) const
213 DStaticPowerResource::GetInfo((TDes8*)info);
214 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
215 buf1->iDefaultLevel = iDefaultLevel;
216 buf1->iMinLevel = iMinLevel;
217 buf1->iMaxLevel = iMaxLevel;
221 //class definition for multilevel single instantaneous positive resource
222 class DLaterRegisterStaticResource2 : public DStaticPowerResource
225 DLaterRegisterStaticResource2();
226 TInt DoRequest(TPowerRequest &req);
227 TInt GetInfo(TDes8* aInfo) const;
234 //Constructors of the resource
235 _LIT(KLaterRegisterStaticResource2, "LaterRegisterStaticResource2");
236 DLaterRegisterStaticResource2::DLaterRegisterStaticResource2() : DStaticPowerResource(KLaterRegisterStaticResource2, E_OFF), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0)
241 TInt DLaterRegisterStaticResource2::DoRequest(TPowerRequest& req)
243 Kern::Printf("DLaterRegisterStaticResource2::DoRequest\n");
244 if(req.ReqType() == TPowerRequest::EGet)
246 req.Level() = iCurrentLevel;
248 else if(req.ReqType() == TPowerRequest::EChange)
250 iCurrentLevel = req.Level();
252 else if(req.ReqType() == TPowerRequest::ESetDefaultLevel)
254 req.Level() = iDefaultLevel;
255 iCurrentLevel = iDefaultLevel;
258 return KErrNotSupported;
262 TInt DLaterRegisterStaticResource2::GetInfo(TDes8* info) const
264 DStaticPowerResource::GetInfo((TDes8*)info);
265 TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info;
266 buf1->iDefaultLevel = iDefaultLevel;
267 buf1->iMinLevel = iMinLevel;
268 buf1->iMaxLevel = iMaxLevel;
272 TUint DTestResManLddFactory::iPostBootNotiCount = 0;
273 SClientInfo DTestResManLddFactory::iClient = {NULL, 0};
274 DTestResManLddFactory::DTestResManLddFactory()
276 iParseMask=0; // Allow info and pdd, but not units
278 // Set version number for this device
279 iVersion=RTestResMan::VersionRequired();
282 DTestResManLddFactory::~DTestResManLddFactory()
288 if(iStaticResArray[0])
289 delete iStaticResArray[0];
290 if(iStaticResArray[2])
291 delete iStaticResArray[2];
294 /** Entry point for this driver */
295 DECLARE_STANDARD_LDD()
297 DTestResManLddFactory* p = new DTestResManLddFactory;
300 TInt r = Kern::DynamicDfcQCreate(p->iDfcQ, KTestResManLddThreadPriority, KTestResManLddThread);
303 Kern::Printf("Memory not allocated");
308 #ifdef CPU_AFFINITY_ANY
309 NKern::ThreadSetCpuAffinity((NThread*)(p->iDfcQ->iThread), KCpuAffinityAny);
312 //Register client with Resource Controller
313 TBuf8<32> ClientName(_L8("Client"));
314 p->iClient.pName = HBuf::New((const TDesC&)ClientName);
315 if(!p->iClient.pName)
321 //Allocating memory earlier so that during failure conditions can cleanup easily
322 p->iStaticRes = new DLaterRegisterStaticResource();
325 delete p->iClient.pName;
330 p->iStaticResArray[0] = new DLaterRegisterStaticResource1();
331 if(!p->iStaticResArray[0])
333 delete p->iStaticRes;
334 delete p->iClient.pName;
339 p->iStaticResArray[2] = new DLaterRegisterStaticResource2();
340 if(!p->iStaticResArray[2])
342 delete p->iStaticRes;
343 delete p->iStaticResArray[0];
344 delete p->iClient.pName;
349 r = PowerResourceManager::RegisterClient(DTestResManLddFactory::iClient.iClientId, (const TDesC&)*DTestResManLddFactory::iClient.pName);
352 Kern::Printf("RegisterClient Failed\n");
353 Kern::Fault("PRM REGISTER CLIENT FAILED", __LINE__);
355 //Set postbootlevel for these resources.
356 p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 1, 0);
357 p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 6, 12);
358 p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 7, 1);
359 p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 12, 10);
360 p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 15, 0);
361 #ifdef PRM_ENABLE_EXTENDED_VERSION
362 p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 65537, -50);
364 //Test the later registration of static resources.
365 r = DPowerResourceController::RegisterStaticResource(DTestResManLddFactory::iClient.iClientId, p->iStaticRes);
367 Kern::Fault("PRM REGISTER STATIC RESOURCE FAILED", __LINE__);
368 DStaticPowerResource **resPtr = &p->iStaticResArray[0];
369 r = DPowerResourceController::RegisterArrayOfStaticResources(DTestResManLddFactory::iClient.iClientId, resPtr, 3);
371 Kern::Fault("PRM REGISTER STATIC RESOURCE FAILED", __LINE__);
372 r = DSimulatedPowerResourceController::CompleteResourceControllerInitialisation();
374 Kern::Fault("PRM INIT FAILED", __LINE__);
378 void DTestResManLddFactory::SetPostBootLevelAndRequestNotification(TUint aClientId, TUint aResId, TInt aPostBootLevel)
380 DPowerResourceController::PostBootLevel(aResId, aPostBootLevel);
381 DPowerResourceNotification* iNoti = new DPowerResourceNotification(PostBootNotificationFunc, (TAny*)NULL, Kern::DfcQue0(), 3);
384 Kern::Fault("PRM NOTI FAILED", __LINE__);
386 //Passing the address of the object so that it could be deleted in callback function
387 new (iNoti) DPowerResourceNotification(PostBootNotificationFunc, iNoti, Kern::DfcQue0(), 3);
388 TInt r = PowerResourceManager::RequestNotification(aClientId, aResId, *iNoti);
390 Kern::Fault("PRM REQ NOTI FAILED", __LINE__);
394 /** Second stage constuctor */
395 TInt DTestResManLddFactory::Install()
397 return(SetName(&KTestPowerRCName));
400 /** Device capabilities */
401 void DTestResManLddFactory::GetCaps(TDes8& aDes)const
403 // Create a capabilities object
404 RTestResMan::TCaps caps;
405 caps.iVersion = iVersion;
406 // Write it back to user memory
407 Kern::InfoCopy(aDes,(TUint8*)&caps,sizeof(caps));
410 /** Create logical channel, only open of one channel is allowed */
411 TInt DTestResManLddFactory::Create(DLogicalChannelBase*& aChannel)
413 if (iOpenChannels != 0) //A Channel is already open
415 //Deregister the client registered in ldd init.
416 TInt r = PowerResourceManager::DeRegisterClient(DTestResManLddFactory::iClient.iClientId);
418 Kern::Fault("PRM CLIENT DEREGISTER FAILED", __LINE__);
419 delete DTestResManLddFactory::iClient.pName;
420 DTestResManLddFactory::iClient.pName = NULL;
421 DTestResManLddFactory::iClient.iClientId = 0;
422 aChannel = new DTestResManLdd;
429 DTestResManLdd::DTestResManLdd(): iAsyncResourceCallback(CallbackFunc, this, 3)
430 #ifdef PRM_ENABLE_EXTENDED_VERSION
431 , iAsyncTestParallelCallback(TestParallelExecutionCallback, this, 3)
436 iCallbackCancel = EFalse;
440 iLevelOwnerIdPtr = NULL;
441 for(TUint c = 0; c < MAX_CLIENTS; c++)
443 clientInfo[c].iClientId = 0;
444 clientInfo[c].pName = NULL;
446 iClientThreadPtr=&Kern::CurrentThread();
447 // Increase the DThread's ref count so that it does not close without us
448 ((DObject*)iClientThreadPtr)->Open();;
452 DTestResManLdd::~DTestResManLdd()
454 if(pBuf) //Buffer created for storing idle resource information
456 #ifdef PRM_ENABLE_EXTENDED_VERSION
457 for(TInt c = 0; c < iDynamicArray.Count(); c++)
459 delete iDynamicArray[c]; //Delete the dynamic array. This includes dynamic dependent resource.
461 iDynamicArray.Close();
463 // Close our reference on the client thread
464 Kern::SafeClose((DObject*&)iClientThreadPtr,NULL);
467 /** Second stage constructor. */
468 TInt DTestResManLdd::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
471 if (!Kern::QueryVersionSupported(RTestResMan::VersionRequired(),aVer))
472 return KErrNotSupported;
473 SetDfcQ(((DTestResManLddFactory*)iDevice)->iDfcQ);
474 iAsyncResourceCallback.SetDfcQ(iDfcQ);
475 #ifdef PRM_ENABLE_EXTENDED_VERSION
476 iAsyncTestParallelCallback.SetDfcQ(iDfcQ);
482 /** Process a message for this logical channel */
483 void DTestResManLdd::HandleMsg(TMessageBase* aMsg)
485 TThreadMessage& m=*(TThreadMessage*)aMsg;
488 if (id==(TInt)ECloseMsg)
491 m.Complete(KErrNone,EFalse);
494 else if (id==KMaxTInt)
497 m.Complete(KErrNone,ETrue);
503 TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
504 TInt r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2());
506 Kern::RequestComplete(iClientThreadPtr,pS,r);
507 m.Complete(KErrNone,ETrue);
512 TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
519 Process synchronous 'control' requests
521 TInt DTestResManLdd::DoControl(TInt aFunction, TAny* a1, TAny* a2)
524 TParameterListInfo ptr = {0, 0, 0, 0, 0};
525 //Copy parameter structure from user space.
526 if((aFunction != RTestResMan::EDeRegisterClient)
527 && (aFunction != RTestResMan::ERequestNotificationUncond)
528 && (aFunction != RTestResMan::EGetIdleResourcesInfo)
529 && (aFunction != RTestResMan::EDeRegisterClientLevelFromResource)
530 && (aFunction != RTestResMan::ECheckPostBootLevelNotifications)
531 && (aFunction != RTestResMan::EGetControllerVersion)
532 #ifdef PRM_ENABLE_EXTENDED_VERSION
533 && (aFunction != RTestResMan::ERegisterDynamicResource))
538 r = Kern::ThreadRawRead(iClientThreadPtr, (TParameterListInfo*)a1, &ptr, sizeof(TParameterListInfo));
544 case RTestResMan::ERegisterClient:
548 //Copy name from user address space
549 r = Kern::ThreadDesRead(iClientThreadPtr, (const TDesC*)ptr.iPtr2, (TDes8&)aName, 0);
552 Kern::Printf("RTestResMan::ERegisterClient ThreadDesRead failed with %d", r);
555 for(c = 0; c < MAX_CLIENTS; c++)
557 if(clientInfo[c].pName == NULL)
559 if(!clientInfo[c].pName->Compare(aName))
560 return KErrAlreadyExists;
564 clientInfo[c].pName = HBuf::New((const TDesC8&)aName);
565 if(!clientInfo[c].pName)
567 r = PowerResourceManager::RegisterClient(clientInfo[c].iClientId, (const TDesC&)*clientInfo[c].pName, (TOwnerType)(TInt)ptr.iPtr3);
570 delete clientInfo[c].pName;
571 clientInfo[c].pName = NULL;
572 clientInfo[c].iClientId = 0;
576 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr1, &clientInfo[c].iClientId, sizeof(TUint));
578 Kern::Printf("RTestResMan::ERegisterClient ThreadRawWrite failed with %d", r);
582 case RTestResMan::EDeRegisterClient: //Deregister client from RM
584 //Cancel all notification pending for this client
585 SNotificationList *pL;
586 SNotificationList* pN = iCondList;
589 if(pN->iClientId == (TUint)a1)
591 PowerResourceManager::CancelNotification(pN->iClientId, pN->iResourceId, *pN->iNoti);
594 LIST_REMOVE(iCondList, pL, iNext, SNotificationList);
604 if(pN->iClientId == (TUint)a1)
606 PowerResourceManager::CancelNotification(pN->iClientId, pN->iResourceId, *pN->iNoti);
609 LIST_REMOVE(iUnCondList, pL, iNext, SNotificationList);
617 r = PowerResourceManager::DeRegisterClient((TUint)a1);
621 for(TUint c = 0; c < MAX_CLIENTS; c++)
623 if(clientInfo[c].iClientId == (TUint)a1)
625 delete clientInfo[c].pName;
626 clientInfo[c].pName = 0;
627 clientInfo[c].iClientId = 0;
635 case RTestResMan::EGetClientName: //Get Client Name
638 r = PowerResourceManager::GetClientName((TUint)ptr.iClientId, (TUint)ptr.iPtr1, (TDes &)aName);
641 r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr2, (const TDesC8&)aName, 0);
643 Kern::Printf("RTestResMan::EGetClientName ThreadDesWrite failed with %d", r);
647 case RTestResMan::EGetClientId: //Get Client Id
651 r = Kern::ThreadDesRead(iClientThreadPtr, (const TDesC*)ptr.iPtr1, (TDes8&)aName, 0,KChunkShiftBy0);
654 Kern::Printf("RTestResMan::EGetClientId ThreadDesRead failed with %d", r);
657 r = PowerResourceManager::GetClientId(ptr.iClientId, (TDesC&)aName, aClientId);
660 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &aClientId, sizeof(TUint));
662 Kern::Printf("RTestResMan::EGetClientId ThreadRawWrite failed with %d", r);
666 case RTestResMan::EGetResourceId: //Get Resource Id
670 r = Kern::ThreadDesRead(iClientThreadPtr, (const TDesC*)ptr.iPtr1, (TDes8&)aName, 0,KChunkShiftBy0);
673 Kern::Printf("RTestResMan::EGetResourceId ThreadDesRead failed with %d", r);
676 r = PowerResourceManager::GetResourceId(ptr.iClientId, (TDesC&)aName, aResourceId);
679 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &aResourceId, sizeof(TUint));
681 Kern::Printf("RTestResMan::EGetResourceId ThreadRawWrite failed with %d", r);
685 case RTestResMan::EGetResourceInfo: //Get resource information
687 NKern::ThreadEnterCS();
688 HBuf *info = HBuf::New(sizeof(TPowerResourceInfoV01));
689 NKern::ThreadLeaveCS();
690 r = PowerResourceManager::GetResourceInfo(ptr.iClientId, (TUint)ptr.iPtr1, (TAny*)info);
693 r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr2, (const TDesC8&)*info, 0);
695 Kern::Printf("RTestResMan::EGetResourceInfo ThreadRawWrite failed with %d", r);
700 case RTestResMan::EGetNumResourcesInUseByClient:
703 r = PowerResourceManager::GetNumResourcesInUseByClient(ptr.iClientId, (TUint)ptr.iPtr1, numResource);
706 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &numResource, sizeof(TUint));
708 Kern::Printf("RTestResMan::EGetNumResourcesInUseByClient ThreadRawWrite failed with %d", r);
712 case RTestResMan::EGetInfoOnResourcesInUseByClient:
716 r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, &numResource, sizeof(TUint));
719 Kern::Printf("RTestResMan::GetInfoOnResourceInUseByClient ThreadRawRead failed with %d", r);
722 if(ptr.iPtr3 != NULL)
724 NKern::ThreadEnterCS();
725 info = HBuf::New(numResource * sizeof(TPowerResourceInfoV01));
726 NKern::ThreadLeaveCS();
728 r = PowerResourceManager::GetInfoOnResourcesInUseByClient(ptr.iClientId, (TUint)ptr.iPtr1, numResource, (TAny*)info);
731 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &numResource, sizeof(TUint));
734 Kern::Printf("RTestResMan::GetInfoOnResourceInUseByClient ThreadRawWrite failed with %d", r);
739 r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr3, (const TDesC8&)*info, 0);
744 case RTestResMan::EGetNumClientsUsingResource:
747 r = PowerResourceManager::GetNumClientsUsingResource(ptr.iClientId, (TUint)ptr.iPtr1, numClient);
750 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &numClient, sizeof(TUint));
752 Kern::Printf("RTestResMan::EGetNumResourcesInUseByClient ThreadRawWrite failed with %d", r);
756 case RTestResMan::EGetInfoOnClientsUsingResource:
760 r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, &numClient, sizeof(TUint));
763 Kern::Printf("RTestResMan::GetInfoOnResourceInUseByClient ThreadRawRead failed with %d", r);
766 if(ptr.iPtr3 != NULL)
768 NKern::ThreadEnterCS();
769 info = HBuf::New(numClient * sizeof(TPowerClientInfoV01));
770 NKern::ThreadLeaveCS();
772 r = PowerResourceManager::GetInfoOnClientsUsingResource(ptr.iClientId, (TUint)ptr.iPtr1, numClient, (TAny*)info);
775 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &numClient, sizeof(TUint));
778 Kern::Printf("RTestResMan::GetInfoOnResourceInUseByClient ThreadRawWrite failed with %d", r);
783 r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr3, (const TDesC8&)*info, 0);
788 case RTestResMan::EAllocReserve:
790 r = PowerResourceManager::AllocReserve(ptr.iClientId, (TUint8)(TUint)ptr.iPtr1, (TUint8)(TUint)ptr.iPtr2);
793 case RTestResMan::EChangeResourceStateSync:
795 SNotificationList* pN;
796 //Zero the conditional notification count for the resource id.
797 for(pN=iCondList; pN != NULL; pN=pN->iNext)
799 if(pN->iResourceId == (TUint)ptr.iPtr1)
805 //Zero the unconditional notification count for the resource id.
806 for(pN=iUnCondList; pN != NULL; pN=pN->iNext)
808 if(pN->iResourceId == (TUint)ptr.iPtr1)
814 iClientId = ptr.iClientId;
815 iResourceId = (TUint)ptr.iPtr1;
816 r = PowerResourceManager::ChangeResourceState(ptr.iClientId, (TUint)ptr.iPtr1, (TInt)ptr.iPtr2);
819 case RTestResMan::EGetResourceStateSync:
821 TInt newState, levelOwnerId;
822 r = PowerResourceManager::GetResourceState(ptr.iClientId, (TUint)ptr.iPtr1, (TBool)ptr.iPtr2, newState, levelOwnerId);
825 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr3, (TAny*)&newState, sizeof(TInt));
828 Kern::Printf("RTestResMan::GetResourceStateSync ThreadRawWrite failed with %d", r);
831 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr4, (TAny*)&levelOwnerId, sizeof(TInt));
833 Kern::Printf("RTestResMan::GetResourceStateSync ThreadRawWrite failed with %d", r);
837 case RTestResMan::ERequestNotificationUncond:
839 SNotificationList *notiList;
840 notiList = new SNotificationList; //Create new notification list
846 //Create notification object to pass to RM
847 notiList->iNoti = new DPowerResourceNotification(UnCondNotificationFunc, this, ((DTestResManLddFactory*)iDevice)->iDfcQ, 3);
854 notiList->iClientId = (TUint)a1;
855 notiList->iResourceId = (TUint)a2;
856 notiList->iCount = 0;
857 LIST_PUSH(iUnCondList, notiList, iNext); //Add to unconditional list.
858 r = PowerResourceManager::RequestNotification((TUint)a1, (TUint)a2, *notiList->iNoti);
861 case RTestResMan::ERequestNotificationCond:
863 SNotificationList *notiList;
864 notiList = new SNotificationList; // Create new notification list
870 //Create notification object to pass to RM
871 notiList->iNoti = new DPowerResourceNotification(CondNotificationFunc, this, ((DTestResManLddFactory*)iDevice)->iDfcQ, 3);
878 notiList->iClientId = ptr.iClientId;
879 notiList->iResourceId = (TUint)ptr.iPtr1;
880 notiList->iCount = 0;
881 LIST_PUSH(iCondList, notiList, iNext); //Add to conditional list.
882 r = PowerResourceManager::RequestNotification((TUint)ptr.iClientId, (TUint)ptr.iPtr1, *notiList->iNoti, (TInt)ptr.iPtr2, (TBool)ptr.iPtr3);
885 case RTestResMan::EDeRegisterClientLevelFromResource:
887 r = PowerResourceManager::DeRegisterClientLevelFromResource((TUint)a1, (TUint)a2);
890 case RTestResMan::ECancelNotification:
893 if(ptr.iPtr2) //Check for notification in conditional list if it is true.
895 for(SNotificationList* pN=iCondList; pN != NULL; pN=pN->iNext)
897 if((pN->iClientId == ptr.iClientId) && (pN->iResourceId == (TUint)ptr.iPtr1))
899 r = PowerResourceManager::CancelNotification(pN->iClientId, pN->iResourceId, *pN->iNoti);
900 LIST_REMOVE(iCondList, pN, iNext, SNotificationList);
907 else //Check for notification in unconditional list.
909 for(SNotificationList* pN=iUnCondList; pN != NULL; pN=pN->iNext)
911 if((pN->iClientId == ptr.iClientId) && (pN->iResourceId == (TUint)ptr.iPtr1))
913 r = PowerResourceManager::CancelNotification(pN->iClientId, pN->iResourceId, *pN->iNoti);
914 LIST_REMOVE(iUnCondList, pN, iNext, SNotificationList);
923 case RTestResMan::ECheckNotifications:
925 NKern::Sleep(NKern::TimerTicks(300)); //This is required as sometimes check is done before callback is called.
926 TUint countCond = 0, countUncond = 0;
927 SNotificationList* pN;
928 //Get the conditional notification callback functions called for the resource id.
929 for(pN=iCondList; pN != NULL; pN=pN->iNext)
931 if(pN->iResourceId == (TUint)ptr.iPtr1)
933 countCond = pN->iCount;
938 //Get the unconditional notification callback functions called for the resource id.
939 for(pN=iUnCondList; pN != NULL; pN=pN->iNext)
941 if(pN->iResourceId == (TUint)ptr.iPtr1)
943 countUncond = pN->iCount;
948 //If the notifications count is not as expected return error.
949 if((countCond != (TUint)ptr.iPtr3) || (countUncond != (TUint)ptr.iPtr2))
953 case RTestResMan::ERegisterForIdleResourcesInfo:
957 r = KErrAlreadyExists;
960 NKern::ThreadEnterCS();
961 pBuf = HBuf::New((TUint)ptr.iPtr1 * sizeof(SIdleResourceInfo)); //Allocate buffer for requested resources
962 NKern::ThreadLeaveCS();
965 r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, (TAny*)pBuf->Ptr(), (TUint)ptr.iPtr1 * sizeof(SIdleResourceInfo));
968 Kern::Printf("RTestResMan::ERegisterForIdleResourceInfo threadRawRead failed with %d\n", r);
971 //Below function calls RegisterForResourceIdle resource controller virtual function,
972 //This is for testing purposes only.
974 r =DSimulatedPowerResourceController::CaptureIdleResourcesInfo((TUint)ptr.iClientId, (TUint)ptr.iPtr1, (TPtr*)pBuf);
979 case RTestResMan::EGetIdleResourcesInfo:
981 //Pass the buffer for comparision
987 pBuf->SetLength(sizeof(SIdleResourceInfo) * (TUint)a1);
988 r = Kern::ThreadDesWrite(iClientThreadPtr, a2, (const TDesC8&)*pBuf, 0);
991 case RTestResMan::ECheckPostBootLevelNotifications:
993 if(DTestResManLddFactory::iPostBootNotiCount != EXPECTED_POST_NOTI_COUNT)
1001 case RTestResMan::EGetControllerVersion:
1004 r = PowerResourceManager::GetResourceControllerVersion((TUint)a1, Version);
1007 r = Kern::ThreadRawWrite(iClientThreadPtr, a2, &Version, sizeof(TUint));
1009 Kern::Printf("RTestResMan::EGetControllerVersion ThreadRawWrite failed with %d", r);
1013 #ifdef PRM_ENABLE_EXTENDED_VERSION
1014 case RTestResMan::ERegisterDynamicResource:
1017 r = Kern::ThreadRawRead(iClientThreadPtr, a2, (TAny*)&resId, sizeof(TUint));
1020 Kern::Printf("RTestResMan::RegisterDynamicResource ThreadRawRead failed with %d", r);
1023 DDynamicPowerResource* pDR = NULL;
1024 switch(resId) //Create the dynamic resource
1027 pDR = new (DBIGISSPDynamicResource);
1030 pDR = new (DMLIGLSSHNDynamicResource);
1033 pDR = new (DBLGLSSHNDynamicResource);
1036 pDR = new (DMLLGLSSHPDynamicResource);
1039 pDR = (DDynamicPowerResource*) new (DDynamicResourceD01);
1042 pDR = (DDynamicPowerResource*) new (DDynamicResourceD02);
1045 pDR = (DDynamicPowerResource*) new (DDynamicResourceD03);
1048 pDR = (DDynamicPowerResource*) new (DDynamicResourceD04);
1052 return KErrNoMemory;
1053 iDynamicArray.Append(pDR);
1054 r = PowerResourceManager::RegisterDynamicResource((TUint)a1, pDR, resId);
1057 r = Kern::ThreadRawWrite(iClientThreadPtr, a2, (TAny*)&resId, sizeof(TUint));
1059 Kern::Printf("RTestResMan::RegisterDynamicResource ThreadRawWrite failed with %d", r);
1063 case RTestResMan::EDeRegisterDynamicResource: //Deregister dynamic resource
1068 r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, &level, sizeof(TInt));
1071 Kern::Printf("RTestResMan::DeRegisterDynamicResource ThreadRawRead failed with %d", r);
1074 r = PowerResourceManager::DeRegisterDynamicResource(ptr.iClientId, (TUint)ptr.iPtr1, &level);
1077 r = PowerResourceManager::DeRegisterDynamicResource(ptr.iClientId, (TUint)ptr.iPtr1, NULL);
1080 case RTestResMan::ERegisterResourceDependency: //Register resource dependency
1082 SResourceDependencyInfo info1, info2;
1083 r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr1, &info1, sizeof(SResourceDependencyInfo));
1086 Kern::Printf("RTestResMan::RegisterResourceDependency ThreadRawRead failed with %d", r);
1089 r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, &info2, sizeof(SResourceDependencyInfo));
1092 Kern::Printf("RTestResMan::RegisterResourceDependency ThreadRawRead failed with %d", r);
1095 r = PowerResourceManager::RegisterResourceDependency(ptr.iClientId, &info1, &info2);
1098 case RTestResMan::EDeRegisterResourceDependency: //Deregister resource dependency
1100 r = PowerResourceManager::DeRegisterResourceDependency(ptr.iClientId, (TUint)ptr.iPtr1, (TUint)ptr.iPtr2);
1103 case RTestResMan::EGetNumDependentsForResource:
1105 TUint numDepResources;
1106 r = PowerResourceManager::GetNumDependentsForResource(ptr.iClientId, (TUint)ptr.iPtr1, numDepResources);
1109 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, (TAny*)&numDepResources, sizeof(TUint));
1111 Kern::Printf("RTestResMan::RegisterDynamicResource ThreadRawWrite failed with %d", r);
1115 case RTestResMan::EGetDependentsIdForResource:
1117 TUint numDepResources;
1118 HBuf* sResDepInfo = NULL;
1119 r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr3, (TAny*)&numDepResources, sizeof(TUint));
1122 Kern::Printf("RTestResMan::GetDependentsIdForResource ThreadRawRead failed with %d", r);
1125 if(ptr.iPtr2 != NULL)
1127 NKern::ThreadEnterCS();
1128 sResDepInfo = HBuf::New(numDepResources * sizeof(SResourceDependencyInfo));
1129 NKern::ThreadLeaveCS();
1131 return KErrNoMemory;
1134 r = PowerResourceManager::GetDependentsIdForResource(ptr.iClientId, (TUint)ptr.iPtr1, (TAny*)sResDepInfo, numDepResources);
1138 r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr2, (const TDesC8&)*sResDepInfo, 0);
1141 Kern::Printf("RTestResMan::GetDepedentsIdForResource ThreadDesWrite failed with %d", r);
1142 Kern::Free(sResDepInfo);
1145 r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr3, (TAny*)&numDepResources, sizeof(TUint));
1148 Kern::Printf("RTestResMan::GetDependentsIdForResource ThreadRawWrite failed with %d", r);
1149 Kern::Free(sResDepInfo);
1153 Kern::Free(sResDepInfo);
1159 r = KErrNotSupported;
1165 TInt DTestResManLdd::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* /*a2*/)
1168 TParameterListInfo ptr;
1169 r = Kern::ThreadRawRead(iClientThreadPtr, (TParameterListInfo*)a1, &ptr, sizeof(TParameterListInfo));
1171 Kern::RequestComplete(iClientThreadPtr, aStatus, r);
1174 case RTestResMan::EChangeResourceStateAsync:
1175 #ifdef PRM_ENABLE_EXTENDED_VERSION
1176 case RTestResMan::EChangeResStateAndDeregisterDynamicRes:
1177 case RTestResMan::ECheckParallelExecutionForChangeResState:
1179 SNotificationList* pN;
1180 //Zero the conditional notification count for the resource id.
1181 for(pN=iCondList; pN != NULL; pN=pN->iNext)
1183 if(pN->iResourceId == (TUint)ptr.iPtr1)
1189 //Zero the unconditional notification count for the resource id.
1190 for(pN=iUnCondList; pN != NULL; pN=pN->iNext)
1192 if(pN->iResourceId == (TUint)ptr.iPtr1)
1198 iLevelOwnerIdPtr = NULL;
1199 iStatePtr = (TInt*)ptr.iPtr2;
1201 r = Kern::ThreadRawRead(iClientThreadPtr, iStatePtr, &state, sizeof(TInt));
1203 Kern::RequestComplete(iClientThreadPtr, aStatus, r);
1205 iClientId = ptr.iClientId;
1206 iResourceId = (TUint)ptr.iPtr1;
1207 iCallbackCancel = EFalse;
1208 r = PowerResourceManager::ChangeResourceState(ptr.iClientId, (TUint)ptr.iPtr1, state, &iAsyncResourceCallback);
1209 #ifdef PRM_ENABLE_EXTENDED_VERSION
1210 if(aReqNo == RTestResMan::EChangeResStateAndDeregisterDynamicRes) //Try to delete the dynamic while resource change
1212 r = PowerResourceManager::DeRegisterDynamicResource(ptr.iClientId, (TUint)ptr.iPtr1, NULL);
1213 if(r == KErrInUse) //Wait for the request to complete
1217 if(aReqNo == RTestResMan::ECheckParallelExecutionForChangeResState)
1219 r = PowerResourceManager::ChangeResourceState(ptr.iClientId, (TUint)ptr.iPtr3, (TInt)ptr.iPtr4, &iAsyncTestParallelCallback);
1220 iTestParallelResourceId = (TUint)ptr.iPtr3;
1221 iValidateCallbackReceived = ETrue;
1225 if(ptr.iPtr3) //Cancel the asynchronous operation if true.
1227 r = PowerResourceManager::CancelAsyncRequestCallBack(ptr.iClientId, (TUint)ptr.iPtr1, iAsyncResourceCallback);
1228 if(r == KErrInUse) //Wait for the request to complete
1231 iCallbackCancel = ETrue;
1234 case RTestResMan::EGetResourceStateAsync:
1236 iCallbackCancel = EFalse;
1237 iClientId = ptr.iClientId;
1238 iResourceId = (TUint)ptr.iPtr1;
1239 iStatePtr = (TInt*)ptr.iPtr4;
1240 iLevelOwnerIdPtr = (TInt*)ptr.iPtr5;
1241 r = PowerResourceManager::GetResourceState(ptr.iClientId, (TUint)ptr.iPtr1, (TBool)ptr.iPtr2, iAsyncResourceCallback);
1242 if(ptr.iPtr3) //Cancel the asynchronous operation if true.
1244 r = PowerResourceManager::CancelAsyncRequestCallBack(ptr.iClientId, (TUint)ptr.iPtr1, iAsyncResourceCallback);
1248 iCallbackCancel = ETrue;
1255 //Function called on Asynchronous operation
1256 void DTestResManLdd::CallbackFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam)
1259 DTestResManLdd *pC = (DTestResManLdd*)aParam;
1260 //Check for correctnes of clientId and resourceId
1261 if((TUint)pC->iClientId != aClientId || pC->iResourceId != aResId)
1262 Kern::RequestComplete(pC->iClientThreadPtr, pC->iStatus, KErrCorrupt);
1263 if(!pC->iCallbackCancel)
1267 r = Kern::ThreadRawWrite(pC->iClientThreadPtr, pC->iStatePtr, (TAny*)&aLevel, sizeof(TInt));
1269 Kern::Printf("RTestResManLdd::CallbackFunc ThreadRawWrite failed with %d", r);
1271 if(pC->iLevelOwnerIdPtr)
1273 r = Kern::ThreadRawWrite(pC->iClientThreadPtr, pC->iLevelOwnerIdPtr, (TAny*)&aLevelOwnerId, sizeof(TInt));
1275 Kern::Printf("RTestResManLdd::CallbackFunc ThreadRawWrite failed with %d", r);
1277 #ifdef PRM_ENABLE_EXTENDED_VERSION
1278 if(pC->iValidateCallbackReceived)
1280 if(!pC->iCallbackReceived)
1281 aResult = KErrCompletion;
1284 Kern::RequestComplete(pC->iClientThreadPtr, pC->iStatus, aResult);
1286 pC->iCallbackCancel = EFalse;
1290 #ifdef PRM_ENABLE_EXTENDED_VERSION
1291 //Function called on completion of asynchronous long latency resource, used only to check parallel execution of DFC's
1292 void DTestResManLdd::TestParallelExecutionCallback(TUint aClientId, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam)
1294 Kern::Printf("DTestResManLdd::TestParallelExecutionCallback:: called");
1295 DTestResManLdd *pC = (DTestResManLdd*)aParam;
1296 //Check for correctness of clientId and resourceId
1297 if((TUint)pC->iClientId == aClientId && pC->iTestParallelResourceId == aResId)
1299 pC->iCallbackReceived = ETrue;
1304 //Function called on Conditional notification
1305 void DTestResManLdd::CondNotificationFunc(TUint /*aClientId*/, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam)
1307 DTestResManLdd *pC = (DTestResManLdd*)aParam;
1308 for(SNotificationList *pN = pC->iCondList; pN!= NULL; pN=pN->iNext)
1310 if((pN->iResourceId == aResId))
1312 pN->iCount++; //Increment the count, as same callback function for all conditioanl notifications.
1318 //Function called on UnConditional notification
1319 void DTestResManLdd::UnCondNotificationFunc(TUint /*aClientId*/, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam)
1321 DTestResManLdd *pC = (DTestResManLdd*)aParam;
1322 for(SNotificationList *pN = pC->iUnCondList; pN!= NULL; pN=pN->iNext)
1324 if((pN->iResourceId == aResId) && (pC->iCallbackCancel == EFalse))
1326 pN->iCount++; //Increment the count as same callback function for all unconditioanl notifications.
1332 //Function called on postbootvalueset.
1333 void DTestResManLddFactory::PostBootNotificationFunc(TUint /*aClientId*/, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam)
1335 iPostBootNotiCount++;
1336 DPowerResourceNotification *ptr = (DPowerResourceNotification*)aParam;
1337 TInt r = PowerResourceManager::CancelNotification(iClient.iClientId, aResId, *ptr);