Cleanup: Make interface name be part of Port class
[lcr.git] / remote.cpp
index 43c9233..d181fb8 100644 (file)
@@ -16,14 +16,13 @@ unsigned int new_remote = 1000;
 /*
  * constructor
  */
-Premote::Premote(int type, char *portname, struct port_settings *settings, struct interface *interface, int remote_id) : Port(type, portname, settings)
+Premote::Premote(int type, char *portname, struct port_settings *settings, struct interface *interface, int remote_id) : Port(type, portname, settings, interface)
 {
        union parameter param;
 
        p_callerinfo.itype = (interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
        p_r_ref = new_remote++;
        SCPY(p_r_remote_app, interface->remote_app);
-       SCPY(p_r_interface_name, interface->name);
        p_r_tones = (interface->is_tones == IS_YES);
 
        /* send new ref to remote socket */
@@ -56,11 +55,12 @@ int Premote::message_epoint(unsigned int epoint_id, int message_type, union para
        if (Port::message_epoint(epoint_id, message_type, param))
                return 1;
 
-       if (message_type == MESSAGE_SETUP) {
+       switch (message_type) {
+       case MESSAGE_SETUP:
                struct interface *interface;
-               interface = getinterfacebyname(p_r_interface_name);
+               interface = getinterfacebyname(p_interface_name);
                if (!interface) {
-                       PERROR("Cannot find interface %s.\n", p_r_interface_name);
+                       PERROR("Cannot find interface %s.\n", p_interface_name);
                        return 0;
                }
                /* attach only if not already */
@@ -81,6 +81,28 @@ int Premote::message_epoint(unsigned int epoint_id, int message_type, union para
                                SCPY(param->setup.dialinginfo.context, "lcr");
                }
 
+               new_state(PORT_STATE_OUT_SETUP);
+               break;
+
+       case MESSAGE_PROCEEDING:
+               new_state(PORT_STATE_IN_PROCEEDING);
+               break;
+
+       case MESSAGE_ALERTING:
+               new_state(PORT_STATE_IN_ALERTING);
+               break;
+
+       case MESSAGE_CONNECT:
+               new_state(PORT_STATE_CONNECT);
+               break;
+
+       case MESSAGE_DISCONNECT:
+               new_state(PORT_STATE_OUT_DISCONNECT);
+               break;
+
+       case MESSAGE_RELEASE:
+               new_state(PORT_STATE_RELEASE);
+               break;
        }
 
        /* look for Remote's interface */
@@ -89,20 +111,6 @@ int Premote::message_epoint(unsigned int epoint_id, int message_type, union para
                return 0;               
        }
 
-#if 0
-       /* enable audio path */
-       if (message_type == MESSAGE_SETUP) {
-               union parameter newparam;
-               memset(&newparam, 0, sizeof(union parameter));
-               admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_PATTERN, &newparam);
-               newparam.audiopath = 1;
-               admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_AUDIOPATH, &newparam);
-       }
-#endif
-
-       if (message_type == MESSAGE_CONNECT)
-               new_state(PORT_STATE_CONNECT);
-
        if (message_type == MESSAGE_RELEASE) {
                new_state(PORT_STATE_RELEASE);
                delete this;
@@ -124,9 +132,9 @@ void Premote::message_remote(int message_type, union parameter *param)
                break;
 
        case MESSAGE_SETUP:
-               interface = getinterfacebyname(p_r_interface_name);
+               interface = getinterfacebyname(p_interface_name);
                if (!interface) {
-                       PERROR("Cannot find interface %s.\n", p_r_interface_name);
+                       PERROR("Cannot find interface %s.\n", p_interface_name);
                        return;
                }
 
@@ -151,20 +159,40 @@ void Premote::message_remote(int message_type, union parameter *param)
                epoint->ep_app = new_endpointapp(epoint, 0, interface->app); //incoming
 
                epointlist_new(epoint->ep_serial);
-               /* FALL THROUGH: */
-       default:
-               if (message_type == MESSAGE_CONNECT)
-                       new_state(PORT_STATE_CONNECT);
-               /* cannot just forward, because param is not of container "struct lcr_msg" */
-               message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, message_type);
-               memcpy(&message->param, param, sizeof(message->param));
-               message_put(message);
-
-               if (message_type == MESSAGE_RELEASE) {
-                       new_state(PORT_STATE_RELEASE);
-                       delete this;
-                       return;
-               }
+
+               new_state(PORT_STATE_IN_SETUP);
+               break;
+
+       case MESSAGE_PROCEEDING:
+               new_state(PORT_STATE_OUT_PROCEEDING);
+               break;
+
+       case MESSAGE_ALERTING:
+               new_state(PORT_STATE_OUT_ALERTING);
+               break;
+
+       case MESSAGE_CONNECT:
+               new_state(PORT_STATE_CONNECT);
+               break;
+
+       case MESSAGE_DISCONNECT:
+               new_state(PORT_STATE_IN_DISCONNECT);
+               break;
+
+       case MESSAGE_RELEASE:
+               new_state(PORT_STATE_RELEASE);
+               break;
+       }
+
+       /* cannot just forward, because param is not of container "struct lcr_msg" */
+       message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, message_type);
+       memcpy(&message->param, param, sizeof(message->param));
+       message_put(message);
+
+       if (message_type == MESSAGE_RELEASE) {
+               new_state(PORT_STATE_RELEASE);
+               delete this;
+               return;
        }
 }