Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

pmsg.h

Go to the documentation of this file.
00001 /*
00002  * $Id: pmsg.h,v 1.9 2005/10/20 07:53:42 cbiere Exp $
00003  *
00004  * Copyright (c) 2002-2003, Raphael Manfredi
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  * A message block
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  * Message priorities.
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  * Flags defined in highest bits of `m_prio'.
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  * Public interface
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  /* _core_pmsg_h_ */
00159 
00160 /* vi: set ts=4 sw=4 cindent: */

Generated on Sun Feb 12 10:49:57 2006 for Gtk-Gnutella by doxygen 1.3.6