Skip to content

Commit

Permalink
finally import the source ;)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.frubar.net/svn/libmaia/trunk@2 76f3bc84-83be-48bd-939e-545709b08832
  • Loading branch information
wiedi authored and wiedi committed Jul 15, 2010
1 parent bf3c081 commit 353a491
Show file tree
Hide file tree
Showing 22 changed files with 1,302 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
libmaia 0.2
* examples reworked

libmaia 0.1
* inital relaease
129 changes: 129 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
libmaia README
--------------

libmaia is a simple XML-RCP library for Qt4!
It makes heavy use of Qt Types and Technologies such as Signals and Slots.


HOW TO COMPILE
--------------
execute:

qmake
make


HOW TO USE
----------

1) qmake: your.pro - Project file, should contain [replace /path/to/libmaia]:

INCLUDEPATH += . ; /path/to/libmaia
LIBS += /path/to/libmaia/libmaia.a
QT += xml network

cmake: CMakeLists.txt [TODO: Make this section complete, anyone familiar with qt+cmake?!]



2) in your header file
#include "maiaXmlRpcClient.h"
AND/OR
#include "maiaXmlRpcServer.h"

4) create object

SERVER: [8080 is the Port, and this is the parent class for destruction]

MaiaXmlRpcServer server = new MaiaXmlRpcServer(8080, this);

CLIENT [First Argument = QURL of the Server, second optional parent again!]:

MaiaXmlRpcClient rpcClient = new MaiaXmlRpcClient(QUrl("http://localhost:8080/RPC2"), this);

5) GENERAL about Methods and Data Types

Allowed types for Argument and Return Values:

C++/Qt-Types XMLRPC-Types
----------------------------------------
* int <int></int
* bool <bool></bool>
* double <double></double>
* QString <string></string>
* QDateTime <datetime.iso8601></datetime.iso8601>
* ByteArray <base64></base64>
* QVariantMap <struct></struct>
* QVariantList <array></array>

PLEASE NOTE:
DO NOT USE QMap<QString, QVariant> even you know that it's the same as QVariantMap [typedef] for libmaia (or QMetaObject::invokeMethod) it is NOT!
Same is true for QVariantList!!!


5) Register a Method

//create method [must be a slot if you want to register it later!]

//in .h file
class MyClass : pulbic QObject {
Q_OBJECT

[...]

private slots:
int myMethod(int, QString);

[...]
}

//in .cpp file
QString MyClass::myMethod(int param1, QString param2) {
if(param1 > 5)
return param2;
else
return "not bigger than 5";
}

//register it
//"example.methodName" <- used to identify the method over XMLRPC
//this <- pointer to the class which contains the method you would export
//"myMethod" the Name of the Method
server->addMethod("example.methodName", this, "myMethod");

6) Call a Method

If calling a Method you need three things!
1) A Slot gets the MethodResponse
2) A Slot gets the FaultResponse
3) A QVariantList containig the arguments for the RPC-Method

1) This Method MUST have TYPES _exact_ like this:

void MyClientClass::myResponseMethod(QVariant &arg) {

//do something with the arg, there its all in!

}

2)

void MyClientClass::myFaultResponse(int error, const QString &message) {

//any fault code here, example:
qDebug() << "An Error occoured, Code: " << error << " Message: " << message;

}

3)
QVariantList args;
args << 5;
args << "this is a string, no, not what you think :>";

rpcClient->call("example.methodName", args,
this, SLOT(myResponseMethod(QVariant&)),
this, SLOT(myFaultResponse(int, const QString &)));




4 changes: 4 additions & 0 deletions examples/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EXAMPLES README
---------------

Client and Server Example
38 changes: 38 additions & 0 deletions examples/client/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "client.h"

Client::Client(QObject* parent) : QObject(parent) {
// rpc = new MaiaXmlRpcClient(QUrl("http://phpxmlrpc.sourceforge.net/server.php"), this);
rpc = new MaiaXmlRpcClient(QUrl("http://localhost:8080/RPC2"), this);

QTimer::singleShot(2000, this, SLOT(doClient()));
}

void Client::doClient() {
QVariantList args;
rpc->call("examples.nix", args,
this, SLOT(testResponse(QVariant &)),
this, SLOT(testFault(int, const QString &)));
args << QVariant(7);
rpc->call("examples.getStateName", args,
this, SLOT(testResponse(QVariant &)),
this, SLOT(testFault(int, const QString &)));
rpc->call("examples.birne", args,
this, SLOT(testResponse(QVariant &)),
this, SLOT(testFault(int, const QString &)));
args[0] = QVariant(-128);
rpc->call("examples.birne", args,
this, SLOT(testResponse(QVariant &)),
this, SLOT(testFault(int, const QString &)));
rpc->call("examples.notfound", args,
this, SLOT(testResponse(QVariant &)),
this, SLOT(testFault(int, const QString &)));
}


void Client::testResponse(QVariant &arg) {
qDebug() << arg.toString();
}

