Giter Site home page Giter Site logo

qflow / wamp Goto Github PK

View Code? Open in Web Editor NEW
9.0 5.0 8.0 125 KB

qt implementation of wamp protocol. Contains both router and client. Could be used from C++ and QML

License: GNU Lesser General Public License v3.0

C++ 96.25% QML 1.85% CMake 1.90%

wamp's Introduction

Build Status Build status

Introduction

Router

Get sources

git clone [email protected]:qflow/wamp.git
cd wamp
git submodule update --init --remote
git submodule foreach git pull origin master
git submodule foreach git checkout master

Build

Use CMake

open main CMakeLists.txt in QtCreator

Client

QML

import QFlow.Core 1.0
import QFlow.Networking 1.0
import QFlow.Wamp 1.0

...
QtObject //example object that will be registered as "object"
    {
        id: root
        property int testInt: 5 //will be registered as "object.testInt"
        function testFunc1() //will be registerd as "object.testFunc"
        {

        }
        property list<QtObject> objList: [ //will be registered as "object.ojList"
            QtObject{property int p: 4}, //will be registered as "object.objList.0"
            QtObject{property string s: "hello"}] ////will be registered as "object.objList.1"
        property QtObject child: QtObject{ //will be registered as "object.child"
            id: child
            function substract(a,b) { //will be registered as "object.child.substract"
                    return a-b;
                }

        }
    }
    
WampConnection
    {
        id: wampConnection
        url: "ws://localhost:8080"
        realm: "realm1"
        user: WampCraUser
        {
            name: "name"
            secret: "secret"
        }
        onConnected:
        {
            wampConnection.registerProcedure("test.add", wampConnection.add); //register procedure
            wampConnection.subscribe("com.myapp.hello", function(param1){ //subscribe to event
                console.log(param1); //event received
            });
            wampConnection.registerObject("object", root); //register object with properties, functions, recursively registering children
            
            var future = wampConnection.call("test.add", [1,2]); //call remote procedure
            future.then(function(){
                console.log(future.result()); //display result
            });
            wampConnection.publish("com.myapp.hello", ["hello"]); //publish event
        }
        function add(a,b)
        {
            return a + b;
        }
        onError:
        {
            console.log(error);
        }
    }

C++

include <wampconnection.h>
using namespace QFlow;

...
//initialize wamp connection
WampConnection* con = new WampConnection();
con->setRealm("realm1");
con->setUser(new WampCraUser("name", "secret", con));
con->setUrl(QUrl("ws://localhost:8080"));
con->connect();

//use connection

//register lambda
con->registerProcedure("test.add", [](int a, int b){
        return a + b;
});
    
//register QObject
con->registerObject("object", obj);

//register method of object 'obj'
con->registerMethod("object.testFunc1", obj, "testFunc1()");

//register integer property 'testInt'. The property getter will be at "object.testInt" and the setter at "object.testInt.set"
con->registerProperty("object.testInt", obj, "testInt")

//subscribe and specify lambda callback
con->subscribe("com.myapp.hello", [](QString param1){
    qDebug() << param1; //event captured
});

//call remote procedure
Future f = con->call("test.add", {1, 2});
f.then([this](const Future& future){
    qDebug() << future.result(); //result received
});

// publish event
con->publish("com.myapp.hello", {"hello"});

wamp's People

Contributors

mfojtak avatar

Stargazers

Alex Pronin avatar Aliakbar Rashidi avatar Jeroen Oomkes avatar Brynjard Øvergård avatar Huang avatar  avatar Tim Süberkrüb avatar followtheart avatar whitglint avatar

Watchers

elderorb avatar James Cloos avatar  avatar Jeroen Oomkes avatar  avatar

wamp's Issues

Existing session

Hi,

Tell me please, can I set up the existing WAMP session?

For instance, I have some code which connected to WAMP router and has its own session ID and I do not need to login again and I want to use the existing session.

Thanks.

Implement WAMP metadata registration configuration parameter

The WAMP qflow library makes the general assumption that the WAMP client will be able to subscribe to some of the WAMP meta topics (i.e. wamp.subscription..) immediately after connection. In a secured environment where the WAMP router is using role based security, this assumption is not valid and causes errors upon connection.

These requests seem to only provide the client with information about available registered procedures. Since this functionality is not required in all version of WAMP I suggest this be some configuration parameter so that it can be disabled.

My fork contemplates this idea and I will update this issue as I work.

Disconnection detection failure

When my WAMP router shuts down (or if I lose connection to it), WAMP seems to continue to think the connection is active and crashes the application when I attempt to send a message in this state.

I believe I have a fix for some of this in my fork. I'll provide updates as I work.

Anonymous authentication causes crash

If you do not call "setUser" on the WampConnection and provide a username and password, when the WampConnection attempts to connect, the application crashes because of a memory allocation issue related to WampCraUser in the WampConnectionPrivate class

The primary issue seems to be the odd way that the parent of the WampCraUser class is managed. I believe if you just remove all the special code related to parent and use it as a standard QtObject struct, you remove any issues related to the memory management. I can't understand why the special parent management is necessary.

