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(class Endpoint *epoint)
55 {
56         class Call **callp;
57
58         if (!epoint)
59         {
60                 PERROR("software error, epoint is NULL.\n");
61                 exit(-1);
62         }
63         c_serial = call_serial++;
64         c_type = CALL_TYPE_NONE;
65
66         /* attach to chain */
67         next = NULL;
68         callp = &call_first;
69         while(*callp)
70                 callp = &((*callp)->next);
71         *callp = this;
72
73         classuse++;
74 }
75
76
77 /*
78  * call descructor
79  */
80 Call::~Call()
81 {
82         class Call *cl, **clp;
83
84         classuse--;
85
86         cl = call_first;
87         clp = &call_first;
88         while(cl)
89         {
90                 if (cl == this)
91                         break;
92                 clp = &cl->next;
93                 cl = cl->next;
94         }
95         if (!cl)
96         {
97                 PERROR("software error, call not in chain! exitting\n");
98                 exit(-1);
99         }
100         *clp = cl->next; /* detach from chain */
101 }
102
103
104
105 /* epoint sends a message to a call
106  *
107  */
108 void Call::message_epoint(unsigned long epoint_id, int message_type, union parameter *param)
109 {
110 }
111
112
113 /* call process is called from the main loop
114  * it processes the current calling state.
115  * returns 0 if call nothing was done
116  */
117 int Call::handler(void)
118 {
119         return(0);
120 }
121
122 void Call::release(unsigned long epoint_id, int hold, int location, int cause)
123 {
124 }
125         
126 /* free all call structures */
127 void call_free(void)
128 {
129
130         if (!call_first)
131         {
132                 PDEBUG(DEBUG_CALL, "no more pending call(s), done!\n");
133                 return;
134         }
135         while(call_first)
136         {
137                 if (options.deb & DEBUG_CALL)
138                 {
139                         PDEBUG(DEBUG_CALL, "freeing pending call\n");
140                 }
141
142                 delete call_first;
143         }
144 }
145
146
147