|
| 1 | +# libmaia |
| 2 | + |
| 3 | +libmaia is a easy-to-use XML-RCP library for Qt! |
| 4 | + |
| 5 | + |
| 6 | +# compiling libmaia |
| 7 | + |
| 8 | + qmake |
| 9 | + make |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +# Qt Datatypes |
| 14 | + |
| 15 | + Allowed types for Argument and Return Values: |
| 16 | + |
| 17 | + C++/Qt-Types XMLRPC-Types |
| 18 | + ---------------------------------------- |
| 19 | + * int <int></int> |
| 20 | + * bool <bool></bool> |
| 21 | + * double <double></double> |
| 22 | + * QString <string></string> |
| 23 | + * QDateTime <datetime.iso8601></datetime.iso8601> |
| 24 | + * ByteArray <base64></base64> |
| 25 | + * QVariantMap <struct></struct> |
| 26 | + * QVariantList <array></array> |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +# using libmaia |
| 31 | + |
| 32 | +1. qmake: your Project file (.pro) should contain |
| 33 | + |
| 34 | + INCLUDEPATH += /path/to/libmaia |
| 35 | + LIBS += /path/to/libmaia/libmaia.a |
| 36 | + QT += xml network |
| 37 | + |
| 38 | +2. in your header file include |
| 39 | + |
| 40 | + #include "maiaXmlRpcClient.h" |
| 41 | + |
| 42 | + and / or |
| 43 | + |
| 44 | + #include "maiaXmlRpcServer.h" |
| 45 | + |
| 46 | + |
| 47 | +3. create object |
| 48 | + |
| 49 | + server: |
| 50 | + |
| 51 | + MaiaXmlRpcServer *server = new MaiaXmlRpcServer(8080, this); |
| 52 | + |
| 53 | + client: |
| 54 | + |
| 55 | + MaiaXmlRpcClient *client = new MaiaXmlRpcClient(QUrl("http://localhost:8080/RPC2"), this); |
| 56 | + |
| 57 | + |
| 58 | +4. register a method |
| 59 | + |
| 60 | + your method has to be a Qt Slot. |
| 61 | + |
| 62 | + |
| 63 | + // example method: |
| 64 | + QString MyClass::myMethod(int param1, QString param2) { |
| 65 | + if(param1 > 5) |
| 66 | + return param2; |
| 67 | + else |
| 68 | + return "not bigger than 5"; |
| 69 | + } |
| 70 | + |
| 71 | + // register it: |
| 72 | + // "example.methodName" <- used to identify the method over xml-rpc |
| 73 | + // this <- pointer to the class which contains the method you would export |
| 74 | + // "myMethod" the name of the method |
| 75 | + server->addMethod("example.methodName", this, "myMethod"); |
| 76 | + |
| 77 | + |
| 78 | +5. call a method |
| 79 | + |
| 80 | + when calling a method you need three things: |
| 81 | + |
| 82 | + 1. a Slot for the MethodResponse |
| 83 | + 2. a Slot for the FaultResponse |
| 84 | + 3. a QVariantList containig the arguments for the RPC-Method |
| 85 | + |
| 86 | + example code: |
| 87 | + |
| 88 | + void MyClientClass::myResponseMethod(QVariant &arg) { |
| 89 | + // do something with the arg |
| 90 | + } |
| 91 | + |
| 92 | + void MyClientClass::myFaultResponse(int error, const QString &message) { |
| 93 | + qDebug() << "An Error occoured, Code: " << error << " Message: " << message; |
| 94 | + } |
| 95 | + |
| 96 | + QVariantList args; |
| 97 | + args << 5; |
| 98 | + args << "second argument"; |
| 99 | + |
| 100 | + rpcClient->call("example.methodName", args, |
| 101 | + this, SLOT(myResponseMethod(QVariant&)), |
| 102 | + this, SLOT(myFaultResponse(int, const QString &))); |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
0 commit comments