Coder Social home page Coder Social logo

yinzara / wamp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qflow/wamp

1.0 2.0 1.0 137 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

CMake 2.11% C++ 95.99% QML 1.80% C 0.10%

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

Wayne Tran avatar

Watchers

Matthew Vance avatar James Cloos avatar

Forkers

jeruntu

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.