/** * @brief Invoked when a new incomming client connection is established. * @memberof GstSwitchController */ static gboolean gst_switch_controller_on_new_connection (GDBusServer * server, GDBusConnection * connection, gpointer user_data) { GstSwitchController *controller = GST_SWITCH_CONTROLLER (user_data); guint register_id = 0; GError *error = NULL; register_id = g_dbus_connection_register_object (connection, SWITCH_CONTROLLER_OBJECT_PATH, introspection_data->interfaces[0], &gst_switch_controller_interface_vtable, controller, /* user_data */ NULL, /* user_data_free_func */ &error); if (error != NULL) { ERROR ("failed to register controller: %s", error->message); g_error_free (error); return FALSE; } else if (register_id <= 0) { ERROR ("register_id invalid (<= 0): %d", register_id); return FALSE; } else { INFO ("registered: %d, %s, %s", register_id, SWITCH_CONTROLLER_OBJECT_PATH, introspection_data->interfaces[0]->name); } g_signal_connect (connection, "closed", G_CALLBACK (gst_switch_controller_on_connection_closed), controller); GST_SWITCH_CONTROLLER_LOCK_CLIENTS (controller); controller->clients = g_list_append (controller->clients, connection); GST_SWITCH_CONTROLLER_UNLOCK_CLIENTS (controller); g_object_ref (connection); return TRUE; }
static void gst_switch_server_prepare_bus_controller (GstSwitchServer * srv) { if (srv->controller == NULL) { GST_SWITCH_SERVER_LOCK_CONTROLLER (srv); if (srv->controller == NULL) { srv->controller = GST_SWITCH_CONTROLLER (g_object_new ( GST_TYPE_SWITCH_CONTROLLER, NULL)); srv->controller->server = srv; } GST_SWITCH_SERVER_UNLOCK_CONTROLLER (srv); } }
static void gst_switch_controller_bus_acquired (GDBusConnection * connection, const gchar * name, gpointer data) { GstSwitchController *controller = GST_SWITCH_CONTROLLER (data); guint register_id; INFO ("bus acquired: %s", name); g_signal_connect (controller, "notify", G_CALLBACK (gst_switch_controller_send_property_change), connection); register_id = g_dbus_connection_register_object (connection, SWITCH_CONTROLLER_OBJECT_PATH, introspection_data->interfaces[0], &gst_switch_controller_interface_vtable, controller, /* user_data */ NULL, /* user_data_free_func */ NULL /* GError** */ ); g_assert (0 < register_id); }
/** * @brief Fetching the controller property remotely (it's useless currently). * @memberof GstSwitchController */ static GVariant * gst_switch_controller_do_get_property (GDBusConnection * connection, const gchar * sender, const gchar * object_path, const gchar * interface_name, const gchar * property_name, GError ** error, gpointer user_data) { GstSwitchController *controller = GST_SWITCH_CONTROLLER (user_data); GVariant *ret = NULL; (void) controller; INFO ("get: %s", property_name); if (g_strcmp0 (property_name, "num") == 0) { } return ret; }
/** * @brief Invoked to cleanup when a connected client is closed. * @memberof GstSwitchController */ static void gst_switch_controller_on_connection_closed (GDBusConnection * connection, gboolean vanished, GError * error, gpointer user_data) { GstSwitchController *controller = GST_SWITCH_CONTROLLER (user_data); (void) controller; if (error) { WARN ("close: %s", error->message); } GST_SWITCH_CONTROLLER_LOCK_CLIENTS (controller); controller->clients = g_list_remove (controller->clients, connection); GST_SWITCH_CONTROLLER_UNLOCK_CLIENTS (controller); INFO ("closed: %p, %d (%d clients remaining)", connection, vanished, g_list_length (controller->clients)); g_object_unref (connection); }
/** * @brief Performing a remoting method call from a gst-switch client. * @memberof GstSwitchController */ static void gst_switch_controller_do_method_call (GDBusConnection * connection, const gchar * sender, const gchar * object_path, const gchar * interface_name, const gchar * method_name, GVariant * parameters, GDBusMethodInvocation * invocation, gpointer user_data) { GstSwitchController *controller = GST_SWITCH_CONTROLLER (user_data); GstSwitchControllerClass *klass = GST_SWITCH_CONTROLLER_CLASS (G_OBJECT_GET_CLASS (controller)); MethodFunc entry = (MethodFunc) g_hash_table_find (klass->methods, (GHRFunc) gst_switch_controller_method_match, (gpointer) method_name); GVariant *results; if (!entry) goto error_no_method; /* INFO ("calling: %s/%s", interface_name, method_name); */ results = (*entry) (G_OBJECT (controller), connection, parameters); g_dbus_method_invocation_return_value (invocation, results); return; error_no_method: { ERROR ("unsupported method: %s", method_name); g_dbus_method_invocation_return_error (invocation, 0, -1, "Unsupported call %s", method_name); } }