backup
[lcr.git] / call.cpp
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** call 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 call_serial = 1; /* must be 1, because 0== no call */
27
28 //CALL_STATES
29
30 class Call *call_first = NULL;
31
32 /*
33  * find the call with call_id
34  */ 
35 class Call *find_call_id(unsigned long call_id)
36 {
37         class Call *call = call_first;
38
39         while(call)
40         {
41 //printf("comparing: '%s' with '%s'\n", name, call->c_name);
42                 if (call->c_serial == call_id)
43                         return(call);
44                 call = call->next;
45         }
46
47         return(NULL);
48 }
49
50
51 /*
52  * constructor for a new call 
53  */
54 Call::Call(void)
55 {
56         class Call **callp;
57
58         c_serial = call_serial++;
59         c_type = CALL_TYPE_NONE;
60
61         /* attach to chain */
62         next = NULL;
63         callp = &call_first;
64         while(*callp)
65                 callp = &((*callp)->next);
66         *callp = this;
67
68         classuse++;
69 }
70
71
72 /*
73  * call descructor
74  */
75 Call::~Call()
76 {
77         class Call *cl, **clp;
78
79         classuse--;
80
81         cl = call_first;
82         clp = &call_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, call not in chain!\n");
92         *clp = cl->next; /* detach from chain */
93 }
94
95
96
97 /* epoint sends a message to a call
98  *
99  */
100 void Call::message_epoint(unsigned long epoint_id, int message_type, union parameter *param)
101 {
102 }
103
104
105 /* call process is called from the main loop
106  * it processes the current calling state.
107  * returns 0 if call nothing was done
108  */
109 int Call::handler(void)
110 {
111         return(0);
112 }
113
114 /* free all call structures */
115 void call_free(void)
116 {
117
118         if (!call_first)
119         {
120                 PDEBUG(DEBUG_CALL, "no more pending call(s), done!\n");
121                 return;
122         }
123         while(call_first)
124         {
125                 if (options.deb & DEBUG_CALL)
126                 {
127                         PDEBUG(DEBUG_CALL, "freeing pending call\n");
128                 }
129
130                 delete call_first;
131         }
132 }
133
134
135