|
1 /* |
|
2 * Copyright (c) 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: Implements the class TMSPubSubListener |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "tmspubsublistener.h" |
|
19 #include "tmspubsubobserver.h" |
|
20 |
|
21 using namespace TMS; |
|
22 |
|
23 // ----------------------------------------------------------------------------- |
|
24 // TMSPubSubListener::TMSPubSubListener |
|
25 // C++ constructor can NOT contain any code, that |
|
26 // might leave. |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 TMSPubSubListener::TMSPubSubListener(const TUid aUid, const TInt aKey, |
|
30 TMSPubSubObserver* aObserver) : |
|
31 CActive(CActive::EPriorityStandard), |
|
32 iUid(aUid), |
|
33 iId(aKey), |
|
34 iObserver(aObserver) |
|
35 { |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // TMSPubSubListener::~TMSPubSubListener |
|
40 // Destructor. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 TMSPubSubListener::~TMSPubSubListener() |
|
44 { |
|
45 Cancel(); |
|
46 iProperty.Close(); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // TMSPubSubListener::RunL |
|
51 // From CActive. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void TMSPubSubListener::RunL() |
|
55 { |
|
56 const TRequestStatus status(iStatus); |
|
57 StartListening(); |
|
58 iObserver->HandleNotifyPSL(iUid, iId, status); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // TMSPubSubListener::DoCancel |
|
63 // From CActive. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void TMSPubSubListener::DoCancel() |
|
67 { |
|
68 |
|
69 iProperty.Cancel(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // TMSPubSubListener::RunError |
|
74 // From CActive. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 TInt TMSPubSubListener::RunError(TInt /*aError*/) |
|
78 { |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // TMSPubSubListener::NewL |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 TMSPubSubListener* TMSPubSubListener::NewL(const TUid aUid, const TInt aKey, |
|
87 TMSPubSubObserver* aObserver) |
|
88 { |
|
89 |
|
90 TMSPubSubListener* self = new (ELeave) TMSPubSubListener(aUid, aKey, |
|
91 aObserver); |
|
92 CleanupStack::PushL(self); |
|
93 self->ConstructL(); |
|
94 CleanupStack::Pop(); |
|
95 return self; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // TMSPubSubListener::StartListening |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void TMSPubSubListener::StartListening() |
|
103 { |
|
104 iProperty.Subscribe(iStatus); |
|
105 SetActive(); |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // TMSPubSubListener::ConstructL |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void TMSPubSubListener::ConstructL() |
|
113 { |
|
114 if (iObserver) |
|
115 { |
|
116 CActiveScheduler::Add(this); |
|
117 } |
|
118 |
|
119 User::LeaveIfError(iProperty.Attach(iUid, iId, EOwnerThread)); |
|
120 |
|
121 if (iObserver) |
|
122 { |
|
123 StartListening(); |
|
124 } |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // TMSPubSubListener::Get |
|
129 // Read integer value. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TInt TMSPubSubListener::Get(TInt& aVal) |
|
133 { |
|
134 return iProperty.Get(iUid, iId, aVal); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // TMSPubSubListener::Get |
|
139 // Read binary value. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 TInt TMSPubSubListener::Get(TDes8& aVal) |
|
143 { |
|
144 return iProperty.Get(iUid, iId, aVal); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // TMSPubSubListener::Get |
|
149 // Read string value. |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 TInt TMSPubSubListener::Get(TDes16& aVal) |
|
153 { |
|
154 return iProperty.Get(iUid, iId, aVal); |
|
155 } |
|
156 |
|
157 // End of File |