|
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 "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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <ssm/ssmstateawaresession.h> |
|
17 #include "ssmstatemonitor.h" |
|
18 #include "cmnpanic.h" |
|
19 #include "ssmdebug.h" |
|
20 |
|
21 /** |
|
22 |
|
23 */ |
|
24 CSsmStateMonitor* CSsmStateMonitor::NewL(CSsmStateAwareSession& aObserver, TDmDomainId aId) |
|
25 { |
|
26 CSsmStateMonitor* self = new (ELeave) CSsmStateMonitor(aObserver); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(aId); |
|
29 CleanupStack::Pop(self); |
|
30 return self; |
|
31 } |
|
32 |
|
33 /** |
|
34 |
|
35 */ |
|
36 CSsmStateMonitor::CSsmStateMonitor(CSsmStateAwareSession& aObserver) : |
|
37 CActive(CActive::EPriorityStandard), |
|
38 iObserver(aObserver) |
|
39 { |
|
40 CActiveScheduler::Add(this); |
|
41 } |
|
42 |
|
43 /** |
|
44 |
|
45 */ |
|
46 CSsmStateMonitor::~CSsmStateMonitor() |
|
47 { |
|
48 Cancel(); |
|
49 iSas.Close(); |
|
50 } |
|
51 |
|
52 /** |
|
53 |
|
54 */ |
|
55 void CSsmStateMonitor::ConstructL(TDmDomainId aId) |
|
56 { |
|
57 SSMLOGLEAVEIFERROR(iSas.Connect(aId)); //will leave in release builds as well |
|
58 |
|
59 //Setup change subscription |
|
60 iStatus = KRequestPending; |
|
61 iSas.RequestStateNotification(iStatus); |
|
62 SetActive(); |
|
63 |
|
64 //Read current state and store locally |
|
65 iState = iSas.State(); |
|
66 } |
|
67 |
|
68 /** |
|
69 |
|
70 */ |
|
71 void CSsmStateMonitor::DoCancel() |
|
72 { |
|
73 iSas.RequestStateNotificationCancel(); |
|
74 } |
|
75 |
|
76 /** |
|
77 |
|
78 */ |
|
79 void CSsmStateMonitor::RunL() |
|
80 { |
|
81 SSMLOGLEAVEIFERROR(iStatus.Int()); |
|
82 |
|
83 //Re-issue a subscription request before retrieving the current value |
|
84 iStatus = KRequestPending; |
|
85 iSas.AcknowledgeAndRequestStateNotification(KErrNone, iStatus); |
|
86 SetActive(); |
|
87 |
|
88 //Update local copy |
|
89 iState = iSas.State(); |
|
90 |
|
91 //Notify our clients |
|
92 iObserver.NotifySubscribers(iState); |
|
93 } |
|
94 |
|
95 /** |
|
96 @panic ECmnStateMonError1 if an error occurs in RunL |
|
97 */ |
|
98 TInt CSsmStateMonitor::RunError(TInt aError) |
|
99 { |
|
100 iSas.AcknowledgeStateNotification(aError); |
|
101 DEBUGPRINT2A("CSsmStateMonitor::RunError: %d", aError); |
|
102 User::Panic(KPanicSsmCmn, ECmnStateMonError1); //A panic here is easier to track than a panic in CActiveScheduler |
|
103 return aError; //lint !e527 Unreachable |
|
104 } |
|
105 |
|
106 /** |
|
107 |
|
108 */ |
|
109 TSsmState CSsmStateMonitor::State() const |
|
110 { |
|
111 return iState; |
|
112 } |