XMMS2
|
00001 /* XMMS2 - X Music Multiplexer System 00002 * Copyright (C) 2003-2011 XMMS2 Team 00003 * 00004 * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!! 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 */ 00016 00017 00018 00019 00020 #ifndef __XMMS_OBJECT_H__ 00021 #define __XMMS_OBJECT_H__ 00022 00023 #include <glib.h> 00024 #include "xmms/xmms_error.h" 00025 #include "xmmsc/xmmsc_idnumbers.h" 00026 #include "xmmsc/xmmsv.h" 00027 #include "xmmsc/xmmsv_coll.h" 00028 00029 #define XMMS_OBJECT_MID 0x00455574 00030 00031 G_BEGIN_DECLS 00032 00033 struct xmms_object_St; 00034 typedef struct xmms_object_St xmms_object_t; 00035 00036 typedef void (*xmms_object_destroy_func_t) (xmms_object_t *object); 00037 00038 /** @addtogroup Object 00039 * @{ 00040 */ 00041 struct xmms_object_St { 00042 guint32 id; 00043 GMutex *mutex; 00044 00045 GTree *signals; 00046 GTree *cmds; 00047 00048 gint ref; 00049 xmms_object_destroy_func_t destroy_func; 00050 }; 00051 00052 00053 /* Convenience wrapper to create #xmmsv_t from GLib types. */ 00054 xmmsv_t *xmms_convert_and_kill_list (GList *list); 00055 xmmsv_t *xmms_convert_and_kill_dict (GTree *dict); 00056 xmmsv_t *xmms_convert_and_kill_string (gchar *str); 00057 xmmsv_t *xmms_convert_and_kill_bin (GString *gs); 00058 00059 int xmms_bin_to_gstring (xmmsv_t *value, GString **gs); 00060 int dummy_identity (xmmsv_t *value, xmmsv_t **arg); 00061 gboolean check_string_list (xmmsv_t *list); 00062 00063 00064 /** @} */ 00065 00066 typedef void (*xmms_object_handler_t) (xmms_object_t *object, xmmsv_t *data, gpointer userdata); 00067 00068 #define XMMS_OBJECT_CMD_MAX_ARGS 6 00069 typedef struct { 00070 xmmsv_t *args; /* list */ 00071 xmmsv_t *retval; 00072 xmms_error_t error; 00073 } xmms_object_cmd_arg_t; 00074 00075 typedef void (*xmms_object_cmd_func_t) (xmms_object_t *object, xmms_object_cmd_arg_t *arg); 00076 00077 #define XMMS_OBJECT(p) ((xmms_object_t *)p) 00078 #define XMMS_IS_OBJECT(p) (XMMS_OBJECT (p)->id == XMMS_OBJECT_MID) 00079 00080 void xmms_object_cleanup (xmms_object_t *object); 00081 00082 void xmms_object_connect (xmms_object_t *object, guint32 signalid, 00083 xmms_object_handler_t handler, gpointer userdata); 00084 00085 void xmms_object_disconnect (xmms_object_t *object, guint32 signalid, 00086 xmms_object_handler_t handler, gpointer userdata); 00087 00088 void xmms_object_emit (xmms_object_t *object, guint32 signalid, xmmsv_t *data); 00089 00090 void xmms_object_emit_f (xmms_object_t *object, guint32 signalid, 00091 xmmsv_type_t type, ...); 00092 00093 void xmms_object_cmd_arg_init (xmms_object_cmd_arg_t *arg); 00094 00095 void xmms_object_cmd_add (xmms_object_t *object, guint cmdid, const xmms_object_cmd_func_t desc); 00096 00097 void xmms_object_cmd_call (xmms_object_t *object, guint cmdid, xmms_object_cmd_arg_t *arg); 00098 00099 00100 void __int_xmms_object_unref (xmms_object_t *object); 00101 xmms_object_t *__int_xmms_object_new (gint size, xmms_object_destroy_func_t destfunc); 00102 00103 #define xmms_object_ref(obj) do { \ 00104 if (obj && XMMS_IS_OBJECT (obj)) { \ 00105 g_atomic_int_inc (&(XMMS_OBJECT (obj)->ref)); \ 00106 } \ 00107 } while (0) 00108 00109 #define xmms_object_unref(obj) do { \ 00110 if (obj && XMMS_IS_OBJECT (obj)) { \ 00111 __int_xmms_object_unref (XMMS_OBJECT (obj)); \ 00112 } \ 00113 } while (0) 00114 00115 #define xmms_object_new(objtype,destroyfunc) (objtype *) __int_xmms_object_new (sizeof (objtype), destroyfunc) 00116 00117 G_END_DECLS 00118 00119 #endif /* __XMMS_OBJECT_H__ */