[ekiga/ds-opal-refactoring] Opal: More refactoring.



commit dc13ecf09b1b9ac206985c43bb52852dcd1a92cf
Author: Damien Sandras <dsandras seconix com>
Date:   Sat Mar 21 13:30:56 2015 +0100

    Opal: More refactoring.

 lib/engine/components/opal/h323-call-manager.cpp   |  102 ++++++++++++++++++--
 lib/engine/components/opal/h323-call-manager.h     |   24 +++--
 lib/engine/components/opal/opal-call-manager.cpp   |   57 ++++-------
 lib/engine/components/opal/opal-call-manager.h     |   75 ++++++++++++---
 lib/engine/components/opal/opal-main.cpp           |    1 +
 .../components/opal/process/h323-endpoint.cpp      |   93 ++----------------
 lib/engine/components/opal/process/h323-endpoint.h |   15 +---
 .../components/opal/process/opal-endpoint.cpp      |   28 ------
 lib/engine/components/opal/process/opal-endpoint.h |    2 -
 .../components/opal/process/sip-endpoint.cpp       |   56 +----------
 lib/engine/components/opal/process/sip-endpoint.h  |   14 +--
 lib/engine/components/opal/sip-call-manager.cpp    |   88 +++++++++++++++--
 lib/engine/components/opal/sip-call-manager.h      |   24 +++--
 lib/engine/protocol/call-manager.h                 |   88 +++++++++++-------
 14 files changed, 355 insertions(+), 312 deletions(-)
---
diff --git a/lib/engine/components/opal/h323-call-manager.cpp 
b/lib/engine/components/opal/h323-call-manager.cpp
index 35f3c30..47cf2ef 100644
--- a/lib/engine/components/opal/h323-call-manager.cpp
+++ b/lib/engine/components/opal/h323-call-manager.cpp
@@ -54,13 +54,14 @@ Opal::H323::CallManager::CallManager (Ekiga::ServiceCore& _core,
   video_codecs_settings = Ekiga::SettingsPtr (new Ekiga::Settings (VIDEO_CODECS_SCHEMA));
 
   setup ();
-  std::cout << "hey: Created Opal::H323::CallManager" << std::endl;
 }
 
 
 Opal::H323::CallManager::~CallManager ()
 {
-  std::cout << "hey: Destroyed Opal::H323::CallManager" << std::endl;
+#if DEBUG
+  std::cout << "Opal::H323::CallManager: Destructor invoked" << std::endl;
+#endif
 }
 
 
@@ -75,6 +76,26 @@ void Opal::H323::CallManager::pull_actions (Ekiga::Actor & actor,
 }
 
 
+bool Opal::H323::CallManager::dial (const std::string & uri)
+{
+  if (!is_supported_uri (uri))
+    return false;
+
+  boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint = endpoint.get_h323_endpoint ();
+  if (h323_endpoint)
+    return h323_endpoint->SetUpCall (uri);
+
+  return false;
+}
+
+
+bool
+Opal::H323::CallManager::is_supported_uri (const std::string & uri)
+{
+  return (!uri.empty () && uri.find ("h323:") == 0);
+}
+
+
 const std::string & Opal::H323::CallManager::get_protocol_name () const
 {
   return protocol_name;
@@ -109,6 +130,67 @@ const Ekiga::CallManager::InterfaceList Opal::H323::CallManager::get_interfaces
 }
 
 