void Client::testFault(int error, const QString &message) {
qDebug() << "EEE:" << error << "-" << message;
}
23 changes: 23 additions & 0 deletions examples/client/client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef CLIENT_H
#define CLIENT_H

#include "maiaXmlRpcClient.h"

class Client : public QObject {
Q_OBJECT

public:
Client(QObject* parent = 0);

public slots:
void doClient();

private slots:
void testResponse(QVariant &);
void testFault(int, const QString &);

private:
MaiaXmlRpcClient *rpc;
};

#endif
18 changes: 18 additions & 0 deletions examples/client/client.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
######################################################################
# Automatically generated by qmake (2.01a) Fr Mai 25 19:04:58 2007
######################################################################

TEMPLATE = app
INCLUDEPATH += . ; ../../
LIBS += ../../libmaia.a

TARGET =
DEPENDPATH += .
INCLUDEPATH += .
QT += xml network
QT -= gui
CONFIG += qt silent debug

# Input
HEADERS += client.h
SOURCES += client.cpp client_main.cpp
9 changes: 9 additions & 0 deletions examples/client/client_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <QtCore>

#include "client.h"

int main( int argc, char *argv[] ) {
QCoreApplication app( argc, argv );
Client x;
return app.exec();
}
28 changes: 28 additions & 0 deletions examples/server/server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "server.h"

Server::Server(QObject* parent) : QObject(parent) {

server = new MaiaXmlRpcServer(8080, this);
server->addMethod("examples.getStateName", this, "callState");
server->addMethod("examples.birne", this, "birne");
server->addMethod("examples.nix", this, "nix");
}


QString Server::callState(int i) {
if(i < 42)
return "Banane";
else
return "Orange";
}

QVariant Server::birne(int x) {
if(x < 0)
return QVariant::fromValue(MaiaFault(7, "Birne is doof"));
else
return "Tolle Birne";
}

void Server::nix() {
qDebug() << "i got called";
}
23 changes: 23 additions & 0 deletions examples/server/server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef SERVER_H
#define SERVER_H

#include "maiaXmlRpcServer.h"

class Server : public QObject {
Q_OBJECT

public:
Server(QObject* parent = 0);

public slots:

private slots:
QString callState(int i);
QVariant birne(int x);
void nix();

private:
MaiaXmlRpcServer *server;
};

#endif
18 changes: 18 additions & 0 deletions examples/server/server.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
######################################################################
# Automatically generated by qmake (2.01a) Fr Mai 25 19:04:58 2007
######################################################################

TEMPLATE = app
INCLUDEPATH += . ; ../../
LIBS += ../../libmaia.a

TARGET =
DEPENDPATH += .
INCLUDEPATH += .
QT += xml network
QT -= gui
CONFIG += qt silent debug

# Input
HEADERS += server.h
SOURCES += server.cpp server_main.cpp
10 changes: 10 additions & 0 deletions examples/server/server_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <QtCore>

#include "maiaObject.h"
#include "server.h"

int main( int argc, char *argv[] ) {
QCoreApplication app( argc, argv );
Server x;
return app.exec();
}
17 changes: 17 additions & 0 deletions maia.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
######################################################################
# Automatically generated by qmake (2.01a) Fr Mai 25 19:04:58 2007
######################################################################

TEMPLATE = lib #app
TARGET =
CONFIG += staticlib

DEPENDPATH += .
INCLUDEPATH += .
QT += xml network
QT -= gui
CONFIG += qt silent #debug

# Input
HEADERS += maiaObject.h maiaFault.h maiaXmlRpcClient.h maiaXmlRpcServer.h maiaXmlRpcServerConnection.h
SOURCES += maiaObject.cpp maiaFault.cpp maiaXmlRpcClient.cpp maiaXmlRpcServer.cpp maiaXmlRpcServerConnection.cpp
50 changes: 50 additions & 0 deletions maiaFault.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* libMaia - maiaFault.cpp
* Copyright (c) 2007 Sebastian Wiedenroth <wiedi@frubar.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "maiaFault.h"
#include "maiaObject.h"


MaiaFault::MaiaFault(const MaiaFault &other) : QObject(other.parent()) {
fault = other.fault;
}

MaiaFault::MaiaFault(int faultCode, QString faultString, QObject *parent) : QObject(parent) {
fault["faultCode"] = faultCode;
fault["faultString"] = faultString;
}

QString MaiaFault::toString() {
QDomDocument doc;
QDomProcessingInstruction header = doc.createProcessingInstruction( "xml", QString("version=\"1.0\" encoding=\"UTF-8\"" ));
doc.appendChild(header);
QDomElement methodResponse = doc.createElement("methodResponse");
doc.appendChild(methodResponse);
QDomElement faultelement = doc.createElement("fault");
methodResponse.appendChild(faultelement);
faultelement.appendChild(MaiaObject::toXml(fault));
return doc.toString();
}
Loading

0 comments on commit 353a491

Please sign in to comment.