예제 #1
0
파일: peer.c 프로젝트: andrey-str/ccnet
static void
create_local_processor (CcnetPeer *peer, int req_id, int argc, char **argv)
{
    CcnetProcessor *processor;
    CcnetProcFactory *factory = peer->manager->session->proc_factory;

    processor = ccnet_proc_factory_create_slave_processor (
        factory, argv[0], peer, req_id);

    if (processor) {
        ccnet_processor_start (processor, argc-1, argv+1);
    } else {
        CcnetService *service;

        service = ccnet_session_get_service (peer->manager->session, argv[0]);
        if (service != NULL) {
            processor = ccnet_proc_factory_create_slave_processor (
                factory, "service-proxy", peer, req_id);
            ccnet_processor_start (processor, 0, NULL);
            ccnet_service_proxy_invoke_local (processor, service->provider,
                                              argc, argv);
        } else {
            ccnet_peer_send_response (peer, req_id, SC_UNKNOWN_SERVICE,
                                    SS_UNKNOWN_SERVICE,
                                    NULL, 0);
            ccnet_debug ("Unknown service %s invoke by %s(%.8s)\n",
                           argv[0], peer->name, peer->id);
        }
    }
}
예제 #2
0
파일: processor.c 프로젝트: aclindsa/ccnet
int ccnet_processor_startl (CcnetProcessor *processor, ...)
{
    va_list ap;
    int argc = 0;
    char **argv = g_malloc (sizeof(char *) * 10);
    char *arg;
    int max = 10;
    int ret;
    
    va_start (ap, processor);
    arg = va_arg (ap, char *);
    while (arg) {
        if (argc >= max) {
            max *= 2;
            argv = realloc (argv, sizeof(char *) * max);
        }
        argv[argc++] = arg;

        arg = va_arg (ap, char *);        
    }
    va_end (ap);
    
    ret = ccnet_processor_start (processor, argc, argv);
    g_free (argv);

    return ret;
}
예제 #3
0
int
ccnetrpc_async_transport_send (void *arg, gchar *fcall_str,
                             size_t fcall_len, void *rpc_priv)
{
    CcnetrpcAsyncTransportParam *priv;
    CcnetClient *session;
    CcnetProcessor *proc;

    g_warn_if_fail (arg != NULL && fcall_str != NULL);

    priv = (CcnetrpcAsyncTransportParam *)arg;
    session = priv->session;
    
    if (!priv->peer_id)
        proc = ccnet_proc_factory_create_master_processor (
            session->proc_factory, "async-rpc");
    else
        proc = ccnet_proc_factory_create_remote_master_processor (
            session->proc_factory, "async-rpc", priv->peer_id);
    
    ccnet_async_rpc_proc_set_rpc ((CcnetAsyncRpcProc *)proc, priv->service, 
                                  fcall_str, fcall_len, rpc_priv);
    ccnet_processor_start (proc, 0, NULL);
    return 0;
}
예제 #4
0
static int
start_mq_client ()
{
    seaf_message ("starting mq client ...\n");
    
    CcnetMqclientProc *mqclient_proc;

    mqclient_proc = (CcnetMqclientProc *)
        ccnet_proc_factory_create_master_processor
        (ctl->client->proc_factory, "mq-client");
    
    if (!mqclient_proc) {
        seaf_warning ("Failed to create mqclient proc.\n");
        return -1;
    }

    static char *topics[] = {
        "seaf_server.heartbeat",
        "seaf_mon.heartbeat",
    };

    ccnet_mqclient_proc_set_message_got_cb (mqclient_proc, mq_cb, NULL);

    /* Subscribe to messages. */
    if (ccnet_processor_start ((CcnetProcessor *)mqclient_proc,
                               G_N_ELEMENTS(topics), topics) < 0) {
        seaf_warning ("Failed to start mqclient proc\n");
        return -1;
    }

    ctl->mqclient_proc = mqclient_proc;

    return 0;
}
예제 #5
0
static void
start_mq_client ()
{
    CcnetMqclientProc *mqclient_proc;
    
    mqclient_proc = (CcnetMqclientProc *)
        ccnet_proc_factory_create_master_processor
        (applet->client->proc_factory, "mq-client");

    if (!mqclient_proc) {
        applet_warning ("Failed to create mq-client!\n");
        applet_exit(1);
    }

    ccnet_mqclient_proc_set_message_got_cb (mqclient_proc, mq_cb, NULL);
    
    static char *topics[] = {
        "seafile.heartbeat",
        "seafile.notification",
    };
    
    /* Subscribe to messages. */
    if (ccnet_processor_start ((CcnetProcessor *)mqclient_proc,
                               G_N_ELEMENTS(topics), topics) < 0) {
        
        applet_warning ("Failed to start mq-client!\n");
        applet_exit(1);
    }

    applet->mqclient_proc = mqclient_proc;
}
예제 #6
0
void
ccnet_service_proxy_invoke_remote (CcnetProcessor *processor,
                                   CcnetPeer *remote,
                                   int argc, char **argv)
{
    CcnetServiceStubProc *stub_proc;
    ServiceProxyPriv *priv = GET_PRIV(processor);

    if (argc < 1) {
        ccnet_processor_send_response (processor, SC_BAD_CMD_FMT,
                                       SS_BAD_CMD_FMT, NULL, 0);
        ccnet_processor_done (processor, FALSE);
        return;
    }
    
    priv->name = proc_name_strjoin_n(" ", argc, argv);

    stub_proc = CCNET_SERVICE_STUB_PROC (
        ccnet_proc_factory_create_master_processor (
            processor->session->proc_factory, "service-stub", remote)
        );
    priv->stub_proc = stub_proc;
    ccnet_service_stub_proc_set_proxy_proc (stub_proc, processor);

    /* Start can fail if the remote end is not connected. */
    if (ccnet_processor_start (CCNET_PROCESSOR(stub_proc), argc, argv) < 0) {
        ccnet_processor_send_response (processor, SC_PROC_DEAD, SS_PROC_DEAD,
                                       NULL, 0);
        ccnet_processor_done (processor, FALSE);
    }
}
예제 #7
0
/* TODO: the same as above, can use one function instead */
void
ccnet_service_proxy_invoke_local (CcnetProcessor *processor,
                                  CcnetPeer *local,
                                  int argc, char **argv)
{
    CcnetServiceStubProc *stub_proc;
    ServiceProxyPriv *priv = GET_PRIV(processor);
    
    if (argc < 1) {
        ccnet_processor_send_response (processor, SC_BAD_CMD_FMT,
                                       SS_BAD_CMD_FMT, NULL, 0);
        ccnet_processor_done (processor, FALSE);
        return;
    }

    priv->name = proc_name_strjoin_n(" ", argc, argv);

    stub_proc = CCNET_SERVICE_STUB_PROC (
        ccnet_proc_factory_create_master_processor (
            processor->session->proc_factory, "service-stub", local)
        );
    priv->stub_proc = stub_proc;
    ccnet_service_stub_proc_set_proxy_proc (stub_proc, processor);

    ccnet_processor_start (CCNET_PROCESSOR(stub_proc), argc, argv);
}
예제 #8
0
파일: mainloop.c 프로젝트: andrey-str/ccnet
void ccnet_send_command (CcnetClient *client, const char *command,
                         SendcmdProcRcvrspCallback cmd_cb, void *cbdata)
{
    CcnetSendcmdProc *sendcmd_proc = (CcnetSendcmdProc *)
        ccnet_proc_factory_create_master_processor (client->proc_factory,
                                                    "send-cmd");
    ccnet_sendcmd_proc_set_rcvrsp_cb (sendcmd_proc, cmd_cb, cbdata);
    ccnet_processor_start (CCNET_PROCESSOR(sendcmd_proc), 0, NULL);
    ccnet_sendcmd_proc_send_command (sendcmd_proc, command);    
}
예제 #9
0
파일: peer.c 프로젝트: andrey-str/ccnet
static void
create_remote_processor (CcnetPeer *peer, CcnetPeer *remote_peer,
                         int req_id, int argc, char **argv)
{
    CcnetProcessor *processor;
    CcnetProcFactory *factory = peer->manager->session->proc_factory;

    processor = ccnet_proc_factory_create_slave_processor (
        factory,"service-proxy", peer, req_id);
    ccnet_processor_start (processor, 0, NULL);

    ccnet_service_proxy_invoke_remote (processor, remote_peer, argc, argv);
}
void MessageListener::startMqClient()
{
    mqclient_proc_ = (CcnetMqclientProc *)
        ccnet_proc_factory_create_master_processor
        (async_client_->proc_factory, "mq-client");

    ccnet_mqclient_proc_set_message_got_cb (mqclient_proc_,
                                            (MessageGotCB)messageCallback,
                                            this);

    static const char *topics[] = {
        // "seafile.heartbeat",
        "seafile.notification",
    };

    if (ccnet_processor_start ((CcnetProcessor *)mqclient_proc_,
                               G_N_ELEMENTS(topics), (char **)topics) < 0) {

        seafApplet->errorAndExit("Failed to start mq client");
    }
}