[ekiga] H323: Several API changes.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] H323: Several API changes.
- Date: Sun, 11 Jan 2015 13:07:43 +0000 (UTC)
commit fbfcc02e37d7e183646582e304904cf5375aff07
Author: Damien Sandras <dsandras seconix com>
Date: Sun Jan 11 13:48:58 2015 +0100
H323: Several API changes.
- The H323 CallProtocolManager is now setup exactly like the SIP one. It
is easier to debug uniform things. Eventually, much code could be
simplified in a further code review.
- Added new methods to enable/disable accounts that do not work on a
const Account reference. Enabling an Account will change some of its
internal details (like its registration status). Working with const
references did not make sense here.
lib/engine/components/opal/h323-endpoint.cpp | 223 +++++++++-------------
lib/engine/components/opal/h323-endpoint.h | 41 +++--
lib/engine/components/opal/opal-call-manager.cpp | 55 +-----
lib/engine/components/opal/opal-call-manager.h | 7 +-
lib/engine/components/opal/opal-main.cpp | 12 +-
5 files changed, 138 insertions(+), 200 deletions(-)
---
diff --git a/lib/engine/components/opal/h323-endpoint.cpp b/lib/engine/components/opal/h323-endpoint.cpp
index 06c0e1a..35e8c53 100644
--- a/lib/engine/components/opal/h323-endpoint.cpp
+++ b/lib/engine/components/opal/h323-endpoint.cpp
@@ -44,54 +44,105 @@ namespace Opal {
namespace H323 {
- class subscriber : public PThread
+ class gatekeeper_handler : public PThread
{
- PCLASSINFO(subscriber, PThread);
+ PCLASSINFO (gatekeeper_handler, PThread);
public:
- subscriber (const Opal::Account & _account,
- Opal::H323::EndPoint& _manager,
- bool _registering,
- const PSafePtr<OpalPresentity> & _presentity)
+ gatekeeper_handler (Opal::Account & _account,
+ Opal::H323::EndPoint& _ep,
+ bool _registering)
: PThread (1000, AutoDeleteThread),
account (_account),
- manager (_manager),
- registering (_registering),
- presentity (_presentity)
+ ep (_ep),
+ registering (_registering)
{
this->Resume ();
- };
+ }
void Main ()
- {
- if (registering) {
- if (presentity && !presentity->IsOpen ())
- presentity->Open ();
- manager.Register (account);
- } else {
- manager.Unregister (account);
+ {
+ std::string info;
- if (presentity && presentity->IsOpen ())
- presentity->Close ();
+ if (!registering && ep.IsRegisteredWithGatekeeper (account.get_host ())) {
+ ep.RemoveGatekeeper (account.get_host ());
+ account.handle_registration_event (Account::Unregistered, std::string ());
+ return;
+ }
+ else if (registering && !ep.IsRegisteredWithGatekeeper (account.get_host ())) {
+
+ ep.RemoveGatekeeper (0);
+
+ if (!account.get_username ().empty ())
+ ep.SetLocalUserName (account.get_username ());
+
+ ep.SetGatekeeperPassword (account.get_password (), account.get_username ());
+ ep.SetGatekeeperTimeToLive (account.get_timeout () * 1000);
+ bool result = ep.UseGatekeeper (account.get_host ());
+
+ // There was an error (missing parameter or registration failed)
+ // or the user chose to not register
+ if (!result) {
+
+ // Registering failed
+ if (ep.GetGatekeeper () != NULL) {
+
+ switch (ep.GetGatekeeper()->GetRegistrationFailReason ()) {
+
+ case H323Gatekeeper::DuplicateAlias :
+ // Translators : The alias we are registering already exists : failure
+ info = _("Duplicate alias");
+ break;
+ case H323Gatekeeper::SecurityDenied :
+ info = _("Bad username/password");
+ break;
+ case H323Gatekeeper::TransportError :
+ info = _("Transport error");
+ break;
+ case H323Gatekeeper::RegistrationSuccessful:
+ break;
+ case H323Gatekeeper::UnregisteredLocally:
+ case H323Gatekeeper::UnregisteredByGatekeeper:
+ case H323Gatekeeper::GatekeeperLostRegistration:
+ case H323Gatekeeper::InvalidListener:
+ case H323Gatekeeper::TryingAlternate:
+ case H323Gatekeeper::NumRegistrationFailReasons:
+ case H323Gatekeeper::GatekeeperRejectReasonMask:
+ case H323Gatekeeper::RegistrationRejectReasonMask:
+ case H323Gatekeeper::UnregistrationRejectReasonMask:
+ default:
+ info = _("Failed");
+ break;
+ }
+ }
+ else
+ info = _("Failed");
+
+ // Signal
+ account.handle_registration_event (Account::RegistrationFailed, info);
+ }
+ else {
+ account.handle_registration_event (Account::Registered, std::string ());
}
- };
+ }
+ }
private:
- const Opal::Account & account;
- Opal::H323::EndPoint& manager;
+ Opal::Account & account;
+ Opal::H323::EndPoint& ep;
bool registering;
- const PSafePtr<OpalPresentity> & presentity;
};
};
};
/* The class */
-Opal::H323::EndPoint::EndPoint (Opal::CallManager & _manager):
- H323EndPoint (_manager),
- manager (_manager)
+Opal::H323::EndPoint::EndPoint (Opal::CallManager & _manager,
+ const Ekiga::ServiceCore& _core): H323EndPoint (_manager),
+ manager (_manager),
+ core (_core)
{
protocol_name = "h323";
uri_prefix = "h323:";
@@ -227,12 +278,14 @@ Opal::H323::EndPoint::set_listen_port (unsigned port)
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;
}
@@ -240,18 +293,19 @@ Opal::H323::EndPoint::set_listen_port (unsigned port)
return false;
}
-void
-Opal::H323::EndPoint::set_initial_bandwidth (unsigned bitrate)
+
+const Ekiga::CallProtocolManager::InterfaceList &
+Opal::H323::EndPoint::get_interfaces () const
{
- SetInitialBandwidth (OpalBandwidth::Tx, bitrate > 0 ? bitrate : 100000);
- PTRACE (4, "Opal::H323::EndPoint\tSet maximum/initial tx bandwidth to " << bitrate);
+ return interfaces;
}
-const Ekiga::CallProtocolManager::Interface&
-Opal::H323::EndPoint::get_listen_interface () const
+void
+Opal::H323::EndPoint::set_initial_bandwidth (unsigned bitrate)
{
- return listen_iface;
+ SetInitialBandwidth (OpalBandwidth::Tx, bitrate > 0 ? bitrate : 100000);
+ PTRACE (4, "Opal::H323::EndPoint\tSet maximum/initial tx bandwidth to " << bitrate);
}
@@ -271,103 +325,17 @@ Opal::H323::EndPoint::get_forward_uri () const
}
-bool
-Opal::H323::EndPoint::subscribe (const Opal::Account & account,
- const PSafePtr<OpalPresentity> & presentity)
-{
- if (account.get_protocol_name () != "H323")
- return false;
-
- new subscriber (account, *this, true, presentity);
-
- return true;
-}
-
-
-bool
-Opal::H323::EndPoint::unsubscribe (const Opal::Account & account,
- const PSafePtr<OpalPresentity> & presentity)
-{
- if (account.get_protocol_name () != "H323")
- return false;
-
- new subscriber (account, *this, false, presentity);
-
- return true;
-}
-
-
void
-Opal::H323::EndPoint::Register (const Opal::Account& account)
+Opal::H323::EndPoint::enable_account (Account& account)
{
- std::string info;
-
- if (account.is_enabled () && !IsRegisteredWithGatekeeper (account.get_host ())) {
-
- H323EndPoint::RemoveGatekeeper (0);
-
- if (!account.get_username ().empty ()) {
- SetLocalUserName (account.get_username ());
- AddAliasName (manager.GetDefaultDisplayName ());
- }
-
- SetGatekeeperPassword (account.get_password (), account.get_username ());
- SetGatekeeperTimeToLive (account.get_timeout () * 1000);
- bool result = UseGatekeeper (account.get_host ());
-
- // There was an error (missing parameter or registration failed)
- // or the user chose to not register
- if (!result) {
-
- // Registering failed
- if (GetGatekeeper () != NULL) {
-
- switch (GetGatekeeper()->GetRegistrationFailReason ()) {
-
- case H323Gatekeeper::DuplicateAlias :
- // Translators : The alias we are registering already exists : failure
- info = _("Duplicate alias");
- break;
- case H323Gatekeeper::SecurityDenied :
- info = _("Bad username/password");
- break;
- case H323Gatekeeper::TransportError :
- info = _("Transport error");
- break;
- case H323Gatekeeper::RegistrationSuccessful:
- break;
- case H323Gatekeeper::UnregisteredLocally:
- case H323Gatekeeper::UnregisteredByGatekeeper:
- case H323Gatekeeper::GatekeeperLostRegistration:
- case H323Gatekeeper::InvalidListener:
- case H323Gatekeeper::TryingAlternate:
- case H323Gatekeeper::NumRegistrationFailReasons:
- case H323Gatekeeper::GatekeeperRejectReasonMask:
- case H323Gatekeeper::RegistrationRejectReasonMask:
- case H323Gatekeeper::UnregistrationRejectReasonMask:
- default:
- info = _("Failed");
- break;
- }
- }
- else
- info = _("Failed");
-
- // Signal
- Ekiga::Runtime::run_in_main (boost::bind (&Opal::H323::EndPoint::registration_event_in_main, this,
boost::cref (account), Account::RegistrationFailed, info));
- }
- else {
-
- Ekiga::Runtime::run_in_main (boost::bind (&Opal::H323::EndPoint::registration_event_in_main, this,
boost::cref (account), Account::Registered, std::string ()));
- }
- }
+ new gatekeeper_handler (account, *this, true);
}
void
-Opal::H323::EndPoint::Unregister (const Opal::Account& account)
+Opal::H323::EndPoint::disable_account (Account& account)
{
- RemoveGatekeeper (account.get_host ());
+ new gatekeeper_handler (account, *this, false);
}
@@ -456,15 +424,6 @@ Opal::H323::EndPoint::OnIncomingConnection (OpalConnection & connection,
void
-Opal::H323::EndPoint::registration_event_in_main (const Opal::Account& account,
- Opal::Account::RegistrationState state,
- const std::string msg)
-{
- account.handle_registration_event (state, msg);
-}
-
-
-void
Opal::H323::EndPoint::setup (const std::string setting)
{
if (setting.empty () || setting == "listen-port") {
diff --git a/lib/engine/components/opal/h323-endpoint.h b/lib/engine/components/opal/h323-endpoint.h
index d9d1671..df14e25 100644
--- a/lib/engine/components/opal/h323-endpoint.h
+++ b/lib/engine/components/opal/h323-endpoint.h
@@ -56,15 +56,24 @@ namespace Opal {
namespace H323 {
class EndPoint : public H323EndPoint,
+ public Ekiga::Service,
public Ekiga::CallProtocolManager
{
PCLASSINFO(EndPoint, H323EndPoint);
public:
- EndPoint (CallManager &_manager);
+ EndPoint (CallManager & ep,
+ const Ekiga::ServiceCore& core);
~EndPoint ();
+ /* Service */
+ const std::string get_name () const
+ { return "opal-h323-endpoint"; }
+
+ const std::string get_description () const
+ { return "\tObject managing H.323 objects with the Opal library"; }
+
/* CallProtocolManager */
bool dial (const std::string & uri);
@@ -81,7 +90,8 @@ namespace Opal {
unsigned get_dtmf_mode () const;
bool set_listen_port (unsigned port);
- const Ekiga::CallProtocolManager::Interface & get_listen_interface () const;
+
+ const Ekiga::CallProtocolManager::InterfaceList & get_interfaces () const;
void set_initial_bandwidth (unsigned max_tx_video_bitrate);
@@ -90,16 +100,13 @@ namespace Opal {
const std::string & get_forward_uri () const;
- /* AccountSubscriber */
- bool subscribe (const Opal::Account & account, const PSafePtr<OpalPresentity> & presentity);
- bool unsubscribe (const Opal::Account & account, const PSafePtr<OpalPresentity> & presentity);
-
+ /* Enable / Disable accounts. The account given as argument
+ * will be updated to reflect the current account state once
+ * the operation has been successful.
+ */
+ void enable_account (Account & account);
+ void disable_account (Account & account);
- /* OPAL methods */
- void Register (const Opal::Account & account);
- void Unregister (const Opal::Account & account);
-
- private:
bool UseGatekeeper (const PString & address = PString::Empty (),
const PString & domain = PString::Empty (),
const PString & iface = PString::Empty ());
@@ -108,16 +115,13 @@ namespace Opal {
bool IsRegisteredWithGatekeeper (const PString & address);
+ void setup (const std::string key = "");
+
+ private:
bool OnIncomingConnection (OpalConnection &connection,
unsigned options,
OpalConnection::StringOptions *str_options);
- void registration_event_in_main (const Opal::Account& account,
- Account::RegistrationState state,
- const std::string msg);
-
- void setup (const std::string key = "");
-
// this object is really managed by opal,
// so the way it is handled here is correct
CallManager & manager;
@@ -133,6 +137,9 @@ namespace Opal {
boost::shared_ptr<Ekiga::Settings> settings;
boost::shared_ptr<Ekiga::Settings> video_codecs_settings;
+ Ekiga::CallProtocolManager::InterfaceList interfaces;
+
+ const Ekiga::ServiceCore & core;
};
};
};
diff --git a/lib/engine/components/opal/opal-call-manager.cpp
b/lib/engine/components/opal/opal-call-manager.cpp
index d0f93f7..c568d04 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -167,11 +167,6 @@ CallManager::CallManager (Ekiga::ServiceCore& core)
PInterfaceMonitor::GetInstance().SetRefreshInterval (15000);
-#ifdef HAVE_H323
- h323_endpoint = boost::shared_ptr<H323::EndPoint> (new H323::EndPoint (*this), null_deleter ());
- add_protocol_manager (h323_endpoint);
-#endif
-
nat_settings =
boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (NAT_SCHEMA));
nat_settings->changed.connect (boost::bind (&CallManager::setup, this, _1));
@@ -861,12 +856,9 @@ CallManager::HandleSTUNResult ()
|| result == PSTUNClient::PartiallyBlocked) {
error = true;
- } else {
+ }
+ else {
- for (Ekiga::CallManager::iterator iter = Ekiga::CallManager::begin ();
- iter != Ekiga::CallManager::end ();
- ++iter)
- (*iter)->set_listen_port ((*iter)->get_listen_interface ().port);
ready ();
}
} else if (patience == 0) {
@@ -935,48 +927,23 @@ CallManager::CreateVideoOutputDevice(const OpalConnection & connection,
return device != NULL;
}
-bool
-CallManager::subscribe (const Opal::Account& account,
- const PSafePtr<OpalPresentity>& presentity)
-{
- if (account.get_protocol_name () == "H323") {
-
-#ifdef HAVE_H323
- return h323_endpoint->subscribe (account, presentity);
-#else
- return false;
-#endif
-
- } else {
- return sip_endpoint->subscribe (account, presentity);
- }
+void
+CallManager::set_sip_endpoint (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint)
+{
+ sip_endpoint = _sip_endpoint;
+ add_protocol_manager (sip_endpoint);
}
-bool
-CallManager::unsubscribe (const Opal::Account& account,
- const PSafePtr<OpalPresentity>& presentity)
-{
- if (account.get_protocol_name () == "H323") {
#ifdef HAVE_H323
- return h323_endpoint->unsubscribe (account, presentity);
-#else
- return false;
-#endif
-
- } else {
-
- return sip_endpoint->unsubscribe (account, presentity);
- }
-}
-
void
-CallManager::set_sip_endpoint (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint)
+CallManager::set_h323_endpoint (boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint)
{
- sip_endpoint = _sip_endpoint;
- add_protocol_manager (sip_endpoint);
+ h323_endpoint = _h323_endpoint;
+ add_protocol_manager (h323_endpoint);
}
+#endif
void
CallManager::setup (const std::string & setting)
diff --git a/lib/engine/components/opal/opal-call-manager.h b/lib/engine/components/opal/opal-call-manager.h
index 05238c8..dbe5de2 100644
--- a/lib/engine/components/opal/opal-call-manager.h
+++ b/lib/engine/components/opal/opal-call-manager.h
@@ -133,12 +133,6 @@ public:
void set_codecs (Ekiga::CodecList & codecs);
const Ekiga::CodecList & get_codecs () const;
- /* presence subscription management */
- bool subscribe (const Opal::Account& account,
- const PSafePtr<OpalPresentity>& presentity);
-
- bool unsubscribe (const Opal::Account& account,
- const PSafePtr<OpalPresentity>& presentity);
/* Extended stuff, OPAL CallManager specific */
@@ -255,6 +249,7 @@ private:
void set_sip_endpoint (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint);
boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
#ifdef HAVE_H323
+ void set_h323_endpoint (boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint);
boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint;
#endif
};
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index e6953c8..a661046 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -51,6 +51,9 @@
#include "opal-plugins-hook.h"
#include "sip-endpoint.h"
+#ifdef HAVE_H323
+#include "h323-endpoint.h"
+#endif
// opal manages its endpoints itself, so we must be wary
struct null_deleter
@@ -114,11 +117,18 @@ struct OPALSpark: public Ekiga::Spark
core.add (call_manager);
boost::shared_ptr<Sip::EndPoint> sip_manager (new Sip::EndPoint (*call_manager, core), null_deleter
());
- std::cout << "FIXME: where is H323" << std::endl << std::flush;
sip_manager->setup ();
call_manager->set_sip_endpoint (sip_manager);
core.add (sip_manager);
+#ifdef HAVE_H323
+ boost::shared_ptr<H323::EndPoint> h323_manager (new H323::EndPoint (*call_manager, core), null_deleter
());
+ h323_manager->setup ();
+ call_manager->set_h323_endpoint (h323_manager);
+ core.add (h323_manager);
+#endif
+
+
boost::shared_ptr<Bank> bank (new Bank (core));
account_core->add_bank (bank);
presence_core->add_cluster (bank);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]