00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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/xmmsc_coll.h"
00027
00028 #define XMMS_OBJECT_MID 0x00455574
00029
00030 G_BEGIN_DECLS
00031
00032 struct xmms_object_St;
00033 typedef struct xmms_object_St xmms_object_t;
00034 typedef struct xmms_object_cmd_desc_St xmms_object_cmd_desc_t;
00035
00036 typedef void (*xmms_object_destroy_func_t) (xmms_object_t *object);
00037
00038
00039
00040
00041 struct xmms_object_St {
00042 guint32 id;
00043 GMutex *mutex;
00044
00045 GList *signals[XMMS_IPC_SIGNAL_END];
00046 xmms_object_cmd_desc_t *cmds[XMMS_IPC_CMD_END];
00047
00048 gint ref;
00049 xmms_object_destroy_func_t destroy_func;
00050 };
00051
00052
00053
00054 typedef void (*xmms_object_handler_t) (xmms_object_t *object, gconstpointer data, gpointer userdata);
00055
00056 typedef struct {
00057 union {
00058 gint32 int32;
00059 guint32 uint32;
00060 gchar *string;
00061 GTree *dict;
00062 GHashTable *hash;
00063 GList *list;
00064 xmmsc_coll_t *coll;
00065 GString *bin;
00066 } value;
00067 xmms_object_cmd_arg_type_t type;
00068 gint refcount;
00069 } xmms_object_cmd_value_t;
00070
00071 xmms_object_cmd_value_t *xmms_object_cmd_value_str_new (const gchar *string);
00072 xmms_object_cmd_value_t *xmms_object_cmd_value_bin_new (GString *bin);
00073 xmms_object_cmd_value_t *xmms_object_cmd_value_uint_new (guint32 uint);
00074 xmms_object_cmd_value_t *xmms_object_cmd_value_int_new (gint32 i);
00075 xmms_object_cmd_value_t *xmms_object_cmd_value_dict_new (GTree *dict);
00076 xmms_object_cmd_value_t *xmms_object_cmd_value_hash_table_new (GHashTable *hash);
00077 xmms_object_cmd_value_t *xmms_object_cmd_value_list_new (GList *list);
00078 xmms_object_cmd_value_t *xmms_object_cmd_value_propdict_new (GList *list);
00079 xmms_object_cmd_value_t *xmms_object_cmd_value_coll_new (xmmsc_coll_t *coll);
00080 xmms_object_cmd_value_t *xmms_object_cmd_value_none_new (void);
00081 xmms_object_cmd_value_t *xmms_object_cmd_value_ref (xmms_object_cmd_value_t *val);
00082 void xmms_object_cmd_value_unref (xmms_object_cmd_value_t *val);
00083
00084 #define XMMS_OBJECT_CMD_MAX_ARGS 6
00085 typedef struct {
00086 xmms_object_cmd_value_t values[XMMS_OBJECT_CMD_MAX_ARGS];
00087 xmms_object_cmd_value_t *retval;
00088 xmms_error_t error;
00089 } xmms_object_cmd_arg_t;
00090
00091 typedef void (*xmms_object_cmd_func_t) (xmms_object_t *object, xmms_object_cmd_arg_t *arg);
00092
00093 struct xmms_object_cmd_desc_St {
00094 xmms_object_cmd_func_t func;
00095 xmms_object_cmd_arg_type_t retval;
00096 xmms_object_cmd_arg_type_t args[XMMS_OBJECT_CMD_MAX_ARGS];
00097
00098
00099
00100 };
00101
00102 #define XMMS_OBJECT(p) ((xmms_object_t *)p)
00103 #define XMMS_IS_OBJECT(p) (XMMS_OBJECT (p)->id == XMMS_OBJECT_MID)
00104
00105 void xmms_object_cleanup (xmms_object_t *object);
00106
00107 void xmms_object_parent_set (xmms_object_t *object, xmms_object_t *parent);
00108
00109 void xmms_object_connect (xmms_object_t *object, guint32 signalid,
00110 xmms_object_handler_t handler, gpointer userdata);
00111
00112 void xmms_object_disconnect (xmms_object_t *object, guint32 signalid,
00113 xmms_object_handler_t handler, gpointer userdata);
00114
00115 void xmms_object_emit (xmms_object_t *object, guint32 signalid,
00116 gconstpointer data);
00117
00118 void xmms_object_emit_f (xmms_object_t *object, guint32 signalid,
00119 xmms_object_cmd_arg_type_t type, ...);
00120
00121 void xmms_object_cmd_arg_init (xmms_object_cmd_arg_t *arg);
00122
00123 void xmms_object_cmd_add (xmms_object_t *object, guint cmdid, xmms_object_cmd_desc_t *desc);
00124
00125 void xmms_object_cmd_call (xmms_object_t *object, guint cmdid, xmms_object_cmd_arg_t *arg);
00126
00127
00128
00129
00130 #define __XMMS_CMD_DO_ARG_NONE(a)
00131 #define __XMMS_CMD_DO_ARG_STRING(a) ,arg->values[a].value.string
00132 #define __XMMS_CMD_DO_ARG_UINT32(a) ,arg->values[a].value.uint32
00133 #define __XMMS_CMD_DO_ARG_INT32(a) ,arg->values[a].value.int32
00134 #define __XMMS_CMD_DO_ARG_STRINGLIST(a) ,arg->values[a].value.list
00135 #define __XMMS_CMD_DO_ARG_COLL(a) ,arg->values[a].value.coll
00136 #define __XMMS_CMD_DO_ARG_BIN(a) ,arg->values[a].value.bin
00137 #define __XMMS_CMD_DO_RETVAL_NONE() arg->retval = xmms_object_cmd_value_none_new();
00138 #define __XMMS_CMD_DO_RETVAL_DICT() arg->retval = xmms_object_cmd_value_dict_new
00139 #define __XMMS_CMD_DO_RETVAL_UINT32() arg->retval = xmms_object_cmd_value_uint_new
00140 #define __XMMS_CMD_DO_RETVAL_INT32() arg->retval = xmms_object_cmd_value_int_new
00141 #define __XMMS_CMD_DO_RETVAL_LIST() arg->retval = xmms_object_cmd_value_list_new
00142 #define __XMMS_CMD_DO_RETVAL_PROPDICT() arg->retval = xmms_object_cmd_value_propdict_new
00143 #define __XMMS_CMD_DO_RETVAL_STRING() arg->retval = xmms_object_cmd_value_str_new
00144 #define __XMMS_CMD_DO_RETVAL_COLL() arg->retval = xmms_object_cmd_value_coll_new
00145 #define __XMMS_CMD_DO_RETVAL_BIN() arg->retval = xmms_object_cmd_value_bin_new
00146
00147 #define XMMS_CMD_DEFINE6(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2, argtype3, argtype4, argtype5, argtype6) static void \
00148 __int_xmms_cmd_##cmdid (xmms_object_t *object, xmms_object_cmd_arg_t *arg) \
00149 { \
00150 g_return_if_fail (XMMS_IS_OBJECT (object)); \
00151 g_return_if_fail (arg->values[0].type == XMMS_OBJECT_CMD_ARG_##argtype1); \
00152 g_return_if_fail (arg->values[1].type == XMMS_OBJECT_CMD_ARG_##argtype2); \
00153 g_return_if_fail (arg->values[2].type == XMMS_OBJECT_CMD_ARG_##argtype3); \
00154 g_return_if_fail (arg->values[3].type == XMMS_OBJECT_CMD_ARG_##argtype4); \
00155 g_return_if_fail (arg->values[4].type == XMMS_OBJECT_CMD_ARG_##argtype5); \
00156 g_return_if_fail (arg->values[5].type == XMMS_OBJECT_CMD_ARG_##argtype6); \
00157 __XMMS_CMD_DO_RETVAL_##_rettype() (realfunc ((argtype0)object __XMMS_CMD_DO_ARG_##argtype1(0) __XMMS_CMD_DO_ARG_##argtype2(1) __XMMS_CMD_DO_ARG_##argtype3(2) __XMMS_CMD_DO_ARG_##argtype4(3) __XMMS_CMD_DO_ARG_##argtype5(4) __XMMS_CMD_DO_ARG_##argtype6(5), &arg->error)); \
00158 } \
00159 xmms_object_cmd_desc_t __int_xmms_cmd_desc_##cmdid = { __int_xmms_cmd_##cmdid, XMMS_OBJECT_CMD_ARG_##_rettype, {XMMS_OBJECT_CMD_ARG_##argtype1, XMMS_OBJECT_CMD_ARG_##argtype2, XMMS_OBJECT_CMD_ARG_##argtype3, XMMS_OBJECT_CMD_ARG_##argtype4, XMMS_OBJECT_CMD_ARG_##argtype5, XMMS_OBJECT_CMD_ARG_##argtype6} }
00160
00161 #define XMMS_CMD_DEFINE(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2) XMMS_CMD_DEFINE6(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2, NONE, NONE, NONE, NONE)
00162 #define XMMS_CMD_DEFINE3(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2, argtype3) XMMS_CMD_DEFINE6(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2, argtype3, NONE, NONE, NONE)
00163 #define XMMS_CMD_DEFINE4(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2, argtype3, argtype4) XMMS_CMD_DEFINE6(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2, argtype3, argtype4, NONE, NONE)
00164 #define XMMS_CMD_DEFINE5(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2, argtype3, argtype4, argtype5) XMMS_CMD_DEFINE6(cmdid, realfunc, argtype0, _rettype, argtype1, argtype2, argtype3, argtype4, argtype5, NONE)
00165
00166 #define XMMS_CMD_FUNC(cmdid) &__int_xmms_cmd_desc_##cmdid
00167
00168
00169 void __int_xmms_object_unref (xmms_object_t *object);
00170 xmms_object_t *__int_xmms_object_new (gint size, xmms_object_destroy_func_t destfunc);
00171
00172 #define xmms_object_ref(obj) do { \
00173 if (obj && XMMS_IS_OBJECT (obj)) { \
00174 XMMS_OBJECT (obj)->ref++; \
00175 } \
00176 } while (0)
00177
00178 #define xmms_object_unref(obj) do { \
00179 if (obj && XMMS_IS_OBJECT (obj)) { \
00180 __int_xmms_object_unref (XMMS_OBJECT (obj)); \
00181 } \
00182 } while (0)
00183
00184 #define xmms_object_new(objtype,destroyfunc) (objtype *) __int_xmms_object_new (sizeof (objtype), destroyfunc)
00185
00186 G_END_DECLS
00187
00188 #endif