crossbario / autobahn-c

Apache License 2.0
14 stars 5 forks source link

Autobahn shared core API #1

Open oberstet opened 8 years ago

oberstet commented 8 years ago

It seems totally possible to mimick the new shared core API in AutobahnPython and AutobahnJS also in an object-oriented style of C.

Having a core API shared across Python, JavaScript and C would be of tremendous value. It allows to apply WAMP and Autobahn API knowledge from tiny microcontrollers to the data-center to browsers and mobile.

oberstet commented 8 years ago

See also:

oberstet commented 8 years ago

Here is a transcription of the Python example:

#include <autobahn.h>

int main () {
    // this is the Autobahn library entry point
    ab_t ab;

    // this represent a WAMP connection
    ab_connection_t connection;

    // initialize the library (once)
    ab_init(&ab);

    // create a new connection
    ab_connection_create(&ab, &connection, "ws://localhost:8080/ws", "realm1");

    // listener that will get attached to "open" event on connection
    void on_open(ab_session_t* session) {
        printf("session connected\n");

        // close the underlying WAMP connection again
        ab_connection_close(&connection);
    }

    // attach a listener to the "open" event on the connection
    ab_connection_on_open(&connection, &on_open);

    // now actually open the connection
    ab_connection_open(&connection);
}

There are multiple open questions:

  1. How to hook up into networking and event loop
  2. Ideally, the library should be able to hook into any bytes stream like abstraction
  3. We need a Deferred for C ...