|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "xqservicelog.h" |
|
23 #include "xqrequestutil.h" |
|
24 #include "xqserviceutil.h" |
|
25 |
|
26 #include <QCoreApplication> |
|
27 #include <QStringList> |
|
28 |
|
29 #include <apgcli.h> |
|
30 #include <apacmdln.h> |
|
31 #include <apgtask.h> |
|
32 #include <coemain.h> |
|
33 #include <e32std.h> |
|
34 #include <w32std.h> // RWsSession |
|
35 #include <apacmdln.h> |
|
36 #include <eikenv.h> |
|
37 |
|
38 // ======== LOCAL FUNCTIONS ======== |
|
39 static bool isKeySet(const QString &key) |
|
40 { |
|
41 XQSERVICE_DEBUG_PRINT("XQServiceUtil isKeySet %s", qPrintable(key)); |
|
42 QStringList args = QCoreApplication::arguments(); |
|
43 foreach (QString arg, args) |
|
44 { |
|
45 XQSERVICE_DEBUG_PRINT("arg: %s", qPrintable(arg)); |
|
46 if (!arg.compare(key,Qt::CaseInsensitive)) |
|
47 { |
|
48 XQSERVICE_DEBUG_PRINT("Key set"); |
|
49 return true; |
|
50 } |
|
51 } |
|
52 XQSERVICE_DEBUG_PRINT("Key not set"); |
|
53 return false; |
|
54 |
|
55 } |
|
56 |
|
57 static bool isKeySet(int argc, char **argv, const QString &key) |
|
58 { |
|
59 XQSERVICE_DEBUG_PRINT("XQServiceUtil argv isKeySet %s", qPrintable(key)); |
|
60 for (int i=0; i < argc; i++) |
|
61 { |
|
62 QString arg(argv[i]); |
|
63 XQSERVICE_DEBUG_PRINT("arg: %s", qPrintable(arg)); |
|
64 if (!arg.compare(key,Qt::CaseInsensitive)) { |
|
65 XQSERVICE_DEBUG_PRINT("Key set"); |
|
66 return true; |
|
67 } |
|
68 } |
|
69 XQSERVICE_DEBUG_PRINT("Key not set"); |
|
70 return false; |
|
71 |
|
72 } |
|
73 |
|
74 |
|
75 |
|
76 static QString keyValue(const QString &key) |
|
77 { |
|
78 XQSERVICE_DEBUG_PRINT("XQServiceUtil keyValue %s", qPrintable(key)); |
|
79 QString ret; |
|
80 QStringList args = QCoreApplication::arguments(); |
|
81 foreach (QString arg, args) { |
|
82 if (arg.contains(key,Qt::CaseInsensitive)) { |
|
83 QStringList l= arg.split("="); |
|
84 ret = l.value(1); |
|
85 } |
|
86 } |
|
87 XQSERVICE_DEBUG_PRINT("key value=%s", qPrintable(ret)); |
|
88 return ret; |
|
89 } |
|
90 |
|
91 |
|
92 static QString keyValue(int argc, char **argv, const QString &key) |
|
93 { |
|
94 XQSERVICE_DEBUG_PRINT("XQServiceUtil argv keyValue %s", qPrintable(key)); |
|
95 QString ret; |
|
96 for (int i=0; i < argc; i++) |
|
97 { |
|
98 QString arg(argv[i]); |
|
99 XQSERVICE_DEBUG_PRINT("arg: %s", qPrintable(arg)); |
|
100 if (arg.contains(key,Qt::CaseInsensitive)) { |
|
101 QStringList l= arg.split("="); |
|
102 ret = l.value(1); |
|
103 } |
|
104 } |
|
105 XQSERVICE_DEBUG_PRINT("key value=%s", qPrintable(ret)); |
|
106 return ret; |
|
107 } |
|
108 |
|
109 |
|
110 // ======== MEMBER FUNCTIONS ======== |
|
111 |
|
112 /*! |
|
113 Send service application to backround in asynchronous service call. |
|
114 \param value Defines should application be send to backround (if set to true) |
|
115 or to be brought back to foreground (if set to false) |
|
116 */ |
|
117 void XQServiceUtil::toBackground( bool value ) |
|
118 { |
|
119 XQSERVICE_DEBUG_PRINT("XQServiceUtil::toBackground"); |
|
120 XQSERVICE_DEBUG_PRINT("value: %d", value); |
|
121 RWsSession ws; |
|
122 int sid = RProcess().SecureId().iId; // Assumes UID3 == SID !!! |
|
123 XQSERVICE_DEBUG_PRINT("sid: %d", sid); |
|
124 if (ws.Connect() == KErrNone) { |
|
125 XQSERVICE_DEBUG_PRINT("Connected to window server"); |
|
126 TApaTaskList tasklist(ws); |
|
127 TApaTask task = tasklist.FindApp(TUid::Uid(sid)); |
|
128 XQSERVICE_DEBUG_PRINT("task.Exists(): %x", task.Exists()); |
|
129 if (task.Exists()) { |
|
130 if (value) { |
|
131 task.SendToBackground(); |
|
132 } |
|
133 else { |
|
134 task.BringToForeground(); |
|
135 } |
|
136 } |
|
137 |
|
138 ws.Close(); |
|
139 } |
|
140 } |
|
141 |
|
142 /*! |
|
143 Check if service application is being launched as an embedded application. |
|
144 This information is passed in the command line arguments to started service application. |
|
145 \return true if service application is as an embedded application, otherwise false. |
|
146 */ |
|
147 bool XQServiceUtil::isEmbedded() |
|
148 { |
|
149 XQSERVICE_DEBUG_PRINT("XQServiceUtil::isEmbedded"); |
|
150 return isKeySet(QString::fromLatin1(XQServiceUtils::StartupArgEmbedded)); |
|
151 } |
|
152 |
|
153 /*! |
|
154 Check if service application is being launched as service (other include stand-alone launch |
|
155 or activity launch). This information is valid upon service application launch. It is passed |
|
156 in the command line arguments so can be used already in main() function before initializing any UI. |
|
157 \return true if launched as service, false otherwise (lanched as stand-alone or activity or other mode). |
|
158 */ |
|
159 bool XQServiceUtil::isService() |
|
160 { |
|
161 XQSERVICE_DEBUG_PRINT("XQServiceUtil::isService"); |
|
162 return isKeySet(QString::fromLatin1(XQServiceUtils::StartupArgService)); |
|
163 } |
|
164 |
|
165 /*! |
|
166 Returns the interface name part of the full service name to be called later. |
|
167 This information is valid upon service application launch. It is passed |
|
168 in the command line arguments so can be used already in main() function before |
|
169 initializing any UI. For example for initializing only necessary components, |
|
170 for generating interface specific UI etc. |
|
171 \return Interface name part of the full service name. |
|
172 - \b Note: The service name part should be known already by the service provider implicitly. |
|
173 */ |
|
174 QString XQServiceUtil::interfaceName() |
|
175 { |
|
176 XQSERVICE_DEBUG_PRINT("XQServiceUtil::interfaceName"); |
|
177 return keyValue(QString::fromLatin1(XQServiceUtils::StartupArgInterfaceName)); |
|
178 } |
|
179 |
|
180 /*! |
|
181 Returns the operation name within the interfaceName() to be called later. |
|
182 This information is valid upon service application launch. It is passed |
|
183 in the command line arguments so can be used already in main() function before |
|
184 initializing any UI. For example for initializing only necessary components |
|
185 for the coming slot call. |
|
186 \return Operation name within the interfaceName() |
|
187 */ |
|
188 QString XQServiceUtil::operationName() |
|
189 { |
|
190 XQSERVICE_DEBUG_PRINT("XQServiceUtil::operationName"); |
|
191 return keyValue(QString::fromLatin1(XQServiceUtils::StartupArgOperationName)); |
|
192 } |
|
193 |
|
194 /*! |
|
195 |
|
196 */ |
|
197 QString XQServiceUtil::serviceName() |
|
198 { |
|
199 XQSERVICE_DEBUG_PRINT("XQServiceUtil::serviceName"); |
|
200 return keyValue(QString::fromLatin1(XQServiceUtils::StartupArgServiceName)); |
|
201 } |
|
202 |
|
203 /*! |
|
204 Check if service application is being launched as an embedded application, |
|
205 based on passed \a argv arguments. |
|
206 \param argc Number of command line arguments. |
|
207 \param argv List of command line arguments. |
|
208 \return true if service application is as an embedded application, otherwise false. |
|
209 \sa isEmbedded() |
|
210 */ |
|
211 bool XQServiceUtil::isEmbedded(int argc, char **argv) |
|
212 { |
|
213 XQSERVICE_DEBUG_PRINT("XQServiceUtil::isEmbedded argv"); |
|
214 return isKeySet(argc,argv,QString::fromLatin1(XQServiceUtils::StartupArgEmbedded)); |
|
215 } |
|
216 |
|
217 /*! |
|
218 Check if service application is being launched as service (other include stand-alone launch |
|
219 or activity launch), based on passed \a argv arguments. |
|
220 \param argc Number of command line arguments. |
|
221 \param argv List of command line arguments. |
|
222 \return true if launched as service, false otherwise (lanched as stand-alone or activity or other mode). |
|
223 \sa isService() |
|
224 */ |
|
225 bool XQServiceUtil::isService(int argc, char **argv) |
|
226 { |
|
227 XQSERVICE_DEBUG_PRINT("XQServiceUtil::isService argv"); |
|
228 return isKeySet(argc,argv,QString::fromLatin1(XQServiceUtils::StartupArgService)); |
|
229 } |
|
230 |
|
231 /*! |
|
232 Returns the interface name part of the full service name to be called later, |
|
233 based on passed \a argv arguments. |
|
234 \param argc Number of command line arguments. |
|
235 \param argv List of command line arguments. |
|
236 \return Interface name part of the full service name. |
|
237 \sa interfaceName() |
|
238 */ |
|
239 QString XQServiceUtil::interfaceName(int argc, char **argv) |
|
240 { |
|
241 XQSERVICE_DEBUG_PRINT("XQServiceUtil::interfaceName"); |
|
242 return keyValue(argc,argv,QString::fromLatin1(XQServiceUtils::StartupArgInterfaceName)); |
|
243 } |
|
244 |
|
245 /*! |
|
246 Returns the operation name within the interfaceName() to be called later, |
|
247 based on passed \a argv arguments. |
|
248 \param argc Number of command line arguments. |
|
249 \param argv List of command line arguments. |
|
250 \return Operation name within the interfaceName() |
|
251 \sa operationName() |
|
252 */ |
|
253 QString XQServiceUtil::operationName(int argc, char **argv) |
|
254 { |
|
255 XQSERVICE_DEBUG_PRINT("XQServiceUtil::operationName argv"); |
|
256 return keyValue(argc,argv,QString::fromLatin1(XQServiceUtils::StartupArgOperationName)); |
|
257 } |
|
258 |
|
259 /*! |
|
260 |
|
261 */ |
|
262 QString XQServiceUtil::serviceName(int argc, char **argv) |
|
263 { |
|
264 XQSERVICE_DEBUG_PRINT("XQServiceUtil::serviceName argv"); |
|
265 return keyValue(argc,argv,QString::fromLatin1(XQServiceUtils::StartupArgServiceName)); |
|
266 } |
|
267 |