|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include "repositorynotifier.h" |
|
24 #include <centralrepository.h> |
|
25 |
|
26 CUsbChargingRepositoryNotifier::CUsbChargingRepositoryNotifier(MUsbChargingRepositoryObserver& aObserver,const TUid& aRepository, TUint aId) |
|
27 : CActive(EPriorityNormal), iObserver(aObserver), iRepositoryUid(aRepository), iId(aId) |
|
28 { |
|
29 CActiveScheduler::Add(this); |
|
30 } |
|
31 |
|
32 void CUsbChargingRepositoryNotifier::ConstructL() |
|
33 { |
|
34 iRepository = CRepository::NewL(iRepositoryUid); |
|
35 TInt state = KErrUnknown; |
|
36 User::LeaveIfError(iRepository->Get(iId, state)); |
|
37 // Update observers with current value if valid |
|
38 if(state >= KErrNone) |
|
39 { |
|
40 iObserver.HandleRepositoryValueChangedL(iRepositoryUid, iId, state); |
|
41 } |
|
42 Notify(); |
|
43 } |
|
44 |
|
45 void CUsbChargingRepositoryNotifier::DoCancel() |
|
46 { |
|
47 // If the call returns an error value, there's nothing meaninful we can do |
|
48 // (void) it to avoid messages from Lint |
|
49 (void) iRepository->NotifyCancel(iId); |
|
50 } |
|
51 |
|
52 CUsbChargingRepositoryNotifier::~CUsbChargingRepositoryNotifier() |
|
53 { |
|
54 Cancel(); |
|
55 delete iRepository; |
|
56 } |
|
57 |
|
58 void CUsbChargingRepositoryNotifier::Notify() |
|
59 { |
|
60 iStatus = KRequestPending; |
|
61 TInt err = iRepository->NotifyRequest(iId, iStatus); |
|
62 if(err == KErrNone) |
|
63 { |
|
64 SetActive(); |
|
65 } |
|
66 } |
|
67 |
|
68 void CUsbChargingRepositoryNotifier::RunL() |
|
69 { |
|
70 TInt state; |
|
71 TInt err = iRepository->Get(iId, state); |
|
72 if(err ==KErrNone) |
|
73 { |
|
74 iObserver.HandleRepositoryValueChangedL(iRepositoryUid, iId, state); |
|
75 } |
|
76 Notify(); |
|
77 } |
|
78 |
|
79 TInt CUsbChargingRepositoryNotifier::RunError(TInt /*aError*/) |
|
80 { |
|
81 return KErrNone; |
|
82 } |
|
83 |
|
84 CUsbChargingRepositoryNotifier* CUsbChargingRepositoryNotifier::NewL(MUsbChargingRepositoryObserver& aObserver,const TUid& aRepository, TUint aId) |
|
85 { |
|
86 CUsbChargingRepositoryNotifier* self = new (ELeave) CUsbChargingRepositoryNotifier(aObserver,aRepository,aId); |
|
87 CleanupStack::PushL(self); |
|
88 self->ConstructL(); |
|
89 CleanupStack::Pop(self); |
|
90 return self; |
|
91 } |