1 /*
2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * Author: Hartmut Brandt <harti@freebsd.org>
28 *
29 * $Begemot: libunimsg/libngatm/unicust.h,v 1.4 2003/09/19 13:10:35 hbb Exp $
30 *
31 * Customisation of signalling source to user space.
32 */
33 #include <sys/types.h>
34 #include <sys/queue.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <assert.h>
39
40 #define ASSERT(E, M) assert(E)
41
42 static __inline__ void *
mzalloc(size_t s)43 mzalloc(size_t s)
44 {
45 void *ptr = malloc(s);
46
47 if (ptr)
48 bzero(ptr, s);
49 return (ptr);
50 }
51
52 #define INS_ALLOC() mzalloc(sizeof(struct uni))
53 #define INS_FREE(P) free(P)
54
55 #define UNI_ALLOC() mzalloc(sizeof(struct uni_all))
56 #define UNI_FREE(P) free(P)
57
58 #define SIG_ALLOC() mzalloc(sizeof(struct sig))
59 #define SIG_FREE(P) free(P)
60
61 #define CALL_ALLOC() mzalloc(sizeof(struct call))
62 #define CALL_FREE(P) free(P)
63
64 #define PARTY_ALLOC() mzalloc(sizeof(struct party))
65 #define PARTY_FREE(P) free(P)
66
67 /*
68 * Timers
69 */
70 struct uni_timer {
71 void *c;
72 };
73
74 #define _TIMER_INIT(X,T) (X)->T.c = NULL
75 #define _TIMER_DESTROY(U,F) _TIMER_STOP(U,F)
76 #define _TIMER_STOP(U,F) \
77 do { \
78 if (F.c != NULL) { \
79 (U)->funcs->stop_timer(U, U->arg, F.c); \
80 F.c = NULL; \
81 } \
82 } while(0)
83 #define _TIMER_START(UNI,ARG,FIELD,DUE,FUNC) \
84 (void)(FIELD.c = (UNI)->funcs->start_timer(UNI, \
85 UNI->arg, DUE, FUNC, ARG))
86
87 #define TIMER_ISACT(X,T) (X->T.c != NULL)
88
89 #define TIMER_FUNC_UNI(T,F) \
90 static void F(struct uni *); \
91 static void \
92 _##T##_func(void *varg) \
93 { \
94 struct uni *uni = (struct uni *)varg; \
95 uni->T.c = NULL; \
96 (F)(uni); \
97 }
98
99 /*
100 * Be careful: call may be invalid after the call to F
101 */
102 #define TIMER_FUNC_CALL(T,F) \
103 static void F(struct call *); \
104 static void \
105 _##T##_func(void *varg) \
106 { \
107 struct call *call = (struct call *)varg; \
108 call->T.c = NULL; \
109 (F)(call); \
110 }
111
112 /*
113 * Be careful: call/party may be invalid after the call to F
114 */
115 #define TIMER_FUNC_PARTY(T,F) \
116 static void F(struct party *); \
117 static void \
118 _##T##_func(void *varg) \
119 { \
120 struct party *party = (struct party *)varg; \
121 party->T.c = NULL; \
122 (F)(party); \
123 }
124