fixes & improvements
[lcr.git] / joinasterisk.cpp
1 /*****************************************************************************\
2 **                                                                           **
3 ** Linux Call Router                                                         **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** join functions for channel driver                                         **
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
27 /*
28  * constructor for a new join 
29  * the join will have a relation to the calling endpoint
30  */
31 JoinAsterisk::JoinAsterisk(unsigned long serial) : Join()
32 {
33         PDEBUG(DEBUG_JOIN, "Constructor(new join)");
34
35         c_type = JOIN_TYPE_ASTERISK;
36
37         c_epoint_id = serial;
38         if (c_epoint_id)
39                 PDEBUG(DEBUG_JOIN, "New join connected to endpoint id %lu\n", c_epoint_id);
40 }
41
42
43 /*
44  * join descructor
45  */
46 JoinAsterisk::~JoinAsterisk()
47 {
48
49 }
50
51
52 /* join process is called from the main loop
53  * it processes the current calling state.
54  * returns 0 if join nothing was done
55  */
56 int JoinAsterisk::handler(void)
57 {
58         return(0);
59 }
60
61
62 void JoinAsterisk::message_epoint(unsigned long epoint_id, int message_type, union parameter *param)
63 {
64         /* if endpoint has just been removed, but still a message in the que */
65         if (epoint_id != c_epoint_id)
66                 return;
67         
68         /* look for asterisk's interface */
69         if (admin_message_from_join(epoint_id, message_type, param)<0)
70         {
71                 PERROR("No socket with asterisk found, this shall not happen. Closing socket shall cause release of all asterisk joins\n");
72                 return;         
73         }
74
75         if (message_type == MESSAGE_RELEASE)
76         {
77                 delete this;
78                 return;
79         }
80 }
81
82 void JoinAsterisk::message_asterisk(unsigned long ref, int message_type, union parameter *param)
83 {
84         struct message *message;
85
86         /* create relation if no relation exists */
87         if (!c_epoint_id)
88         {
89                 class Endpoint          *epoint;
90
91                 if (!(epoint = new Endpoint(0, c_serial, ref)))
92                         FATAL("No memory for Endpoint instance\n");
93                 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint)))
94                         FATAL("No memory for Endpoint Application instance\n");
95         }
96
97         message = message_create(c_serial, c_epoint_id, JOIN_TO_EPOINT, message_type);
98         memcpy(&message->param, param, sizeof(message->param));
99         message_put(message);
100
101         if (message_type == MESSAGE_RELEASE)
102         {
103                 delete this;
104                 return;
105         }
106 }
107
108
109