[ekiga] Reimplemented presence fetching in the opal component
- From: Julien Puydt <jpuydt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] Reimplemented presence fetching in the opal component
- Date: Fri, 3 Jan 2014 09:16:47 +0000 (UTC)
commit 55a169bcefca180a7bf3af9089651d3d95eec66c
Author: Julien Puydt <jpuydt free fr>
Date: Fri Jan 3 10:15:25 2014 +0100
Reimplemented presence fetching in the opal component
lib/engine/components/opal/opal-account.cpp | 83 ++++++++++++++++++++-------
lib/engine/components/opal/opal-account.h | 13 ++--
lib/engine/components/opal/opal-bank.cpp | 24 --------
lib/engine/components/opal/opal-bank.h | 7 +--
lib/engine/components/opal/opal-main.cpp | 1 -
5 files changed, 70 insertions(+), 58 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 2c9d64e..489e736 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -76,6 +76,33 @@ canonize_uri (std::string uri)
return uri;
}
+struct presence_status_helper
+{
+ presence_status_helper (const std::string uri_,
+ const std::string presence_,
+ const std::string status_):
+ uri(uri_),
+ presence(presence_),
+ status(status_)
+ {}
+
+ const std::string uri;
+ const std::string presence;
+ const std::string status;
+
+ bool operator() (Ekiga::PresentityPtr pres)
+ {
+ Opal::PresentityPtr presentity = boost::dynamic_pointer_cast<Opal::Presentity> (pres);
+ if (presentity && presentity->has_uri(uri)) {
+
+ presentity->set_presence (presence);
+ presentity->set_status (status);
+ }
+ return true;
+}
+};
+
+
xmlNodePtr
Opal::Account::build_node(Opal::Account::Type typus,
std::string name,
@@ -183,8 +210,8 @@ Opal::Account::Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
presnode));
pres->trigger_saving.connect (boost::ref (trigger_saving));
- pres->removed.connect (boost::bind (boost::ref (presentity_removed), pres));
- pres->updated.connect (boost::bind (boost::ref (presentity_updated), pres));
+ pres->removed.connect (boost::bind (&Opal::Account::when_presentity_removed, this, pres));
+ pres->updated.connect (boost::bind (&Opal::Account::when_presentity_updated, this, pres));
add_object (pres);
presentity_added (pres);
}
@@ -442,10 +469,12 @@ Opal::Account::disable ()
if (presentity) {
- for (std::set<std::string>::iterator iter = watched_uris.begin ();
- iter != watched_uris.end (); ++iter) {
- presentity->UnsubscribeFromPresence (PString (*iter));
- Ekiga::Runtime::run_in_main (boost::bind (&Opal::Account::presence_status_in_main, this, *iter,
"unknown", ""));
+ for (iterator iter = begin ();
+ iter != end ();
+ ++iter) {
+
+ (*iter)->set_presence ("unknown");
+ (*iter)->set_status ("");
}
}
@@ -810,6 +839,7 @@ Opal::Account::on_add_contact_form_submitted (bool submitted,
pres->updated.connect (boost::bind (boost::ref (presentity_updated), pres));
add_object (pres);
presentity_added (pres);
+ fetch (pres->get_uri ());
} else {
@@ -874,12 +904,11 @@ Opal::Account::publish (const Ekiga::PersonalDetails& details)
void
-Opal::Account::fetch (const std::string uri)
+Opal::Account::fetch (const std::string uri) const
{
// Check if this is a presentity we watch
if (!is_myself (uri))
return;
- watched_uris.insert (uri);
// Account is disabled, bye
if (!is_enabled ())
@@ -894,11 +923,10 @@ Opal::Account::fetch (const std::string uri)
void
-Opal::Account::unfetch (const std::string uri)
+Opal::Account::unfetch (const std::string uri) const
{
if (is_myself (uri) && presentity) {
presentity->UnsubscribeFromPresence (PString (uri));
- watched_uris.erase (uri);
Ekiga::Runtime::run_in_main (boost::bind (&Opal::Account::presence_status_in_main, this, uri, "unknown",
""));
}
}
@@ -917,13 +945,15 @@ Opal::Account::handle_registration_event (RegistrationState state_,
// Translators: this is a state, not an action, i.e. it should be read as
// "(you are) registered", and not as "(you have been) registered"
status = _("Registered");
+ state = state_;
+ failed_registration_already_notified = false;
if (presentity) {
- for (std::set<std::string>::iterator iter = watched_uris.begin ();
- iter != watched_uris.end (); ++iter) {
- PTRACE(4, "Ekiga\tSubscribeToPresence for " << iter->c_str () << " (Account Registered)");
- presentity->SubscribeToPresence (PString (*iter));
- }
+ for (const_iterator iter = begin ();
+ iter != end ();
+ ++iter)
+ fetch ((*iter)->get_uri());
+
presentity->SetLocalPresence (personal_state, presence_status);
if (type != Account::H323) {
sip_endpoint->Subscribe (SIPSubscribe::MessageSummary, 3600, get_aor ());
@@ -933,8 +963,6 @@ Opal::Account::handle_registration_event (RegistrationState state_,
if (details)
const_cast<Account*>(this)->publish (*details);
- state = state_;
- failed_registration_already_notified = false;
updated ();
}
break;
@@ -1240,10 +1268,25 @@ Opal::Account::OnPresenceChange (OpalPresentity& /*presentity*/,
void
Opal::Account::presence_status_in_main (std::string uri,
std::string uri_presence,
- std::string uri_status)
+ std::string uri_status) const
+{
+ presence_status_helper helper(uri, uri_presence, uri_status);
+ visit_presentities (helper);
+}
+
+void
+Opal::Account::when_presentity_removed (Opal::PresentityPtr pres)
+{
+ unfetch (pres->get_uri ());
+ presentity_removed (pres);
+}
+
+void
+Opal::Account::when_presentity_updated (Opal::PresentityPtr pres)
{
- presence_received (uri, uri_presence);
- status_received (uri, uri_status);
+ // we don't unfetch the previous uri here...
+ fetch (pres->get_uri ());
+ presentity_updated (pres);
}
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index e1c2d4d..8da0691 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -66,8 +66,7 @@ namespace Opal
public Ekiga::Account,
public Ekiga::Heap,
protected Ekiga::RefLister<Presentity>,
- public Ekiga::PresencePublisher,
- public Ekiga::PresenceFetcher
+ public Ekiga::PresencePublisher
{
public:
@@ -170,11 +169,8 @@ public:
/*
* This is because an opal account is an Ekiga::PresencePublisher
- * and an Ekiga::PresenceFetcher
*/
void publish (const Ekiga::PersonalDetails& details);
- void fetch (const std::string uri);
- void unfetch (const std::string uri);
/* This method is public to be called by an opal endpoint, which will push
* this Opal::Account's new registration state
@@ -195,6 +191,8 @@ public:
Ekiga::MenuBuilder& builder);
private:
+ void fetch (const std::string uri) const;
+ void unfetch (const std::string uri) const;
void decide_type ();
@@ -232,12 +230,13 @@ private:
boost::function0<std::set<std::string> > existing_groups;
xmlNodePtr node;
xmlNodePtr roster_node;
- std::set<std::string> watched_uris;
OpalPresenceInfo::State personal_state;
std::string presence_status;
void presence_status_in_main (std::string uri,
std::string presence,
- std::string status);
+ std::string status) const;
+ void when_presentity_removed (boost::shared_ptr<Opal::Presentity> pres);
+ void when_presentity_updated (boost::shared_ptr<Opal::Presentity> pres);
boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
boost::weak_ptr<Ekiga::PresenceCore> presence_core;
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 855a73c..7b9937e 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -88,8 +88,6 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core):
Ekiga::BankImpl<Account>::add_connection (account, account->presentity_updated.connect (boost::bind
(boost::ref(presentity_updated), account, _1)));
Ekiga::BankImpl<Account>::add_connection (account, account->presentity_removed.connect (boost::bind
(boost::ref(presentity_removed), account, _1)));
Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind
(&Opal::Bank::save, this)));
- Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref
(presence_received)));
- Ekiga::BankImpl<Account>::add_connection (account, account->status_received.connect (boost::ref
(status_received)));
}
}
@@ -312,8 +310,6 @@ Opal::Bank::add (Account::Type acc_type,
child));
add_account (account);
Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind
(&Opal::Bank::save, this)));
- Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref
(presence_received)));
- Ekiga::BankImpl<Account>::add_connection (account, account->status_received.connect (boost::ref
(status_received)));
}
@@ -372,26 +368,6 @@ Opal::Bank::publish (const Ekiga::PersonalDetails& details)
void
-Opal::Bank::fetch (const std::string uri)
-{
- for (iterator iter = begin ();
- iter != end ();
- iter++)
- (*iter)->fetch (uri);
-}
-
-
-void
-Opal::Bank::unfetch (const std::string uri)
-{
- for (iterator iter = begin ();
- iter != end ();
- iter++)
- (*iter)->unfetch (uri);
-}
-
-
-void
Opal::Bank::on_registration_event (std::string aor,
Opal::Account::RegistrationState state,
std::string msg)
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index f96ca11..79323a7 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -56,7 +56,6 @@ namespace Opal
public Ekiga::BankImpl<Account>,
public Ekiga::Cluster,
public Ekiga::PresencePublisher,
- public Ekiga::PresenceFetcher,
public Ekiga::ContactDecorator,
public Ekiga::PresentityDecorator,
public Ekiga::Service
@@ -76,14 +75,10 @@ public:
{ return "\tStores the opal accounts"; }
/*
- * this object is an Ekiga::PresenceFetcher and an Ekiga::PresencePublisher
+ * this object is an Ekiga::PresencePublisher
*/
void publish (const Ekiga::PersonalDetails& details);
- void fetch (const std::string uri);
-
- void unfetch (const std::string uri);
-
void new_account (Account::Type acc_type,
std::string username = "",
std::string password = "");
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index e0b5e0d..0fa18b4 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -126,7 +126,6 @@ struct OPALSpark: public Ekiga::Spark
call_manager->ready.connect (boost::bind (&Opal::Bank::call_manager_ready, &*bank));
call_manager->setup ();
presence_core->add_presence_publisher (bank);
- presence_core->add_presence_fetcher (bank);
call_core->add_manager (call_manager);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]