2007-05-06 13:54:52 +00:00
/*****************************************************************************\
* * * *
2007-07-17 17:28:09 +00:00
* * Linux Call Router * *
2007-05-06 13:54:52 +00:00
* * * *
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * *
* * Copyright : Andreas Eversberg * *
* * * *
2007-07-17 17:28:09 +00:00
* * The Endpoint is the link between the join and the port . * *
2007-05-06 13:54:52 +00:00
* * * *
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "main.h"
2008-06-14 06:34:50 +00:00
unsigned int epoint_serial = 1 ; /* initial value must be 1, because 0== no epoint */
2007-05-06 13:54:52 +00:00
class Endpoint * epoint_first = NULL ;
/*
* find the epoint with epoint_id
*/
2008-06-14 06:34:50 +00:00
class Endpoint * find_epoint_id ( unsigned int epoint_id )
2007-05-06 13:54:52 +00:00
{
class Endpoint * epoint = epoint_first ;
2009-07-05 20:14:21 +00:00
while ( epoint ) {
2007-05-06 13:54:52 +00:00
//printf("comparing: '%s' with '%s'\n", name, epoint->name);
if ( epoint - > ep_serial = = epoint_id )
return ( epoint ) ;
epoint = epoint - > next ;
}
return ( NULL ) ;
}
2010-01-16 10:20:23 +00:00
int delete_endpoint ( struct lcr_work * work , void * instance , int index ) ;
2007-05-06 13:54:52 +00:00
/*
2007-07-17 17:28:09 +00:00
* endpoint constructor ( link with either port or join id )
2007-05-06 13:54:52 +00:00
*/
2008-06-14 06:34:50 +00:00
Endpoint : : Endpoint ( unsigned int port_id , unsigned int join_id )
2007-05-06 13:54:52 +00:00
{
class Port * port ;
class Endpoint * * epointpointer ;
2007-05-09 05:39:20 +00:00
int earlyb = 0 ;
2007-05-06 13:54:52 +00:00
/* epoint structure */
2007-07-17 17:28:09 +00:00
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 " : " " ) ;
2007-05-06 13:54:52 +00:00
ep_portlist = NULL ;
ep_app = NULL ;
2010-01-16 10:20:23 +00:00
memset ( & ep_delete , 0 , sizeof ( ep_delete ) ) ;
add_work ( & ep_delete , delete_endpoint , this , 0 ) ;
2007-05-06 13:54:52 +00:00
ep_use = 1 ;
/* add endpoint to chain */
next = NULL ;
epointpointer = & epoint_first ;
while ( * epointpointer )
epointpointer = & ( ( * epointpointer ) - > next ) ;
* epointpointer = this ;
/* serial */
2007-08-11 13:57:58 +00:00
ep_serial = epoint_serial + + ;
2007-05-06 13:54:52 +00:00
2007-07-17 17:28:09 +00:00
/* link to join or port */
2009-07-05 20:14:21 +00:00
if ( port_id ) {
2007-05-06 13:54:52 +00:00
port = find_port_id ( port_id ) ;
2009-07-05 20:14:21 +00:00
if ( port ) {
2012-01-27 06:27:52 +00:00
# ifdef WITH_MISDN
2009-05-11 09:07:58 +00:00
if ( ( port - > p_type & PORT_CLASS_MASK ) = = PORT_CLASS_mISDN )
2007-07-07 15:13:20 +00:00
earlyb = ( ( class PmISDN * ) port ) - > p_m_mISDNport - > earlyb ;
2012-01-27 06:27:52 +00:00
# else
earlyb = 0 ;
# endif
2007-05-09 05:39:20 +00:00
if ( ! portlist_new ( port_id , port - > p_type , earlyb ) )
2007-07-15 10:01:27 +00:00
FATAL ( " No memory for portlist. \n " ) ;
2007-05-06 13:54:52 +00:00
}
}
2007-07-17 17:28:09 +00:00
ep_join_id = join_id ;
2007-05-06 13:54:52 +00:00
ep_park = 0 ;
ep_park_len = 0 ;
classuse + + ;
}
/*
* endpoint destructor
*/
Endpoint : : ~ Endpoint ( void )
{
class Endpoint * temp , * * tempp ;
struct port_list * portlist , * mtemp ;
classuse - - ;
/* remote application */
if ( ep_app )
delete ep_app ;
/* free relations */
2009-07-05 20:14:21 +00:00
if ( ep_join_id ) {
2007-07-17 17:28:09 +00:00
PERROR ( " warning: still relation to join. \n " ) ;
2007-05-06 13:54:52 +00:00
}
/* free portlist */
portlist = ep_portlist ;
2009-07-05 20:14:21 +00:00
while ( portlist ) {
if ( portlist - > port_id ) {
2012-02-21 17:03:43 +00:00
PERROR ( " Endpoint(%d) warning: still relation to port %d (portlist list) \n " , ep_serial , portlist - > port_id ) ;
2007-05-06 13:54:52 +00:00
}
mtemp = portlist ;
portlist = portlist - > next ;
memset ( mtemp , 0 , sizeof ( struct port_list ) ) ;
2007-07-15 10:01:27 +00:00
FREE ( mtemp , sizeof ( struct port_list ) ) ;
2007-05-06 13:54:52 +00:00
ememuse - - ;
}
/* detach */
temp = epoint_first ;
tempp = & epoint_first ;
2009-07-05 20:14:21 +00:00
while ( temp ) {
2007-05-06 13:54:52 +00:00
if ( temp = = this )
break ;
tempp = & temp - > next ;
temp = temp - > next ;
}
if ( temp = = 0 )
2007-07-15 10:01:27 +00:00
FATAL ( " Endpoint not in Endpoint's list. \n " ) ;
2007-05-06 13:54:52 +00:00
* tempp = next ;
2010-01-16 10:20:23 +00:00
del_work ( & ep_delete ) ;
2007-05-06 13:54:52 +00:00
/* free */
PDEBUG ( DEBUG_EPOINT , " removed endpoint %d. \n " , ep_serial ) ;
}
/* create new portlist relation
*/
2008-06-14 06:34:50 +00:00
struct port_list * Endpoint : : portlist_new ( unsigned int port_id , int port_type , int earlyb )
2007-05-06 13:54:52 +00:00
{
struct port_list * portlist , * * portlistpointer ;
/* portlist structure */
2007-07-15 10:01:27 +00:00
portlist = ( struct port_list * ) MALLOC ( sizeof ( struct port_list ) ) ;
2007-05-06 13:54:52 +00:00
ememuse + + ;
2012-02-21 17:03:43 +00:00
PDEBUG ( DEBUG_EPOINT , " EPOINT(%d) allocating port_list, attaching to port %d \n " , ep_serial , port_id ) ;
2007-05-06 13:54:52 +00:00
/* add port_list to chain */
portlist - > next = NULL ;
portlistpointer = & ep_portlist ;
while ( * portlistpointer )
portlistpointer = & ( ( * portlistpointer ) - > next ) ;
* portlistpointer = portlist ;
2007-07-17 17:28:09 +00:00
/* link to join or port */
2007-05-06 13:54:52 +00:00
portlist - > port_id = port_id ;
portlist - > port_type = port_type ;
2007-06-27 06:23:50 +00:00
portlist - > early_b = earlyb ;
2007-05-06 13:54:52 +00:00
return ( portlist ) ;
}
/* free portlist relation
*/
void Endpoint : : free_portlist ( struct port_list * portlist )
{
struct port_list * temp , * * tempp ;
temp = ep_portlist ;
tempp = & ep_portlist ;
2009-07-05 20:14:21 +00:00
while ( temp ) {
2007-05-06 13:54:52 +00:00
if ( temp = = portlist )
break ;
tempp = & temp - > next ;
temp = temp - > next ;
}
2007-07-15 10:01:27 +00:00
if ( ! temp )
FATAL ( " port_list not in Endpoint's list. \n " ) ;
2007-05-06 13:54:52 +00:00
/* detach */
* tempp = portlist - > next ;
/* free */
2012-02-21 17:03:43 +00:00
PDEBUG ( DEBUG_EPOINT , " EPOINT(%d) removed port %d from port_list of endpoint \n " , ep_serial , portlist - > port_id ) ;
2007-07-15 10:01:27 +00:00
FREE ( portlist , sizeof ( struct port_list ) ) ;
2007-05-06 13:54:52 +00:00
ememuse - - ;
}
2010-01-16 10:20:23 +00:00
int delete_endpoint ( struct lcr_work * work , void * instance , int index )
2007-05-06 13:54:52 +00:00
{
2010-01-16 10:20:23 +00:00
class Endpoint * ep = ( class Endpoint * ) instance ;
2007-05-06 13:54:52 +00:00
2010-01-16 10:20:23 +00:00
if ( ep - > ep_use < = 0 )
delete ep ;
return 0 ;
2007-05-06 13:54:52 +00:00
}
2010-01-16 10:20:23 +00:00