|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "../../../../src/publishsubscribe/qvaluespacesubscriber.h" |
|
43 #include "../../../../src/publishsubscribe/qvaluespacepublisher.h" |
|
44 |
|
45 #include <QCoreApplication> |
|
46 #include <QStringList> |
|
47 #include <QTimer> |
|
48 #include <QUuid> |
|
49 |
|
50 #include <QDebug> |
|
51 |
|
52 QTM_USE_NAMESPACE |
|
53 |
|
54 #define TIMEOUT 700 |
|
55 |
|
56 #define ERROR_SETVALUE_NOT_SUPPORTED 1 |
|
57 |
|
58 class Controller : public QObject |
|
59 { |
|
60 Q_OBJECT |
|
61 |
|
62 public: |
|
63 enum Function { Invalid, IpcTests, IpcInterestNotification, IpcRemoveKey }; |
|
64 |
|
65 Controller(Function function, const QUuid uuid) |
|
66 : QObject(0), index(0), abortCode(0) |
|
67 { |
|
68 switch (function) { |
|
69 case Invalid: |
|
70 QTimer::singleShot(0, this, SLOT(quit())); |
|
71 break; |
|
72 case IpcTests: |
|
73 publisher = new QValueSpacePublisher(uuid, "/usr/lackey/subdir", this); |
|
74 publisher->setObjectName("original_lackey"); |
|
75 publisher->setValue("value", 100); |
|
76 publisher->sync(); |
|
77 subscriber = new QValueSpaceSubscriber(uuid, "/usr/lackey/subdir", this); |
|
78 connect(subscriber, SIGNAL(contentsChanged()), this, SLOT(changes())); |
|
79 |
|
80 QTimer::singleShot(TIMEOUT, this, SLOT(proceed())); |
|
81 break; |
|
82 case IpcInterestNotification: |
|
83 publisher = new QValueSpacePublisher(uuid, "/ipcInterestNotification", this); |
|
84 connect(publisher, SIGNAL(interestChanged(QString,bool)), |
|
85 this, SLOT(interestChanged(QString,bool))); |
|
86 break; |
|
87 case IpcRemoveKey: |
|
88 publisher = new QValueSpacePublisher(uuid, "/ipcRemoveKey", this); |
|
89 publisher->setValue("value", 100); |
|
90 publisher->sync(); |
|
91 QTimer::singleShot(TIMEOUT, this, SLOT(removeKey())); |
|
92 break; |
|
93 } |
|
94 } |
|
95 |
|
96 private slots: |
|
97 void proceed() { |
|
98 switch (index) { |
|
99 case 0: |
|
100 //qDebug() << "Setting 101"; |
|
101 publisher->setValue("value", 101); |
|
102 break; |
|
103 case 1: |
|
104 //qDebug() << "Removing"; |
|
105 publisher->resetValue("value"); |
|
106 break; |
|
107 case 2: |
|
108 //qDebug() << "Setting 102"; |
|
109 publisher->setValue("value", 102); |
|
110 break; |
|
111 case 3: |
|
112 qDebug() << "Removing"; |
|
113 publisher->resetValue("value"); |
|
114 break; |
|
115 } |
|
116 publisher->sync(); |
|
117 |
|
118 index++; |
|
119 if (index == 4) |
|
120 QTimer::singleShot(TIMEOUT, qApp, SLOT(quit())); |
|
121 else |
|
122 QTimer::singleShot(TIMEOUT, this, SLOT(proceed())); |
|
123 } |
|
124 |
|
125 void abort() { |
|
126 qApp->exit(abortCode); |
|
127 } |
|
128 |
|
129 void changes() |
|
130 { |
|
131 //qDebug() << "changes:" << subscriber->value("mine", 6).toInt(); |
|
132 } |
|
133 |
|
134 void interestChanged(const QString &attribute, bool interested) |
|
135 { |
|
136 //qDebug() << Q_FUNC_INFO << path << interested; |
|
137 if (interested) { |
|
138 if (attribute == "/value") |
|
139 publisher->setValue(attribute, 5); |
|
140 } else { |
|
141 publisher->resetValue(attribute); |
|
142 } |
|
143 } |
|
144 |
|
145 void removeKey() |
|
146 { |
|
147 if (publisher) { |
|
148 delete publisher; |
|
149 publisher = 0; |
|
150 } |
|
151 |
|
152 QTimer::singleShot(TIMEOUT, qApp, SLOT(quit())); |
|
153 } |
|
154 |
|
155 private: |
|
156 QValueSpacePublisher *publisher; |
|
157 QValueSpaceSubscriber *subscriber; |
|
158 int index; |
|
159 int abortCode; |
|
160 }; |
|
161 |
|
162 int main(int argc, char** argv) |
|
163 { |
|
164 QCoreApplication app(argc, argv); |
|
165 QStringList arguments = app.arguments(); |
|
166 arguments.takeFirst(); |
|
167 |
|
168 if (arguments.count() != 2) { |
|
169 qWarning("lackey expects 2 arguments."); |
|
170 return 1; |
|
171 } |
|
172 |
|
173 Controller::Function function = Controller::Invalid; |
|
174 { |
|
175 const QString arg = arguments.takeFirst(); |
|
176 |
|
177 if (arg == "-ipcTests") { |
|
178 function = Controller::IpcTests; |
|
179 } else if (arg == "-ipcInterestNotification") { |
|
180 function = Controller::IpcInterestNotification; |
|
181 } else if (arg == "-ipcRemoveKey") { |
|
182 function = Controller::IpcRemoveKey; |
|
183 } |
|
184 } |
|
185 |
|
186 QUuid uuid(arguments.takeFirst()); |
|
187 |
|
188 Controller controler(function, uuid); |
|
189 qDebug() << "Starting lackey"; |
|
190 return app.exec(); |
|
191 } |
|
192 |
|
193 #include "main.moc" |