Example #1
0
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);
	}
}
Example #2
0
File: ipc.c Project: dreamerc/xmms2
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);
	}
}