Commit 7aa2bb7b authored by Garcia's avatar Garcia
Browse files

Add SIP framework, start development based on GNU oSip external library

parent a434f16c
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line


#pragma once

#include "LibSip_Interface.hh"

namespace LibSip__Interface {

	class OperatorPort : public OperatorPort_BASE {
	public:
		OperatorPort(const char *par_port_name): OperatorPort_BASE(par_port_name) { };
		~OperatorPort() { };

	protected:
		virtual void outgoing_call(const s__SIP__conversation_call& call_par) { };
		virtual void outgoing_call(const s__SIP__ringing_call& call_par) { };
		virtual void outgoing_call(const s__SIP__announcementA_call& call_par) { };
		virtual void outgoing_call(const s__SIP__announcementB_call& call_par) { };
		virtual void outgoing_call(const s__SIP__announcement_call& call_par) { };
		virtual void outgoing_call(const s__SIP__voiceMessage_call& call_par) { };
		virtual void outgoing_call(const s__SIP__mediastopped_call& call_par) { };
		virtual void outgoing_reply(const s__SIP__conversation_reply& reply_par) { };
		virtual void outgoing_reply(const s__SIP__ringing_reply& reply_par) { };
		virtual void outgoing_reply(const s__SIP__announcementA_reply& reply_par) { };
		virtual void outgoing_reply(const s__SIP__announcementB_reply& reply_par) { };
		virtual void outgoing_reply(const s__SIP__announcement_reply& reply_par) { };
		virtual void outgoing_reply(const s__SIP__voiceMessage_reply& reply_par) { };
		virtual void outgoing_reply(const s__SIP__mediastopped_reply& reply_par) { };
	}; // End of class OperatorPort

}
+90 −0
Original line number Diff line number Diff line
#include "SipPort.hh"
#include "sip_layer_factory.hh"
#include "loggers.hh"

namespace LibSip__Interface {

  SipPort::SipPort(const char *par_port_name): SipPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(nullptr), _time_key("SipPort::outgoing_send") {
    // Nothing to do
  } // End of constructor

  SipPort::~SipPort() {
    loggers::get_instance().log(">>> SipPort::~SipPort");

    if (_layer != nullptr) {
      delete _layer;
    }
  } // End of destructor

  void SipPort::set_parameter(const char * parameter_name, const char * parameter_value)
  {
    loggers::get_instance().log("SipPort::set_parameter: %s=%s", parameter_name, parameter_value);
    _cfg_params.insert(std::pair<std::string, std::string>(std::string(parameter_name), std::string(parameter_value)));
  }

  /*void SipPort::Handle_Fd_Event(int fd, boolean is_readable,
    boolean is_writable, boolean is_error) {}*/

  void SipPort::Handle_Fd_Event_Error(int /*fd*/)
  {

  }

  void SipPort::Handle_Fd_Event_Writable(int /*fd*/)
  {

  }

  void SipPort::Handle_Fd_Event_Readable(int /*fd*/)
  {

  }

  /*void SipPort::Handle_Timeout(double time_since_last_call) {}*/

  void SipPort::user_map(const char * system_port)
  {
    loggers::get_instance().log(">>> SipPort::user_map: %s", system_port);
    // Build layer stack
    params::iterator it = _cfg_params.find(std::string("params"));
    if (it != _cfg_params.end()) {
      loggers::get_instance().log("SipPort::user_map: %s", it->second.c_str());
      // Setup parameters
      params::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless
      // Create layer
      _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str());
      if (static_cast<sip_layer *>(_layer) == nullptr) {
        loggers::get_instance().error("SipPort::user_map: Invalid stack configuration: %s", it->second.c_str());
      }
      static_cast<sip_layer *>(_layer)->add_upper_port(this);

    } else {
      loggers::get_instance().error("SipPort::user_map: No layers defined in configuration file");
    }
  } // End of user_map method

  void SipPort::user_unmap(const char * system_port)
  {
    loggers::get_instance().log(">>> SipPort::user_unmap: %s", system_port);

    // Reset layers
    if (_layer != nullptr) {
      delete _layer;
      _layer = nullptr;
    }
  } // End of user_unmap method

  void SipPort::user_start()
  {
    loggers::get_instance().log(">>> SipPort::user_start");

  } // End of user_start method

  void SipPort::user_stop()
  {
    loggers::get_instance().log(">>> SipPort::user_stop");

  } // End of user_stop method

}
+62 −0
Original line number Diff line number Diff line
#pragma once

#include "LibSip_Interface.hh"

#include "layer.hh"
#include "params.hh"

namespace LibSip__SIPTypesAndValues {
  class REGISTER__Request;
}

namespace LibSip__Interface {

  class SipPort : public SipPort_BASE {
    params _cfg_params;
    params _layer_params;
    layer* _layer;
    std::string _time_key;
  public:
    SipPort(const char *par_port_name);
    ~SipPort();

    void set_parameter(const char *parameter_name, const char *parameter_value);
    void receiveMsg (const LibSip__SIPTypesAndValues::REGISTER__Request&, const params&);

  private:
    /* void Handle_Fd_Event(int fd, boolean is_readable,
       boolean is_writable, boolean is_error); */
    void Handle_Fd_Event_Error(int fd);
    void Handle_Fd_Event_Writable(int fd);
    void Handle_Fd_Event_Readable(int fd);
    /* void Handle_Timeout(double time_since_last_call); */

  protected:
    void user_map(const char *system_port);
    void user_unmap(const char *system_port);

    void user_start();
    void user_stop();

  protected:
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::REGISTER__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::INVITE__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::OPTIONS__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::BYE__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::CANCEL__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::ACK__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::PRACK__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::NOTIFY__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::SUBSCRIBE__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::PUBLISH__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::UPDATE__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::REFER__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::MESSAGE__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::INFO__Request& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const LibSip__SIPTypesAndValues::Response& send_par, const Address4SIP *destination_address) { };
    virtual void outgoing_send(const CHARSTRING& send_par, const Address4SIP *destination_address) { };
  }; // End of class SipPort

}