コード例 #1
0
ファイル: ui.c プロジェクト: imgflo/imgflo
static void
handle_network_message(UiConnection *self, const gchar *command, JsonObject *payload,
                       SoupWebsocketConnection *ws)
{
    g_return_if_fail(payload);

    const gchar *graph_id = json_object_get_string_member(payload, "graph");
    Network *network = (graph_id) ? g_hash_table_lookup(self->network_map, graph_id) : NULL;
    g_return_if_fail(network);

    if (g_strcmp0(command, "start") == 0) {
        imgflo_info("\tNetwork START\n");
        network_set_running(network, TRUE);
    } else if (g_strcmp0(command, "stop") == 0) {
        imgflo_info("\tNetwork STOP\n");
        network_set_running(network, FALSE);
    } else if (g_strcmp0(command, "edges") == 0) {
        // TODO: update subscriptions
        send_response(ws, "network", "edges", payload);
    } else if (g_strcmp0(command, "getstatus") == 0) {
        JsonObject *info = json_object_new();
        json_object_set_string_member(info, "graph", graph_id);
        json_object_set_boolean_member(info, "running", network_is_processing(network));
        json_object_set_boolean_member(info, "started", network->running);
        send_response(ws, "network", "status", info);

    } else if (g_strcmp0(command, "debug") == 0) {
        // Ignored, not implemented
    } else {
        imgflo_warning("Unhandled message on protocol 'network', command='%s'", command);
    }
}
コード例 #2
0
ファイル: ui.c プロジェクト: automata/imgflo
static void
handle_network_message(UiConnection *self, const gchar *command, JsonObject *payload,
                       SoupWebsocketConnection *ws)
{
    g_return_if_fail(payload);

    Network *network = NULL;
    {
        const gchar *graph_id = json_object_get_string_member(payload, "graph");
        network = (graph_id) ? g_hash_table_lookup(self->network_map, graph_id) : NULL;
    }
    g_return_if_fail(network);

    if (g_strcmp0(command, "start") == 0) {
        // FIXME: response should be done in callback monitoring network state changes
        // TODO: send timestamp, graph id
        JsonObject *info = json_object_new();
        send_response(ws, "network", "started", info);

        g_print("\tNetwork START\n");
        network_set_running(network, TRUE);

    } else if (g_strcmp0(command, "stop") == 0) {
        // FIXME: response should be done in callback monitoring network state changes
        // TODO: send timestamp, graph id
        JsonObject *info = json_object_new();
        send_response(ws, "network", "stopped", info);

        g_print("\tNetwork STOP\n");
        network_set_running(network, FALSE);
    } else {
        g_printerr("Unhandled message on protocol 'network', command='%s'", command);
    }
}
コード例 #3
0
ファイル: ui.c プロジェクト: imgflo/imgflo
// Takes ownership of Network
void
ui_connection_set_default_network(UiConnection *self, Network *net) {
    g_return_if_fail(self);
    g_return_if_fail(net);
    gchar * id = net->graph->id;
    g_assert(id);

    ui_connection_add_network(self, id, net);

    self->main_network = g_strdup(id);
    g_assert(self->main_network);
    network_set_running(net, TRUE);
}