|
1 /* |
|
2 * Copyright (c) 2010 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 #include "coreinterface.h" |
|
19 #include "eventconsumerinterface.h" |
|
20 |
|
21 #include "logger.h" |
|
22 #include "cenreplistener.h" |
|
23 #include "settingschangeeventsprovidermessages.h" |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <centralrepository.h> |
|
27 |
|
28 namespace java |
|
29 { |
|
30 namespace captain |
|
31 { |
|
32 |
|
33 // General listener used as a base value indicating that whole repository is being |
|
34 // listened instead of individual key. |
|
35 CenRepListener::CenRepListener() : mKeyType(CenRepListener::GENERAL_LISTENER) |
|
36 { |
|
37 JELOG2(EJavaCaptain); |
|
38 } |
|
39 |
|
40 CenRepListener::~CenRepListener() |
|
41 { |
|
42 JELOG2(EJavaCaptain); |
|
43 Close(); |
|
44 } |
|
45 |
|
46 void CenRepListener::Close() |
|
47 { |
|
48 JELOG2(EJavaCaptain); |
|
49 if (mNotifyHandler ) { |
|
50 mNotifyHandler->StopListening(); |
|
51 delete mNotifyHandler; |
|
52 mNotifyHandler = 0; |
|
53 } |
|
54 if ( mCenRepSession ) { |
|
55 delete mCenRepSession; |
|
56 mCenRepSession = 0; |
|
57 } |
|
58 } |
|
59 |
|
60 CenRepListener* CenRepListener::NewLC(CoreInterface* aCore, TUid aRepoId, TUint32 aKeyId, |
|
61 CCenRepNotifyHandler::TCenRepKeyType aKeyType) |
|
62 { |
|
63 JELOG2(EJavaCaptain); |
|
64 CenRepListener* crListener = new (ELeave) CenRepListener(); |
|
65 CleanupStack::PushL(crListener); |
|
66 crListener->ConstructL(aCore, aRepoId, aKeyId, aKeyType); |
|
67 return (crListener); |
|
68 } |
|
69 |
|
70 CenRepListener* CenRepListener::NewL(CoreInterface* aCore, TUid aRepoId, TUint32 aKeyId, |
|
71 CCenRepNotifyHandler::TCenRepKeyType aKeyType) |
|
72 { |
|
73 JELOG2(EJavaCaptain); |
|
74 CenRepListener* crListener = CenRepListener::NewLC(aCore, aRepoId, aKeyId, aKeyType); |
|
75 CleanupStack::Pop(crListener); |
|
76 return (crListener); |
|
77 } |
|
78 |
|
79 CenRepListener* CenRepListener::NewLC(CoreInterface* aCore, TUid aRepoId) |
|
80 { |
|
81 JELOG2(EJavaCaptain); |
|
82 CenRepListener* crListener = new (ELeave) CenRepListener(); |
|
83 CleanupStack::PushL(crListener); |
|
84 crListener->ConstructL(aCore, aRepoId); |
|
85 return (crListener); |
|
86 } |
|
87 |
|
88 CenRepListener* CenRepListener::NewL(CoreInterface* aCore, TUid aRepoId) |
|
89 { |
|
90 JELOG2(EJavaCaptain); |
|
91 CenRepListener* crListener = CenRepListener::NewLC(aCore, aRepoId); |
|
92 CleanupStack::Pop(crListener); |
|
93 return (crListener); |
|
94 } |
|
95 |
|
96 void CenRepListener::ConstructL(CoreInterface* aCore, TUid aRepoId, TUint32 aKeyId, |
|
97 CCenRepNotifyHandler::TCenRepKeyType aKeyType) |
|
98 { |
|
99 JELOG2(EJavaCaptain); |
|
100 mCore = aCore; |
|
101 mRepoId = aRepoId; |
|
102 mKeyType = aKeyType; |
|
103 mCenRepSession = CRepository::NewL(mRepoId); |
|
104 mNotifyHandler = CCenRepNotifyHandler::NewL(*this, *mCenRepSession, |
|
105 aKeyType, aKeyId); |
|
106 mNotifyHandler->StartListeningL(); |
|
107 } |
|
108 |
|
109 void CenRepListener::ConstructL(CoreInterface* aCore, TUid aRepoId) |
|
110 { |
|
111 JELOG2(EJavaCaptain); |
|
112 mCore = aCore; |
|
113 mRepoId = aRepoId; |
|
114 mCenRepSession = CRepository::NewL(mRepoId); |
|
115 mNotifyHandler = CCenRepNotifyHandler::NewL(*this, *mCenRepSession); |
|
116 mNotifyHandler->StartListeningL(); |
|
117 } |
|
118 |
|
119 void CenRepListener::HandleNotifyInt(TUint32 aKeyId, TInt /*aNewValue*/) |
|
120 { |
|
121 JELOG2(EJavaCaptain); |
|
122 WLOG1(EJavaCaptain, "Change in Unrecognised cenrep TInt key noticed! " |
|
123 "CR Key= %0x", aKeyId); |
|
124 } |
|
125 |
|
126 void CenRepListener::HandleNotifyReal( TUint32 aKeyId, TReal /*aNewValue*/ ) |
|
127 { |
|
128 JELOG2(EJavaCaptain); |
|
129 WLOG1(EJavaCaptain, "Change in Unrecognised cenrep TReal key noticed! " |
|
130 "CR Key= %0x", aKeyId); |
|
131 } |
|
132 |
|
133 void CenRepListener::HandleNotifyBinary( TUint32 aKeyId, const TDesC8& /*aNewValue*/ ) |
|
134 { |
|
135 JELOG2(EJavaCaptain); |
|
136 WLOG1(EJavaCaptain, "Change in Unrecognised cenrep Binary key noticed! " |
|
137 "CR Key= %0x", aKeyId); |
|
138 } |
|
139 |
|
140 void CenRepListener::HandleNotifyGeneric(TUint32 aKeyId) |
|
141 { |
|
142 JELOG2(EJavaCaptain); |
|
143 WLOG1(EJavaCaptain, "Change in Unrecognised cenrep key noticed! " |
|
144 "CR Key= %0x", aKeyId); |
|
145 } |
|
146 |
|
147 void CenRepListener::HandleNotifyString( TUint32 aKeyId, const TDesC16& /*aNewValue*/ ) |
|
148 { |
|
149 JELOG2(EJavaCaptain); |
|
150 if ( KCRUidJavaRuntime == mRepoId && KJavaRuntimeMIDPClasspath == aKeyId ) { |
|
151 ILOG(EJavaCaptain, "CenRepListener::HandleNotifyString: change notified " |
|
152 "in key KJavaRuntimeMIDPClasspath"); |
|
153 dispatchEvent(SETTINGS_CHANGE_EVENT_PROVIDER, |
|
154 MIDP_CLASS_PATH_CHANGE); |
|
155 } else { |
|
156 WLOG1(EJavaCaptain, "Change in Unrecognised cenrep string key noticed! " |
|
157 "CR Key= %0x", aKeyId); |
|
158 } |
|
159 } |
|
160 |
|
161 void CenRepListener::HandleNotifyError(TUint32 aKeyId, TInt error, CCenRepNotifyHandler* /* aHandler */) |
|
162 { |
|
163 JELOG2(EJavaCaptain); |
|
164 ELOG2(EJavaCaptain, "Error (code: %d) occured when listening changes on " |
|
165 "Cenrep key (Key ID: %0x). Listening stopped!", error, aKeyId); |
|
166 Close(); |
|
167 } |
|
168 |
|
169 void CenRepListener::dispatchEvent(const std::string& aEvent, |
|
170 const SettingsChangeEventType_t& aType) const |
|
171 { |
|
172 JELOG2(EJavaCaptain); |
|
173 ILOG2(EJavaCaptain, "CenRepListener::dispatchEvent: dispatching event=%s " |
|
174 "type=%d", aEvent.c_str(), aType); |
|
175 CommsMessage eventMsg; |
|
176 setSettingsChangeEventMessageParams(eventMsg, aType); |
|
177 mCore->getEventDispatcher()->event(aEvent, eventMsg); |
|
178 } |
|
179 |
|
180 } // namespace captain |
|
181 } // namespace java |
|
182 |