void ipcam_base_app_send_message(IpcamBaseApp *base_app, IpcamMessage *msg, const gchar *name, const gchar *client_id, MsgHandler callback, guint timeout) { g_return_if_fail(IPCAM_IS_BASE_APP(base_app)); g_return_if_fail(IPCAM_IS_MESSAGE(msg)); IpcamBaseAppPrivate *priv = ipcam_base_app_get_instance_private(base_app); gboolean is_server = ipcam_service_is_server(IPCAM_SERVICE(base_app), name); const gchar *token = ""; if (!is_server) { token = ipcam_base_app_get_config(base_app, "token"); } g_object_set(G_OBJECT(msg), "token", token, NULL); if (ipcam_message_is_request(msg)) { ipcam_message_manager_register(priv->msg_manager, msg, G_OBJECT(base_app), callback, timeout); } gchar **strings = (gchar **)g_new(gpointer, 2); strings[0] = (gchar *)ipcam_message_to_string(msg); strings[1] = NULL; ipcam_service_send_strings(IPCAM_SERVICE(base_app), name, (const gchar **)strings, client_id); g_free(strings[0]); g_free(strings); }
static void ipcam_base_app_connect_to_timer(IpcamBaseApp *base_app) { const gchar *token = ipcam_base_app_get_config(base_app, "token"); ipcam_service_connect_by_name(IPCAM_SERVICE(base_app), IPCAM_TIMER_CLIENT_NAME, IPCAM_TIMER_PUMP_ADDRESS, token); }
void ipcam_base_app_add_timer(IpcamBaseApp *base_app, const gchar *timer_id, const gchar *interval, TCFunc callback) { IpcamBaseAppPrivate *priv = ipcam_base_app_get_instance_private(base_app); ipcam_timer_manager_add_timer(priv->timer_manager, timer_id, G_OBJECT(base_app), callback); const gchar **strings = (const gchar **)g_new(gpointer, 3); strings[0] = timer_id; strings[1] = interval; strings[2] = NULL; const gchar *token = ipcam_base_app_get_config(base_app, "token"); ipcam_service_send_strings(IPCAM_SERVICE(base_app), IPCAM_TIMER_CLIENT_NAME, strings, token); g_free(strings); }
static JsonNode *query_network_address(IpcamIAjax *iajax) { const gchar *token = ipcam_base_app_get_config(IPCAM_BASE_APP(iajax), "token"); IpcamRequestMessage *req_msg; IpcamMessage *resp_msg; JsonBuilder *builder; JsonNode *addr_node = NULL; gboolean ret; builder = json_builder_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "items"); json_builder_begin_array(builder); json_builder_add_string_value(builder, "address"); json_builder_end_array(builder); json_builder_end_object(builder); req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE, "action", "get_network", "body", json_builder_get_root(builder), NULL); ipcam_base_app_send_message(IPCAM_BASE_APP(iajax), IPCAM_MESSAGE(req_msg), "iconfig", token, NULL, 5); ret = ipcam_base_app_wait_response(IPCAM_BASE_APP(iajax), ipcam_request_message_get_id(req_msg), 5000, &resp_msg); if (ret) { JsonNode *resp_body; JsonObject *items_obj; g_object_get(G_OBJECT(resp_msg), "body", &resp_body, NULL); items_obj = json_object_get_object_member(json_node_get_object(resp_body), "items"); addr_node = json_node_copy(json_object_get_member(items_obj, "address")); g_object_unref(resp_msg); } g_object_unref(req_msg); g_object_unref(builder); return addr_node; }
static gboolean onvif_invocate_action(IpcamIOnvifDiscovery *ionvif_discovery, const char *action, JsonNode *request, JsonNode **response) { const gchar *token; IpcamRequestMessage *req_msg; IpcamMessage *resp_msg; gboolean ret = FALSE; token = ipcam_base_app_get_config(IPCAM_BASE_APP(ionvif_discovery), "token"); req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE, "action", action, "body", request, NULL); ipcam_base_app_send_message(IPCAM_BASE_APP(ionvif_discovery), IPCAM_MESSAGE(req_msg), "iconfig", token, NULL, 10); ret = ipcam_base_app_wait_response(IPCAM_BASE_APP(ionvif_discovery), ipcam_request_message_get_id(req_msg), 5000, &resp_msg); if (ret) { JsonNode *resp_body; if (response) { g_object_get(G_OBJECT(resp_msg), "body", &resp_body, NULL); *response = json_node_copy(resp_body); } g_object_unref(resp_msg); } g_object_unref(req_msg); return ret; }
g_object_get(G_OBJECT(handler), "app", &iconfig, NULL); gchar *hwaddr = NULL, *ipaddr = NULL, *netmask = NULL, *gateway = NULL; char *dns[2] = { [0 ... (ARRAY_SIZE(dns) - 1)] = NULL }; int nr_dns = 2; struct __key_val { gchar *key; gchar **pval; } kv[] = { { "hwaddr", &hwaddr }, { "ipaddr", &ipaddr }, { "netmask", &netmask }, { "gateway", &gateway }, { "dns1", &dns[0] }, { "dns2", &dns[1] } }; const gchar *netif = ipcam_base_app_get_config(IPCAM_BASE_APP(iconfig), "netif"); if (sysutils_network_get_hwaddr(netif, &hwaddr) != 0) { perror("error get mac address: "); } if (sysutils_network_get_address(netif, &ipaddr, &netmask, NULL) != 0) { value = ipcam_iconfig_read(iconfig, IPCAM_NETWORK_STATIC_TYPE, "ipaddr", "value"); if (value) { ipaddr = strdup(g_variant_get_string(value, NULL)); if (!ipaddr) perror("error get network address: "); g_variant_unref(value); } }
static void ipcam_base_app_connect(gpointer key, gpointer value, gpointer user_data) { IpcamBaseApp *base_app = IPCAM_BASE_APP(user_data); const gchar *token = ipcam_base_app_get_config(base_app, "token"); ipcam_service_connect_by_name(IPCAM_SERVICE(base_app), (gchar *)key, (gchar *)value, token); }
static void ipcam_itrain_before_start(IpcamBaseService *base_service) { IpcamITrain *itrain = IPCAM_ITRAIN(base_service); IpcamITrainPrivate *priv = ipcam_itrain_get_instance_private(itrain); const gchar *addr = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:address"); const gchar *port = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:port"); const gchar *osd_port = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:osd-port"); JsonBuilder *builder; const gchar *token = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "token"); IpcamRequestMessage *req_msg; if (!addr || !port) { g_critical("address and port must be specified.\n"); return; } priv->itrain_server = g_object_new(IPCAM_TYPE_ITRAIN_SERVER, "itrain", itrain, "address", addr, "port", strtoul(port, NULL, 0), "osd-port", strtoul(osd_port, NULL, 0), NULL); ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "video_occlusion_event", IPCAM_TYPE_ITRAIN_EVENT_HANDLER); ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "set_base_info", IPCAM_TYPE_ITRAIN_EVENT_HANDLER); ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "set_szyc", IPCAM_TYPE_ITRAIN_EVENT_HANDLER); /* Request the Base Information */ builder = json_builder_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "items"); json_builder_begin_array(builder); json_builder_add_string_value(builder, "device_name"); json_builder_add_string_value(builder, "comment"); json_builder_add_string_value(builder, "location"); json_builder_add_string_value(builder, "hardware"); json_builder_add_string_value(builder, "firmware"); json_builder_add_string_value(builder, "manufacturer"); json_builder_add_string_value(builder, "model"); json_builder_add_string_value(builder, "serial"); json_builder_add_string_value(builder, "device_type"); json_builder_end_array(builder); json_builder_end_object(builder); req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE, "action", "get_base_info", "body", json_builder_get_root(builder), NULL); ipcam_base_app_send_message(IPCAM_BASE_APP(itrain), IPCAM_MESSAGE(req_msg), "iconfig", token, base_info_message_handler, 60); g_object_unref(req_msg); g_object_unref(builder); /* Request the SZYC Information */ builder = json_builder_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "items"); json_builder_begin_array(builder); json_builder_add_string_value(builder, "train_num"); json_builder_add_string_value(builder, "carriage_num"); json_builder_add_string_value(builder, "position_num"); json_builder_end_array(builder); json_builder_end_object(builder); req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE, "action", "get_szyc", "body", json_builder_get_root(builder), NULL); ipcam_base_app_send_message(IPCAM_BASE_APP(itrain), IPCAM_MESSAGE(req_msg), "iconfig", token, szyc_message_handler, 60); g_object_unref(req_msg); g_object_unref(builder); }