1 /*****************************************************************************\
3 ** Linux Call Router **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** join functions for remote application **
10 \*****************************************************************************/
17 //#include <sys/types.h>
18 //#include <sys/stat.h>
21 //#define __u8 unsigned char
22 //#define __u16 unsigned short
23 //#define __u32 unsigned long
24 //#include "linux/isdnif.h"
28 * constructor for a new join
29 * the join will have a relation to the calling endpoint
31 JoinRemote::JoinRemote(unsigned long serial, char *remote_name, int remote_id) : Join()
33 PDEBUG(DEBUG_JOIN, "Constructor(new join)");
34 union parameter *param;
36 SCPY(j_remote_name, remote_name);
37 j_remote_id = remote_id;
38 j_type = JOIN_TYPE_REMOTE;
40 j_epoint_id = serial; /* this is the endpoint, if created by epoint */
42 PDEBUG(DEBUG_JOIN, "New remote join connected to endpoint id %lu and application %s\n", j_epoint_id, remote_name);
44 /* send new ref to remote socket */
45 memset(¶m, 0, sizeof(param));
46 /* the j_serial is assigned by Join() parent. this is sent as new ref */
47 if (admin_message_from_join(j_remote_id, j_serial, MESSAGE_NEWREF, param)<0)
48 FATAL("No socket with remote application '%s' found, this shall not happen. because we already created one.\n", j_remote_name);
55 JoinRemote::~JoinRemote()
60 /* join process is called from the main loop
61 * it processes the current calling state.
62 * returns 0 if join nothing was done
64 int JoinRemote::handler(void)
70 void JoinRemote::message_epoint(unsigned long epoint_id, int message_type, union parameter *param)
72 /* if endpoint has just been removed, but still a message in the que */
73 if (epoint_id != j_epoint_id)
76 /* look for Remote's interface */
77 if (admin_message_from_join(j_remote_id, j_serial, message_type, param)<0)
79 PERROR("No socket with remote application '%s' found, this shall not happen. Closing socket shall cause release of all joins.\n", j_remote_name);
83 if (message_type == MESSAGE_RELEASE)
90 void JoinRemote::message_remote(int message_type, union parameter *param)
92 struct message *message;
94 /* create relation if no relation exists */
97 class Endpoint *epoint;
99 if (!(epoint = new Endpoint(0, j_serial)))
100 FATAL("No memory for Endpoint instance\n");
101 j_epoint_id = epoint->ep_serial;
102 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint)))
103 FATAL("No memory for Endpoint Application instance\n");
106 /* set serial on bchannel message
107 * also ref is given, so we send message with ref */
108 if (message_type == MESSAGE_BCHANNEL)
110 message_bchannel_from_join(this, param->bchannel.type, param->bchannel.addr);
114 /* cannot just forward, because param is not of container "struct message" */
115 message = message_create(j_serial, j_epoint_id, JOIN_TO_EPOINT, message_type);
116 memcpy(&message->param, param, sizeof(message->param));
117 message_put(message);
119 if (message_type == MESSAGE_RELEASE)
126 void message_bchannel_to_join(int serial, int type, unsigned long addr)
128 union parameter param;
130 class JoinRemote *joinremote;
132 /* find join serial */
133 join = find_join_id(serial);
136 PDEBUG(DEBUG_JOIN | DEBUG_BCHANNEL, "Join %d not found\n", serial);
139 if (!join->j_type != JOIN_TYPE_REMOTE)
141 PERROR("Join %d not of remote type. This shall not happen.\n", serial);
144 joinremote = (class JoinRemote *)join;
146 memset(¶m, 0, sizeof(union parameter));
147 param.bchannel.type = type;
148 param.bchannel.addr = addr;
149 if (admin_message_from_join(joinremote->j_remote_id, joinremote->j_serial, MESSAGE_BCHANNEL, ¶m)<0)
151 PERROR("No socket with remote application '%s' found, this shall not happen. Closing socket shall cause release of all joins.\n", joinremote->j_remote_name);