I have fixed this issue in my fork and will update when I have more information.

cannot build wamp.qbs

Hi, i'm trying to build your project with Qt5.5.0 on Linux 32bit but i get the following errors:

/home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/39301be37a6f50b4/moc_helperfunctions.cpp.o: nella funzione "QFlow::HelperFunctions::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)": /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/GeneratedFiles/moc_helperfunctions.cpp:165: riferimento non definito a "QFlow::FileInfo::~FileInfo()" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/GeneratedFiles/moc_helperfunctions.cpp:165: riferimento non definito a "QFlow::FileInfo::~FileInfo()" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/coreplugin.cpp.o: nella funzione "QFlow::CorePlugin::registerTypes(char const*)": /media/sf_Virtual_Machine_Xubuntu-14.04_32bit/wamp/wamp/core/src/coreplugin.cpp:61: riferimento non definito a "QFlow::FileInfo::absoluteFilePath() const" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/coreplugin.cpp.o: nella funzione "int qmlRegisterUncreatableType<QFlow::FileInfo>(char const*, int, int, char const*, QString const&)": /home/test/Qt/5.5.0/5.5/gcc/include/QtQml/qqml.h:134: riferimento non definito a "QFlow::FileInfo::staticMetaObject" /home/test/Qt/5.5.0/5.5/gcc/include/QtQml/qqml.h:157: riferimento non definito a "QFlow::FileInfo::staticMetaObject" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/coreplugin.cpp.o: nella funzione "QMetaTypeIdQObject<QFlow::FileInfo, 512>::qt_metatype_id()": /home/test/Qt/5.5.0/5.5/gcc/include/QtCore/qmetatype.h:1784: riferimento non definito a "QFlow::FileInfo::staticMetaObject" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/coreplugin.cpp.o: nella funzione "QtMetaTypePrivate::QMetaTypeFunctionHelper<QFlow::FileInfo, true>::Destruct(void*)": /home/test/Qt/5.5.0/5.5/gcc/include/QtCore/qmetatype.h:749: riferimento non definito a "QFlow::FileInfo::~FileInfo()" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/coreplugin.cpp.o: nella funzione "QtMetaTypePrivate::QMetaTypeFunctionHelper<QFlow::FileInfo, true>::Construct(void*, void const*)": /home/test/Qt/5.5.0/5.5/gcc/include/QtCore/qmetatype.h:756: riferimento non definito a "QFlow::FileInfo::FileInfo()" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/coreplugin.cpp.o: nella funzione "QtPrivate::MetaObjectForType<QFlow::FileInfo, void>::value()": /home/test/Qt/5.5.0/5.5/gcc/include/QtCore/qmetatype.h:1409: riferimento non definito a "QFlow::FileInfo::staticMetaObject" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/helperfunctions.cpp.o: nella funzione "QFlow::HelperFunctions::getFileList(QString, QString)": /media/sf_Virtual_Machine_Xubuntu-14.04_32bit/wamp/wamp/core/src/helperfunctions.cpp:80: riferimento non definito a "QFlow::FileInfo::FileInfo(QFileInfo)" /media/sf_Virtual_Machine_Xubuntu-14.04_32bit/wamp/wamp/core/src/helperfunctions.cpp:80: riferimento non definito a "QFlow::FileInfo::~FileInfo()" /media/sf_Virtual_Machine_Xubuntu-14.04_32bit/wamp/wamp/core/src/helperfunctions.cpp:80: riferimento non definito a "QFlow::FileInfo::~FileInfo()" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/helperfunctions.cpp.o: nella funzione "QFlow::HelperFunctions::getFileListRecursive(QString, QString)": /media/sf_Virtual_Machine_Xubuntu-14.04_32bit/wamp/wamp/core/src/helperfunctions.cpp:92: riferimento non definito a "QFlow::FileInfo::FileInfo(QFileInfo)" /media/sf_Virtual_Machine_Xubuntu-14.04_32bit/wamp/wamp/core/src/helperfunctions.cpp:94: riferimento non definito a "QFlow::FileInfo::~FileInfo()" /media/sf_Virtual_Machine_Xubuntu-14.04_32bit/wamp/wamp/core/src/helperfunctions.cpp:94: riferimento non definito a "QFlow::FileInfo::~FileInfo()" /home/test/wamp/build/qtc_Qt_5_5_0_14f75cac-debug/core.qtc-Qt-5-5-0-14f75cac.635a302d/.obj/3a52ce780950d4d9/helperfunctions.cpp.o: nella funzione "QFlow::HelperFunctions::getFileInfo(QString)": /media/sf_Virtual_Machine_Xubuntu-14.04_32bit/wamp/wamp/core/src/helperfunctions.cpp:100: riferimento non definito a "QFlow::FileInfo::FileInfo(QString)" collect2: error: ld returned 1 exit status

What i'm doing wrong? I need to install some dependencies?

Thanks in advance

Implement disconnect/close functionality

There is no method to disconnect a WampConnection after it is established. There should be a "close" method and the ability to connect again.

This feature is being implemented in my fork and I will update this issue as I work.

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.