00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00036 #ifndef _core_pmsg_h_
00037 #define _core_pmsg_h_
00038
00039 #include <glib.h>
00040
00061 typedef void (*pdata_free_t)(gpointer p, gpointer arg);
00062
00063 typedef struct pdata {
00064 pdata_free_t d_free;
00065 gpointer d_arg;
00066 gint d_refcnt;
00067 gchar *d_arena;
00068 gchar *d_end;
00069 gchar d_embedded[1];
00070 } pdata_t;
00071
00072 #define pdata_start(x) ((x)->d_arena)
00073 #define pdata_len(x) ((size_t) ((x)->d_end - (x)->d_arena))
00074 #define pdata_addref(x) do { (x)->d_refcnt++; } while (0)
00075
00076
00077
00078
00079
00080 struct mqueue;
00081
00082 typedef struct pmsg pmsg_t;
00083 typedef gboolean (*pmsg_check_t)(pmsg_t *mb, const struct mqueue *q);
00084
00085 struct pmsg {
00086 gchar *m_rptr;
00087 gchar *m_wptr;
00088 pdata_t *m_data;
00089 guint m_prio;
00090 pmsg_check_t m_check;
00091 };
00092
00093 typedef void (*pmsg_free_t)(pmsg_t *mb, gpointer arg);
00094
00095 #define PMSG_PRIO_MASK 0x00ffffff
00097 #define pmsg_start(x) ((x)->m_data->d_arena)
00098 #define pmsg_phys_len(x) pdata_len((x)->m_data)
00099 #define pmsg_is_writable(x) ((x)->m_data->d_refcnt == 1)
00100 #define pmsg_prio(x) ((x)->m_prio & PMSG_PRIO_MASK)
00101
00102 #define pmsg_is_unread(x) ((x)->m_rptr == (x)->m_data->d_arena)
00103 #define pmsg_read_base(x) ((x)->m_rptr)
00104
00105 #define pmsg_check(x,y) ((x)->m_check ? (x)->m_check((x), (y)) : TRUE)
00106
00107
00108
00109
00110
00111 #define PMSG_P_DATA 0
00112 #define PMSG_P_CONTROL 1
00113 #define PMSG_P_URGENT 2
00114 #define PMSG_P_HIGHEST 3
00116
00117
00118
00119
00120 #define PMSG_PF_EXT 0x80000000
00121 #define PMSG_PF_SENT 0x40000000
00123 #define pmsg_is_extended(x) ((x)->m_prio & PMSG_PF_EXT)
00124 #define pmsg_was_sent(x) ((x)->m_prio & PMSG_PF_SENT)
00125 #define pmsg_mark_sent(x) do { (x)->m_prio |= PMSG_PF_SENT; } while (0)
00126
00127
00128
00129
00130
00131 void pmsg_init(void);
00132 void pmsg_close(void);
00133
00134 gint pmsg_size(pmsg_t *mb);
00135 pmsg_t *pmsg_new(gint prio, gconstpointer buf, gint len);
00136 pmsg_t * pmsg_new_extend(
00137 gint prio, gconstpointer buf, gint len,
00138 pmsg_free_t free_cb, gpointer arg);
00139 pmsg_t *pmsg_alloc(gint prio, pdata_t *db, gint roff, gint woff);
00140 pmsg_t *pmsg_clone(pmsg_t *mb);
00141 pmsg_t *pmsg_clone_extend(pmsg_t *mb, pmsg_free_t free_cb, gpointer arg);
00142 pmsg_free_t pmsg_replace_ext(
00143 pmsg_t *mb, pmsg_free_t nfree, gpointer narg, gpointer *oarg);
00144 gpointer pmsg_get_metadata(pmsg_t *mb);
00145 pmsg_check_t pmsg_set_check(pmsg_t *mb, pmsg_check_t check);
00146 void pmsg_free(pmsg_t *mb);
00147 gint pmsg_write(pmsg_t *mb, gconstpointer data, gint len);
00148 gint pmsg_read(pmsg_t *mb, gpointer data, gint len);
00149
00150 pdata_t *pdata_new(gint len);
00151 pdata_t *pdata_allocb(void *buf, gint len,
00152 pdata_free_t freecb, gpointer freearg);
00153 pdata_t *pdata_allocb_ext(void *buf, gint len,
00154 pdata_free_t freecb, gpointer freearg);
00155 void pdata_free_nop(gpointer p, gpointer arg);
00156 void pdata_unref(pdata_t *db);
00157
00158 #endif
00159
00160