oRTP 0.16.5
src/utils.h
00001 /***************************************************************************
00002  *            utils.h
00003  *
00004  *  Wed Feb 23 14:15:36 2005
00005  *  Copyright  2005  Simon Morlat
00006  *  Email simon.morlat@linphone.org
00007  ****************************************************************************/
00008 /*
00009   The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
00010   Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
00011 
00012   This library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU Lesser General Public
00014   License as published by the Free Software Foundation; either
00015   version 2.1 of the License, or (at your option) any later version.
00016 
00017   This library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020   Lesser General Public License for more details.
00021 
00022   You should have received a copy of the GNU Lesser General Public
00023   License along with this library; if not, write to the Free Software
00024   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 */
00026 
00027 #ifndef UTILS_H
00028 #define UTILS_H
00029 
00030 #include "ortp/event.h"
00031 
00032 struct _OList {
00033         struct _OList *next;
00034         struct _OList *prev;
00035         void *data;
00036 };
00037 
00038 typedef struct _OList OList;
00039 
00040 
00041 #define o_list_next(elem) ((elem)->next)
00042 
00043 OList * o_list_append(OList *elem, void * data);
00044 OList * o_list_remove(OList *list, void *data);
00045 OList * o_list_free(OList *elem);
00046 OList *o_list_remove_link(OList *list, OList *elem);
00047 
00048 #ifndef MIN
00049 #define MIN(a,b) (((a)>(b)) ? (b) : (a))
00050 #endif
00051 #ifndef MAX
00052 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
00053 #endif
00054 
00055 #define return_if_fail(expr) if (!(expr)) {printf("%s:%i- assertion"#expr "failed\n",__FILE__,__LINE__); return;}
00056 #define return_val_if_fail(expr,ret) if (!(expr)) {printf("%s:%i- assertion" #expr "failed\n",__FILE__,__LINE__); return (ret);}
00057 
00058 
00059 #define INT_TO_POINTER(truc)    ((long)(long)(truc))
00060 #define POINTER_TO_INT(truc)    ((int)(long)(truc))
00061 
00062 typedef struct _dwsplit_t{
00063 #ifdef ORTP_BIGENDIAN
00064         uint16_t hi;
00065         uint16_t lo;
00066 #else
00067         uint16_t lo;
00068         uint16_t hi;
00069 #endif
00070 } dwsplit_t;
00071 
00072 typedef union{
00073         dwsplit_t split;
00074         uint32_t one;
00075 } poly32_t;
00076 
00077 #ifdef ORTP_BIGENDIAN
00078 #define hton24(x) (x)
00079 #else
00080 #define hton24(x) ((( (x) & 0x00ff0000) >>16) | (( (x) & 0x000000ff) <<16) | ( (x) & 0x0000ff00) )
00081 #endif
00082 #define ntoh24(x) hton24(x)
00083 
00084 #if defined(WIN32) || defined(_WIN32_WCE)
00085 #define is_would_block_error(errnum)    (errnum==WSAEWOULDBLOCK)
00086 #else
00087 #define is_would_block_error(errnum)    (errnum==EWOULDBLOCK || errnum==EAGAIN)
00088 #endif
00089 
00090 void ortp_ev_queue_put(OrtpEvQueue *q, OrtpEvent *ev);
00091 
00092 #endif