+bool
+Opal::H323::CallManager::set_listen_port (unsigned port)
+{
+  boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint = endpoint.get_h323_endpoint ();
+  if (h323_endpoint)
+    return h323_endpoint->StartListener (port);
+
+  return false;
+}
+
+
+void
+Opal::H323::CallManager::set_dtmf_mode (unsigned mode)
+{
+  boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint = endpoint.get_h323_endpoint ();
+  if (h323_endpoint) {
+    switch (mode)
+      {
+      case 0:
+        h323_endpoint->SetSendUserInputMode (OpalConnection::SendUserInputAsString);
+        PTRACE (4, "Opal::H323::CallManager\tSet DTMF Mode to String");
+        break;
+      case 1:
+        h323_endpoint->SetSendUserInputMode (OpalConnection::SendUserInputAsTone);
+        PTRACE (4, "Opal::H323::CallManager\tSet DTMF Mode to Tone");
+        break;
+      case 3:
+        h323_endpoint->SetSendUserInputMode (OpalConnection::SendUserInputAsQ931);
+        PTRACE (4, "Opal::H323::CallManager\tSet DTMF Mode to Q931");
+        break;
+      default:
+        h323_endpoint->SetSendUserInputMode (OpalConnection::SendUserInputAsInlineRFC2833);
+        PTRACE (4, "Opal::H323::CallManager\tSet DTMF Mode to RFC2833");
+        break;
+      }
+  }
+}
+
+
+unsigned
+Opal::H323::CallManager::get_dtmf_mode () const
+{
+  boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint = endpoint.get_h323_endpoint ();
+  if (h323_endpoint) {
+    if (h323_endpoint->GetSendUserInputMode () == OpalConnection::SendUserInputAsString)
+      return 0;
+
+    if (h323_endpoint->GetSendUserInputMode () == OpalConnection::SendUserInputAsTone)
+      return 1;
+
+    if (h323_endpoint->GetSendUserInputMode () == OpalConnection::SendUserInputAsInlineRFC2833)
+      return 2;
+
+    if (h323_endpoint->GetSendUserInputMode () == OpalConnection::SendUserInputAsQ931)
+      return 2;
+  }
+
+  g_return_val_if_reached (1);
+}
+
+
 void Opal::H323::CallManager::setup (const std::string & setting)
 {
   std::cout << "In Opal::H323::EndPoint::setup " << std::endl;
@@ -117,7 +199,7 @@ void Opal::H323::CallManager::setup (const std::string & setting)
 
     if (setting.empty () || setting == "listen-port") {
 
-      h323_endpoint->set_listen_port (h323_settings->get_int ("listen-port"));
+      set_listen_port (h323_settings->get_int ("listen-port"));
     }
     if (setting.empty () || setting == "maximum-video-tx-bitrate") {
 
@@ -144,7 +226,7 @@ void Opal::H323::CallManager::setup (const std::string & setting)
     }
     if (setting.empty () || setting == "dtmf-mode") {
 
-      h323_endpoint->set_dtmf_mode (h323_settings->get_enum ("dtmf-mode"));
+      set_dtmf_mode (h323_settings->get_enum ("dtmf-mode"));
     }
     if (setting.empty () || setting == "forward-host") {
 
@@ -153,15 +235,15 @@ void Opal::H323::CallManager::setup (const std::string & setting)
     if (setting.empty () || setting == "video-role") {
 
       /*
-         CallManager::VideoOptions options;
-         endpoint.get_video_options (options);
-         options.extended_video_roles = h323_settings->get_enum ("video-role");
-         endpoint.set_video_options (options);
-       */
-
+      CallManager::VideoOptions options;
+      endpoint.get_video_options (options);
+      options.extended_video_roles = h323_settings->get_enum ("video-role");
+      endpoint.set_video_options (options);
+      */
       std::cout << "FIXME" << std::endl;
     }
     if (setting.empty () || setting == "enable-h239") {
+
       h323_endpoint->SetDefaultH239Control(h323_settings->get_bool ("enable-h239"));
       PTRACE (4, "Opal::H323::EndPoint\tH.239 Control: " << h323_settings->get_bool ("enable-h239"));
     }
diff --git a/lib/engine/components/opal/h323-call-manager.h b/lib/engine/components/opal/h323-call-manager.h
index fb852e6..9252e35 100644
--- a/lib/engine/components/opal/h323-call-manager.h
+++ b/lib/engine/components/opal/h323-call-manager.h
@@ -48,9 +48,9 @@ namespace Opal {
 
   namespace H323 {
 
-    /* This is the engine CallManager implementation.
-     * It uses the Opal::Manager object to implement the engine
-     * CallManager interface.
+    /* This is one engine H.323 CallManager implementation.
+     * It uses the Opal::CallManager class to implement a
+     * more specialized H.323 engine CallManager.
      */
     class CallManager :
         public Opal::CallManager,
@@ -67,21 +67,23 @@ namespace Opal {
                          const std::string & uri);
 
       /* CallManager methods we implement */
+      bool dial (const std::string & uri);
+
+      bool is_supported_uri (const std::string & uri);
+
       const std::string & get_protocol_name () const;
 
+      bool set_listen_port (unsigned port);
+
       const Ekiga::CallManager::InterfaceList get_interfaces () const;
 
-      /*
-         void set_dtmf_mode (unsigned mode);
-         unsigned get_dtmf_mode ();
-         bool set_listen_port (unsigned port);
-         const InterfaceList & get_interfaces () const;
-       */
+      void set_dtmf_mode (unsigned mode);
 
-      /* Set up endpoint: all options or a specific setting */
-      void setup (const std::string & setting = "");
+      unsigned get_dtmf_mode () const;
 
   private:
+      void setup (const std::string & setting = "");
+
       Ekiga::SettingsPtr h323_settings;
       Ekiga::SettingsPtr video_codecs_settings;
 
diff --git a/lib/engine/components/opal/opal-call-manager.cpp 
b/lib/engine/components/opal/opal-call-manager.cpp
index 708eb65..db2eea2 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -70,34 +70,33 @@ Opal::CallManager::~CallManager ()
 }
 
 
-/* CallManager Methods */
-bool Opal::CallManager::dial (const std::string & uri)
+void Opal::CallManager::hang_up ()
 {
-  return endpoint.dial (uri);
+  endpoint.ClearAllCalls (OpalConnection::EndedByLocalUser, FALSE);
 }
 
 
-void Opal::CallManager::hang_up ()
+void Opal::CallManager::set_reject_delay (unsigned delay)
 {
-  endpoint.ClearAllCalls (OpalConnection::EndedByLocalUser, FALSE);
+  endpoint.set_reject_delay (delay);
 }
 
 
-bool Opal::CallManager::is_supported_uri (const std::string & uri)
+unsigned Opal::CallManager::get_reject_delay () const
 {
-  return endpoint.is_supported_uri (uri);
+  return endpoint.get_reject_delay ();
 }
 
 
-void Opal::CallManager::set_codecs (Ekiga::CodecList & codecs)
+void Opal::CallManager::set_auto_answer (bool enabled)
 {
-  endpoint.set_codecs (codecs);
+  endpoint.set_auto_answer (enabled);
 }
 
 
-const Ekiga::CodecList& Opal::CallManager::get_codecs () const
+bool Opal::CallManager::get_auto_answer () const
 {
-  return endpoint.get_codecs ();
+  return endpoint.get_auto_answer ();
 }
 
 
@@ -114,6 +113,18 @@ const std::string & Opal::CallManager::get_display_name () const
 }
 
 
+void Opal::CallManager::set_codecs (Ekiga::CodecList & codecs)
+{
+  endpoint.set_codecs (codecs);
+}
+
+
+const Ekiga::CodecList& Opal::CallManager::get_codecs () const
+{
+  return endpoint.get_codecs ();
+}
+
+
 void Opal::CallManager::set_echo_cancellation (bool enabled)
 {
   endpoint.SetEchoCancellation (enabled);
@@ -150,30 +161,6 @@ unsigned Opal::CallManager::get_maximum_jitter () const
 }
 
 
-void Opal::CallManager::set_reject_delay (unsigned delay)
-{
-  endpoint.set_reject_delay (delay);
-}
-
-
-unsigned Opal::CallManager::get_reject_delay () const
-{
-  return endpoint.get_reject_delay ();
-}
-
-
-void Opal::CallManager::set_auto_answer (bool enabled)
-{
-  endpoint.set_auto_answer (enabled);
-}
-
-
-bool Opal::CallManager::get_auto_answer () const
-{
-  return endpoint.get_auto_answer ();
-}
-
-
 void Opal::CallManager::setup (const std::string & setting)
 {
   std::cout << "IN Opal::CallManager::setup" << std::endl;
diff --git a/lib/engine/components/opal/opal-call-manager.h b/lib/engine/components/opal/opal-call-manager.h
index 3543989..e664d3b 100644
--- a/lib/engine/components/opal/opal-call-manager.h
+++ b/lib/engine/components/opal/opal-call-manager.h
@@ -45,9 +45,14 @@
 
 namespace Opal {
 
-  /* This is the engine CallManager implementation.
+  /* This is the base class for the engine CallManager implementation.
+   *
    * It uses the Opal::Manager object to implement the engine
    * CallManager interface.
+   *
+   * It can not be directly added to the CallCore, some methods need
+   * a more specific implementation in a protocol dependant derived
+   * class.
    */
   class CallManager : public Ekiga::CallManager
   {
@@ -56,30 +61,76 @@ public:
                  Opal::EndPoint& _manager);
     ~CallManager ();
 
-    /* CallManager Methods */
-    bool dial (const std::string & uri);
+    /* CallManager Methods
+     *
+     * Pure virtual methods have a protocol specific implementation.
+     * They are thus implemented by the derived class.
+     */
+    virtual bool dial (const std::string & uri) = 0;
+
     void hang_up ();
-    bool is_supported_uri (const std::string & uri);
-    void set_codecs (Ekiga::CodecList & codecs);
-    const Ekiga::CodecList & get_codecs () const;
+
+    void set_reject_delay (unsigned delay);
+
+    unsigned get_reject_delay () const;
+
+    void set_auto_answer (bool enabled);
+
+    bool get_auto_answer () const;
+
+    virtual bool is_supported_uri (const std::string & uri) = 0;
+
+
+    /*
+     */
+    virtual const std::string & get_protocol_name () const = 0;
+
+    virtual const InterfaceList get_interfaces () const = 0;
+
+    virtual bool set_listen_port (unsigned port) = 0;
+
+    virtual void set_dtmf_mode (unsigned mode) = 0;
+
+    virtual unsigned get_dtmf_mode () const = 0;
+
+
+    /*
+     */
     void set_display_name (const std::string & name);
+
     const std::string & get_display_name () const;
 
+
+    /*
+     */
+    void set_codecs (Ekiga::CodecList & codecs);
+
+    const Ekiga::CodecList & get_codecs () const;
+
     void set_echo_cancellation (bool enabled);
+
     bool get_echo_cancellation () const;
+
     void set_silence_detection (bool enabled);
+
     bool get_silence_detection () const;
+
     void set_maximum_jitter (unsigned max_val);
+
     unsigned get_maximum_jitter () const;
-    void set_reject_delay (unsigned delay);
-    unsigned get_reject_delay () const;
-    void set_auto_answer (bool enabled);
-    bool get_auto_answer () const;
+
+
+protected:
 
     /* Set up endpoint: all options or a specific setting */
     virtual void setup (const std::string & setting = "");
 
+    Ekiga::ServiceCore& core;
+    EndPoint& endpoint;
+
+
 private:
+
     /* We use a callback instead of directly connecting the signal
      * to the add_call method of the CallCore to prevent boost to
      * keep a reference to the CallCore until the ECallManager is
@@ -98,10 +149,6 @@ private:
     Ekiga::SettingsPtr personal_data_settings;
 
     std::string display_name;
-
-protected:
-    Ekiga::ServiceCore& core;
-    EndPoint& endpoint;
   };
 };
 #endif
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index c84bf16..981b86f 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -101,6 +101,7 @@ struct OPALSpark: public Ekiga::Spark
       call_core->add_manager (h323_call_manager);
 #endif
 
+      std::cout << "FIXME HERE" << std::endl;
       boost::shared_ptr<Opal::Bank> bank = boost::shared_ptr<Opal::Bank> (new Opal::Bank (core,
 #ifdef HAVE_H323
                                                                                           
GnomeMeeting::Process ()->get_endpoint ().get_h323_endpoint ().get (),
diff --git a/lib/engine/components/opal/process/h323-endpoint.cpp 
b/lib/engine/components/opal/process/h323-endpoint.cpp
index cf47f17..37ffc40 100644
--- a/lib/engine/components/opal/process/h323-endpoint.cpp
+++ b/lib/engine/components/opal/process/h323-endpoint.cpp
@@ -143,7 +143,6 @@ Opal::H323::EndPoint::EndPoint (Opal::EndPoint & _endpoint,
     endpoint (_endpoint),
     core (_core)
 {
-  protocol_name = "h323";
   uri_prefix = "h323:";
   /* Ready to take calls */
   endpoint.AddRouteEntry("h323:.* = pc:*");
@@ -159,11 +158,8 @@ Opal::H323::EndPoint::~EndPoint ()
 
 
 bool
-Opal::H323::EndPoint::dial (const std::string&  uri)
+Opal::H323::EndPoint::SetUpCall (const std::string&  uri)
 {
-  if (!is_supported_uri (uri))
-    return false;
-
   PString token;
   endpoint.SetUpCall("pc:*", uri, token, (void*) uri.c_str());
 
@@ -179,10 +175,8 @@ Opal::H323::EndPoint::transfer (const std::string & uri,
   if (attended)
     return false;
 
-  if (GetConnectionCount () == 0 || !is_supported_uri (uri))
-      return false; /* No active SIP connection to transfer, or
-                     * transfer request to unsupported uri
-                     */
+  if (GetConnectionCount () == 0)
+      return false;
 
   /* We don't handle several calls here */
   for (PSafePtr<OpalConnection> connection(connectionsActive, PSafeReference);
@@ -207,83 +201,18 @@ Opal::H323::EndPoint::message (G_GNUC_UNUSED const Ekiga::ContactPtr & contact,
 
 
 bool
-Opal::H323::EndPoint::is_supported_uri (const std::string & uri)
-{
-  return (!uri.empty () && uri.find ("h323:") == 0);
-}
-
-
-const std::string&
-Opal::H323::EndPoint::get_protocol_name () const
+Opal::H323::EndPoint::StartListener (unsigned port)
 {
-  return protocol_name;
-}
+  if (port > 0) {
 
+    RemoveListener (NULL);
 
-void
-Opal::H323::EndPoint::set_dtmf_mode (unsigned mode)
-{
-  switch (mode)
-    {
-    case 0:
-      SetSendUserInputMode (OpalConnection::SendUserInputAsString);
-      PTRACE (4, "Opal::H323::EndPoint\tSet DTMF Mode to String");
-      break;
-    case 1:
-      SetSendUserInputMode (OpalConnection::SendUserInputAsTone);
-      PTRACE (4, "Opal::H323::EndPoint\tSet DTMF Mode to Tone");
-      break;
-    case 3:
-      SetSendUserInputMode (OpalConnection::SendUserInputAsQ931);
-      PTRACE (4, "Opal::H323::EndPoint\tSet DTMF Mode to Q931");
-      break;
-    default:
-      SetSendUserInputMode (OpalConnection::SendUserInputAsInlineRFC2833);
-      PTRACE (4, "Opal::H323::EndPoint\tSet DTMF Mode to RFC2833");
-      break;
+    std::stringstream str;
+    str << "tcp$*:" << port;
+    if (StartListeners (PStringArray (str.str ()))) {
+      PTRACE (4, "Opal::H323::EndPoint\tSet listen port to " << port);
+      return true;
     }
-}
-
-
-unsigned
-Opal::H323::EndPoint::get_dtmf_mode () const
-{
-  if (GetSendUserInputMode () == OpalConnection::SendUserInputAsString)
-    return 0;
-
-  if (GetSendUserInputMode () == OpalConnection::SendUserInputAsTone)
-    return 1;
-
-  if (GetSendUserInputMode () == OpalConnection::SendUserInputAsInlineRFC2833)
-    return 2;
-
-  if (GetSendUserInputMode () == OpalConnection::SendUserInputAsQ931)
-    return 2;
-
-  return 1;
-}
-
-
-bool
-Opal::H323::EndPoint::set_listen_port (unsigned port)
-{
-  listen_iface.protocol = "tcp";
-  listen_iface.voip_protocol = "h323";
-  listen_iface.id = "*";
-
-  port = (port > 0 ? port : 1720);
-
-  std::stringstream str;
-  interfaces.clear ();
-  RemoveListener (NULL);
-
-  str << "tcp$*:" << port;
-  if (StartListeners (PStringArray (str.str ()))) {
-
-    listen_iface.port = port;
-    interfaces.push_back (listen_iface);
-    PTRACE (4, "Opal::H323::EndPoint\tSet listen port to " << port);
-    return true;
   }
 
   return false;
diff --git a/lib/engine/components/opal/process/h323-endpoint.h 
b/lib/engine/components/opal/process/h323-endpoint.h
index 183b59f..4baa697 100644
--- a/lib/engine/components/opal/process/h323-endpoint.h
+++ b/lib/engine/components/opal/process/h323-endpoint.h
@@ -65,21 +65,13 @@ namespace Opal {
 
       ~EndPoint ();
 
-      /* CallProtocolManager */
-      bool dial (const std::string & uri);
+      bool SetUpCall (const std::string & uri);
       bool transfer (const std::string & uri,
                      bool attended);
       bool message (const Ekiga::ContactPtr & contact,
                     const std::string & uri);
-      bool is_supported_uri (const std::string & uri);
 
-
-      const std::string & get_protocol_name () const;
-
-      void set_dtmf_mode (unsigned mode);
-      unsigned get_dtmf_mode () const;
-
-      bool set_listen_port (unsigned port);
+      bool StartListener (unsigned port);
 
       const Ekiga::CallManager::InterfaceList & get_interfaces () const;
 
@@ -117,9 +109,6 @@ namespace Opal {
       PMutex gk_name_mutex;
       PString gk_name;
 
-      Ekiga::CallManager::Interface listen_iface;
-
-      std::string protocol_name;
       std::string uri_prefix;
       std::string forward_uri;
 
diff --git a/lib/engine/components/opal/process/opal-endpoint.cpp 
b/lib/engine/components/opal/process/opal-endpoint.cpp
index 651872b..dc49d20 100644
--- a/lib/engine/components/opal/process/opal-endpoint.cpp
+++ b/lib/engine/components/opal/process/opal-endpoint.cpp
@@ -184,34 +184,6 @@ Opal::EndPoint::~EndPoint ()
 }
 
 
-bool Opal::EndPoint::dial (const std::string & uri)
-{
-  if (sip_endpoint && sip_endpoint->is_supported_uri (uri))
-    return sip_endpoint->dial (uri);
-
-#ifdef HAVE_H323
-  if (h323_endpoint && h323_endpoint->is_supported_uri (uri))
-    return h323_endpoint->dial (uri);
-#endif
-
-  return false;
-}
-
-
-bool Opal::EndPoint::is_supported_uri (const std::string & uri)
-{
-  if (sip_endpoint && sip_endpoint->is_supported_uri (uri))
-    return true;
-
-#ifdef HAVE_H323
-  if (h323_endpoint && h323_endpoint->is_supported_uri (uri))
-    return true;
-#endif
-
-  return false;
-}
-
-
 void Opal::EndPoint::SetEchoCancellation (bool enabled)
 {
   OpalEchoCanceler::Params ec;
diff --git a/lib/engine/components/opal/process/opal-endpoint.h 
b/lib/engine/components/opal/process/opal-endpoint.h
index 94a8d78..65fbc2a 100644
--- a/lib/engine/components/opal/process/opal-endpoint.h
+++ b/lib/engine/components/opal/process/opal-endpoint.h
@@ -81,9 +81,7 @@ public:
     ~EndPoint ();
 
     /** Call Manager **/
-    bool dial (const std::string & uri);
     void hang_up ();
-    bool is_supported_uri (const std::string & uri);
 
     void SetEchoCancellation (bool enabled);
     bool GetEchoCancellation () const;
diff --git a/lib/engine/components/opal/process/sip-endpoint.cpp 
b/lib/engine/components/opal/process/sip-endpoint.cpp
index 4c6ab3b..4c1267c 100644
--- a/lib/engine/components/opal/process/sip-endpoint.cpp
+++ b/lib/engine/components/opal/process/sip-endpoint.cpp
@@ -171,13 +171,10 @@ Opal::Sip::EndPoint::send_message (const std::string & _uri,
 
 
 bool
-Opal::Sip::EndPoint::dial (const std::string & uri)
+Opal::Sip::EndPoint::SetUpCall (const std::string & uri)
 {
   std::stringstream ustr;
 
-  if (!is_supported_uri (uri))
-    return false;
-
   if (uri.find (":") == string::npos)
     ustr << "sip:" << uri;
   else
@@ -202,48 +199,7 @@ Opal::Sip::EndPoint::dial (const std::string & uri)
 
 
 bool
-Opal::Sip::EndPoint::is_supported_uri (const std::string & uri)
-{
-  return (!uri.empty () && (uri.find ("sip:") == 0 || uri.find (':') == string::npos));
-}
-
-
-void
-Opal::Sip::EndPoint::set_dtmf_mode (unsigned mode)
-{
-  switch (mode) {
-
-  case 0:  // RFC2833
-    PTRACE (4, "Opal::Sip::EndPoint\tSet DTMF Mode to RFC2833");
-    SetSendUserInputMode (OpalConnection::SendUserInputAsInlineRFC2833);
-    break;
-  case 1:  // SIP Info
-  default:
-    PTRACE (4, "Opal::Sip::EndPoint\tSet DTMF Mode to SIP INFO");
-    SetSendUserInputMode (OpalConnection::SendUserInputAsTone);
-    break;
-  }
-}
-
-
-unsigned
-Opal::Sip::EndPoint::get_dtmf_mode () const
-{
-  // RFC2833
-  if (GetSendUserInputMode () == OpalConnection::SendUserInputAsInlineRFC2833)
-    return 0;
-
-  // SIP Info
-  if (GetSendUserInputMode () == OpalConnection::SendUserInputAsTone)
-    return 1;
-
-  g_return_val_if_reached (1);
-  return 1;
-}
-
-
-bool
-Opal::Sip::EndPoint::set_listen_port (unsigned port)
+Opal::Sip::EndPoint::StartListener (unsigned port)
 {
   unsigned udp_min = endpoint.GetUDPPortBase ();
   unsigned udp_max = endpoint.GetUDPPortMax ();
@@ -260,17 +216,12 @@ Opal::Sip::EndPoint::set_listen_port (unsigned port)
 
       std::stringstream str;
       str << protocols[i] << "$*:" << port;
-      listen_iface.protocol = protocols[i];
-      listen_iface.voip_protocol = "sip";
-      listen_iface.id = "*";
       if (!StartListeners (PStringArray (str.str ()))) {
 
         port = ports[i][0];
         while (port <= ports[i][1]) {
           str << protocols[i] << "$*:" << port;
-
           if (StartListeners (PStringArray (str.str ()))) {
-
             PTRACE (4, "Opal::Sip::EndPoint\tSet listen port to " << port << " (" << protocols[i] << ")");
             break;
           }
@@ -278,9 +229,8 @@ Opal::Sip::EndPoint::set_listen_port (unsigned port)
           port++;
         }
       }
-      else {
+      else
         PTRACE (4, "Opal::Sip::EndPoint\tSet listen port to " << port << " (" << protocols[i] << ")");
-      }
     }
   }
 
diff --git a/lib/engine/components/opal/process/sip-endpoint.h 
b/lib/engine/components/opal/process/sip-endpoint.h
index fb0e3d1..980c8e2 100644
--- a/lib/engine/components/opal/process/sip-endpoint.h
+++ b/lib/engine/components/opal/process/sip-endpoint.h
@@ -71,19 +71,13 @@ namespace Opal {
 
       ~EndPoint ();
 
+      bool SetUpCall (const std::string & uri);
+
       /* Chat subsystem */
       bool send_message (const std::string & uri,
                          const Ekiga::Message::payload_type payload);
 
-      /* CallProtocolManager */
-      bool dial (const std::string & uri);
-
-      bool is_supported_uri (const std::string & uri);
-
-      void set_dtmf_mode (unsigned mode);
-      unsigned get_dtmf_mode () const;
-
-      bool set_listen_port (unsigned port);
+      bool StartListener (unsigned port);
 
       const Ekiga::CallManager::InterfaceList & get_interfaces () const;
 
@@ -142,8 +136,6 @@ namespace Opal {
 
       std::map<std::string, PString> publications;
 
-      Ekiga::CallManager::Interface listen_iface;
-
       std::string uri_prefix;
       std::string forward_uri;
       std::string outbound_proxy;
diff --git a/lib/engine/components/opal/sip-call-manager.cpp b/lib/engine/components/opal/sip-call-manager.cpp
index e5dea7e..648a13e 100644
--- a/lib/engine/components/opal/sip-call-manager.cpp
+++ b/lib/engine/components/opal/sip-call-manager.cpp
@@ -46,34 +46,55 @@
 
 /* The engine class */
 Opal::Sip::CallManager::CallManager (Ekiga::ServiceCore& _core,
-                               Opal::EndPoint& _endpoint) : Opal::CallManager (_core, _endpoint), 
protocol_name ("sip")
+                                     Opal::EndPoint& _endpoint) : Opal::CallManager (_core, _endpoint), 
protocol_name ("sip")
 {
   /* Setup things */
   Ekiga::SettingsCallback setup_cb = boost::bind (&Opal::Sip::CallManager::setup, this, _1);
   sip_settings = Ekiga::SettingsPtr (new Ekiga::Settings (SIP_SCHEMA, setup_cb));
 
   setup ();
-  std::cout << "hey: Created Opal::Sip::CallManager" << std::endl;
 }
 
 
 Opal::Sip::CallManager::~CallManager ()
 {
-  std::cout << "hey: Destroyed Opal::Sip::CallManager" << std::endl;
+#if DEBUG
+  std::cout << "Opal::Sip::CallManager: Destructor invoked" << std::endl;
+#endif
 }
 
 
 /* URIActionProvider Methods */
 void Opal::Sip::CallManager::pull_actions (Ekiga::Actor & actor,
-                                     G_GNUC_UNUSED const std::string & name,
-                                     const std::string & uri)
+                                           G_GNUC_UNUSED const std::string & name,
+                                           const std::string & uri)
 {
   if (is_supported_uri (uri)) {
-    add_action (actor, Ekiga::ActionPtr (new Ekiga::Action ("call", _("Call"), boost::bind 
(&Opal::Sip::CallManager::dial, this, uri))));
+    add_action (actor, Ekiga::ActionPtr (new Ekiga::Action ("call", _("Call"), boost::bind 
(&Opal::CallManager::dial, this, uri))));
   }
 }
 
 
+bool Opal::Sip::CallManager::dial (const std::string & uri)
+{
+  if (!is_supported_uri (uri))
+    return false;
+
+  boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint = endpoint.get_sip_endpoint ();
+  if (sip_endpoint)
+    return sip_endpoint->SetUpCall (uri);
+
+  return false;
+}
+
+
+bool
+Opal::Sip::CallManager::is_supported_uri (const std::string & uri)
+{
+  return (!uri.empty () && (uri.find ("sip:") == 0 || uri.find (':') == string::npos));
+}
+
+
 const std::string & Opal::Sip::CallManager::get_protocol_name () const
 {
   return protocol_name;
@@ -108,13 +129,62 @@ const Ekiga::CallManager::InterfaceList Opal::Sip::CallManager::get_interfaces (
 }
 
 
+bool
+Opal::Sip::CallManager::set_listen_port (unsigned port)
+{
+  boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint = endpoint.get_sip_endpoint ();
+  if (sip_endpoint)
+    return sip_endpoint->StartListener (port);
+
+  return false;
+}
+
+
+void
+Opal::Sip::CallManager::set_dtmf_mode (unsigned mode)
+{
+  boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint = endpoint.get_sip_endpoint ();
+  if (sip_endpoint) {
+    switch (mode) {
+
+    case 0:  // RFC2833
+      PTRACE (4, "Opal::Sip::CallManager\tSet DTMF Mode to RFC2833");
+      sip_endpoint->SetSendUserInputMode (OpalConnection::SendUserInputAsInlineRFC2833);
+      break;
+    case 1:  // SIP Info
+    default:
+      PTRACE (4, "Opal::Sip::CallManager\tSet DTMF Mode to SIP INFO");
+      sip_endpoint->SetSendUserInputMode (OpalConnection::SendUserInputAsTone);
+      break;
+    }
+  }
+}
+
+
+unsigned
+Opal::Sip::CallManager::get_dtmf_mode () const
+{
+  boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint = endpoint.get_sip_endpoint ();
+  if (sip_endpoint) {
+    // RFC2833
+    if (sip_endpoint->GetSendUserInputMode () == OpalConnection::SendUserInputAsInlineRFC2833)
+      return 0;
+
+    // SIP Info
+    if (sip_endpoint->GetSendUserInputMode () == OpalConnection::SendUserInputAsTone)
+      return 1;
+  }
+
+  g_return_val_if_reached (1);
+}
+
+
 void Opal::Sip::CallManager::setup (const std::string & setting)
 {
-  std::cout << "In Opal::Sip::CallManager::setup " << std::endl;
   boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint = endpoint.get_sip_endpoint ();
   if (sip_endpoint) {
     if (setting.empty () || setting == "listen-port")  {
-      sip_endpoint->set_listen_port (sip_settings->get_int ("listen-port"));
+      set_listen_port (sip_settings->get_int ("listen-port"));
     }
     if (setting.empty () || setting == "binding-timeout")  {
       sip_endpoint->set_nat_binding_delay (sip_settings->get_int ("binding-timeout"));
@@ -124,7 +194,7 @@ void Opal::Sip::CallManager::setup (const std::string & setting)
     }
 
     if (setting.empty () || setting == "dtmf-mode")  {
-      sip_endpoint->set_dtmf_mode (sip_settings->get_enum ("dtmf-mode"));
+      set_dtmf_mode (sip_settings->get_enum ("dtmf-mode"));
     }
 
     if (setting.empty () || setting == "forward-host")  {
diff --git a/lib/engine/components/opal/sip-call-manager.h b/lib/engine/components/opal/sip-call-manager.h
index 112a58b..517bbec 100644
--- a/lib/engine/components/opal/sip-call-manager.h
+++ b/lib/engine/components/opal/sip-call-manager.h
@@ -48,9 +48,9 @@ namespace Opal {
 
   namespace Sip {
 
-    /* This is the engine CallManager implementation.
-     * It uses the Opal::Manager object to implement the engine
-     * CallManager interface.
+    /* This is one engine SIP CallManager implementation.
+     * It uses the Opal::CallManager class to implement a
+     * more specialized SIP engine CallManager.
      */
     class CallManager :
         public Opal::CallManager,
@@ -67,21 +67,23 @@ namespace Opal {
                          const std::string & uri);
 
       /* CallManager methods we implement */
+      bool dial (const std::string & uri);
+
+      bool is_supported_uri (const std::string & uri);
+
       const std::string & get_protocol_name () const;
 
       const Ekiga::CallManager::InterfaceList get_interfaces () const;
 
-      /*
-         void set_dtmf_mode (unsigned mode);
-         unsigned get_dtmf_mode ();
-         bool set_listen_port (unsigned port);
-         const InterfaceList & get_interfaces () const;
-       */
+      bool set_listen_port (unsigned port);
 
-      /* Set up endpoint: all options or a specific setting */
-      void setup (const std::string & setting = "");
+      void set_dtmf_mode (unsigned mode);
+
+      unsigned get_dtmf_mode () const;
 
   private:
+      void setup (const std::string & setting = "");
+
       Ekiga::SettingsPtr sip_settings;
       std::string protocol_name;
     };
diff --git a/lib/engine/protocol/call-manager.h b/lib/engine/protocol/call-manager.h
index 35a7e2b..4e10ad8 100644
--- a/lib/engine/protocol/call-manager.h
+++ b/lib/engine/protocol/call-manager.h
@@ -93,6 +93,30 @@ namespace Ekiga
      */
     virtual void hang_up () = 0;
 
+    /** Set delay before dropping an incoming call
+     * @param delay is the delay after which the call should be rejected
+     * (or forwarded if supported by the CallManager and if forward
+     *  on no answer is enabled).
+     */
+    virtual void set_reject_delay (unsigned delay) = 0;
+
+    /** Get delay before dropping an incoming call
+     * @return the delay in seconds after which a call should be rejected
+     * (or forwarded if supported by the CallManager and if forward
+     *  on no answer is enabled).
+     */
+    virtual unsigned get_reject_delay () const = 0;
+
+    /** Set auto answer
+     * @param true if incoming calls should be auto answered.
+     */
+    virtual void set_auto_answer (bool enabled) = 0;
+
+    /** Get auto answer
+     * @return true if incoming calls should be auto answered.
+     */
+    virtual bool get_auto_answer () const = 0;
+
     /* Return true if URI can be handled by the CallCore,
      * false otherwise.
      * @param the URI to test
@@ -102,7 +126,7 @@ namespace Ekiga
 
 
     /*
-     * PROTOCOL INFORMATION
+     * PROTOCOL DETAILS
      */
 
     /** Return the protocol name
@@ -116,9 +140,38 @@ namespace Ekiga
      */
     virtual const InterfaceList get_interfaces () const = 0;
 
+    /** Set the port to listen to for incoming calls
+     * @param port is the port on which we should bind
+     */
+    virtual bool set_listen_port (unsigned port) = 0;
+
+    /** Set the DTMF mode to use to send DTMFs
+     * @param mode is the desired DTMF mode
+     */
+    virtual void set_dtmf_mode (unsigned mode) = 0;
+
+    /** Return the current DTMF mode
+     * @return the desired DTMF mode
+     */
+    virtual unsigned get_dtmf_mode () const = 0;
+
 
     /*
-     * Misc
+     * MISC
+     */
+
+    /** Set the display name used on outgoing calls
+     * @param name is the display name to use.
+     */
+    virtual void set_display_name (const std::string & name) = 0;
+
+    /** Return the display name used on outgoing calls
+     */
+    virtual const std::string & get_display_name () const = 0;
+
+
+    /*
+     * AUDIO, VIDEO AND CODECS DETAILS
      */
 
     /** Enable the given codecs
@@ -134,15 +187,6 @@ namespace Ekiga
      */
     virtual const Ekiga::CodecList & get_codecs () const = 0;
 
-    /** Set the display name used on outgoing calls
-     * @param name is the display name to use.
-     */
-    virtual void set_display_name (const std::string & name) = 0;
-
-    /** Return the display name used on outgoing calls
-     */
-    virtual const std::string & get_display_name () const = 0;
-
     /** Enable echo cancellation
      * @param enabled is true if echo cancellation should be enabled, false
      * otherwise.
@@ -175,28 +219,6 @@ namespace Ekiga
      */
     virtual unsigned get_maximum_jitter () const = 0;
 
-    /** Set delay before dropping an incoming call
-     * @param delay is the delay after which the call should be rejected
-     * (or forwarded if supported by the CallManager).
-     */
-    virtual void set_reject_delay (unsigned delay) = 0;
-
-    /** Get delay before dropping an incoming call
-     * @return the delay in seconds after which a call should be rejected
-     * (or forwarded if supported by the CallManager).
-     */
-    virtual unsigned get_reject_delay () const = 0;
-
-    /** Set auto answer
-     * @param true if incoming calls should be auto answered.
-     */
-    virtual void set_auto_answer (bool enabled) = 0;
-
-    /** Get auto answer
-     * @return true if incoming calls should be auto answered.
-     */
-    virtual bool get_auto_answer () const = 0;
-
 
     /*
      * MISC


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]