|
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 <e32base.h> |
|
19 #include <centralrepository.h> |
|
20 |
|
21 #include "coreinterface.h" |
|
22 #include "eventconsumerinterface.h" |
|
23 |
|
24 #include "logger.h" |
|
25 #include "cenreplistener.h" |
|
26 #include "settingschangeeventsprovidermessages.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 } |
|
38 |
|
39 CenRepListener::~CenRepListener() |
|
40 { |
|
41 close(); |
|
42 } |
|
43 |
|
44 void CenRepListener::close() |
|
45 { |
|
46 if (mNotifyHandler) |
|
47 { |
|
48 mNotifyHandler->StopListening(); |
|
49 delete mNotifyHandler; |
|
50 mNotifyHandler = 0; |
|
51 } |
|
52 if (mCenRepSession) |
|
53 { |
|
54 delete mCenRepSession; |
|
55 mCenRepSession = 0; |
|
56 } |
|
57 } |
|
58 |
|
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) |
|
84 { |
|
85 ILOG(EJavaCaptain, "CenRepListener::HandleNotifyString: change notified " |
|
86 "in key KJavaRuntimeMIDPClasspath"); |
|
87 dispatchEvent(SETTINGS_CHANGE_EVENT_PROVIDER, |
|
88 MIDP_CLASS_PATH_CHANGE); |
|
89 } |
|
90 else |
|
91 { |
|
92 WLOG1(EJavaCaptain, "Change in Unrecognised cenrep string key noticed! " |
|
93 "CR Key= %0x", aKeyId); |
|
94 } |
|
95 } |
|
96 |
|
97 void CenRepListener::HandleNotifyError(TUint32 aKeyId, TInt aError, CCenRepNotifyHandler* /* aHandler */) |
|
98 { |
|
99 ELOG2(EJavaCaptain, "Error (code: %d) occured when listening changes on " |
|
100 "Cenrep key (Key ID: %0x). Listening stopped!", aError, aKeyId); |
|
101 close(); |
|
102 } |
|
103 |
|
104 void CenRepListener::dispatchEvent(const std::string& aEvent, |
|
105 const SettingsChangeEventType_t& aType) const |
|
106 { |
|
107 ILOG2(EJavaCaptain, "CenRepListener::dispatchEvent: dispatching event=%s " |
|
108 "type=%d", aEvent.c_str(), aType); |
|
109 CommsMessage eventMsg; |
|
110 setSettingsChangeEventMessageParams(eventMsg, aType); |
|
111 mCore->getEventDispatcher()->event(aEvent, eventMsg); |
|
112 } |
|
113 |
|
114 } // namespace captain |
|
115 } // namespace java |
|
116 |