Beispiel #1
0
static twps_server_t *twps_new(bool verbose, bool proxy_log) {
    zsys_info("twps: TWPS is initializing.");
    twps_server_t *self = (twps_server_t *) calloc(1, sizeof(twps_server_t));
    self->verbose = verbose;
    self->ticket_printers = zlistx_new();
    self->ticket_store = zactor_new(ticket_store, NULL);
    self->printer_store = zactor_new(printer_store, NULL);
    self->client_proxy = zactor_new(client_proxy, NULL);
    zsys_info("twps: actors created.");
    if (verbose) {
        zstr_send(self->ticket_store, "VERBOSE");
        zstr_send(self->printer_store, "VERBOSE");
    }
    if (proxy_log)
        zstr_send(self->client_proxy, "VERBOSE");
    zstr_sendx(self->ticket_store, "START", TICKET_STORE_REP_ENDPOINT, TICKET_STORE_PUB_ENDPOINT, NULL);
    zsock_wait(self->ticket_store);
    zsys_info("twps: ticket store started listening on %s and publishing on %s", TICKET_STORE_REP_ENDPOINT,
              TICKET_STORE_PUB_ENDPOINT);
    zstr_sendx(self->printer_store, "START", PRINTER_STORE_REP_ENDPOINT, PRINTER_STORE_PUB_ENDPOINT, NULL);
    zsock_wait(self->printer_store);
    zsys_info("twps: printer store started listening on %s and publishing on %s", PRINTER_STORE_REP_ENDPOINT,
              PRINTER_STORE_PUB_ENDPOINT);
    zstr_sendx(self->client_proxy, "START", CLIENT_PROXY_ROUTE_ENDPOINT, CLIENT_PROXY_PUB_ENDPOINT, NULL);
    zsock_wait(self->client_proxy);
    zsys_info("twps: client proxy started listening on %s and publishing on %s", CLIENT_PROXY_ROUTE_ENDPOINT,
              CLIENT_PROXY_PUB_ENDPOINT);

    zstr_sendx(self->client_proxy, "SETTICKETSTORE", TICKET_STORE_REP_ENDPOINT, TICKET_STORE_PUB_ENDPOINT, NULL);
    zsock_wait(self->client_proxy);
    zstr_sendx(self->client_proxy, "SETPRINTERSTORE", PRINTER_STORE_REP_ENDPOINT, PRINTER_STORE_PUB_ENDPOINT, NULL);
    zsock_wait(self->client_proxy);
    self->printer_store_sub = zsock_new_sub(PRINTER_STORE_PUB_ENDPOINT, "");
    zsys_info("twps: initialized with ticket store, printer store and client proxy");
    zsys_info("twps: scanning for printers");
    zstr_send(self->printer_store,"SCANPRINTERS");
    return self;
}
Beispiel #2
0
///
//  Create a SUB socket, and optionally subscribe to some prefix string. Default
//  action is connect.                                                          
QZsock* QZsock::newSub (const QString &endpoint, const QString &subscribe, QObject *qObjParent)
{
    return new QZsock (zsock_new_sub (endpoint.toUtf8().data(), subscribe.toUtf8().data()), qObjParent);
}
Beispiel #3
0
Z K2(zsocknewsub){R ptr(zsock_new_sub(xs,ys));}
Beispiel #4
0
static int pipe_loop_handler(zloop_t *loop, zsock_t *pipe, void *arg) {
    int ret = 0;
    client_proxy_t *self = arg;
    zmsg_t *request = zmsg_recv(pipe);
    if (!request) {
        return ret;
    }
    char *command = zmsg_popstr(request);
    if (self->verbose) {
        zsys_debug("client proxy: API command %s", command);
    }
    if (streq(command, "START")) {
        char *endpoint = zmsg_popstr(request);
        self->rep = zsock_new_rep(endpoint);
        assert(self->rep);
        zsys_info("client proxy: is listening on %s", endpoint);
        zloop_reader(self->loop, self->rep, reader_rep_event, self);
        zstr_free(&endpoint);

        char *pub_ep = zmsg_popstr(request);
        self->pub = zsock_new_pub(pub_ep);
        assert(self->pub);
        zsys_info("client proxy: is publishing on %s", pub_ep);
        zstr_free(&pub_ep);

        zsock_signal(self->pipe, 0);
    } else if (streq(command, "SETTICKETSTORE")) {
        char *ep = zmsg_popstr(request);
        self->ticket_store_req = zsock_new_req(ep);
        assert(self->ticket_store_req);
        zsys_info("client proxy: ticket api using %s", ep);
        zstr_free(&ep);

        char *pub_ep = zmsg_popstr(request);
        self->ticket_store_sub = zsock_new_sub(pub_ep, "");
        zloop_reader(self->loop, self->ticket_store_sub, reader_internal_sub_event, self);
        zsys_info("client proxy: republishing messages from %s", pub_ep);
        zstr_free(&pub_ep);

        zsock_signal(self->pipe, 0);
    } else if (streq(command, "SETPRINTERSTORE")) {
        char *ep = zmsg_popstr(request);
        self->printer_store_req = zsock_new_req(ep);
        assert(self->printer_store_req);
        zsys_info("client proxy: printer api is ready from %s", ep);
        zstr_free(&ep);

        char *subep = zmsg_popstr(request);
        self->printer_store_sub = zsock_new_sub(subep, "");
        zloop_reader(self->loop, self->printer_store_sub, reader_internal_sub_event, self);
        zsys_info("client proxy: republishing message from %s", subep);
        zstr_free(&subep);
        zsock_signal(self->pipe, 0);
    }
    else if (streq(command, "$TERM")) {
        ret = -1;
    } else if (streq(command, "VERBOSE")) {
        self->verbose = true;
    }
    zstr_free(&command);
    zmsg_destroy(&request);
    return ret;
}
Beispiel #5
0
///
//  Create a SUB socket, and optionally subscribe to some prefix string. Default
//  action is connect.                                                          
QmlZsock *QmlZsockAttached::constructSub (const QString &endpoint, const QString &subscribe) {
    QmlZsock *qmlSelf = new QmlZsock ();
    qmlSelf->self = zsock_new_sub (endpoint.toUtf8().data(), subscribe.toUtf8().data());
    return qmlSelf;
};
Beispiel #6
0
///
//  Create a SUB socket, and optionally subscribe to some prefix string. Default
//  action is connect.                                                          
QmlZsock *QmlZsockAttached::newSub (const QString &endpoint, const QString &subscribe) {
    QmlZsock *retQ_ = new QmlZsock ();
    retQ_->self = zsock_new_sub (endpoint.toUtf8().data(), subscribe.toUtf8().data());
    return retQ_;
};