Example #1
0
File: ui.c Project: 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);
    }
}
Example #2
0
void
net_emit_state_changed(Network *self) {
    const gboolean is_processing = network_is_processing(self);
    if (self->on_state_changed) {
        self->on_state_changed(self, self->running, is_processing, self->on_state_changed_data);
    }

    if (self->running && !is_processing) {
        // We assume that every edge changed
        graph_visit_edges(self->graph, net_emit_edge_changed_func, self);
    }
}