Data-Over-Voice
[lcr.git] / endpoint.cpp
index 28ea12f..3c59f53 100644 (file)
@@ -33,6 +33,7 @@ class Endpoint *find_epoint_id(unsigned int epoint_id)
        return(NULL);
 }
 
+int delete_endpoint(struct lcr_work *work, void *instance, int index);
 
 /*
  * endpoint constructor (link with either port or join id)
@@ -48,6 +49,8 @@ Endpoint::Endpoint(unsigned int port_id, unsigned int 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 */
@@ -64,8 +67,12 @@ Endpoint::Endpoint(unsigned int port_id, unsigned int join_id)
        if (port_id) {
                port = find_port_id(port_id);
                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");
                }
@@ -102,7 +109,7 @@ Endpoint::~Endpoint(void)
        portlist = ep_portlist;
        while(portlist) {
                if (portlist->port_id) {
-                       PERROR("warning: still relation to port (portlist list)\n");
+                       PERROR("Endpoint(%d) warning: still relation to port %d (portlist list)\n", ep_serial, portlist->port_id);
                }
                mtemp = portlist;
                portlist = portlist->next;
@@ -125,6 +132,8 @@ 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);
 }
@@ -138,7 +147,7 @@ struct port_list *Endpoint::portlist_new(unsigned int port_id, int port_type, in
        /* 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;
@@ -177,23 +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;
 }
+