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;
36 int delete_endpoint(struct lcr_work *work, void *instance, int index);
39 * endpoint constructor (link with either port or join id)
41 Endpoint::Endpoint(unsigned int port_id, unsigned int join_id)
44 class Endpoint **epointpointer;
47 /* epoint structure */
48 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":"");
52 memset(&ep_delete, 0, sizeof(ep_delete));
53 add_work(&ep_delete, delete_endpoint, this, 0);
56 /* add endpoint to chain */
58 epointpointer = &epoint_first;
60 epointpointer = &((*epointpointer)->next);
61 *epointpointer = this;
64 ep_serial = epoint_serial++;
66 /* link to join or port */
68 port = find_port_id(port_id);
71 if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_mISDN)
72 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 */
105 PERROR("warning: still relation to join.\n");
109 portlist = ep_portlist;
111 if (portlist->port_id) {
112 PERROR("Endpoint(%d) warning: still relation to port %d (portlist list)\n", ep_serial, portlist->port_id);
115 portlist = portlist->next;
116 memset(mtemp, 0, sizeof(struct port_list));
117 FREE(mtemp, sizeof(struct port_list));
123 tempp = &epoint_first;
132 FATAL("Endpoint not in Endpoint's list.\n");
135 del_work(&ep_delete);
138 PDEBUG(DEBUG_EPOINT, "removed endpoint %d.\n", ep_serial);
141 /* create new portlist relation
143 struct port_list *Endpoint::portlist_new(unsigned int port_id, int port_type, int earlyb)
145 struct port_list *portlist, **portlistpointer;
147 /* portlist structure */
148 portlist = (struct port_list *)MALLOC(sizeof(struct port_list));
150 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocating port_list, attaching to port %d\n", ep_serial, port_id);
152 /* add port_list to chain */
153 portlist->next = NULL;
154 portlistpointer = &ep_portlist;
155 while(*portlistpointer)
156 portlistpointer = &((*portlistpointer)->next);
157 *portlistpointer = portlist;
159 /* link to join or port */
160 portlist->port_id = port_id;
161 portlist->port_type = port_type;
162 portlist->early_b = earlyb;
168 /* free portlist relation
170 void Endpoint::free_portlist(struct port_list *portlist)
172 struct port_list *temp, **tempp;
175 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 %d from port_list of endpoint\n", ep_serial, portlist->port_id);
190 FREE(portlist, sizeof(struct port_list));
195 int delete_endpoint(struct lcr_work *work, void *instance, int index)
197 class Endpoint *ep = (class Endpoint *)instance;