X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=endpoint.cpp;h=3c59f5390ab01241baf8b91ec236495dc8fe1377;hp=e0f6365bb3482959b55955a5dbf490c566313e22;hb=79bd731c0db3e3202cfeed2af3fb217ae744b70f;hpb=cbe9d412a37e75b61cc74e8a65b0293923eb5160 diff --git a/endpoint.cpp b/endpoint.cpp index e0f6365..3c59f53 100644 --- a/endpoint.cpp +++ b/endpoint.cpp @@ -9,10 +9,9 @@ ** ** \*****************************************************************************/ -#include #include "main.h" -unsigned long epoint_serial = 1; /* initial value must be 1, because 0== no epoint */ +unsigned int epoint_serial = 1; /* initial value must be 1, because 0== no epoint */ class Endpoint *epoint_first = NULL; @@ -20,12 +19,11 @@ class Endpoint *epoint_first = NULL; /* * find the epoint with epoint_id */ -class Endpoint *find_epoint_id(unsigned long epoint_id) +class Endpoint *find_epoint_id(unsigned int epoint_id) { class Endpoint *epoint = epoint_first; - while(epoint) - { + while(epoint) { //printf("comparing: '%s' with '%s'\n", name, epoint->name); if (epoint->ep_serial == epoint_id) return(epoint); @@ -35,11 +33,12 @@ class Endpoint *find_epoint_id(unsigned long epoint_id) return(NULL); } +int delete_endpoint(struct lcr_work *work, void *instance, int index); /* * endpoint constructor (link with either port or join id) */ -Endpoint::Endpoint(unsigned long port_id, unsigned long join_id) +Endpoint::Endpoint(unsigned int port_id, unsigned int join_id) { class Port *port; class Endpoint **epointpointer; @@ -50,6 +49,8 @@ Endpoint::Endpoint(unsigned long port_id, unsigned long join_id) ep_portlist = NULL; ep_app = NULL; + memset(&ep_delete, 0, sizeof(ep_delete)); + add_work(&ep_delete, delete_endpoint, this, 0); ep_use = 1; /* add endpoint to chain */ @@ -63,13 +64,15 @@ Endpoint::Endpoint(unsigned long port_id, unsigned long join_id) ep_serial = epoint_serial++; /* link to join or port */ - if (port_id) - { + if (port_id) { port = find_port_id(port_id); - if (port) - { - if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1) + if (port) { +#ifdef WITH_MISDN + if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_mISDN) earlyb = ((class PmISDN *)port)->p_m_mISDNport->earlyb; +#else + earlyb = 0; +#endif if (!portlist_new(port_id, port->p_type, earlyb)) FATAL("No memory for portlist.\n"); } @@ -98,18 +101,15 @@ Endpoint::~Endpoint(void) delete ep_app; /* free relations */ - if (ep_join_id) - { + if (ep_join_id) { PERROR("warning: still relation to join.\n"); } /* free portlist */ portlist = ep_portlist; - while(portlist) - { - if (portlist->port_id) - { - PERROR("warning: still relation to port (portlist list)\n"); + while(portlist) { + if (portlist->port_id) { + PERROR("Endpoint(%d) warning: still relation to port %d (portlist list)\n", ep_serial, portlist->port_id); } mtemp = portlist; portlist = portlist->next; @@ -121,8 +121,7 @@ Endpoint::~Endpoint(void) /* detach */ temp =epoint_first; tempp = &epoint_first; - while(temp) - { + while(temp) { if (temp == this) break; @@ -133,20 +132,22 @@ Endpoint::~Endpoint(void) FATAL("Endpoint not in Endpoint's list.\n"); *tempp = next; + del_work(&ep_delete); + /* free */ PDEBUG(DEBUG_EPOINT, "removed endpoint %d.\n", ep_serial); } /* create new portlist relation */ -struct port_list *Endpoint::portlist_new(unsigned long port_id, int port_type, int earlyb) +struct port_list *Endpoint::portlist_new(unsigned int port_id, int port_type, int earlyb) { struct port_list *portlist, **portlistpointer; /* portlist structure */ portlist = (struct port_list *)MALLOC(sizeof(struct port_list)); ememuse++; - PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocating port_list.\n", ep_serial); + PDEBUG(DEBUG_EPOINT, "EPOINT(%d) allocating port_list, attaching to port %d\n", ep_serial, port_id); /* add port_list to chain */ portlist->next = NULL; @@ -172,8 +173,7 @@ void Endpoint::free_portlist(struct port_list *portlist) temp = ep_portlist; tempp = &ep_portlist; - while(temp) - { + while(temp) { if (temp == portlist) break; @@ -186,24 +186,19 @@ void Endpoint::free_portlist(struct port_list *portlist) *tempp=portlist->next; /* free */ - PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removed port_list from endpoint\n", ep_serial); + PDEBUG(DEBUG_EPOINT, "EPOINT(%d) removed port %d from port_list of endpoint\n", ep_serial, portlist->port_id); FREE(portlist, sizeof(struct port_list)); ememuse--; } -/* handler for endpoint - */ -int Endpoint::handler(void) +int delete_endpoint(struct lcr_work *work, void *instance, int index) { - if (ep_use <= 0) - { - delete this; - return(-1); - } + class Endpoint *ep = (class Endpoint *)instance; - /* call application handler */ - if (ep_app) - return(ep_app->handler()); - return(0); + if (ep->ep_use <= 0) + delete ep; + + return 0; } +