oRTP  0.16.1
utils.h
1 /***************************************************************************
2  * utils.h
3  *
4  * Wed Feb 23 14:15:36 2005
5  * Copyright 2005 Simon Morlat
6  * Email simon.morlat@linphone.org
7  ****************************************************************************/
8 /*
9  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
10  Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
11 
12  This library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU Lesser General Public
14  License as published by the Free Software Foundation; either
15  version 2.1 of the License, or (at your option) any later version.
16 
17  This library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  Lesser General Public License for more details.
21 
22  You should have received a copy of the GNU Lesser General Public
23  License along with this library; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26 
27 #ifndef UTILS_H
28 #define UTILS_H
29 
30 #include "ortp/event.h"
31 
32 struct _OList {
33  struct _OList *next;
34  struct _OList *prev;
35  void *data;
36 };
37 
38 typedef struct _OList OList;
39 
40 
41 #define o_list_next(elem) ((elem)->next)
42 
43 OList * o_list_append(OList *elem, void * data);
44 OList * o_list_remove(OList *list, void *data);
45 OList * o_list_free(OList *elem);
46 
47 #ifndef MIN
48 #define MIN(a,b) (((a)>(b)) ? (b) : (a))
49 #endif
50 #ifndef MAX
51 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
52 #endif
53 
54 #define return_if_fail(expr) if (!(expr)) {printf("%s:%i- assertion"#expr "failed\n",__FILE__,__LINE__); return;}
55 #define return_val_if_fail(expr,ret) if (!(expr)) {printf("%s:%i- assertion" #expr "failed\n",__FILE__,__LINE__); return (ret);}
56 
57 
58 #define INT_TO_POINTER(truc) ((long)(long)(truc))
59 #define POINTER_TO_INT(truc) ((int)(long)(truc))
60 
61 typedef struct _dwsplit_t{
62 #ifdef ORTP_BIGENDIAN
63  uint16_t hi;
64  uint16_t lo;
65 #else
66  uint16_t lo;
67  uint16_t hi;
68 #endif
69 } dwsplit_t;
70 
71 typedef union{
72  dwsplit_t split;
73  uint32_t one;
74 } poly32_t;
75 
76 #ifdef ORTP_BIGENDIAN
77 #define hton24(x) (x)
78 #else
79 #define hton24(x) ((( (x) & 0x00ff0000) >>16) | (( (x) & 0x000000ff) <<16) | ( (x) & 0x0000ff00) )
80 #endif
81 #define ntoh24(x) hton24(x)
82 
83 #if defined(WIN32) || defined(_WIN32_WCE)
84 #define is_would_block_error(errnum) (errnum==WSAEWOULDBLOCK)
85 #else
86 #define is_would_block_error(errnum) (errnum==EWOULDBLOCK || errnum==EAGAIN)
87 #endif
88 
89 void ortp_ev_queue_put(OrtpEvQueue *q, OrtpEvent *ev);
90 
91 #endif