00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef QTDBUSXML_H_
00028 #define QTDBUSXML_H_
00029
00030 #include <casa/Containers/Record.h>
00031
00032 #include <QDomDocument>
00033 #include <QDBusArgument>
00034 #include <QMetaType>
00035
00036 namespace casa {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 class QtDBusXML {
00056 public:
00057
00058
00059
00060
00061
00062 static QtDBusXML constructXML(const String& from = "",
00063 const String& to = "", const String& methodName = "",
00064 bool methodIsAsync = false, const Record& methodParams = Record(),
00065 const Record& retValue = Record()) {
00066 return constructXML(QString(from.c_str()), QString(to.c_str()),
00067 QString(methodName.c_str()), methodIsAsync, methodParams,
00068 retValue); }
00069 static QtDBusXML constructXML(const QString& from = "",
00070 const QString& to = "", const QString& methodName = "",
00071 bool methodIsAsync = false, const Record& methodParams = Record(),
00072 const Record& retValue = Record());
00073
00074
00075
00076
00077 static QtDBusXML fromString(const String& xmlStr) {
00078 return fromString(QString(xmlStr.c_str())); }
00079 static QtDBusXML fromString(const QString& xmlStr);
00080
00081
00082
00083
00084
00085 static void extractXML(const QtDBusXML& xml, String* time = NULL,
00086 String* from = NULL, String* to = NULL, String* methodName = NULL,
00087 Record* methodParams = NULL, Record* retValue = NULL) {
00088 QString* qtime = NULL, *qfrom = NULL, *qto = NULL, *qmethodName = NULL;
00089 if(time != NULL) qtime = new QString();
00090 if(from != NULL) qfrom = new QString();
00091 if(to != NULL) qto = new QString();
00092 if(methodName != NULL) qmethodName = new QString();
00093 extractXML(xml, qtime, qfrom, qto, qmethodName, methodParams,retValue);
00094 if(time != NULL) { *time = qtime->toStdString(); delete qtime; }
00095 if(from != NULL) { *from = qfrom->toStdString(); delete qfrom; }
00096 if(to != NULL) { *to = qto->toStdString(); delete qto; }
00097 if(methodName != NULL) { *methodName = qmethodName->toStdString();
00098 delete qmethodName; }
00099 }
00100 static void extractXML(const QtDBusXML& xml, QString* time = NULL,
00101 QString* from = NULL, QString* to = NULL, QString* methodName=NULL,
00102 Record* methodParams = NULL, Record* retValue = NULL);
00103
00104
00105
00106
00107
00108
00109 QtDBusXML();
00110
00111
00112 QtDBusXML(const QtDBusXML& copy);
00113
00114
00115 virtual ~QtDBusXML();
00116
00117
00118
00119
00120 String time() const { return qtime().toStdString(); }
00121 QString qtime() const;
00122
00123
00124
00125 void setTime();
00126
00127
00128
00129 String from() const { return qfrom().toStdString(); }
00130 QString qfrom() const;
00131 void setFrom(const String& value) { setFrom(QString(value.c_str())); }
00132 void setFrom(const QString& value);
00133
00134
00135
00136
00137 String to() const { return qto().toStdString(); }
00138 QString qto() const;
00139 void setTo(const String& value) { setTo(QString(value.c_str())); }
00140 void setTo(const QString& value);
00141
00142
00143
00144
00145
00146 String methodName() const { return qmethodName().toStdString(); }
00147 QString qmethodName() const;
00148 bool methodIsAsync() const;
00149 void setMethodName(const String& value, bool isAsync = false) {
00150 setMethodName(QString(value.c_str()), isAsync); }
00151 void setMethodName(const QString& value, bool isAsync = false);
00152 void setMethodIsAsync(bool value);
00153
00154
00155
00156
00157
00158 String methodParamType(const String& paramName) const {
00159 return qmethodParamType(QString(paramName.c_str())).toStdString(); }
00160 QString qmethodParamType(const QString& paramName) const;
00161
00162
00163
00164
00165
00166 bool methodParamIsBool(const String& paramName) const;
00167 bool methodParamIsInt(const String& paramName) const;
00168 bool methodParamIsUInt(const String& paramName) const;
00169 bool methodParamIsDouble(const String& paramName) const;
00170 bool methodParamIsString(const String& paramName) const;
00171 bool methodParamIsRecord(const String& paramName) const;
00172 bool methodParamIsArrayBool(const String& paramName) const;
00173 bool methodParamIsArrayInt(const String& paramName) const;
00174
00175
00176
00177
00178
00179
00180
00181 bool methodParamBool(const String& paramName) const {
00182 return methodParamBool(QString(paramName.c_str())); }
00183 bool methodParamBool(const QString& paramName) const;
00184 int methodParamInt(const String& paramName) const {
00185 return methodParamInt(QString(paramName.c_str())); }
00186 int methodParamInt(const QString& paramName) const;
00187 uInt methodParamUInt(const String& paramName) const {
00188 return methodParamUInt(QString(paramName.c_str())); }
00189 uInt methodParamUInt(const QString& paramName) const;
00190 double methodParamDouble(const String& paramName) const {
00191 return methodParamDouble(QString(paramName.c_str())); }
00192 double methodParamDouble(const QString& paramName) const;
00193 String methodParamString(const String& paramName) const {
00194 return methodParamQString(QString(paramName.c_str())).toStdString(); }
00195 QString methodParamQString(const QString& paramName) const;
00196 Record methodParamRecord(const String& paramName) const {
00197 return methodParamRecord(QString(paramName.c_str())); }
00198 Record methodParamRecord(const QString& paramName) const;
00199 Array<Bool> methodParamArrayBool(const String& paramName) const {
00200 return methodParamArrayBool(QString(paramName.c_str())); }
00201 Array<Bool> methodParamArrayBool(const QString& paramName) const;
00202 Array<Int> methodParamArrayInt(const String& paramName) const {
00203 return methodParamArrayInt(QString(paramName.c_str())); }
00204 Array<Int> methodParamArrayInt(const QString& paramName) const;
00205
00206
00207
00208
00209
00210 void setMethodParam(const String& paramName, bool value) {
00211 setMethodParam(QString(paramName.c_str()), value); }
00212 void setMethodParam(const QString& paramName, bool value);
00213 void setMethodParam(const String& paramName, int value) {
00214 setMethodParam(QString(paramName.c_str()), value); }
00215 void setMethodParam(const QString& paramName, int value);
00216 void setMethodParam(const String& paramName, uInt value) {
00217 setMethodParam(QString(paramName.c_str()), value); }
00218 void setMethodParam(const QString& paramName, uInt value);
00219 void setMethodParam(const String& paramName, double value) {
00220 setMethodParam(QString(paramName.c_str()), value); }
00221 void setMethodParam(const QString& paramName, double value);
00222 void setMethodParam(const String& paramName, const String& value) {
00223 setMethodParam(QString(paramName.c_str()), QString(value.c_str())); }
00224 void setMethodParam(const QString& paramName, const QString& value);
00225 void setMethodParam(const String& paramName, const Record& value) {
00226 setMethodParam(QString(paramName.c_str()), value); }
00227 void setMethodParam(const QString& paramName, const Record& value);
00228 void setMethodParam(const String& paramName, const Array<bool>& value) {
00229 setMethodParam(QString(paramName.c_str()), value); }
00230 void setMethodParam(const QString& paramName, const Array<bool>& value);
00231 void setMethodParam(const String& paramName, const Array<int>& value) {
00232 setMethodParam(QString(paramName.c_str()), value); }
00233 void setMethodParam(const QString& paramName, const Array<int>& value);
00234
00235
00236
00237
00238 Record methodParams() const;
00239 void setMethodParams(const Record& parameters);
00240
00241
00242
00243 bool returnedSet() const { return !qreturnedType().isEmpty(); }
00244
00245
00246
00247 String returnedType() const { return qreturnedType().toStdString(); }
00248 QString qreturnedType() const;
00249
00250
00251
00252
00253 bool returnedIsBool() const;
00254 bool returnedIsInt() const;
00255 bool returnedIsUInt() const;
00256 bool returnedIsDouble() const;
00257 bool returnedIsString() const;
00258 bool returnedIsRecord() const;
00259 bool returnedIsArrayBool() const;
00260 bool returnedIsArrayInt() const;
00261
00262
00263
00264
00265
00266
00267 bool returnedBool() const;
00268 int returnedInt() const;
00269 uInt returnedUInt() const;
00270 double returnedDouble() const;
00271 String returnedString() const { return returnedQString().toStdString(); }
00272 QString returnedQString() const;
00273 Record returnedRecord() const;
00274 Array<bool> returnedArrayBool() const;
00275 Array<int> returnedArrayInt() const;
00276
00277
00278
00279
00280 void setReturnedValue(bool value);
00281 void setReturnedValue(int value);
00282 void setReturnedValue(uInt value);
00283 void setReturnedValue(double value);
00284 void setReturnedValue(const String& value) {
00285 setReturnedValue(QString(value.c_str())); }
00286 void setReturnedValue(const QString& value);
00287 void setReturnedValue(const Record& value);
00288 void setReturnedValue(const Array<Bool>& value);
00289 void setReturnedValue(const Array<Int>& value);
00290
00291
00292
00293
00294 Record returnedValue() const;
00295 void setReturnedValueRec(const Record& retValue);
00296
00297
00298
00299
00300
00301 String toXMLString() const { return toXMLQString().toStdString(); }
00302 QString toXMLQString() const;
00303
00304
00305
00307
00308 bool fromXMLString(const String& value) {
00309 return fromXMLString(QString(value.c_str())); }
00310 bool fromXMLString(const QString& value);
00311
00312
00313
00314
00315 QDomDocument& domDocument();
00316 const QDomDocument& domDocument() const;
00317
00318
00319
00320
00321 QtDBusXML& operator=(const QtDBusXML& copy);
00322
00323 private:
00324
00325 QDomDocument itsXML_;
00326
00327
00328
00329 void initialize();
00330
00331
00332 QString elemChildText(const QString& name) const {
00333 return elemChildText(itsXML_, name, false); }
00334
00335
00336 void setElemChildText(const QString& name, const QString& value) {
00337 setElemChildText(itsXML_, name, value, true); }
00338
00339
00340
00341 QDomElement methodParam(const QString& paramName,
00342 bool createIfAbsent = false) const;
00343
00344
00345 void setMethodParam(const QString& name, const QString& type,
00346 const QString& value);
00347
00348
00349 void setReturnedValue(const QString& type, const QString& value);
00350
00351
00352
00353
00354
00355
00356 static bool qstringToBool(const QString& value);
00357 static QString qstringFromBool(bool value);
00358
00359
00360
00361
00362
00363
00364
00365 static QDomElement elemChild(QDomDocument doc, const QString& name,
00366 bool createIfAbsent = false) {
00367 return elemChild(doc.documentElement(), name, createIfAbsent); }
00368 static QDomElement elemChild(QDomElement elem, const QString& name,
00369 bool createIfAbsent = false);
00370
00371
00372
00373
00374
00375 static QString elemChildText(QDomDocument doc, const QString& name,
00376 bool createIfAbsent = false) {
00377 return elemChildText(doc.documentElement(), name, createIfAbsent); }
00378 static QString elemChildText(QDomElement elem, const QString& name,
00379 bool createIfAbsent = false) {
00380 return elemChild(elem, name, createIfAbsent).text();
00381 }
00382
00383
00384
00385
00386
00387 static void setElemChildText(QDomDocument doc, const QString& name,
00388 const QString& value, bool createIfAbsent = false) {
00389 setElemChildText(doc.documentElement(), name, value, createIfAbsent); }
00390 static void setElemChildText(QDomElement elem, const QString& name,
00391 const QString& value, bool createIfAbsent = false) {
00392 setElemText(elemChild(elem, name, createIfAbsent), value); }
00393
00394
00395
00396
00397 static void setElemText(QDomElement elem, const QString& text);
00398
00399
00400
00401 static Record elemToRecord(QDomElement value);
00402 static void elemToRecord(Record& rec, QDomElement value);
00403 static void elemFromRecord(QDomElement elem, const Record& value);
00404
00405
00406
00407 static Array<Bool> elemToArrayBool(QDomElement value);
00408 static void elemFromArrayBool(QDomElement elem, const Array<Bool>& value);
00409
00410
00411
00412 static Array<Int> elemToArrayInt(QDomElement value);
00413 static void elemFromArrayInt(QDomElement elem, const Array<Int>& value);
00414
00415 };
00416
00417 }
00418
00419 #endif