1 /*****************************************************************************\
3 ** Linux Call Router **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** The Endpoint is the link between the join and the port. **
10 \*****************************************************************************/
14 unsigned int epoint_serial = 1; /* initial value must be 1, because 0== no epoint */
16 class Endpoint *epoint_first = NULL;
20 * find the epoint with epoint_id
22 class Endpoint *find_epoint_id(unsigned int epoint_id)
24 class Endpoint *epoint = epoint_first;
27 //printf("comparing: '%s' with '%s'\n", name, epoint->name);
28 if (epoint->ep_serial == epoint_id)
30 epoint = epoint->next;
38 * endpoint constructor (link with either port or join id)
40 Endpoint::Endpoint(unsigned int port_id, unsigned int join_id)
43 class Endpoint **epointpointer;
46 /* epoint structure */
47 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":"");
53 /* add endpoint to chain */
55 epointpointer = &epoint_first;
57 epointpointer = &((*epointpointer)->next);
58 *epointpointer = this;
61 ep_serial = epoint_serial++;
63 /* link to join or port */
65 port = find_port_id(port_id);
67 if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_mISDN)
68 earlyb = ((class PmISDN *)port)->p_m_mISDNport->earlyb;
69 if (!portlist_new(port_id, port->p_type, earlyb))
70 FATAL("No memory for portlist.\n");
85 Endpoint::~Endpoint(void)
87 class Endpoint *temp, **tempp;
88 struct port_list *portlist, *mtemp;
92 /* remote application */
98 PERROR("warning: still relation to join.\n");
102 portlist = ep_portlist;
104 if (portlist->port_id) {
105 PERROR("warning: still relation to port (portlist list)\n");
108 portlist = portlist->next;
109 memset(mtemp, 0, sizeof(struct port_list));
110 FREE(mtemp, sizeof(struct port_list));
116 tempp = &epoint_first;
125 FATAL("Endpoint not in Endpoint's list.\n");
129 PDEBUG(DEBUG_EPOINT, "removed endpoint %d.\n", ep_serial);
132 /* create new portlist relation
134 struct port_list *Endpoint::portlist_new(unsigned int port_id, int port_type, int earlyb)
136 struct port_list *portlist, **portlistpointer;
138 /* portlist structure */
139 portlist = (struct port_list *)MALLOC(sizeof(struct port_list));
141 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocating port_list.\n", ep_serial);
143 /* add port_list to chain */
144 portlist->next = NULL;
145 portlistpointer = &ep_portlist;
146 while(*portlistpointer)
147 portlistpointer = &((*portlistpointer)->next);
148 *portlistpointer = portlist;
150 /* link to join or port */
151 portlist->port_id = port_id;
152 portlist->port_type = port_type;
153 portlist->early_b = earlyb;
159 /* free portlist relation
161 void Endpoint::free_portlist(struct port_list *portlist)
163 struct port_list *temp, **tempp;
166 tempp = &ep_portlist;
168 if (temp == portlist)
175 FATAL("port_list not in Endpoint's list.\n");
177 *tempp=portlist->next;
180 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removed port_list from endpoint\n", ep_serial);
181 FREE(portlist, sizeof(struct port_list));
186 /* handler for endpoint
188 int Endpoint::handler(void)
195 /* call application handler */
197 return(ep_app->handler());