socket mISDN work
[lcr.git] / join.cpp
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** join functions                                                            **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include <stdio.h>
13 //#include <string.h>
14 //#include <stdlib.h>
15 //#include <unistd.h>
16 //#include <poll.h>
17 //#include <sys/types.h>
18 //#include <sys/stat.h>
19 //#include <fcntl.h>
20 #include "main.h"
21 //#define __u8 unsigned char
22 //#define __u16 unsigned short
23 //#define __u32 unsigned long
24 //#include "linux/isdnif.h"
25
26 unsigned long join_serial = 1; /* must be 1, because 0== no join */
27
28 //JOIN_STATES
29
30 class Join *join_first = NULL;
31
32 /*
33  * find the join with join_id
34  */ 
35 class Join *find_join_id(unsigned long join_id)
36 {
37         class Join *join = join_first;
38
39         while(join)
40         {
41 //printf("comparing: '%s' with '%s'\n", name, join->j_name);
42                 if (join->j_serial == join_id)
43                         return(join);
44                 join = join->next;
45         }
46
47         return(NULL);
48 }
49
50
51 /*
52  * constructor for a new join 
53  */
54 Join::Join(void)
55 {
56         class Join **joinp;
57
58         j_serial = join_serial++;
59         j_type = JOIN_TYPE_NONE;
60
61         /* attach to chain */
62         next = NULL;
63         joinp = &join_first;
64         while(*joinp)
65                 joinp = &((*joinp)->next);
66         *joinp = this;
67
68         classuse++;
69 }
70
71
72 /*
73  * join descructor
74  */
75 Join::~Join()
76 {
77         class Join *cl, **clp;
78
79         classuse--;
80
81         cl = join_first;
82         clp = &join_first;
83         while(cl)
84         {
85                 if (cl == this)
86                         break;
87                 clp = &cl->next;
88                 cl = cl->next;
89         }
90         if (!cl)
91                 FATAL("software error, join not in chain!\n");
92         *clp = cl->next; /* detach from chain */
93 }
94
95
96
97 /* epoint sends a message to a join
98  *
99  */
100 void Join::message_epoint(unsigned long epoint_id, int message_type, union parameter *param)
101 {
102 }
103
104
105 /* join process is called from the main loop
106  * it processes the current calling state.
107  * returns 0 if nothing was done
108  */
109 int Join::handler(void)
110 {
111         return(0);
112 }
113
114 /* free all join structures */
115 void join_free(void)
116 {
117
118         if (!join_first)
119         {
120                 PDEBUG(DEBUG_JOIN, "no more pending join(s), done!\n");
121                 return;
122         }
123         while(join_first)
124         {
125                 if (options.deb & DEBUG_JOIN)
126                 {
127                         PDEBUG(DEBUG_JOIN, "freeing pending join\n");
128                 }
129
130                 delete join_first;
131         }
132 }
133
134
135