85
|
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: canotifier.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
94
|
18 |
#include <caservice.h>
|
|
19 |
|
85
|
20 |
#include "canotifier.h"
|
|
21 |
#include "canotifier_p.h"
|
|
22 |
#include "canotifierfilter.h"
|
|
23 |
#include "caclientnotifierproxy.h"
|
93
|
24 |
#include "caobserver.h"
|
85
|
25 |
|
|
26 |
/*!
|
|
27 |
\class CaNotifier.
|
|
28 |
\brief This class describes notifier.
|
|
29 |
|
|
30 |
\example
|
|
31 |
It's example how client can be notified about changes on data specified by client's filter
|
|
32 |
|
|
33 |
\code
|
|
34 |
// example Client class which wants to be notified about changes
|
|
35 |
|
|
36 |
class Client: public QObject
|
|
37 |
{
|
|
38 |
Q_OBJECT
|
|
39 |
...
|
|
40 |
public slots:
|
|
41 |
|
|
42 |
updateModelForEntryChanged(int,ChangeType);
|
|
43 |
updateModelForEntryChanged(const CaEntry &,ChangeType);
|
|
44 |
updateModelForEntryTouched(int);
|
|
45 |
updateModelForgroupContentChanged(int);
|
|
46 |
...
|
|
47 |
};
|
|
48 |
\endcode
|
|
49 |
|
|
50 |
\code
|
|
51 |
// example code showed how to register for notifications
|
|
52 |
Client * client;
|
|
53 |
...
|
|
54 |
QSharedPointer<CaService> service = CaService::instance();
|
|
55 |
CaNotifierFilter notifierFilter();
|
|
56 |
CaNotifier * notifier = service->createNotifier(notifierfilter);
|
|
57 |
|
94
|
58 |
CaService instance is a singleton and is deleted when nothing references
|
|
59 |
it but CaNotifier contains a member referencing it,
|
|
60 |
so, CaService instance is not deleted before notifier is deleted.
|
|
61 |
|
85
|
62 |
// Connections cause that notifier is registered to server distributed
|
|
63 |
// notifications while data changes.
|
|
64 |
if( notifier )
|
|
65 |
{
|
|
66 |
connect( notifier, SIGNAL(entryChanged(int,ChangeType)),
|
|
67 |
client, SLOT(updateModelForEntryChanged(int,ChangeType)) );
|
|
68 |
connect( notifier, SIGNAL(entryChanged(CaEntry,ChangeType)),
|
|
69 |
client, SLOT(updateModelForEntryChanged(CaEntry,ChangeType)) );
|
|
70 |
connect( notifier, SIGNAL(entryTouched(int)),
|
|
71 |
client, SLOT(updateModelForEntryTouched(int)) );
|
|
72 |
connect( notifier, SIGNAL(groupContentChanged(int)),
|
|
73 |
client, SLOT(updateModelForgroupContentChanged(int)) );
|
|
74 |
}
|
|
75 |
...
|
|
76 |
// creation new entry causes sent notification to the client
|
|
77 |
CaEntry entry;
|
|
78 |
entry.setText( "Text" );
|
|
79 |
entry.setTypeName( "TypeName" );
|
|
80 |
CaEntry * newEntry = service->createEntry( entry );
|
|
81 |
...
|
|
82 |
\endcode
|
|
83 |
|
|
84 |
\code
|
|
85 |
// here client is being get notifications new entry was created
|
|
86 |
...
|
|
87 |
Client::updateModelForEntryChanged(int entryId ,ChangeType changeType)
|
|
88 |
{
|
|
89 |
...
|
|
90 |
changeType == AddChangeType;
|
|
91 |
...
|
|
92 |
}
|
|
93 |
|
|
94 |
\endcode
|
|
95 |
|
|
96 |
*/
|
|
97 |
|
|
98 |
/*!
|
93
|
99 |
\var CaNotifierPrivate::m_q
|
|
100 |
Points to the CaNotifier instance that uses
|
|
101 |
this private implementation.
|
|
102 |
*/
|
|
103 |
|
|
104 |
/*!
|
|
105 |
\var CaNotifierPrivate::mNotifierFilter
|
|
106 |
Own.
|
|
107 |
*/
|
|
108 |
|
|
109 |
/*!
|
|
110 |
\var CaNotifierPrivate::mNotifierProxy
|
|
111 |
Not own.
|
|
112 |
*/
|
|
113 |
|
|
114 |
/*!
|
85
|
115 |
Constructor.
|
|
116 |
\param entryPrivate pointer to private implementation.
|
|
117 |
*/
|
87
|
118 |
CaNotifier::CaNotifier(CaNotifierPrivate *const notifierPrivate) :
|
85
|
119 |
QObject(0), m_d(notifierPrivate)
|
|
120 |
{
|
|
121 |
m_d->m_q = this;
|
|
122 |
m_d->makeConnect();
|
|
123 |
}
|
|
124 |
|
|
125 |
/*!
|
|
126 |
Destructor.
|
|
127 |
*/
|
|
128 |
CaNotifier::~CaNotifier()
|
|
129 |
{
|
93
|
130 |
m_d->unregisterNotifier(
|
|
131 |
CaNotifierPrivate::EntryChangedWithIdNotifierType);
|
|
132 |
m_d->unregisterNotifier(
|
|
133 |
CaNotifierPrivate::EntryChangedWithEntryNotifierType);
|
|
134 |
m_d->unregisterNotifier(
|
|
135 |
CaNotifierPrivate::EntryTouchedNotifierType);
|
|
136 |
m_d->unregisterNotifier(
|
|
137 |
CaNotifierPrivate::GroupContentChangedNotifierType);
|
85
|
138 |
delete m_d;
|
|
139 |
}
|
|
140 |
|
|
141 |
/*!
|
|
142 |
This method is called when something has been
|
|
143 |
connected to signal in this object.
|
|
144 |
\param signal which is used to register an appropriate notifier.
|
|
145 |
*/
|
|
146 |
void CaNotifier::connectNotify(const char *signal)
|
|
147 |
{
|
|
148 |
qDebug("CaNotifier::connectNotify");
|
|
149 |
qDebug("\tsignal: %s", signal);
|
|
150 |
if (QLatin1String(signal)
|
87
|
151 |
== SIGNAL(entryChanged(int,ChangeType))) {
|
|
152 |
// signal is entryChanged(int, ChangeType)
|
85
|
153 |
if (receivers(SIGNAL(entryChanged(int,ChangeType))) == 1) {
|
|
154 |
m_d->registerNotifier(
|
|
155 |
CaNotifierPrivate::EntryChangedWithIdNotifierType);
|
|
156 |
}
|
87
|
157 |
} else if (QLatin1String(signal)
|
|
158 |
== SIGNAL(entryChanged(CaEntry,ChangeType))) {
|
85
|
159 |
// signal is entryChanged(const CaEntry &, ChangeType)
|
|
160 |
if (receivers(SIGNAL(entryChanged(const CaEntry &,ChangeType))) == 1) {
|
|
161 |
m_d->registerNotifier(
|
|
162 |
CaNotifierPrivate::EntryChangedWithEntryNotifierType);
|
|
163 |
}
|
87
|
164 |
} else if (QLatin1String(signal)
|
|
165 |
== SIGNAL(entryTouched(int))) {
|
85
|
166 |
// signal is entryTouched(int)
|
|
167 |
if (receivers(SIGNAL(entryTouched(int)))) {
|
|
168 |
m_d->registerNotifier(
|
|
169 |
CaNotifierPrivate::EntryTouchedNotifierType);
|
|
170 |
}
|
87
|
171 |
} else if (QLatin1String(signal)
|
|
172 |
== SIGNAL(groupContentChanged(int))) {
|
85
|
173 |
// signal is groupContentChanged(int)
|
|
174 |
if (receivers(SIGNAL(groupContentChanged(int)))) {
|
|
175 |
m_d->registerNotifier(
|
|
176 |
CaNotifierPrivate::GroupContentChangedNotifierType);
|
|
177 |
}
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
/*!
|
|
182 |
This method is called when something has been
|
|
183 |
disconnected from signal in this object.
|
|
184 |
\param signal which is used to unregister an appropriate notifier.
|
|
185 |
*/
|
|
186 |
void CaNotifier::disconnectNotify(const char *signal)
|
|
187 |
{
|
|
188 |
qDebug("CaNotifier::disconnectNotify");
|
|
189 |
qDebug("\tsignal: %s", signal);
|
|
190 |
if (QLatin1String(signal)
|
87
|
191 |
== SIGNAL(entryChanged(int,ChangeType))) {
|
|
192 |
// signal is entryChanged(int, ChangeType)
|
|
193 |
if (receivers(SIGNAL(entryChanged(int,ChangeType)))==0) {
|
85
|
194 |
m_d->unregisterNotifier(
|
|
195 |
CaNotifierPrivate::EntryChangedWithIdNotifierType);
|
|
196 |
}
|
87
|
197 |
} else if (QLatin1String(signal)
|
|
198 |
== SIGNAL(entryChanged(CaEntry,ChangeType))) {
|
85
|
199 |
// signal is entryChanged(const CaEntry &, ChangeType)
|
|
200 |
if (receivers(SIGNAL(entryChanged(const CaEntry &,ChangeType)))==0) {
|
|
201 |
m_d->unregisterNotifier(
|
|
202 |
CaNotifierPrivate::EntryChangedWithEntryNotifierType);
|
|
203 |
}
|
87
|
204 |
} else if (QLatin1String(signal)
|
|
205 |
== SIGNAL(entryTouched(int))) {
|
85
|
206 |
// signal is entryTouched(int)
|
|
207 |
if (receivers(SIGNAL(entryTouched(int))) == 0) {
|
|
208 |
m_d->unregisterNotifier(
|
|
209 |
CaNotifierPrivate::EntryTouchedNotifierType);
|
|
210 |
}
|
87
|
211 |
} else if (QLatin1String(signal)
|
|
212 |
== SIGNAL(groupContentChanged(int))) {
|
85
|
213 |
// signal is groupContentChanged(int)
|
|
214 |
if (receivers(SIGNAL(groupContentChanged(int))) == 0) {
|
|
215 |
m_d->unregisterNotifier(
|
|
216 |
CaNotifierPrivate::GroupContentChangedNotifierType);
|
|
217 |
}
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
/*!
|
|
222 |
Constructor.
|
|
223 |
\param notifierFilter descrbies entries to observe.
|
|
224 |
*/
|
|
225 |
CaNotifierPrivate::CaNotifierPrivate(
|
93
|
226 |
const CaNotifierFilter ¬ifierFilter,
|
|
227 |
CaClientNotifierProxy *notifierProxy) :
|
85
|
228 |
m_q(NULL),
|
93
|
229 |
mNotifierFilter(NULL),
|
94
|
230 |
mObserver(NULL),
|
|
231 |
mCaService(CaService::instance())
|
85
|
232 |
{
|
93
|
233 |
mNotifierProxy = notifierProxy;
|
87
|
234 |
mNotifierFilter = new CaNotifierFilter(notifierFilter);
|
85
|
235 |
}
|
|
236 |
|
|
237 |
/*!
|
|
238 |
Destructor.
|
|
239 |
*/
|
|
240 |
CaNotifierPrivate::~CaNotifierPrivate()
|
|
241 |
{
|
|
242 |
if (mNotifierProxy) {
|
|
243 |
mNotifierProxy->unregisterNotifier(*mNotifierFilter,
|
87
|
244 |
EntryChangedWithIdNotifierType);
|
85
|
245 |
mNotifierProxy->unregisterNotifier(*mNotifierFilter,
|
87
|
246 |
EntryChangedWithEntryNotifierType);
|
85
|
247 |
mNotifierProxy->unregisterNotifier(*mNotifierFilter,
|
87
|
248 |
EntryTouchedNotifierType);
|
85
|
249 |
mNotifierProxy->unregisterNotifier(*mNotifierFilter,
|
87
|
250 |
GroupContentChangedNotifierType);
|
85
|
251 |
}
|
|
252 |
delete mNotifierFilter;
|
|
253 |
}
|
|
254 |
/*!
|
|
255 |
Registers notifier
|
|
256 |
\param notifierType type of notifier to register (class of events to listen)
|
|
257 |
*/
|
|
258 |
int CaNotifierPrivate::registerNotifier(NotifierType notifierType)
|
|
259 |
{
|
|
260 |
if (mNotifierProxy) {
|
|
261 |
return mNotifierProxy->registerNotifier(
|
87
|
262 |
mNotifierFilter,
|
|
263 |
notifierType,
|
93
|
264 |
mObserver);
|
85
|
265 |
}
|
|
266 |
return 0;
|
|
267 |
}
|
|
268 |
/*!
|
|
269 |
Unregisters notifier
|
|
270 |
\param notifierType type of notifier event type to unregister
|
|
271 |
(class of events to listen)
|
|
272 |
*/
|
|
273 |
void CaNotifierPrivate::unregisterNotifier(NotifierType notifierType)
|
|
274 |
{
|
|
275 |
if (mNotifierProxy) {
|
|
276 |
mNotifierProxy->unregisterNotifier(*mNotifierFilter, notifierType);
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
/*!
|
|
281 |
Connects this Notifier
|
|
282 |
*/
|
|
283 |
void CaNotifierPrivate::makeConnect()
|
|
284 |
{
|
|
285 |
if (m_q) {
|
93
|
286 |
mObserver = new CaObserver();
|
|
287 |
m_q->connect(mObserver,
|
87
|
288 |
SIGNAL(signalEntryChanged(int,ChangeType)),
|
|
289 |
m_q,
|
|
290 |
SIGNAL(entryChanged(int,ChangeType)));
|
93
|
291 |
m_q->connect(mObserver,
|
87
|
292 |
SIGNAL(signalEntryChanged(const CaEntry &,ChangeType)),
|
|
293 |
m_q,
|
|
294 |
SIGNAL(entryChanged(const CaEntry &,ChangeType)));
|
93
|
295 |
m_q->connect(mObserver,
|
87
|
296 |
SIGNAL(signalEntryTouched(int)),
|
|
297 |
m_q,
|
|
298 |
SIGNAL(entryTouched(int)));
|
93
|
299 |
m_q->connect(mObserver,
|
87
|
300 |
SIGNAL(signalGroupContentChanged(int)),
|
|
301 |
m_q,
|
|
302 |
SIGNAL(groupContentChanged(int)));
|
85
|
303 |
}
|
|
304 |
}
|
93
|
305 |
|