/** * @internal Destroy the main object * @param[in] object The object to destroy */ static void xmms_main_destroy (xmms_object_t *object) { xmms_main_t *mainobj = (xmms_main_t *) object; xmms_object_cmd_arg_t arg; xmms_config_property_t *cv; cv = xmms_config_lookup ("core.shutdownpath"); do_scriptdir (xmms_config_property_get_string (cv), "stop"); /* stop output */ xmms_object_cmd_arg_init (&arg); xmms_object_cmd_call (XMMS_OBJECT (mainobj->output), XMMS_IPC_CMD_STOP, &arg); g_usleep (G_USEC_PER_SEC); /* wait for the output thread to end */ xmms_object_unref (mainobj->vis); xmms_object_unref (mainobj->output); xmms_object_unref (xform_obj); xmms_config_save (); xmms_config_shutdown (); xmms_plugin_shutdown (); xmms_ipc_object_unregister (XMMS_IPC_OBJECT_MAIN); xmms_ipc_shutdown (); xmms_log_shutdown (); }
static void process_msg (xmms_ipc_client_t *client, xmms_ipc_msg_t *msg) { xmms_object_t *object; xmms_object_cmd_arg_t arg; xmms_ipc_msg_t *retmsg; xmmsv_t *error, *arguments; uint32_t objid, cmdid; g_return_if_fail (msg); objid = xmms_ipc_msg_get_object (msg); cmdid = xmms_ipc_msg_get_cmd (msg); if (!xmms_ipc_msg_get_value (msg, &arguments)) { xmms_log_error ("Cannot read command arguments. " "Ignoring command."); return; } if (objid == XMMS_IPC_OBJECT_SIGNAL) { if (cmdid == XMMS_IPC_CMD_SIGNAL) { xmms_ipc_register_signal (client, msg, arguments); } else if (cmdid == XMMS_IPC_CMD_BROADCAST) { xmms_ipc_register_broadcast (client, msg, arguments); } else { xmms_log_error ("Bad command id (%d) for signal object", cmdid); } goto out; } if (objid >= XMMS_IPC_OBJECT_END) { xmms_log_error ("Bad object id (%d)", objid); goto out; } g_mutex_lock (ipc_object_pool_lock); object = ipc_object_pool->objects[objid]; g_mutex_unlock (ipc_object_pool_lock); if (!object) { xmms_log_error ("Object %d was not found!", objid); goto out; } if (!g_tree_lookup (object->cmds, GUINT_TO_POINTER (cmdid))) { xmms_log_error ("No such cmd %d on object %d", cmdid, objid); goto out; } xmms_object_cmd_arg_init (&arg); arg.args = arguments; xmms_object_cmd_call (object, cmdid, &arg); if (xmms_error_isok (&arg.error)) { retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_REPLY); xmms_ipc_handle_cmd_value (retmsg, arg.retval); } else { /* FIXME: or we could omit setting the command to _CMD_ERROR * and let the client check whether the value it got is an * error xmmsv_t. If so, don't forget to * update the client-side of IPC too. */ retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_ERROR); error = xmmsv_new_error (xmms_error_message_get (&arg.error)); xmms_ipc_msg_put_value (retmsg, error); xmmsv_unref (error); /* retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_REPLY); xmms_ipc_handle_cmd_value (retmsg, arg.retval); */ } if (arg.retval) xmmsv_unref (arg.retval); err: xmms_ipc_msg_set_cookie (retmsg, xmms_ipc_msg_get_cookie (msg)); g_mutex_lock (client->lock); xmms_ipc_client_msg_write (client, retmsg); g_mutex_unlock (client->lock); out: if (arguments) { xmmsv_unref (arguments); } }
static void process_msg (xmms_ipc_client_t *client, xmms_ipc_msg_t *msg) { xmms_object_t *object; xmms_object_cmd_desc_t *cmd = NULL; xmms_object_cmd_arg_t arg; xmms_ipc_msg_t *retmsg; xmmsv_t *error, *arguments; uint32_t objid, cmdid; gint i; g_return_if_fail (msg); objid = xmms_ipc_msg_get_object (msg); cmdid = xmms_ipc_msg_get_cmd (msg); if (!xmms_ipc_msg_get_value (msg, &arguments)) { xmms_log_error ("Cannot read command arguments. " "Ignoring command."); return; } if (objid == XMMS_IPC_OBJECT_SIGNAL) { if (cmdid == XMMS_IPC_CMD_SIGNAL) { xmms_ipc_register_signal (client, msg, arguments); } else if (cmdid == XMMS_IPC_CMD_BROADCAST) { xmms_ipc_register_broadcast (client, msg, arguments); } else { xmms_log_error ("Bad command id (%d) for signal object", cmdid); } goto out; } if (objid >= XMMS_IPC_OBJECT_END) { xmms_log_error ("Bad object id (%d)", objid); goto out; } g_mutex_lock (ipc_object_pool_lock); object = ipc_object_pool->objects[objid]; g_mutex_unlock (ipc_object_pool_lock); if (!object) { xmms_log_error ("Object %d was not found!", objid); goto out; } if (object->cmds) cmd = g_tree_lookup (object->cmds, GUINT_TO_POINTER (cmdid)); if (!cmd) { xmms_log_error ("No such cmd %d on object %d", cmdid, objid); goto out; } xmms_object_cmd_arg_init (&arg); for (i = 0; i < XMMS_OBJECT_CMD_MAX_ARGS; i++) { if (!type_and_msg_to_arg (cmd->args[i], arguments, &arg, i)) { xmms_log_error ("Error parsing args"); if (objid == XMMS_IPC_OBJECT_MAIN && cmdid == XMMS_IPC_CMD_HELLO) { xmms_log_error ("Couldn't parse hello message. " "Maybe the client or libxmmsclient " "needs to be updated."); } retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_ERROR); error = xmmsv_new_error ("Corrupt msg"); xmms_ipc_msg_put_value (retmsg, error); xmmsv_unref (error); goto err; } } xmms_object_cmd_call (object, cmdid, &arg); if (xmms_error_isok (&arg.error)) { retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_REPLY); xmms_ipc_handle_cmd_value (retmsg, arg.retval); } else { /* FIXME: or we could omit setting the command to _CMD_ERROR * and let the client check whether the value it got is an * error xmmsv_t. If so, don't forget to * update the client-side of IPC too. */ retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_ERROR); error = xmmsv_new_error (xmms_error_message_get (&arg.error)); xmms_ipc_msg_put_value (retmsg, error); xmmsv_unref (error); /* retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_REPLY); xmms_ipc_handle_cmd_value (retmsg, arg.retval); */ } if (arg.retval) xmmsv_unref (arg.retval); err: for (i = 0; i < XMMS_OBJECT_CMD_MAX_ARGS; i++) { if (arg.values[i]) xmmsv_unref (arg.values[i]); } xmms_ipc_msg_set_cookie (retmsg, xmms_ipc_msg_get_cookie (msg)); g_mutex_lock (client->lock); xmms_ipc_client_msg_write (client, retmsg); g_mutex_unlock (client->lock); out: if (arguments) { xmmsv_unref (arguments); } }
static void process_msg (xmms_ipc_client_t *client, xmms_ipc_msg_t *msg) { xmms_object_t *object; xmms_object_cmd_desc_t *cmd = NULL; xmms_object_cmd_arg_t arg; xmms_ipc_msg_t *retmsg; uint32_t objid, cmdid; gint i; g_return_if_fail (msg); objid = xmms_ipc_msg_get_object (msg); cmdid = xmms_ipc_msg_get_cmd (msg); if (objid == XMMS_IPC_OBJECT_SIGNAL && cmdid == XMMS_IPC_CMD_SIGNAL) { gint32 signalid; if (!xmms_ipc_msg_get_int32 (msg, &signalid)) { xmms_log_error ("No signalid in this msg?!"); return; } if (signalid < 0 || signalid >= XMMS_IPC_SIGNAL_END) { xmms_log_error ("Bad signal id (%d)", signalid); return; } g_mutex_lock (client->lock); client->pendingsignals[signalid] = xmms_ipc_msg_get_cookie (msg); g_mutex_unlock (client->lock); return; } else if (objid == XMMS_IPC_OBJECT_SIGNAL && cmdid == XMMS_IPC_CMD_BROADCAST) { gint32 broadcastid; if (!xmms_ipc_msg_get_int32 (msg, &broadcastid)) { xmms_log_error ("No broadcastid in this msg?!"); return; } if (broadcastid < 0 || broadcastid >= XMMS_IPC_SIGNAL_END) { xmms_log_error ("Bad broadcast id (%d)", broadcastid); return; } g_mutex_lock (client->lock); client->broadcasts[broadcastid] = g_list_append (client->broadcasts[broadcastid], GUINT_TO_POINTER (xmms_ipc_msg_get_cookie (msg))); g_mutex_unlock (client->lock); return; } if (objid >= XMMS_IPC_OBJECT_END) { xmms_log_error ("Bad object id (%d)", objid); return; } g_mutex_lock (ipc_object_pool_lock); object = ipc_object_pool->objects[objid]; g_mutex_unlock (ipc_object_pool_lock); if (!object) { xmms_log_error ("Object %d was not found!", objid); return; } if (cmdid >= XMMS_IPC_CMD_END) { xmms_log_error ("Bad command id (%d)", cmdid); return; } if (object->cmds) cmd = g_tree_lookup (object->cmds, GUINT_TO_POINTER (cmdid)); if (!cmd) { xmms_log_error ("No such cmd %d on object %d", cmdid, objid); return; } xmms_object_cmd_arg_init (&arg); for (i = 0; i < XMMS_OBJECT_CMD_MAX_ARGS; i++) { if (!type_and_msg_to_arg (cmd->args[i], msg, &arg, i)) { xmms_log_error ("Error parsing args"); retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_ERROR); xmms_ipc_msg_put_string (retmsg, "Corrupt msg"); goto err; } } xmms_object_cmd_call (object, cmdid, &arg); if (xmms_error_isok (&arg.error)) { retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_REPLY); xmms_ipc_handle_cmd_value (retmsg, arg.retval); } else { /* FIXME: or we could change the client code to transform * CMD_ERROR to an error value_t. If so, don't forget to * update the client-side of IPC too. */ retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_ERROR); xmms_ipc_msg_put_string (retmsg, xmms_error_message_get (&arg.error)); /* retmsg = xmms_ipc_msg_new (objid, XMMS_IPC_CMD_REPLY); xmms_ipc_handle_cmd_value (retmsg, arg.retval); */ } if (arg.retval) xmmsv_unref (arg.retval); err: for (i = 0; i < XMMS_OBJECT_CMD_MAX_ARGS; i++) { xmmsv_unref (arg.values[i]); } xmms_ipc_msg_set_cookie (retmsg, xmms_ipc_msg_get_cookie (msg)); g_mutex_lock (client->lock); xmms_ipc_client_msg_write (client, retmsg); g_mutex_unlock (client->lock); }