sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\resourceman\d_rescontrol_cli.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "d_rescontrolcli.h" sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: #include "dynamicresource.h" sl@0: #endif sl@0: #include "./resourceman_psl/rescontrol_psl.h" sl@0: sl@0: #ifndef PRM_ENABLE_EXTENDED_VERSION sl@0: _LIT(KTestPowerRCName, "D_RESCONTROLCLI.LDD"); sl@0: #else sl@0: _LIT(KTestPowerRCName, "D_EXTENDEDRESCONTROLCLI.LDD"); sl@0: #endif sl@0: sl@0: const TInt KTestResManLddThreadPriority = 0x5; sl@0: _LIT(KTestResManLddThread, "TestResManLddThread"); sl@0: sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: #define EXPECTED_POST_NOTI_COUNT 6 //Expected number of notifications as a result of post boot level setting. sl@0: #else sl@0: #define EXPECTED_POST_NOTI_COUNT 5 sl@0: #endif sl@0: #define MAX_DYNAMIC_RES_NUM 5 sl@0: /** sl@0: Structure for holding resource information sl@0: */ sl@0: struct SClientInfo sl@0: { sl@0: HBuf8* pName; sl@0: TUint iClientId; sl@0: }; sl@0: /** sl@0: The logical device (factory class) for the resource manager client side test. sl@0: */ sl@0: class DTestResManLddFactory : public DLogicalDevice sl@0: { sl@0: public: sl@0: DTestResManLddFactory(); sl@0: ~DTestResManLddFactory(); sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8 &aDes) const; sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); sl@0: static void PostBootNotificationFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam); sl@0: void SetPostBootLevelAndRequestNotification(TUint aClientId, TUint aResId, TInt aPostBootLevel); sl@0: TDynamicDfcQue* iDfcQ; sl@0: DStaticPowerResource *iStaticRes; sl@0: DStaticPowerResource *iStaticResArray[3]; sl@0: static SClientInfo iClient; //Need to be static to access them in PostBootNotificationFunc (callback function). sl@0: static TUint iPostBootNotiCount; sl@0: }; sl@0: sl@0: /** Logical channel class for Resource manager test LDD */ sl@0: class DTestResManLdd : public DLogicalChannel sl@0: { sl@0: public: sl@0: DTestResManLdd(); sl@0: virtual ~DTestResManLdd(); sl@0: // Inherited from DLogicalChannel sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual void HandleMsg(TMessageBase* aMsg); sl@0: private: sl@0: TInt DoControl(TInt aFunction, TAny* a1, TAny* a2); sl@0: TInt DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2); sl@0: TInt DoCancel(TUint aMask); sl@0: static void CallbackFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam); sl@0: static void CondNotificationFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam); sl@0: static void UnCondNotificationFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam); sl@0: private: sl@0: DThread* iClientThreadPtr; sl@0: TPowerResourceCb iAsyncResourceCallback; //Callback object for handling long latency resources. sl@0: //Structure for storing the notification information sl@0: struct SNotificationList sl@0: { sl@0: TUint iClientId; sl@0: TUint iResourceId; sl@0: TUint iCount; sl@0: DPowerResourceNotification *iNoti; sl@0: SNotificationList *iNext; sl@0: }; sl@0: SNotificationList *iCondList; //List for maintaining conditional notification sl@0: SNotificationList *iUnCondList; //List for maintaining unconditional notification sl@0: TRequestStatus *iStatus; //Store the status and complete on callback function. sl@0: TBool iCallbackCancel; sl@0: TInt iClientId; //ID of the client that requested long latency operation, to compare in callback and notifications. sl@0: TUint iResourceId; //Id of the resource of long latency operation, to compare in callback and notifications. sl@0: //Below 2 variables are used only for asynchronous get resource state operation sl@0: TInt *iStatePtr; //Pointer to hold the address of state variable, where state is updated in callback function. sl@0: TInt *iLevelOwnerIdPtr; //Pointer to hold the address of level owner Id variable, where owner Id is updated in callback function. sl@0: HBuf *pBuf; //Buffer for testing caching of resource information for Idle power management sl@0: SClientInfo clientInfo[MAX_CLIENTS]; sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: TUint iTestParallelResourceId; //Variable to hold the long latency resource id, this is used only in test parallel execution of DFC's sl@0: static void TestParallelExecutionCallback(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam); sl@0: TBool iCallbackReceived; sl@0: TBool iValidateCallbackReceived; sl@0: TPowerResourceCb iAsyncTestParallelCallback; //Callback object for handling long latency resources change state while deregistering non-dependency resource. sl@0: RArray iDynamicArray; //Array to hold dynamic resources. This includes dynamic dependent resource sl@0: #endif sl@0: }; sl@0: sl@0: //class definition for multilevel single instantaneous positive resource sl@0: class DLaterRegisterStaticResource : public DStaticPowerResource sl@0: { sl@0: public: sl@0: DLaterRegisterStaticResource(); sl@0: TInt DoRequest(TPowerRequest &req); sl@0: TInt GetInfo(TDes8* aInfo) const; sl@0: private: sl@0: TInt iMinLevel; sl@0: TInt iMaxLevel; sl@0: TInt iCurrentLevel; sl@0: }; sl@0: sl@0: //Constructors of the resource sl@0: _LIT(KLaterRegisterStaticResource, "LaterRegisterStaticResource"); sl@0: DLaterRegisterStaticResource::DLaterRegisterStaticResource() : DStaticPowerResource(KLaterRegisterStaticResource, E_OFF), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0) sl@0: { sl@0: iFlags = KBinary; sl@0: } sl@0: sl@0: TInt DLaterRegisterStaticResource::DoRequest(TPowerRequest& req) sl@0: { sl@0: Kern::Printf("DLaterRegisterStaticResource::DoRequest\n"); sl@0: if(req.ReqType() == TPowerRequest::EGet) sl@0: { sl@0: req.Level() = iCurrentLevel; sl@0: } sl@0: else if(req.ReqType() == TPowerRequest::EChange) sl@0: { sl@0: iCurrentLevel = req.Level(); sl@0: } sl@0: else if(req.ReqType() == TPowerRequest::ESetDefaultLevel) sl@0: { sl@0: req.Level() = iDefaultLevel; sl@0: iCurrentLevel = iDefaultLevel; sl@0: } sl@0: else sl@0: return KErrNotSupported; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DLaterRegisterStaticResource::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iDefaultLevel = iDefaultLevel; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: //class definition for multilevel single instantaneous positive resource sl@0: class DLaterRegisterStaticResource1 : public DStaticPowerResource sl@0: { sl@0: public: sl@0: DLaterRegisterStaticResource1(); sl@0: TInt DoRequest(TPowerRequest &req); sl@0: TInt GetInfo(TDes8* aInfo) const; sl@0: private: sl@0: TInt iMinLevel; sl@0: TInt iMaxLevel; sl@0: TInt iCurrentLevel; sl@0: }; sl@0: sl@0: //Constructors of the resource sl@0: _LIT(KLaterRegisterStaticResource1, "LaterRegisterStaticResource1"); sl@0: DLaterRegisterStaticResource1::DLaterRegisterStaticResource1() : DStaticPowerResource(KLaterRegisterStaticResource1, E_OFF), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0) sl@0: { sl@0: iFlags = KBinary; sl@0: } sl@0: sl@0: TInt DLaterRegisterStaticResource1::DoRequest(TPowerRequest& req) sl@0: { sl@0: Kern::Printf("DLaterRegisterStaticResource1::DoRequest\n"); sl@0: if(req.ReqType() == TPowerRequest::EGet) sl@0: { sl@0: req.Level() = iCurrentLevel; sl@0: } sl@0: else if(req.ReqType() == TPowerRequest::EChange) sl@0: { sl@0: iCurrentLevel = req.Level(); sl@0: } sl@0: else if(req.ReqType() == TPowerRequest::ESetDefaultLevel) sl@0: { sl@0: req.Level() = iDefaultLevel; sl@0: iCurrentLevel = iDefaultLevel; sl@0: } sl@0: else sl@0: return KErrNotSupported; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DLaterRegisterStaticResource1::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iDefaultLevel = iDefaultLevel; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: //class definition for multilevel single instantaneous positive resource sl@0: class DLaterRegisterStaticResource2 : public DStaticPowerResource sl@0: { sl@0: public: sl@0: DLaterRegisterStaticResource2(); sl@0: TInt DoRequest(TPowerRequest &req); sl@0: TInt GetInfo(TDes8* aInfo) const; sl@0: private: sl@0: TInt iMinLevel; sl@0: TInt iMaxLevel; sl@0: TInt iCurrentLevel; sl@0: }; sl@0: sl@0: //Constructors of the resource sl@0: _LIT(KLaterRegisterStaticResource2, "LaterRegisterStaticResource2"); sl@0: DLaterRegisterStaticResource2::DLaterRegisterStaticResource2() : DStaticPowerResource(KLaterRegisterStaticResource2, E_OFF), iMinLevel(0), iMaxLevel(1), iCurrentLevel(0) sl@0: { sl@0: iFlags = KBinary; sl@0: } sl@0: sl@0: TInt DLaterRegisterStaticResource2::DoRequest(TPowerRequest& req) sl@0: { sl@0: Kern::Printf("DLaterRegisterStaticResource2::DoRequest\n"); sl@0: if(req.ReqType() == TPowerRequest::EGet) sl@0: { sl@0: req.Level() = iCurrentLevel; sl@0: } sl@0: else if(req.ReqType() == TPowerRequest::EChange) sl@0: { sl@0: iCurrentLevel = req.Level(); sl@0: } sl@0: else if(req.ReqType() == TPowerRequest::ESetDefaultLevel) sl@0: { sl@0: req.Level() = iDefaultLevel; sl@0: iCurrentLevel = iDefaultLevel; sl@0: } sl@0: else sl@0: return KErrNotSupported; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DLaterRegisterStaticResource2::GetInfo(TDes8* info) const sl@0: { sl@0: DStaticPowerResource::GetInfo((TDes8*)info); sl@0: TPowerResourceInfoV01 *buf1 = (TPowerResourceInfoV01*)info; sl@0: buf1->iDefaultLevel = iDefaultLevel; sl@0: buf1->iMinLevel = iMinLevel; sl@0: buf1->iMaxLevel = iMaxLevel; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TUint DTestResManLddFactory::iPostBootNotiCount = 0; sl@0: SClientInfo DTestResManLddFactory::iClient = {NULL, 0}; sl@0: DTestResManLddFactory::DTestResManLddFactory() sl@0: { sl@0: iParseMask=0; // Allow info and pdd, but not units sl@0: iUnitsMask=0; sl@0: // Set version number for this device sl@0: iVersion=RTestResMan::VersionRequired(); sl@0: } sl@0: sl@0: DTestResManLddFactory::~DTestResManLddFactory() sl@0: { sl@0: if(iDfcQ) sl@0: iDfcQ->Destroy(); sl@0: if(iStaticRes) sl@0: delete iStaticRes; sl@0: if(iStaticResArray[0]) sl@0: delete iStaticResArray[0]; sl@0: if(iStaticResArray[2]) sl@0: delete iStaticResArray[2]; sl@0: } sl@0: sl@0: /** Entry point for this driver */ sl@0: DECLARE_STANDARD_LDD() sl@0: { sl@0: DTestResManLddFactory* p = new DTestResManLddFactory; sl@0: if(!p) sl@0: return NULL; sl@0: TInt r = Kern::DynamicDfcQCreate(p->iDfcQ, KTestResManLddThreadPriority, KTestResManLddThread); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("Memory not allocated"); sl@0: p->AsyncDelete(); sl@0: return NULL; sl@0: } sl@0: sl@0: #ifdef CPU_AFFINITY_ANY sl@0: NKern::ThreadSetCpuAffinity((NThread*)(p->iDfcQ->iThread), KCpuAffinityAny); sl@0: #endif sl@0: sl@0: //Register client with Resource Controller sl@0: TBuf8<32> ClientName(_L8("Client")); sl@0: p->iClient.pName = HBuf::New((const TDesC&)ClientName); sl@0: if(!p->iClient.pName) sl@0: { sl@0: p->iDfcQ->Destroy(); sl@0: p->AsyncDelete(); sl@0: return NULL; sl@0: } sl@0: //Allocating memory earlier so that during failure conditions can cleanup easily sl@0: p->iStaticRes = new DLaterRegisterStaticResource(); sl@0: if(!p->iStaticRes) sl@0: { sl@0: delete p->iClient.pName; sl@0: p->iDfcQ->Destroy(); sl@0: p->AsyncDelete(); sl@0: return NULL; sl@0: } sl@0: p->iStaticResArray[0] = new DLaterRegisterStaticResource1(); sl@0: if(!p->iStaticResArray[0]) sl@0: { sl@0: delete p->iStaticRes; sl@0: delete p->iClient.pName; sl@0: p->iDfcQ->Destroy(); sl@0: p->AsyncDelete(); sl@0: return NULL; sl@0: } sl@0: p->iStaticResArray[2] = new DLaterRegisterStaticResource2(); sl@0: if(!p->iStaticResArray[2]) sl@0: { sl@0: delete p->iStaticRes; sl@0: delete p->iStaticResArray[0]; sl@0: delete p->iClient.pName; sl@0: p->iDfcQ->Destroy(); sl@0: p->AsyncDelete(); sl@0: return NULL; sl@0: } sl@0: r = PowerResourceManager::RegisterClient(DTestResManLddFactory::iClient.iClientId, (const TDesC&)*DTestResManLddFactory::iClient.pName); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RegisterClient Failed\n"); sl@0: Kern::Fault("PRM REGISTER CLIENT FAILED", __LINE__); sl@0: } sl@0: //Set postbootlevel for these resources. sl@0: p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 1, 0); sl@0: p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 6, 12); sl@0: p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 7, 1); sl@0: p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 12, 10); sl@0: p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 15, 0); sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: p->SetPostBootLevelAndRequestNotification(DTestResManLddFactory::iClient.iClientId, 65537, -50); sl@0: #endif sl@0: //Test the later registration of static resources. sl@0: r = DPowerResourceController::RegisterStaticResource(DTestResManLddFactory::iClient.iClientId, p->iStaticRes); sl@0: if(r != KErrNone) sl@0: Kern::Fault("PRM REGISTER STATIC RESOURCE FAILED", __LINE__); sl@0: DStaticPowerResource **resPtr = &p->iStaticResArray[0]; sl@0: r = DPowerResourceController::RegisterArrayOfStaticResources(DTestResManLddFactory::iClient.iClientId, resPtr, 3); sl@0: if(r != KErrNone) sl@0: Kern::Fault("PRM REGISTER STATIC RESOURCE FAILED", __LINE__); sl@0: r = DSimulatedPowerResourceController::CompleteResourceControllerInitialisation(); sl@0: if(r != KErrNone) sl@0: Kern::Fault("PRM INIT FAILED", __LINE__); sl@0: return p; sl@0: } sl@0: sl@0: void DTestResManLddFactory::SetPostBootLevelAndRequestNotification(TUint aClientId, TUint aResId, TInt aPostBootLevel) sl@0: { sl@0: DPowerResourceController::PostBootLevel(aResId, aPostBootLevel); sl@0: DPowerResourceNotification* iNoti = new DPowerResourceNotification(PostBootNotificationFunc, (TAny*)NULL, Kern::DfcQue0(), 3); sl@0: if(!iNoti) sl@0: { sl@0: Kern::Fault("PRM NOTI FAILED", __LINE__); sl@0: } sl@0: //Passing the address of the object so that it could be deleted in callback function sl@0: new (iNoti) DPowerResourceNotification(PostBootNotificationFunc, iNoti, Kern::DfcQue0(), 3); sl@0: TInt r = PowerResourceManager::RequestNotification(aClientId, aResId, *iNoti); sl@0: if(r != KErrNone) sl@0: Kern::Fault("PRM REQ NOTI FAILED", __LINE__); sl@0: } sl@0: sl@0: sl@0: /** Second stage constuctor */ sl@0: TInt DTestResManLddFactory::Install() sl@0: { sl@0: return(SetName(&KTestPowerRCName)); sl@0: } sl@0: sl@0: /** Device capabilities */ sl@0: void DTestResManLddFactory::GetCaps(TDes8& aDes)const sl@0: { sl@0: // Create a capabilities object sl@0: RTestResMan::TCaps caps; sl@0: caps.iVersion = iVersion; sl@0: // Write it back to user memory sl@0: Kern::InfoCopy(aDes,(TUint8*)&caps,sizeof(caps)); sl@0: } sl@0: sl@0: /** Create logical channel, only open of one channel is allowed */ sl@0: TInt DTestResManLddFactory::Create(DLogicalChannelBase*& aChannel) sl@0: { sl@0: if (iOpenChannels != 0) //A Channel is already open sl@0: return KErrInUse; sl@0: //Deregister the client registered in ldd init. sl@0: TInt r = PowerResourceManager::DeRegisterClient(DTestResManLddFactory::iClient.iClientId); sl@0: if(r != KErrNone) sl@0: Kern::Fault("PRM CLIENT DEREGISTER FAILED", __LINE__); sl@0: delete DTestResManLddFactory::iClient.pName; sl@0: DTestResManLddFactory::iClient.pName = NULL; sl@0: DTestResManLddFactory::iClient.iClientId = 0; sl@0: aChannel = new DTestResManLdd; sl@0: if(!aChannel) sl@0: return KErrNoMemory; sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** Constructor */ sl@0: DTestResManLdd::DTestResManLdd(): iAsyncResourceCallback(CallbackFunc, this, 3) sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: , iAsyncTestParallelCallback(TestParallelExecutionCallback, this, 3) sl@0: #endif sl@0: { sl@0: iCondList = NULL; sl@0: iUnCondList = NULL; sl@0: iCallbackCancel = EFalse; sl@0: iClientId = 0; sl@0: iResourceId = 0; sl@0: iStatePtr = NULL; sl@0: iLevelOwnerIdPtr = NULL; sl@0: for(TUint c = 0; c < MAX_CLIENTS; c++) sl@0: { sl@0: clientInfo[c].iClientId = 0; sl@0: clientInfo[c].pName = NULL; sl@0: } sl@0: iClientThreadPtr=&Kern::CurrentThread(); sl@0: // Increase the DThread's ref count so that it does not close without us sl@0: ((DObject*)iClientThreadPtr)->Open();; sl@0: } sl@0: sl@0: /** Destructor */ sl@0: DTestResManLdd::~DTestResManLdd() sl@0: { sl@0: if(pBuf) //Buffer created for storing idle resource information sl@0: delete pBuf; sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: for(TInt c = 0; c < iDynamicArray.Count(); c++) sl@0: { sl@0: delete iDynamicArray[c]; //Delete the dynamic array. This includes dynamic dependent resource. sl@0: } sl@0: iDynamicArray.Close(); sl@0: #endif sl@0: // Close our reference on the client thread sl@0: Kern::SafeClose((DObject*&)iClientThreadPtr,NULL); sl@0: } sl@0: sl@0: /** Second stage constructor. */ sl@0: TInt DTestResManLdd::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer) sl@0: { sl@0: // Check version sl@0: if (!Kern::QueryVersionSupported(RTestResMan::VersionRequired(),aVer)) sl@0: return KErrNotSupported; sl@0: SetDfcQ(((DTestResManLddFactory*)iDevice)->iDfcQ); sl@0: iAsyncResourceCallback.SetDfcQ(iDfcQ); sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: iAsyncTestParallelCallback.SetDfcQ(iDfcQ); sl@0: #endif sl@0: iMsgQ.Receive(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** Process a message for this logical channel */ sl@0: void DTestResManLdd::HandleMsg(TMessageBase* aMsg) sl@0: { sl@0: TThreadMessage& m=*(TThreadMessage*)aMsg; sl@0: TInt id=m.iValue; sl@0: sl@0: if (id==(TInt)ECloseMsg) sl@0: { sl@0: // Channel close. sl@0: m.Complete(KErrNone,EFalse); sl@0: return; sl@0: } sl@0: else if (id==KMaxTInt) sl@0: { sl@0: // DoCancel sl@0: m.Complete(KErrNone,ETrue); sl@0: return; sl@0: } sl@0: else if (id<0) sl@0: { sl@0: // DoRequest sl@0: TRequestStatus* pS=(TRequestStatus*)m.Ptr0(); sl@0: TInt r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2()); sl@0: if (r!=KErrNone) sl@0: Kern::RequestComplete(iClientThreadPtr,pS,r); sl@0: m.Complete(KErrNone,ETrue); sl@0: } sl@0: else sl@0: { sl@0: // DoControl sl@0: TInt r=DoControl(id,m.Ptr0(),m.Ptr1()); sl@0: m.Complete(r,ETrue); sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: Process synchronous 'control' requests sl@0: */ sl@0: TInt DTestResManLdd::DoControl(TInt aFunction, TAny* a1, TAny* a2) sl@0: { sl@0: TInt r = KErrNone; sl@0: TParameterListInfo ptr = {0, 0, 0, 0, 0}; sl@0: //Copy parameter structure from user space. sl@0: if((aFunction != RTestResMan::EDeRegisterClient) sl@0: && (aFunction != RTestResMan::ERequestNotificationUncond) sl@0: && (aFunction != RTestResMan::EGetIdleResourcesInfo) sl@0: && (aFunction != RTestResMan::EDeRegisterClientLevelFromResource) sl@0: && (aFunction != RTestResMan::ECheckPostBootLevelNotifications) sl@0: && (aFunction != RTestResMan::EGetControllerVersion) sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: && (aFunction != RTestResMan::ERegisterDynamicResource)) sl@0: #else sl@0: ) sl@0: #endif sl@0: { sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, (TParameterListInfo*)a1, &ptr, sizeof(TParameterListInfo)); sl@0: if(r != KErrNone) sl@0: return r; sl@0: } sl@0: switch(aFunction) sl@0: { sl@0: case RTestResMan::ERegisterClient: sl@0: { sl@0: TBuf8<256> aName; sl@0: TUint c; sl@0: //Copy name from user address space sl@0: r = Kern::ThreadDesRead(iClientThreadPtr, (const TDesC*)ptr.iPtr2, (TDes8&)aName, 0); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::ERegisterClient ThreadDesRead failed with %d", r); sl@0: break; sl@0: } sl@0: for(c = 0; c < MAX_CLIENTS; c++) sl@0: { sl@0: if(clientInfo[c].pName == NULL) sl@0: break; sl@0: if(!clientInfo[c].pName->Compare(aName)) sl@0: return KErrAlreadyExists; sl@0: } sl@0: if(c == MAX_CLIENTS) sl@0: return KErrOverflow; sl@0: clientInfo[c].pName = HBuf::New((const TDesC8&)aName); sl@0: if(!clientInfo[c].pName) sl@0: return KErrNoMemory; sl@0: r = PowerResourceManager::RegisterClient(clientInfo[c].iClientId, (const TDesC&)*clientInfo[c].pName, (TOwnerType)(TInt)ptr.iPtr3); sl@0: if(r != KErrNone) sl@0: { sl@0: delete clientInfo[c].pName; sl@0: clientInfo[c].pName = NULL; sl@0: clientInfo[c].iClientId = 0; sl@0: } sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr1, &clientInfo[c].iClientId, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::ERegisterClient ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::EDeRegisterClient: //Deregister client from RM sl@0: { sl@0: //Cancel all notification pending for this client sl@0: SNotificationList *pL; sl@0: SNotificationList* pN = iCondList; sl@0: while(pN != NULL) sl@0: { sl@0: if(pN->iClientId == (TUint)a1) sl@0: { sl@0: PowerResourceManager::CancelNotification(pN->iClientId, pN->iResourceId, *pN->iNoti); sl@0: pL = pN; sl@0: pN = pN->iNext; sl@0: LIST_REMOVE(iCondList, pL, iNext, SNotificationList); sl@0: delete pL->iNoti; sl@0: delete pL; sl@0: } sl@0: else sl@0: pN = pN->iNext; sl@0: } sl@0: pN = iUnCondList; sl@0: while(pN != NULL) sl@0: { sl@0: if(pN->iClientId == (TUint)a1) sl@0: { sl@0: PowerResourceManager::CancelNotification(pN->iClientId, pN->iResourceId, *pN->iNoti); sl@0: pL = pN; sl@0: pN = pN->iNext; sl@0: LIST_REMOVE(iUnCondList, pL, iNext, SNotificationList); sl@0: delete pL->iNoti; sl@0: delete pL; sl@0: } sl@0: else sl@0: pN = pN->iNext; sl@0: } sl@0: iClientId = -1; sl@0: r = PowerResourceManager::DeRegisterClient((TUint)a1); sl@0: if(r != KErrNone) sl@0: break; sl@0: r = KErrNotFound; sl@0: for(TUint c = 0; c < MAX_CLIENTS; c++) sl@0: { sl@0: if(clientInfo[c].iClientId == (TUint)a1) sl@0: { sl@0: delete clientInfo[c].pName; sl@0: clientInfo[c].pName = 0; sl@0: clientInfo[c].iClientId = 0; sl@0: r = KErrNone; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: break; sl@0: } sl@0: case RTestResMan::EGetClientName: //Get Client Name sl@0: { sl@0: TBuf8<32> aName; sl@0: r = PowerResourceManager::GetClientName((TUint)ptr.iClientId, (TUint)ptr.iPtr1, (TDes &)aName); sl@0: if(r== KErrNone) sl@0: { sl@0: r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr2, (const TDesC8&)aName, 0); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::EGetClientName ThreadDesWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::EGetClientId: //Get Client Id sl@0: { sl@0: TBuf8<256> aName; sl@0: TUint aClientId; sl@0: r = Kern::ThreadDesRead(iClientThreadPtr, (const TDesC*)ptr.iPtr1, (TDes8&)aName, 0,KChunkShiftBy0); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::EGetClientId ThreadDesRead failed with %d", r); sl@0: break; sl@0: } sl@0: r = PowerResourceManager::GetClientId(ptr.iClientId, (TDesC&)aName, aClientId); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &aClientId, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::EGetClientId ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::EGetResourceId: //Get Resource Id sl@0: { sl@0: TBuf8<256> aName; sl@0: TUint aResourceId; sl@0: r = Kern::ThreadDesRead(iClientThreadPtr, (const TDesC*)ptr.iPtr1, (TDes8&)aName, 0,KChunkShiftBy0); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::EGetResourceId ThreadDesRead failed with %d", r); sl@0: break; sl@0: } sl@0: r = PowerResourceManager::GetResourceId(ptr.iClientId, (TDesC&)aName, aResourceId); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &aResourceId, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::EGetResourceId ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::EGetResourceInfo: //Get resource information sl@0: { sl@0: NKern::ThreadEnterCS(); sl@0: HBuf *info = HBuf::New(sizeof(TPowerResourceInfoV01)); sl@0: NKern::ThreadLeaveCS(); sl@0: r = PowerResourceManager::GetResourceInfo(ptr.iClientId, (TUint)ptr.iPtr1, (TAny*)info); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr2, (const TDesC8&)*info, 0); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::EGetResourceInfo ThreadRawWrite failed with %d", r); sl@0: } sl@0: Kern::Free(info); sl@0: break; sl@0: } sl@0: case RTestResMan::EGetNumResourcesInUseByClient: sl@0: { sl@0: TUint numResource; sl@0: r = PowerResourceManager::GetNumResourcesInUseByClient(ptr.iClientId, (TUint)ptr.iPtr1, numResource); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &numResource, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::EGetNumResourcesInUseByClient ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::EGetInfoOnResourcesInUseByClient: sl@0: { sl@0: TUint numResource; sl@0: HBuf* info = NULL; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, &numResource, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::GetInfoOnResourceInUseByClient ThreadRawRead failed with %d", r); sl@0: break; sl@0: } sl@0: if(ptr.iPtr3 != NULL) sl@0: { sl@0: NKern::ThreadEnterCS(); sl@0: info = HBuf::New(numResource * sizeof(TPowerResourceInfoV01)); sl@0: NKern::ThreadLeaveCS(); sl@0: } sl@0: r = PowerResourceManager::GetInfoOnResourcesInUseByClient(ptr.iClientId, (TUint)ptr.iPtr1, numResource, (TAny*)info); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &numResource, sizeof(TUint)); sl@0: if(r !=KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::GetInfoOnResourceInUseByClient ThreadRawWrite failed with %d", r); sl@0: Kern::Free(info); sl@0: break; sl@0: } sl@0: if(ptr.iPtr3) sl@0: r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr3, (const TDesC8&)*info, 0); sl@0: } sl@0: Kern::Free(info); sl@0: break; sl@0: } sl@0: case RTestResMan::EGetNumClientsUsingResource: sl@0: { sl@0: TUint numClient; sl@0: r = PowerResourceManager::GetNumClientsUsingResource(ptr.iClientId, (TUint)ptr.iPtr1, numClient); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &numClient, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::EGetNumResourcesInUseByClient ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::EGetInfoOnClientsUsingResource: sl@0: { sl@0: TUint numClient; sl@0: HBuf* info = NULL; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, &numClient, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::GetInfoOnResourceInUseByClient ThreadRawRead failed with %d", r); sl@0: break; sl@0: } sl@0: if(ptr.iPtr3 != NULL) sl@0: { sl@0: NKern::ThreadEnterCS(); sl@0: info = HBuf::New(numClient * sizeof(TPowerClientInfoV01)); sl@0: NKern::ThreadLeaveCS(); sl@0: } sl@0: r = PowerResourceManager::GetInfoOnClientsUsingResource(ptr.iClientId, (TUint)ptr.iPtr1, numClient, (TAny*)info); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, &numClient, sizeof(TUint)); sl@0: if(r !=KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::GetInfoOnResourceInUseByClient ThreadRawWrite failed with %d", r); sl@0: Kern::Free(info); sl@0: break; sl@0: } sl@0: if(ptr.iPtr3) sl@0: r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr3, (const TDesC8&)*info, 0); sl@0: } sl@0: Kern::Free(info); sl@0: break; sl@0: } sl@0: case RTestResMan::EAllocReserve: sl@0: { sl@0: r = PowerResourceManager::AllocReserve(ptr.iClientId, (TUint8)(TUint)ptr.iPtr1, (TUint8)(TUint)ptr.iPtr2); sl@0: break; sl@0: } sl@0: case RTestResMan::EChangeResourceStateSync: sl@0: { sl@0: SNotificationList* pN; sl@0: //Zero the conditional notification count for the resource id. sl@0: for(pN=iCondList; pN != NULL; pN=pN->iNext) sl@0: { sl@0: if(pN->iResourceId == (TUint)ptr.iPtr1) sl@0: { sl@0: pN->iCount = 0; sl@0: break; sl@0: } sl@0: } sl@0: //Zero the unconditional notification count for the resource id. sl@0: for(pN=iUnCondList; pN != NULL; pN=pN->iNext) sl@0: { sl@0: if(pN->iResourceId == (TUint)ptr.iPtr1) sl@0: { sl@0: pN->iCount = 0; sl@0: break; sl@0: } sl@0: } sl@0: iClientId = ptr.iClientId; sl@0: iResourceId = (TUint)ptr.iPtr1; sl@0: r = PowerResourceManager::ChangeResourceState(ptr.iClientId, (TUint)ptr.iPtr1, (TInt)ptr.iPtr2); sl@0: break; sl@0: } sl@0: case RTestResMan::EGetResourceStateSync: sl@0: { sl@0: TInt newState, levelOwnerId; sl@0: r = PowerResourceManager::GetResourceState(ptr.iClientId, (TUint)ptr.iPtr1, (TBool)ptr.iPtr2, newState, levelOwnerId); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr3, (TAny*)&newState, sizeof(TInt)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::GetResourceStateSync ThreadRawWrite failed with %d", r); sl@0: break; sl@0: } sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr4, (TAny*)&levelOwnerId, sizeof(TInt)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::GetResourceStateSync ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::ERequestNotificationUncond: sl@0: { sl@0: SNotificationList *notiList; sl@0: notiList = new SNotificationList; //Create new notification list sl@0: if(!notiList) sl@0: { sl@0: r = KErrNoMemory; sl@0: break; sl@0: } sl@0: //Create notification object to pass to RM sl@0: notiList->iNoti = new DPowerResourceNotification(UnCondNotificationFunc, this, ((DTestResManLddFactory*)iDevice)->iDfcQ, 3); sl@0: if(!notiList->iNoti) sl@0: { sl@0: delete notiList; sl@0: r = KErrNoMemory; sl@0: break; sl@0: } sl@0: notiList->iClientId = (TUint)a1; sl@0: notiList->iResourceId = (TUint)a2; sl@0: notiList->iCount = 0; sl@0: LIST_PUSH(iUnCondList, notiList, iNext); //Add to unconditional list. sl@0: r = PowerResourceManager::RequestNotification((TUint)a1, (TUint)a2, *notiList->iNoti); sl@0: break; sl@0: } sl@0: case RTestResMan::ERequestNotificationCond: sl@0: { sl@0: SNotificationList *notiList; sl@0: notiList = new SNotificationList; // Create new notification list sl@0: if(!notiList) sl@0: { sl@0: r = KErrNoMemory; sl@0: break; sl@0: } sl@0: //Create notification object to pass to RM sl@0: notiList->iNoti = new DPowerResourceNotification(CondNotificationFunc, this, ((DTestResManLddFactory*)iDevice)->iDfcQ, 3); sl@0: if(!notiList->iNoti) sl@0: { sl@0: delete notiList; sl@0: r = KErrNoMemory; sl@0: break; sl@0: } sl@0: notiList->iClientId = ptr.iClientId; sl@0: notiList->iResourceId = (TUint)ptr.iPtr1; sl@0: notiList->iCount = 0; sl@0: LIST_PUSH(iCondList, notiList, iNext); //Add to conditional list. sl@0: r = PowerResourceManager::RequestNotification((TUint)ptr.iClientId, (TUint)ptr.iPtr1, *notiList->iNoti, (TInt)ptr.iPtr2, (TBool)ptr.iPtr3); sl@0: break; sl@0: } sl@0: case RTestResMan::EDeRegisterClientLevelFromResource: sl@0: { sl@0: r = PowerResourceManager::DeRegisterClientLevelFromResource((TUint)a1, (TUint)a2); sl@0: break; sl@0: } sl@0: case RTestResMan::ECancelNotification: sl@0: { sl@0: r = KErrNotFound; sl@0: if(ptr.iPtr2) //Check for notification in conditional list if it is true. sl@0: { sl@0: for(SNotificationList* pN=iCondList; pN != NULL; pN=pN->iNext) sl@0: { sl@0: if((pN->iClientId == ptr.iClientId) && (pN->iResourceId == (TUint)ptr.iPtr1)) sl@0: { sl@0: r = PowerResourceManager::CancelNotification(pN->iClientId, pN->iResourceId, *pN->iNoti); sl@0: LIST_REMOVE(iCondList, pN, iNext, SNotificationList); sl@0: delete pN->iNoti; sl@0: delete pN; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: else //Check for notification in unconditional list. sl@0: { sl@0: for(SNotificationList* pN=iUnCondList; pN != NULL; pN=pN->iNext) sl@0: { sl@0: if((pN->iClientId == ptr.iClientId) && (pN->iResourceId == (TUint)ptr.iPtr1)) sl@0: { sl@0: r = PowerResourceManager::CancelNotification(pN->iClientId, pN->iResourceId, *pN->iNoti); sl@0: LIST_REMOVE(iUnCondList, pN, iNext, SNotificationList); sl@0: delete pN->iNoti; sl@0: delete pN; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::ECheckNotifications: sl@0: { sl@0: NKern::Sleep(NKern::TimerTicks(300)); //This is required as sometimes check is done before callback is called. sl@0: TUint countCond = 0, countUncond = 0; sl@0: SNotificationList* pN; sl@0: //Get the conditional notification callback functions called for the resource id. sl@0: for(pN=iCondList; pN != NULL; pN=pN->iNext) sl@0: { sl@0: if(pN->iResourceId == (TUint)ptr.iPtr1) sl@0: { sl@0: countCond = pN->iCount; sl@0: pN->iCount = 0; sl@0: break; sl@0: } sl@0: } sl@0: //Get the unconditional notification callback functions called for the resource id. sl@0: for(pN=iUnCondList; pN != NULL; pN=pN->iNext) sl@0: { sl@0: if(pN->iResourceId == (TUint)ptr.iPtr1) sl@0: { sl@0: countUncond = pN->iCount; sl@0: pN->iCount = 0; sl@0: break; sl@0: } sl@0: } sl@0: //If the notifications count is not as expected return error. sl@0: if((countCond != (TUint)ptr.iPtr3) || (countUncond != (TUint)ptr.iPtr2)) sl@0: r = KErrUnderflow; sl@0: break; sl@0: } sl@0: case RTestResMan::ERegisterForIdleResourcesInfo: sl@0: { sl@0: if(pBuf) sl@0: { sl@0: r = KErrAlreadyExists; sl@0: break; sl@0: } sl@0: NKern::ThreadEnterCS(); sl@0: pBuf = HBuf::New((TUint)ptr.iPtr1 * sizeof(SIdleResourceInfo)); //Allocate buffer for requested resources sl@0: NKern::ThreadLeaveCS(); sl@0: if(!pBuf) sl@0: return KErrNoMemory; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, (TAny*)pBuf->Ptr(), (TUint)ptr.iPtr1 * sizeof(SIdleResourceInfo)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::ERegisterForIdleResourceInfo threadRawRead failed with %d\n", r); sl@0: break; sl@0: } sl@0: //Below function calls RegisterForResourceIdle resource controller virtual function, sl@0: //This is for testing purposes only. sl@0: sl@0: r =DSimulatedPowerResourceController::CaptureIdleResourcesInfo((TUint)ptr.iClientId, (TUint)ptr.iPtr1, (TPtr*)pBuf); sl@0: if( r == KErrInUse) sl@0: delete pBuf; sl@0: break; sl@0: } sl@0: case RTestResMan::EGetIdleResourcesInfo: sl@0: { sl@0: //Pass the buffer for comparision sl@0: if(!pBuf) sl@0: { sl@0: r = KErrNotFound; sl@0: break; sl@0: } sl@0: pBuf->SetLength(sizeof(SIdleResourceInfo) * (TUint)a1); sl@0: r = Kern::ThreadDesWrite(iClientThreadPtr, a2, (const TDesC8&)*pBuf, 0); sl@0: break; sl@0: } sl@0: case RTestResMan::ECheckPostBootLevelNotifications: sl@0: { sl@0: if(DTestResManLddFactory::iPostBootNotiCount != EXPECTED_POST_NOTI_COUNT) sl@0: { sl@0: r = KErrUnderflow; sl@0: break; sl@0: } sl@0: r = KErrNone; sl@0: break; sl@0: } sl@0: case RTestResMan::EGetControllerVersion: sl@0: { sl@0: TUint Version; sl@0: r = PowerResourceManager::GetResourceControllerVersion((TUint)a1, Version); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, a2, &Version, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::EGetControllerVersion ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: case RTestResMan::ERegisterDynamicResource: sl@0: { sl@0: TUint resId; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, a2, (TAny*)&resId, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::RegisterDynamicResource ThreadRawRead failed with %d", r); sl@0: break; sl@0: } sl@0: DDynamicPowerResource* pDR = NULL; sl@0: switch(resId) //Create the dynamic resource sl@0: { sl@0: case 1: sl@0: pDR = new (DBIGISSPDynamicResource); sl@0: break; sl@0: case 2: sl@0: pDR = new (DMLIGLSSHNDynamicResource); sl@0: break; sl@0: case 3: sl@0: pDR = new (DBLGLSSHNDynamicResource); sl@0: break; sl@0: case 4: sl@0: pDR = new (DMLLGLSSHPDynamicResource); sl@0: break; sl@0: case 5: sl@0: pDR = (DDynamicPowerResource*) new (DDynamicResourceD01); sl@0: break; sl@0: case 6: sl@0: pDR = (DDynamicPowerResource*) new (DDynamicResourceD02); sl@0: break; sl@0: case 7: sl@0: pDR = (DDynamicPowerResource*) new (DDynamicResourceD03); sl@0: break; sl@0: case 8: sl@0: pDR = (DDynamicPowerResource*) new (DDynamicResourceD04); sl@0: break; sl@0: } sl@0: if(!pDR) sl@0: return KErrNoMemory; sl@0: iDynamicArray.Append(pDR); sl@0: r = PowerResourceManager::RegisterDynamicResource((TUint)a1, pDR, resId); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, a2, (TAny*)&resId, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::RegisterDynamicResource ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::EDeRegisterDynamicResource: //Deregister dynamic resource sl@0: { sl@0: if(ptr.iPtr2) sl@0: { sl@0: TInt level; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, &level, sizeof(TInt)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::DeRegisterDynamicResource ThreadRawRead failed with %d", r); sl@0: break; sl@0: } sl@0: r = PowerResourceManager::DeRegisterDynamicResource(ptr.iClientId, (TUint)ptr.iPtr1, &level); sl@0: } sl@0: else sl@0: r = PowerResourceManager::DeRegisterDynamicResource(ptr.iClientId, (TUint)ptr.iPtr1, NULL); sl@0: break; sl@0: } sl@0: case RTestResMan::ERegisterResourceDependency: //Register resource dependency sl@0: { sl@0: SResourceDependencyInfo info1, info2; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr1, &info1, sizeof(SResourceDependencyInfo)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::RegisterResourceDependency ThreadRawRead failed with %d", r); sl@0: break; sl@0: } sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr2, &info2, sizeof(SResourceDependencyInfo)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::RegisterResourceDependency ThreadRawRead failed with %d", r); sl@0: break; sl@0: } sl@0: r = PowerResourceManager::RegisterResourceDependency(ptr.iClientId, &info1, &info2); sl@0: break; sl@0: } sl@0: case RTestResMan::EDeRegisterResourceDependency: //Deregister resource dependency sl@0: { sl@0: r = PowerResourceManager::DeRegisterResourceDependency(ptr.iClientId, (TUint)ptr.iPtr1, (TUint)ptr.iPtr2); sl@0: break; sl@0: } sl@0: case RTestResMan::EGetNumDependentsForResource: sl@0: { sl@0: TUint numDepResources; sl@0: r = PowerResourceManager::GetNumDependentsForResource(ptr.iClientId, (TUint)ptr.iPtr1, numDepResources); sl@0: if(r == KErrNone) sl@0: { sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr2, (TAny*)&numDepResources, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResMan::RegisterDynamicResource ThreadRawWrite failed with %d", r); sl@0: } sl@0: break; sl@0: } sl@0: case RTestResMan::EGetDependentsIdForResource: sl@0: { sl@0: TUint numDepResources; sl@0: HBuf* sResDepInfo = NULL; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, ptr.iPtr3, (TAny*)&numDepResources, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::GetDependentsIdForResource ThreadRawRead failed with %d", r); sl@0: break; sl@0: } sl@0: if(ptr.iPtr2 != NULL) sl@0: { sl@0: NKern::ThreadEnterCS(); sl@0: sResDepInfo = HBuf::New(numDepResources * sizeof(SResourceDependencyInfo)); sl@0: NKern::ThreadLeaveCS(); sl@0: if(!sResDepInfo) sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: r = PowerResourceManager::GetDependentsIdForResource(ptr.iClientId, (TUint)ptr.iPtr1, (TAny*)sResDepInfo, numDepResources); sl@0: if(r == KErrNone) sl@0: { sl@0: if(ptr.iPtr2) sl@0: r = Kern::ThreadDesWrite(iClientThreadPtr, ptr.iPtr2, (const TDesC8&)*sResDepInfo, 0); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::GetDepedentsIdForResource ThreadDesWrite failed with %d", r); sl@0: Kern::Free(sResDepInfo); sl@0: break; sl@0: } sl@0: r = Kern::ThreadRawWrite(iClientThreadPtr, ptr.iPtr3, (TAny*)&numDepResources, sizeof(TUint)); sl@0: if(r != KErrNone) sl@0: { sl@0: Kern::Printf("RTestResMan::GetDependentsIdForResource ThreadRawWrite failed with %d", r); sl@0: Kern::Free(sResDepInfo); sl@0: break; sl@0: } sl@0: } sl@0: Kern::Free(sResDepInfo); sl@0: break; sl@0: } sl@0: sl@0: #endif sl@0: default: sl@0: r = KErrNotSupported; sl@0: break; sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: TInt DTestResManLdd::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* /*a2*/) sl@0: { sl@0: TInt r = KErrNone; sl@0: TParameterListInfo ptr; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, (TParameterListInfo*)a1, &ptr, sizeof(TParameterListInfo)); sl@0: if(r != KErrNone) sl@0: Kern::RequestComplete(iClientThreadPtr, aStatus, r); sl@0: switch(aReqNo) sl@0: { sl@0: case RTestResMan::EChangeResourceStateAsync: sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: case RTestResMan::EChangeResStateAndDeregisterDynamicRes: sl@0: case RTestResMan::ECheckParallelExecutionForChangeResState: sl@0: #endif sl@0: SNotificationList* pN; sl@0: //Zero the conditional notification count for the resource id. sl@0: for(pN=iCondList; pN != NULL; pN=pN->iNext) sl@0: { sl@0: if(pN->iResourceId == (TUint)ptr.iPtr1) sl@0: { sl@0: pN->iCount = 0; sl@0: break; sl@0: } sl@0: } sl@0: //Zero the unconditional notification count for the resource id. sl@0: for(pN=iUnCondList; pN != NULL; pN=pN->iNext) sl@0: { sl@0: if(pN->iResourceId == (TUint)ptr.iPtr1) sl@0: { sl@0: pN->iCount = 0; sl@0: break; sl@0: } sl@0: } sl@0: iLevelOwnerIdPtr = NULL; sl@0: iStatePtr = (TInt*)ptr.iPtr2; sl@0: TInt state; sl@0: r = Kern::ThreadRawRead(iClientThreadPtr, iStatePtr, &state, sizeof(TInt)); sl@0: if(r != KErrNone) sl@0: Kern::RequestComplete(iClientThreadPtr, aStatus, r); sl@0: iStatus = aStatus; sl@0: iClientId = ptr.iClientId; sl@0: iResourceId = (TUint)ptr.iPtr1; sl@0: iCallbackCancel = EFalse; sl@0: r = PowerResourceManager::ChangeResourceState(ptr.iClientId, (TUint)ptr.iPtr1, state, &iAsyncResourceCallback); sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: if(aReqNo == RTestResMan::EChangeResStateAndDeregisterDynamicRes) //Try to delete the dynamic while resource change sl@0: { sl@0: r = PowerResourceManager::DeRegisterDynamicResource(ptr.iClientId, (TUint)ptr.iPtr1, NULL); sl@0: if(r == KErrInUse) //Wait for the request to complete sl@0: r = KErrNone; sl@0: break; sl@0: } sl@0: if(aReqNo == RTestResMan::ECheckParallelExecutionForChangeResState) sl@0: { sl@0: r = PowerResourceManager::ChangeResourceState(ptr.iClientId, (TUint)ptr.iPtr3, (TInt)ptr.iPtr4, &iAsyncTestParallelCallback); sl@0: iTestParallelResourceId = (TUint)ptr.iPtr3; sl@0: iValidateCallbackReceived = ETrue; sl@0: break; sl@0: } sl@0: #endif sl@0: if(ptr.iPtr3) //Cancel the asynchronous operation if true. sl@0: { sl@0: r = PowerResourceManager::CancelAsyncRequestCallBack(ptr.iClientId, (TUint)ptr.iPtr1, iAsyncResourceCallback); sl@0: if(r == KErrInUse) //Wait for the request to complete sl@0: r = KErrNone; sl@0: else sl@0: iCallbackCancel = ETrue; sl@0: } sl@0: break; sl@0: case RTestResMan::EGetResourceStateAsync: sl@0: iStatus = aStatus; sl@0: iCallbackCancel = EFalse; sl@0: iClientId = ptr.iClientId; sl@0: iResourceId = (TUint)ptr.iPtr1; sl@0: iStatePtr = (TInt*)ptr.iPtr4; sl@0: iLevelOwnerIdPtr = (TInt*)ptr.iPtr5; sl@0: r = PowerResourceManager::GetResourceState(ptr.iClientId, (TUint)ptr.iPtr1, (TBool)ptr.iPtr2, iAsyncResourceCallback); sl@0: if(ptr.iPtr3) //Cancel the asynchronous operation if true. sl@0: { sl@0: r = PowerResourceManager::CancelAsyncRequestCallBack(ptr.iClientId, (TUint)ptr.iPtr1, iAsyncResourceCallback); sl@0: if(r == KErrInUse) sl@0: r = KErrNone; sl@0: else sl@0: iCallbackCancel = ETrue; sl@0: } sl@0: break; sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: //Function called on Asynchronous operation sl@0: void DTestResManLdd::CallbackFunc(TUint aClientId, TUint aResId, TInt aLevel, TInt aLevelOwnerId, TInt aResult, TAny* aParam) sl@0: { sl@0: TInt r; sl@0: DTestResManLdd *pC = (DTestResManLdd*)aParam; sl@0: //Check for correctnes of clientId and resourceId sl@0: if((TUint)pC->iClientId != aClientId || pC->iResourceId != aResId) sl@0: Kern::RequestComplete(pC->iClientThreadPtr, pC->iStatus, KErrCorrupt); sl@0: if(!pC->iCallbackCancel) sl@0: { sl@0: if(pC->iStatePtr) sl@0: { sl@0: r = Kern::ThreadRawWrite(pC->iClientThreadPtr, pC->iStatePtr, (TAny*)&aLevel, sizeof(TInt)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResManLdd::CallbackFunc ThreadRawWrite failed with %d", r); sl@0: } sl@0: if(pC->iLevelOwnerIdPtr) sl@0: { sl@0: r = Kern::ThreadRawWrite(pC->iClientThreadPtr, pC->iLevelOwnerIdPtr, (TAny*)&aLevelOwnerId, sizeof(TInt)); sl@0: if(r != KErrNone) sl@0: Kern::Printf("RTestResManLdd::CallbackFunc ThreadRawWrite failed with %d", r); sl@0: } sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: if(pC->iValidateCallbackReceived) sl@0: { sl@0: if(!pC->iCallbackReceived) sl@0: aResult = KErrCompletion; sl@0: } sl@0: #endif sl@0: Kern::RequestComplete(pC->iClientThreadPtr, pC->iStatus, aResult); sl@0: } sl@0: pC->iCallbackCancel = EFalse; sl@0: pC->iStatus = NULL; sl@0: } sl@0: sl@0: #ifdef PRM_ENABLE_EXTENDED_VERSION sl@0: //Function called on completion of asynchronous long latency resource, used only to check parallel execution of DFC's sl@0: void DTestResManLdd::TestParallelExecutionCallback(TUint aClientId, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam) sl@0: { sl@0: Kern::Printf("DTestResManLdd::TestParallelExecutionCallback:: called"); sl@0: DTestResManLdd *pC = (DTestResManLdd*)aParam; sl@0: //Check for correctness of clientId and resourceId sl@0: if((TUint)pC->iClientId == aClientId && pC->iTestParallelResourceId == aResId) sl@0: { sl@0: pC->iCallbackReceived = ETrue; sl@0: } sl@0: } sl@0: #endif sl@0: sl@0: //Function called on Conditional notification sl@0: void DTestResManLdd::CondNotificationFunc(TUint /*aClientId*/, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam) sl@0: { sl@0: DTestResManLdd *pC = (DTestResManLdd*)aParam; sl@0: for(SNotificationList *pN = pC->iCondList; pN!= NULL; pN=pN->iNext) sl@0: { sl@0: if((pN->iResourceId == aResId)) sl@0: { sl@0: pN->iCount++; //Increment the count, as same callback function for all conditioanl notifications. sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: //Function called on UnConditional notification sl@0: void DTestResManLdd::UnCondNotificationFunc(TUint /*aClientId*/, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam) sl@0: { sl@0: DTestResManLdd *pC = (DTestResManLdd*)aParam; sl@0: for(SNotificationList *pN = pC->iUnCondList; pN!= NULL; pN=pN->iNext) sl@0: { sl@0: if((pN->iResourceId == aResId) && (pC->iCallbackCancel == EFalse)) sl@0: { sl@0: pN->iCount++; //Increment the count as same callback function for all unconditioanl notifications. sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: //Function called on postbootvalueset. sl@0: void DTestResManLddFactory::PostBootNotificationFunc(TUint /*aClientId*/, TUint aResId, TInt /*aLevel*/, TInt /*aLevelOwnerId*/, TInt /*aResult*/, TAny* aParam) sl@0: { sl@0: iPostBootNotiCount++; sl@0: DPowerResourceNotification *ptr = (DPowerResourceNotification*)aParam; sl@0: TInt r = PowerResourceManager::CancelNotification(iClient.iClientId, aResId, *ptr); sl@0: if(r == KErrNone) sl@0: delete ptr; sl@0: }