|
1 /* |
|
2 * Copyright (c) 2007 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 <QDebug> |
|
19 #include "caclientnotifierproxy.h" |
|
20 #include "caentry.h" |
|
21 #include "cainnerentry.h" |
|
22 #include "caobjectadapter.h" |
|
23 |
|
24 //---------------------------------------------------------------------------- |
|
25 // |
|
26 //---------------------------------------------------------------------------- |
|
27 CaClientNotifierProxy::CaClientNotifierProxy(QObject *parent) : |
|
28 QObject(parent) |
|
29 { |
|
30 } |
|
31 //---------------------------------------------------------------------------- |
|
32 // |
|
33 //---------------------------------------------------------------------------- |
|
34 CaClientNotifierProxy::~CaClientNotifierProxy() |
|
35 { |
|
36 } |
|
37 |
|
38 //---------------------------------------------------------------------------- |
|
39 // |
|
40 //---------------------------------------------------------------------------- |
|
41 void CaClientNotifierProxy::entryChanged(TInt entryId, |
|
42 TChangeType changeType) const |
|
43 { |
|
44 qDebug() << "CaClientProxy::entryChanged entryId:" |
|
45 << entryId << "changeType:" << changeType; |
|
46 |
|
47 int entryChangedId(entryId); |
|
48 ChangeType entryChangeType(AddChangeType); |
|
49 CaObjectAdapter::convert(changeType, entryChangeType); |
|
50 |
|
51 emit signalEntryChanged(entryChangedId, entryChangeType); |
|
52 } |
|
53 |
|
54 //---------------------------------------------------------------------------- |
|
55 // |
|
56 //---------------------------------------------------------------------------- |
|
57 void CaClientNotifierProxy::entryChanged(const CCaInnerEntry &entry, |
|
58 TChangeType changeType) const |
|
59 { |
|
60 qDebug() << "CaClientProxy::entryChanged changeType:" << changeType; |
|
61 |
|
62 CaEntry *caEntry = new CaEntry(static_cast<EntryRole>(entry.GetRole())); |
|
63 ChangeType entryChangeType(AddChangeType); |
|
64 CaObjectAdapter::convert(entry, *caEntry); |
|
65 CaObjectAdapter::convert(changeType, entryChangeType); |
|
66 |
|
67 emit signalEntryChanged(*caEntry, entryChangeType); |
|
68 } |
|
69 |
|
70 //---------------------------------------------------------------------------- |
|
71 // |
|
72 //---------------------------------------------------------------------------- |
|
73 void CaClientNotifierProxy::entryTouched(TInt id) const |
|
74 { |
|
75 qDebug() << "CaClientProxy::entryTouched id:" << id; |
|
76 emit signalEntryTouched(id); |
|
77 } |
|
78 |
|
79 //---------------------------------------------------------------------------- |
|
80 // |
|
81 //---------------------------------------------------------------------------- |
|
82 void CaClientNotifierProxy::groupContentChanged(TInt groupId) const |
|
83 { |
|
84 qDebug() << "CaClientProxy::groupContentChanged groupId:" << groupId; |
|
85 |
|
86 int groupChangedId(groupId); |
|
87 |
|
88 emit signalGroupContentChanged(groupChangedId); |
|
89 } |
|
90 |
|
91 //---------------------------------------------------------------------------- |
|
92 // |
|
93 //---------------------------------------------------------------------------- |
|
94 int CaClientNotifierProxy::registerNotifier( |
|
95 const CaNotifierFilter *notifierFilter, |
|
96 CaNotifierPrivate::NotifierType notifierType, |
|
97 const CaClientNotifierProxy *notifierProxy) |
|
98 { |
|
99 qDebug() << "CaClientProxy::registerNotifier notifierType:" |
|
100 << notifierType; |
|
101 |
|
102 CCaInnerNotifierFilter::TNotifierType innerNotifierType( |
|
103 CCaInnerNotifierFilter::EEntryChangedWithId); |
|
104 |
|
105 CaObjectAdapter::convert(notifierType, |
|
106 innerNotifierType); |
|
107 CCaInnerNotifierFilter *innerNotifierFilter(NULL); |
|
108 |
|
109 TRAPD(error, |
|
110 innerNotifierFilter = |
|
111 CCaInnerNotifierFilter::NewLC(innerNotifierType); |
|
112 CaObjectAdapter::convertL(*notifierFilter, *innerNotifierFilter); |
|
113 CleanupStack::Pop(innerNotifierFilter) |
|
114 ); |
|
115 |
|
116 if (!error) { |
|
117 // Lock the access to mSessions. |
|
118 // It will be automatically unlocked at the end of the current range. |
|
119 QMutexLocker locker(&mMutex); |
|
120 RCaClientNotifierSession *session = findSession(); |
|
121 if (!session) { |
|
122 session = newSession(error); |
|
123 } |
|
124 if (!error) { |
|
125 error = session->RegisterNotifier(innerNotifierFilter, |
|
126 notifierFilter, notifierProxy); |
|
127 } |
|
128 } |
|
129 |
|
130 qDebug() << "CaClientProxy::registerNotifier result:" << error; |
|
131 |
|
132 return error; |
|
133 } |
|
134 |
|
135 //---------------------------------------------------------------------------- |
|
136 // |
|
137 //---------------------------------------------------------------------------- |
|
138 void CaClientNotifierProxy::unregisterNotifier( |
|
139 const CaNotifierFilter ¬ifierFilter, |
|
140 CaNotifierPrivate::NotifierType notifierType) |
|
141 { |
|
142 qDebug() << "CaClientProxy::unregisterNotifier notifierType:" |
|
143 << notifierType; |
|
144 |
|
145 CCaInnerNotifierFilter::TNotifierType innerNotifierType( |
|
146 CCaInnerNotifierFilter::EEntryChangedWithId); |
|
147 CaObjectAdapter::convert( |
|
148 notifierType, |
|
149 innerNotifierType); |
|
150 TInt pos = findSession(notifierFilter, innerNotifierType); |
|
151 if (pos != KErrNotFound) { |
|
152 // Lock the access to mSessions. |
|
153 // It will be automatically unlocked at the end of the current range. |
|
154 QMutexLocker locker(&mMutex); |
|
155 mSessions[pos].UnregisterNotifier(¬ifierFilter, |
|
156 innerNotifierType); |
|
157 if (mSessions[pos].SubsessionsCount() == 0) { |
|
158 mSessions[pos].Close(); |
|
159 mSessions.Remove(pos); |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 //---------------------------------------------------------------------------- |
|
165 // |
|
166 //---------------------------------------------------------------------------- |
|
167 RCaClientNotifierSession *CaClientNotifierProxy::findSession() |
|
168 { |
|
169 RCaClientNotifierSession *session(NULL); |
|
170 TInt count(mSessions.Count()); |
|
171 for (int i = 0; i < count; i++) { |
|
172 if (mSessions[i].SubsessionsCount() < KDefaultMessageSlots) { |
|
173 session = &mSessions[i]; |
|
174 break; |
|
175 } |
|
176 } |
|
177 return session; |
|
178 } |
|
179 |
|
180 //---------------------------------------------------------------------------- |
|
181 // |
|
182 //---------------------------------------------------------------------------- |
|
183 TInt CaClientNotifierProxy::findSession( |
|
184 const CaNotifierFilter ¬ifierFilter, |
|
185 CCaInnerNotifierFilter::TNotifierType innerNotifierType) const |
|
186 { |
|
187 TInt count(mSessions.Count()); |
|
188 TInt pos(KErrNotFound); |
|
189 for (int i = 0; i < count; i++) { |
|
190 if (mSessions[i].ContainsSubsession(¬ifierFilter, |
|
191 innerNotifierType)) { |
|
192 pos = i; |
|
193 break; |
|
194 } |
|
195 } |
|
196 return pos; |
|
197 } |
|
198 |
|
199 //---------------------------------------------------------------------------- |
|
200 // |
|
201 //---------------------------------------------------------------------------- |
|
202 RCaClientNotifierSession *CaClientNotifierProxy::newSession(TInt &error) |
|
203 { |
|
204 RCaClientNotifierSession session; |
|
205 error = session.Connect(); |
|
206 if (!error) { |
|
207 error = mSessions.Append(session); |
|
208 } |
|
209 if (error) { |
|
210 session.Close(); |
|
211 qDebug("CaClientProxy::newSession: error (%d)", error); |
|
212 return NULL; |
|
213 } else { |
|
214 return &mSessions[mSessions.Count() - 1]; |
|
215 } |
|
216 } |