1122213Sharti/* 2122213Sharti * Copyright (c) 2001-2003 3122213Sharti * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4122213Sharti * All rights reserved. 5122213Sharti * 6122213Sharti * Redistribution and use in source and binary forms, with or without 7122213Sharti * modification, are permitted provided that the following conditions 8122213Sharti * are met: 9122213Sharti * 1. Redistributions of source code must retain the above copyright 10122213Sharti * notice, this list of conditions and the following disclaimer. 11122213Sharti * 2. Redistributions in binary form must reproduce the above copyright 12122213Sharti * notice, this list of conditions and the following disclaimer in the 13122213Sharti * documentation and/or other materials provided with the distribution. 14122213Sharti * 15122213Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16122213Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17122213Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18122213Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19122213Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20122213Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21122213Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22122213Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23122213Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24122213Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25122213Sharti * SUCH DAMAGE. 26122213Sharti * 27122213Sharti * Author: Hartmut Brandt <harti@freebsd.org> 28122213Sharti * 29133488Sharti * $Begemot: libunimsg/libngatm/unicust.h,v 1.4 2003/09/19 13:10:35 hbb Exp $ 30122213Sharti * 31122213Sharti * Customisation of signalling source to user space. 32122213Sharti */ 33122213Sharti#include <sys/types.h> 34122213Sharti#include <sys/queue.h> 35122213Sharti#include <stdio.h> 36122213Sharti#include <stdlib.h> 37122213Sharti#include <string.h> 38122213Sharti#include <assert.h> 39122213Sharti 40122213Sharti#define ASSERT(E, M) assert(E) 41122213Sharti 42122213Shartistatic __inline__ void * 43122213Shartimzalloc(size_t s) 44122213Sharti{ 45122213Sharti void *ptr = malloc(s); 46122213Sharti 47122213Sharti if (ptr) 48122213Sharti bzero(ptr, s); 49122213Sharti return (ptr); 50122213Sharti} 51122213Sharti 52122213Sharti#define INS_ALLOC() mzalloc(sizeof(struct uni)) 53122213Sharti#define INS_FREE(P) free(P) 54122213Sharti 55122213Sharti#define UNI_ALLOC() mzalloc(sizeof(struct uni_all)) 56122213Sharti#define UNI_FREE(P) free(P) 57122213Sharti 58122213Sharti#define SIG_ALLOC() mzalloc(sizeof(struct sig)) 59122213Sharti#define SIG_FREE(P) free(P) 60122213Sharti 61122213Sharti#define CALL_ALLOC() mzalloc(sizeof(struct call)) 62122213Sharti#define CALL_FREE(P) free(P) 63122213Sharti 64122213Sharti#define PARTY_ALLOC() mzalloc(sizeof(struct party)) 65122213Sharti#define PARTY_FREE(P) free(P) 66122213Sharti 67122213Sharti/* 68122213Sharti * Timers 69122213Sharti */ 70122213Shartistruct uni_timer { 71122213Sharti void *c; 72122213Sharti}; 73122213Sharti 74122213Sharti#define _TIMER_INIT(X,T) (X)->T.c = NULL 75122213Sharti#define _TIMER_DESTROY(U,F) _TIMER_STOP(U,F) 76122213Sharti#define _TIMER_STOP(U,F) \ 77122213Sharti do { \ 78122213Sharti if (F.c != NULL) { \ 79122213Sharti (U)->funcs->stop_timer(U, U->arg, F.c); \ 80122213Sharti F.c = NULL; \ 81122213Sharti } \ 82122213Sharti } while(0) 83122213Sharti#define _TIMER_START(UNI,ARG,FIELD,DUE,FUNC) \ 84122213Sharti (void)(FIELD.c = (UNI)->funcs->start_timer(UNI, \ 85122213Sharti UNI->arg, DUE, FUNC, ARG)) 86122213Sharti 87122213Sharti#define TIMER_ISACT(X,T) (X->T.c != NULL) 88122213Sharti 89122213Sharti#define TIMER_FUNC_UNI(T,F) \ 90122213Shartistatic void F(struct uni *); \ 91122213Shartistatic void \ 92122213Sharti_##T##_func(void *varg) \ 93122213Sharti{ \ 94122213Sharti struct uni *uni = (struct uni *)varg; \ 95122213Sharti uni->T.c = NULL; \ 96122213Sharti (F)(uni); \ 97122213Sharti} 98122213Sharti 99122213Sharti/* 100122213Sharti * Be careful: call may be invalid after the call to F 101122213Sharti */ 102122213Sharti#define TIMER_FUNC_CALL(T,F) \ 103122213Shartistatic void F(struct call *); \ 104122213Shartistatic void \ 105122213Sharti_##T##_func(void *varg) \ 106122213Sharti{ \ 107122213Sharti struct call *call = (struct call *)varg; \ 108122213Sharti call->T.c = NULL; \ 109122213Sharti (F)(call); \ 110122213Sharti} 111122213Sharti 112122213Sharti/* 113122213Sharti * Be careful: call/party may be invalid after the call to F 114122213Sharti */ 115122213Sharti#define TIMER_FUNC_PARTY(T,F) \ 116122213Shartistatic void F(struct party *); \ 117122213Shartistatic void \ 118122213Sharti_##T##_func(void *varg) \ 119122213Sharti{ \ 120122213Sharti struct party *party = (struct party *)varg; \ 121122213Sharti party->T.c = NULL; \ 122122213Sharti (F)(party); \ 123122213Sharti} 124