1 /*****************************************************************************\
3 ** Linux Call Router **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** The Endpoint is the link between the join and the port. **
10 \*****************************************************************************/
15 unsigned long epoint_serial = 1; /* initial value must be 1, because 0== no epoint */
17 class Endpoint *epoint_first = NULL;
21 * find the epoint with epoint_id
23 class Endpoint *find_epoint_id(unsigned long epoint_id)
25 class Endpoint *epoint = epoint_first;
29 //printf("comparing: '%s' with '%s'\n", name, epoint->name);
30 if (epoint->ep_serial == epoint_id)
32 epoint = epoint->next;
40 * endpoint constructor (link with either port or join id)
42 Endpoint::Endpoint(unsigned long port_id, unsigned long join_id, unsigned long use_epoint_id)
45 class Endpoint **epointpointer;
48 /* epoint structure */
49 PDEBUG(DEBUG_EPOINT, "EPOINT(%d): Allocating enpoint %d and connecting it with:%s%s\n", epoint_serial, epoint_serial, (port_id)?" ioport":"", (join_id)?" join":"");
55 /* add endpoint to chain */
57 epointpointer = &epoint_first;
59 epointpointer = &((*epointpointer)->next);
60 *epointpointer = this;
64 ep_serial = use_epoint_id;
66 ep_serial = epoint_serial++;
68 /* link to join or port */
71 port = find_port_id(port_id);
74 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
75 earlyb = ((class PmISDN *)port)->p_m_mISDNport->earlyb;
76 if (!portlist_new(port_id, port->p_type, earlyb))
77 FATAL("No memory for portlist.\n");
92 Endpoint::~Endpoint(void)
94 class Endpoint *temp, **tempp;
95 struct port_list *portlist, *mtemp;
99 /* remote application */
106 PERROR("warning: still relation to join.\n");
110 portlist = ep_portlist;
113 if (portlist->port_id)
115 PERROR("warning: still relation to port (portlist list)\n");
118 portlist = portlist->next;
119 memset(mtemp, 0, sizeof(struct port_list));
120 FREE(mtemp, sizeof(struct port_list));
126 tempp = &epoint_first;
136 FATAL("Endpoint not in Endpoint's list.\n");
140 PDEBUG(DEBUG_EPOINT, "removed endpoint %d.\n", ep_serial);
143 /* create new portlist relation
145 struct port_list *Endpoint::portlist_new(unsigned long port_id, int port_type, int earlyb)
147 struct port_list *portlist, **portlistpointer;
149 /* portlist structure */
150 portlist = (struct port_list *)MALLOC(sizeof(struct port_list));
152 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocating port_list.\n", ep_serial);
154 /* add port_list to chain */
155 portlist->next = NULL;
156 portlistpointer = &ep_portlist;
157 while(*portlistpointer)
158 portlistpointer = &((*portlistpointer)->next);
159 *portlistpointer = portlist;
161 /* link to join or port */
162 portlist->port_id = port_id;
163 portlist->port_type = port_type;
164 portlist->early_b = earlyb;
170 /* free portlist relation
172 void Endpoint::free_portlist(struct port_list *portlist)
174 struct port_list *temp, **tempp;
177 tempp = &ep_portlist;
180 if (temp == portlist)
187 FATAL("port_list not in Endpoint's list.\n");
189 *tempp=portlist->next;
192 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removed port_list from endpoint\n", ep_serial);
193 FREE(portlist, sizeof(struct port_list));
198 /* handler for endpoint
200 int Endpoint::handler(void)
208 /* call application handler */
210 return(ep_app->handler());