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