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;
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":"", (call_id)?" call":"");
54 /* add endpoint to chain */
56 epointpointer = &epoint_first;
58 epointpointer = &((*epointpointer)->next);
59 *epointpointer = this;
62 ep_serial = epoint_serial++;
64 /* link to call or port */
67 port = find_port_id(port_id);
69 if (!portlist_new(port_id, port->p_type))
71 PERROR("no mem for portlist, exitting...\n");
87 Endpoint::~Endpoint(void)
89 class Endpoint *temp, **tempp;
90 struct port_list *portlist, *mtemp;
94 /* remote application */
101 PERROR("warning: still relation to call.\n");
105 portlist = ep_portlist;
108 if (portlist->port_id)
110 PERROR("warning: still relation to port (portlist list)\n");
113 portlist = portlist->next;
114 memset(mtemp, 0, sizeof(struct port_list));
121 tempp = &epoint_first;
132 PERROR("error: endpoint not in endpoint's list, exitting.\n");
138 PDEBUG(DEBUG_EPOINT, "removed endpoint %d.\n", ep_serial);
141 /* create new portlist relation
143 struct port_list *Endpoint::portlist_new(unsigned long port_id, int port_type)
145 struct port_list *portlist, **portlistpointer;
147 /* portlist structure */
148 portlist = (struct port_list *)calloc(1, sizeof(struct port_list));
151 PERROR("no mem for allocating port_list\n");
155 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocating port_list.\n", ep_serial);
156 memset(portlist, 0, sizeof(struct port_list));
158 /* add port_list to chain */
159 portlist->next = NULL;
160 portlistpointer = &ep_portlist;
161 while(*portlistpointer)
162 portlistpointer = &((*portlistpointer)->next);
163 *portlistpointer = portlist;
165 /* link to call or port */
166 portlist->port_id = port_id;
167 portlist->port_type = port_type;
173 /* free portlist relation
175 void Endpoint::free_portlist(struct port_list *portlist)
177 struct port_list *temp, **tempp;
180 tempp = &ep_portlist;
183 if (temp == portlist)
191 PERROR("port_list not in endpoint's list, exitting.\n");
195 *tempp=portlist->next;
198 PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removed port_list from endpoint\n", ep_serial);
199 memset(portlist, 0, sizeof(struct port_list));
205 /* handler for endpoint
207 int Endpoint::handler(void)
215 /* call application handler */
217 return(ep_app->handler());