1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** The Endpoint is the link between the call 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 call id)
42 Endpoint::Endpoint(int port_id, int call_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":"", (call_id)?" call":"");
55 /* add endpoint to chain */
57 epointpointer = &epoint_first;
59 epointpointer = &((*epointpointer)->next);
60 *epointpointer = this;
63 ep_serial = epoint_serial++;
65 /* link to call or port */
68 port = find_port_id(port_id);
71 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
72 earlyb = ((class PmISDN *)port)->p_m_mISDNport->earlyb;
73 if (!portlist_new(port_id, port->p_type, earlyb))
75 PERROR("no mem for portlist, exitting...\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 call.\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));
126 tempp = &epoint_first;
137 PERROR("error: endpoint not in endpoint's list, exitting.\n");
143 PDEBUG(DEBUG_EPOINT, "removed endpoint %d.\n", ep_serial);
146 /* create new portlist relation
148 struct port_list *Endpoint::portlist_new(unsigned long port_id, int port_type, int earlyb)
150 struct port_list *portlist, **portlistpointer;
152 /* portlist structure */
153 portlist = (struct port_list *)calloc(1, sizeof(struct port_list));
156 PERROR("no mem for allocating port_list\n");
160 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocating port_list.\n", ep_serial);
161 memset(portlist, 0, sizeof(struct port_list));
163 /* add port_list to chain */
164 portlist->next = NULL;
165 portlistpointer = &ep_portlist;
166 while(*portlistpointer)
167 portlistpointer = &((*portlistpointer)->next);
168 *portlistpointer = portlist;
170 /* link to call or port */
171 portlist->port_id = port_id;
172 portlist->port_type = port_type;
173 portlist->early_b = earlyb;
179 /* free portlist relation
181 void Endpoint::free_portlist(struct port_list *portlist)
183 struct port_list *temp, **tempp;
186 tempp = &ep_portlist;
189 if (temp == portlist)
197 PERROR("port_list not in endpoint's list, exitting.\n");
201 *tempp=portlist->next;
204 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removed port_list from endpoint\n", ep_serial);
205 memset(portlist, 0, sizeof(struct port_list));
211 /* handler for endpoint
213 int Endpoint::handler(void)
221 /* call application handler */
223 return(ep_app->handler());