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)
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;
63 ep_serial = epoint_serial++;
65 /* link to join 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))
74 FATAL("No memory for portlist.\n");
89 Endpoint::~Endpoint(void)
91 class Endpoint *temp, **tempp;
92 struct port_list *portlist, *mtemp;
96 /* remote application */
103 PERROR("warning: still relation to join.\n");
107 portlist = ep_portlist;
110 if (portlist->port_id)
112 PERROR("warning: still relation to port (portlist list)\n");
115 portlist = portlist->next;
116 memset(mtemp, 0, sizeof(struct port_list));
117 FREE(mtemp, sizeof(struct port_list));
123 tempp = &epoint_first;
133 FATAL("Endpoint not in Endpoint's list.\n");
137 PDEBUG(DEBUG_EPOINT, "removed endpoint %d.\n", ep_serial);
140 /* create new portlist relation
142 struct port_list *Endpoint::portlist_new(unsigned long port_id, int port_type, int earlyb)
144 struct port_list *portlist, **portlistpointer;
146 /* portlist structure */
147 portlist = (struct port_list *)MALLOC(sizeof(struct port_list));
149 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocating port_list.\n", ep_serial);
151 /* add port_list to chain */
152 portlist->next = NULL;
153 portlistpointer = &ep_portlist;
154 while(*portlistpointer)
155 portlistpointer = &((*portlistpointer)->next);
156 *portlistpointer = portlist;
158 /* link to join or port */
159 portlist->port_id = port_id;
160 portlist->port_type = port_type;
161 portlist->early_b = earlyb;
167 /* free portlist relation
169 void Endpoint::free_portlist(struct port_list *portlist)
171 struct port_list *temp, **tempp;
174 tempp = &ep_portlist;
177 if (temp == portlist)
184 FATAL("port_list not in Endpoint's list.\n");
186 *tempp=portlist->next;
189 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removed port_list from endpoint\n", ep_serial);
190 FREE(portlist, sizeof(struct port_list));
195 /* handler for endpoint
197 int Endpoint::handler(void)
205 /* call application handler */
207 return(ep_app->handler());