Coder Social home page Coder Social logo

libmaia's Introduction

libmaia

libmaia is a easy-to-use XML-RPC library for Qt!

compiling libmaia

qmake
make

Qt Datatypes

Allowed types for Argument and Return Values:

C++/Qt-Types	XMLRPC-Types
----------------------------------------
* int           <int></int>
* qint64        <long></long>                         (non standard)
* bool          <bool></bool>
* double        <double></double>
* QString       <string></string>
* QDateTime     <datetime.iso8601></datetime.iso8601>
* ByteArray     <base64></base64>
* QVariant      <nil/>                                (non standard)
* QVariantMap   <struct></struct>
* QVariantList  <array></array>

using libmaia

  1. qmake: your Project file (.pro) should contain

    INCLUDEPATH += /path/to/libmaia
    LIBS += /path/to/libmaia/libmaia.a
    QT   += xml network
    
  2. in your header file include

     #include "maiaXmlRpcClient.h"
    

    and / or

     #include "maiaXmlRpcServer.h"
    
  3. create object

    server:

     MaiaXmlRpcServer *server = new MaiaXmlRpcServer(8080, this);
    

    client:

     MaiaXmlRpcClient *client = new MaiaXmlRpcClient(QUrl("http://localhost:8080/RPC2"), this);
    
  4. register a method

    your method has to be a Qt Slot.

     // example method:
     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 xml-rpc
     // this <- pointer to the class which contains the method you would export
     // "myMethod" the name of the method
     server->addMethod("example.methodName", this, "myMethod");
    
  5. call a method

    when calling a method you need three things:

    1. a Slot for the MethodResponse
    2. a Slot for the FaultResponse
    3. a QVariantList containig the arguments for the RPC-Method

    example code:

     void MyClientClass::myResponseMethod(QVariant &arg) {
     	// do something with the arg
     }
    
     void MyClientClass::myFaultResponse(int error, const QString &message) {
     	qDebug() << "An Error occoured, Code: " << error << " Message: " << message;
     }
    
     QVariantList args;
     args << 5;
     args << "second argument";
    
     rpcClient->call("example.methodName", args,
     	this, SLOT(myResponseMethod(QVariant&)),
     	this, SLOT(myFaultResponse(int, const QString &)));
    

libmaia's People

Contributors

carlos22 avatar eduardobeloni avatar mbogda avatar msarehn avatar naihil avatar olafmandel avatar tatraian avatar wiedi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libmaia's Issues

install libmaia system wide

what has to done after qmake, make to use libmaia as a wide system library?
Because i put libmaia.a to /usr/lib, but i couldn't include any of header file to the source file

make output:
fatal error: maiaXmlRpcClient.h: No such file or directory

QHttpHeader Issue

The server didn't work until I checked the MaiaXmlRpcServerConnection::readFromSocket() method. It gave me the following output:

headerString: "POST /RPC2 HTTP/1.1\r\n"
headerString: "User-Agent: XMLRPC++ 0.7\r\n"
headerString: "Host: 192.168.2.101:8888\r\n"
headerString: "Content-Type: text/xml\r\n"
headerString: "Content-length: 1252\r\n"

but statet that the header->contentLength() == 0 so that nothing happens. As you can see the contentLength isn't 0 I removed the following return statement for that check.

void MaiaXmlRpcServerConnection::readFromSocket() {
    QString lastLine;

    while(clientConnection->canReadLine() && !header) {
        lastLine = clientConnection->readLine();
        headerString += lastLine;
        if(lastLine == "\r\n") { /* http header end */
            header = new QHttpRequestHeader(headerString);
            if(!header->isValid()) {
                /* return http error */
                qDebug() << "Invalid Header";
                return;
            } else if(header->method() != "POST") {
                /* return http error */
                qDebug() << "No Post!";
                return;
            } else if(!header->contentLength()) {
                /* return fault */
                qDebug() << "No Content Length (maybe a bug in QtHttpHeader)";
                //return;
            }
        }
    }
    if(header) {
        if(header->contentLength() <= clientConnection->bytesAvailable()) {
            /* all data complete */
            parseCall(clientConnection->readAll());
        }
    }
}

Default Method

How I implement a DefaultMehtod for server like xml-rpc-c library?
A Method called by any method not registered. It could be optional using a function of type setDefaultMethod (....)

Segmentation fault when delete MaiaXmlRpcServer instance

Application crash when delete a MaiaXmlRpcServer instance.
The crash ocurs in MaiaXmlRpcServerConnection destructor in clientConnection->deleteLater(); line. Removing this line the server instance its destroyed without segmentation fault and the QTcpSocket its closed. Its posible that te clientConnection its destroyed by QTcpServer and with the deleted line in destructor it was destroyed twice.

Edit: Happen with allowPersistentConnection enabled.

array in request

Hello.
On the server has the following function:

public int func(int[] stateNum){...}

The client is doing something like this:

QVariantList args;
args<<1<<2<<3;
rpc->call("examples.func",args,
this, SLOT(testResponse(QVariant &)),
this, SLOT(testFault(int, const QString &)));

I get this error:
EEE: 0 - "request contains integer value where array expected [request : parameter 1]"
Passing a pointer to an array as a parameter leads to errors.
How to do it right? I would be very grateful to you. Thanks

Floating point rounded to too few digits

When transmitting a QVariant with type QVariant::Double (e.g. an argument to MaiaXmlRpcClient::call()), the double value gets rounded to a precision of 6 digits: this is far fewer than can be reliably expressed with double.

Suggest increasing the precision to the maximum number of base-10-digits that can be expressed in double without incurring rounding errors.

Usage Questions

Hi,

First, please forgive my misuse of the issues function on GitHub, but I didn't see any other support/QA communication methods. Secondly, great project!

I have a couple questions, and I am a mostly novice developer:

  1. When using libmaia, I'd like to make multiple RPC's to different hosts (XML-RPC service instances that reside on disjoint servers) and utilize the same RPC response/fault handler methods. Is it possible to discover what host (URL) the RPC is from when in one of the "RPC handling" methods? Due to the default asynchronous nature of Qt's signals/slots, if I make several RPC's they don't necessarily arrive in the order they were called, correct? I could obviously modify libmaia and add support for this to work for my application, but I wanted to find out if there was something obvious that I was missing first.

  2. Any thoughts on handling timeouts (eg, too long of a running RPC on the server side, or something stuck, or the XML-RPC server instance died/crashed)? Or what about performing an RPC from a client to a web server that isn't actually an XML-RPC server and doesn't respond? I haven't read up on how XML-RPC works itself, and if there is some type of handshake first, or just send from the client to the server and wait for a response. So maybe both causes of timeouts described behave the same.

Thanks for your time.

--Marc

[Qt5] Error when calling method without params

Qt 4.8.5 - all works fine
Qt 5.3.2 - client example get
EEE: -32602 - "server error: invalid method parameters"
when calling "examples.nix"

server prints: Trying to create a QVariant instance of QMetaType::Void type, an invalid QVariant will be constructed instead

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.