1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of the License "Eclipse Public License v1.0" |
4 // under the terms of the License "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
401 pN = _LOFF(pNL, DPowerResourceNotification, iNotificationLink); |
401 pN = _LOFF(pNL, DPowerResourceNotification, iNotificationLink); |
402 #ifdef PRM_ENABLE_EXTENDED_VERSION |
402 #ifdef PRM_ENABLE_EXTENDED_VERSION |
403 //If dyanmic resource is deregistering, send notification to all clients requested for it |
403 //If dyanmic resource is deregistering, send notification to all clients requested for it |
404 if((pN->iCallback.iResourceId & KIdMaskDynamic) && (aClientId == KDynamicResourceDeRegistering)) |
404 if((pN->iCallback.iResourceId & KIdMaskDynamic) && (aClientId == KDynamicResourceDeRegistering)) |
405 { |
405 { |
|
406 pN->iCallback.iResult=aReturnCode; |
|
407 pN->iCallback.iMutex = iResourceMutex; |
|
408 pN->iCallback.iPendingRequestCount++; |
406 pN->iCallback.iResult = aReturnCode; |
409 pN->iCallback.iResult = aReturnCode; |
407 pN->iCallback.iLevel = aState; |
410 pN->iCallback.iLevel = aState; |
408 pN->iCallback.iClientId = aClientId; |
411 pN->iCallback.iClientId = aClientId; |
409 pN->iCallback.iLevelOwnerId = aLevelOwnerId; |
412 pN->iCallback.iLevelOwnerId = aLevelOwnerId; |
410 __KTRACE_OPT(KRESMANAGER, Kern::Printf("Notification ClientId = 0x%x, ResourceId = %d, state = %d, Result = %d", |
413 __KTRACE_OPT(KRESMANAGER, Kern::Printf("Notification ClientId = 0x%x, ResourceId = %d, state = %d, Result = %d", |
416 #endif |
419 #endif |
417 if((pN->iType==DPowerResourceNotification::EUnconditional) || |
420 if((pN->iType==DPowerResourceNotification::EUnconditional) || |
418 (pN->iDirection && ((pN->iPreviousLevel < pN->iThreshold) && (aState >= pN->iThreshold))) || |
421 (pN->iDirection && ((pN->iPreviousLevel < pN->iThreshold) && (aState >= pN->iThreshold))) || |
419 (!pN->iDirection && ((pN->iPreviousLevel > pN->iThreshold) && (aState <= pN->iThreshold)))) |
422 (!pN->iDirection && ((pN->iPreviousLevel > pN->iThreshold) && (aState <= pN->iThreshold)))) |
420 { |
423 { |
421 pN->iCallback.iResult=aReturnCode; |
424 pN->iCallback.iResult=aReturnCode; |
422 pN->iCallback.iLevel=aState; |
425 pN->iCallback.iMutex = iResourceMutex; |
423 pN->iCallback.iClientId = aClientId; |
426 pN->iCallback.iPendingRequestCount++; |
|
427 pN->iCallback.iLevel=aState; |
|
428 pN->iCallback.iClientId = aClientId; |
424 pN->iCallback.iLevelOwnerId = aLevelOwnerId; |
429 pN->iCallback.iLevelOwnerId = aLevelOwnerId; |
|
430 |
425 __KTRACE_OPT(KRESMANAGER, Kern::Printf("Notifications ClientId = 0x%x, ResourceId = %d, State = %d, Result = %d", |
431 __KTRACE_OPT(KRESMANAGER, Kern::Printf("Notifications ClientId = 0x%x, ResourceId = %d, State = %d, Result = %d", |
426 pN->iCallback.iClientId, pN->iCallback.iResourceId, aState, aReturnCode)); |
432 pN->iCallback.iClientId, pN->iCallback.iResourceId, aState, aReturnCode)); |
427 PRM_POSTNOTIFICATION_SENT_TRACE |
433 PRM_POSTNOTIFICATION_SENT_TRACE |
428 pN->iCallback.Enque(); |
434 |
|
435 pN->iCallback.Enque(); |
|
436 |
429 } |
437 } |
430 pN->iPreviousLevel = aState; //Update the state |
438 pN->iPreviousLevel = aState; //Update the state |
431 } |
439 } |
432 __KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::CompleteNotifications")); |
440 __KTRACE_OPT(KRESMANAGER, Kern::Printf("<DPowerResourceController::CompleteNotifications")); |
433 if(aLock) |
441 if(aLock) |
706 #endif |
714 #endif |
707 //Check whether callback is cancelled and if not queue the DFC. |
715 //Check whether callback is cancelled and if not queue the DFC. |
708 TPowerResourceCb* pCb = aReq->ResourceCb(); |
716 TPowerResourceCb* pCb = aReq->ResourceCb(); |
709 if(pCb) |
717 if(pCb) |
710 { |
718 { |
|
719 pCb->iMutex = pRC->iResourceMutex; |
|
720 pCb->iPendingRequestCount++; |
711 pCb->iResult=aReq->ReturnCode(); |
721 pCb->iResult=aReq->ReturnCode(); |
712 pCb->iLevel=aReq->Level(); |
722 pCb->iLevel=aReq->Level(); |
713 pCb->iResourceId=aReq->ResourceId(); |
723 pCb->iResourceId=aReq->ResourceId(); |
714 pCb->iClientId=aReq->ClientId(); |
724 pCb->iClientId=aReq->ClientId(); |
715 pCb->iLevelOwnerId = pR->iLevelOwnerId; |
725 pCb->iLevelOwnerId = pR->iLevelOwnerId; |
779 #endif |
789 #endif |
780 //Check whether callback is cancelled and if not queue the DFC. |
790 //Check whether callback is cancelled and if not queue the DFC. |
781 TPowerResourceCb* pCb = aReq->ResourceCb(); |
791 TPowerResourceCb* pCb = aReq->ResourceCb(); |
782 if(pCb) |
792 if(pCb) |
783 { |
793 { |
|
794 pCb->iMutex = pRC->iResourceMutex; |
|
795 pCb->iPendingRequestCount++; |
784 pCb->iResult=aReq->ReturnCode(); |
796 pCb->iResult=aReq->ReturnCode(); |
785 pCb->iLevel=aReq->Level(); |
797 pCb->iLevel=aReq->Level(); |
786 pCb->iResourceId=aReq->ResourceId(); |
798 pCb->iResourceId=aReq->ResourceId(); |
787 pCb->iClientId=aReq->ClientId(); |
799 pCb->iClientId=aReq->ClientId(); |
788 pCb->iLevelOwnerId = pR->iLevelOwnerId; |
800 pCb->iLevelOwnerId = pR->iLevelOwnerId; |
2473 if(!pR) |
2485 if(!pR) |
2474 UNLOCK_RETURN(KErrNotFound); |
2486 UNLOCK_RETURN(KErrNotFound); |
2475 #endif |
2487 #endif |
2476 //Return if the resource is already in that state and client is also the same. |
2488 //Return if the resource is already in that state and client is also the same. |
2477 if((aNewState == pR->iCachedLevel) && ((TInt)aClientId == pR->iLevelOwnerId)) |
2489 if((aNewState == pR->iCachedLevel) && ((TInt)aClientId == pR->iLevelOwnerId)) |
2478 UNLOCK_RETURN(KErrNone); |
2490 { |
2479 |
2491 if(aCb) |
|
2492 { |
|
2493 //Invoke callback function |
|
2494 TUint ClientId = aClientId; |
|
2495 TUint ResourceId = aResourceId; |
|
2496 TInt Level = aNewState; |
|
2497 TInt LevelOwnerId = pR->iLevelOwnerId; |
|
2498 TInt Result = KErrNone; |
|
2499 TAny* Param = aCb->iParam; |
|
2500 aCb->iPendingRequestCount++; |
|
2501 UnLock(); |
|
2502 // Call the client specified callback function |
|
2503 aCb->iCallback(ClientId, ResourceId, Level, LevelOwnerId, Result, Param); |
|
2504 Lock(); |
|
2505 aCb->iPendingRequestCount--; |
|
2506 if(aCb->iPendingRequestCount == 0) |
|
2507 { |
|
2508 aCb->iResult = KErrCompletion; |
|
2509 } |
|
2510 } |
|
2511 UNLOCK_RETURN(KErrNone); |
|
2512 } |
2480 |
2513 |
2481 PRM_CLIENT_CHANGE_STATE_START_TRACE |
2514 PRM_CLIENT_CHANGE_STATE_START_TRACE |
2482 //If long latency resource requested synchronously from DFC thread 0 Panic |
2515 //If long latency resource requested synchronously from DFC thread 0 Panic |
2483 |
2516 |
2484 const TDesC8* pDfc0 = &KDfcThread0Name; |
2517 const TDesC8* pDfc0 = &KDfcThread0Name; |
2614 req->Level() = pR->iCachedLevel; |
2647 req->Level() = pR->iCachedLevel; |
2615 #ifdef PRM_ENABLE_EXTENDED_VERSION |
2648 #ifdef PRM_ENABLE_EXTENDED_VERSION |
2616 if(aResourceId & KIdMaskDynamic) |
2649 if(aResourceId & KIdMaskDynamic) |
2617 ((DDynamicPowerResource*)pR)->UnLock(); |
2650 ((DDynamicPowerResource*)pR)->UnLock(); |
2618 #endif |
2651 #endif |
2619 UnLock(); |
|
2620 if(aCb) |
2652 if(aCb) |
2621 { |
2653 { |
2622 //Invoke callback function |
2654 //Invoke callback function |
2623 aCb->iCallback(req->ClientId(), aResourceId, req->Level(), pR->iLevelOwnerId, r, aCb->iParam); |
2655 TUint ClientId = req->ClientId(); |
2624 //Mark the callback object to act properly during cancellation of this request. |
2656 TUint ResourceId = aResourceId; |
2625 aCb->iResult = KErrCompletion; |
2657 TInt Level = req->Level(); |
2626 } |
2658 TInt LevelOwnerId = pR->iLevelOwnerId; |
|
2659 TInt Result = r; |
|
2660 TAny* Param = aCb->iParam; |
|
2661 aCb->iPendingRequestCount++; |
|
2662 UnLock(); |
|
2663 // Call the client specified callback function |
|
2664 aCb->iCallback(ClientId, ResourceId, Level, LevelOwnerId, Result, Param); |
|
2665 Lock(); |
|
2666 aCb->iPendingRequestCount--; |
|
2667 if(aCb->iPendingRequestCount == 0) |
|
2668 { |
|
2669 aCb->iResult = KErrCompletion; |
|
2670 } |
|
2671 } |
|
2672 |
2627 PRM_CLIENT_CHANGE_STATE_END_TRACE |
2673 PRM_CLIENT_CHANGE_STATE_END_TRACE |
2628 return(r); |
2674 UNLOCK_RETURN(r); |
2629 } |
2675 } |
2630 } |
2676 } |
2631 else if(pR->iLevelOwnerId == -1) |
2677 else if(pR->iLevelOwnerId == -1) |
2632 { |
2678 { |
2633 /* Add client Level */ |
2679 /* Add client Level */ |
2682 } |
2728 } |
2683 #ifdef PRM_ENABLE_EXTENDED_VERSION |
2729 #ifdef PRM_ENABLE_EXTENDED_VERSION |
2684 if(aResourceId & KIdMaskDynamic) |
2730 if(aResourceId & KIdMaskDynamic) |
2685 ((DDynamicPowerResource*)pR)->UnLock(); |
2731 ((DDynamicPowerResource*)pR)->UnLock(); |
2686 #endif |
2732 #endif |
2687 UnLock(); |
|
2688 if(aCb) |
2733 if(aCb) |
2689 { |
2734 { |
2690 //Invoke callback function |
2735 //Invoke callback function |
2691 aCb->iCallback(req->ClientId(), aResourceId, req->Level(), pR->iLevelOwnerId, r, aCb->iParam); |
2736 TUint ClientId = req->ClientId(); |
2692 aCb->iResult = KErrCompletion; //Mark the callback object to act properly during cancellation of this request. |
2737 TUint ResourceId = aResourceId; |
|
2738 TInt Level = req->Level(); |
|
2739 TInt LevelOwnerId = pR->iLevelOwnerId; |
|
2740 TInt Result = r; |
|
2741 TAny* Param = aCb->iParam; |
|
2742 aCb->iPendingRequestCount++; |
|
2743 UnLock(); |
|
2744 // Call the client specified callback function |
|
2745 aCb->iCallback(ClientId, ResourceId, Level, LevelOwnerId, Result, Param); |
|
2746 Lock(); |
|
2747 aCb->iPendingRequestCount--; |
|
2748 if(aCb->iPendingRequestCount == 0) |
|
2749 { |
|
2750 aCb->iResult = KErrCompletion; |
|
2751 } |
2693 } |
2752 } |
2694 __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::ChangeResourceState, Level = %d", req->Level())); |
2753 __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::ChangeResourceState, Level = %d", req->Level())); |
2695 PRM_CLIENT_CHANGE_STATE_END_TRACE |
2754 PRM_CLIENT_CHANGE_STATE_END_TRACE |
2696 return r; |
2755 UNLOCK_RETURN(r); |
2697 } |
2756 } |
2698 |
2757 |
2699 /** |
2758 /** |
2700 @publishedPartner |
2759 @publishedPartner |
2701 @prototype 9.5 |
2760 @prototype 9.5 |
2913 aCb.iClientId = aClientId; |
2972 aCb.iClientId = aClientId; |
2914 |
2973 |
2915 PRM_RESOURCE_GET_STATE_START_TRACE |
2974 PRM_RESOURCE_GET_STATE_START_TRACE |
2916 if(aCached) //Call the callback directly |
2975 if(aCached) //Call the callback directly |
2917 { |
2976 { |
2918 UnLock(); |
2977 //Invoke callback function |
2919 aCb.iCallback(aClientId, aResourceId, pR->iCachedLevel, pR->iLevelOwnerId, KErrNone, aCb.iParam); |
2978 TUint ClientId = aClientId; |
2920 aCb.iResult = KErrCompletion; //Mark the callback object to act properly during cancellation of this request. |
2979 TUint ResourceId = aResourceId; |
|
2980 TInt Level = pR->iCachedLevel; |
|
2981 TInt LevelOwnerId = pR->iLevelOwnerId; |
|
2982 TInt Result = KErrNone; |
|
2983 TAny* Param = aCb.iParam; |
|
2984 aCb.iPendingRequestCount++; |
|
2985 UnLock(); |
|
2986 // Call the client specified callback function |
|
2987 aCb.iCallback(ClientId, ResourceId, Level, LevelOwnerId, Result, Param); |
|
2988 Lock(); |
|
2989 aCb.iPendingRequestCount--; |
|
2990 if(aCb.iPendingRequestCount == 0) |
|
2991 { |
|
2992 aCb.iResult = KErrCompletion; //Mark the callback object to act properly during cancellation of this request. |
|
2993 } |
2921 #ifdef PRM_INSTRUMENTATION_MACRO |
2994 #ifdef PRM_INSTRUMENTATION_MACRO |
2922 TInt aState = pR->iCachedLevel; |
2995 TInt aState = pR->iCachedLevel; |
2923 PRM_RESOURCE_GET_STATE_END_TRACE |
2996 PRM_RESOURCE_GET_STATE_END_TRACE |
2924 #endif |
2997 #endif |
2925 return(KErrNone); |
2998 UNLOCK_RETURN(KErrNone); |
2926 } |
2999 } |
2927 TPowerRequest* req=NULL; |
3000 TPowerRequest* req=NULL; |
2928 if(pR->LatencyGet()) |
3001 if(pR->LatencyGet()) |
2929 { |
3002 { |
2930 //Check the client quota of requests |
3003 //Check the client quota of requests |
2985 } |
3058 } |
2986 #ifdef PRM_ENABLE_EXTENDED_VERSION |
3059 #ifdef PRM_ENABLE_EXTENDED_VERSION |
2987 if(aResourceId & KIdMaskDynamic) |
3060 if(aResourceId & KIdMaskDynamic) |
2988 ((DDynamicPowerResource*)pR)->UnLock(); |
3061 ((DDynamicPowerResource*)pR)->UnLock(); |
2989 #endif |
3062 #endif |
2990 UnLock(); |
3063 |
2991 // Call the client callback function directly as it is already executing in the context of client thread. |
3064 //Invoke callback function |
2992 aCb.iCallback(aClientId, aResourceId, req->Level(), pR->iLevelOwnerId, r, aCb.iParam); |
3065 TUint ClientId = aClientId; |
2993 aCb.iResult = KErrCompletion; //Mark the callback object to act properly during cancellation of this request. |
3066 TUint ResourceId = aResourceId; |
|
3067 TInt Level = req->Level(); |
|
3068 TInt LevelOwnerId = pR->iLevelOwnerId; |
|
3069 TInt Result = r; |
|
3070 TAny* Param = aCb.iParam; |
|
3071 aCb.iPendingRequestCount++; |
|
3072 UnLock(); |
|
3073 // Call the client specified callback function |
|
3074 aCb.iCallback(ClientId, ResourceId, Level, LevelOwnerId, Result, Param); |
|
3075 Lock(); |
|
3076 aCb.iPendingRequestCount--; |
|
3077 if(aCb.iPendingRequestCount == 0) |
|
3078 { |
|
3079 aCb.iResult = KErrCompletion; //Mark the callback object to act properly during cancellation of this request. |
|
3080 } |
|
3081 UnLock(); |
2994 } |
3082 } |
2995 __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::GetResourceState(asynchronous), Level = %d", req->Level())); |
3083 __KTRACE_OPT(KRESMANAGER, Kern::Printf(">DPowerResourceController::GetResourceState(asynchronous), Level = %d", req->Level())); |
2996 if(pR->LatencyGet()) |
3084 if(pR->LatencyGet()) |
2997 return r; |
3085 return r; |
2998 #ifdef PRM_INSTRUMENTATION_MACRO |
3086 #ifdef PRM_INSTRUMENTATION_MACRO |