[ekiga] Push all presence code into the opal bank&account code and out of the sip endpoint code



commit 9b6f441fbeb04055adfd992c46a3f6c29e379730
Author: Snark <jpuydt gnome org>
Date:   Mon Dec 27 14:31:41 2010 +0100

    Push all presence code into the opal bank&account code and out of the sip endpoint code

 lib/engine/components/opal/opal-account.cpp |    6 +-
 lib/engine/components/opal/opal-bank.cpp    |  107 ++++++++++++++++++
 lib/engine/components/opal/opal-bank.h      |   17 +++
 lib/engine/components/opal/opal-main.cpp    |    1 -
 lib/engine/components/opal/sip-endpoint.cpp |  158 ---------------------------
 lib/engine/components/opal/sip-endpoint.h   |   24 ----
 6 files changed, 127 insertions(+), 186 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 6004aac..a44916c 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -487,7 +487,7 @@ Opal::Account::on_consult (const std::string url)
 void
 Opal::Account::publish (const Ekiga::PersonalDetails& details)
 {
-  if (presentity && presentity->IsOpen ()) {
+  if (presentity) {
 
     std::cout << __PRETTY_FUNCTION__ << ": ok" << std::endl;
 
@@ -505,7 +505,7 @@ Opal::Account::publish (const Ekiga::PersonalDetails& details)
 void
 Opal::Account::fetch (const std::string uri)
 {
-  if (presentity && presentity->IsOpen ()) {
+  if (presentity) {
 
     std::cout << __PRETTY_FUNCTION__ << " " << uri << std::endl;
 
@@ -516,7 +516,7 @@ Opal::Account::fetch (const std::string uri)
 void
 Opal::Account::unfetch (const std::string uri)
 {
-  if (presentity && presentity->IsOpen ()) {
+  if (presentity) {
 
     std::cout << __PRETTY_FUNCTION__ << " " << uri << std::endl;
 
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index b74efdc..fca8712 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -43,6 +43,8 @@
 
 #include <glib/gi18n.h>
 
+#include <sip/sipep.h>
+
 #include "gmconf.h"
 #include "menu-builder.h"
 
@@ -287,3 +289,108 @@ Opal::Bank::unfetch (const std::string uri)
        iter++)
     (*iter)->unfetch (uri);
 }
+
+void
+Opal::Bank::OnPresenceChange (OpalPresentity& /*presentity*/,
+			      const OpalPresenceInfo& info)
+{
+  std::string presence = "unknown";
+  std::string status;
+
+  /* we could do something precise */
+  switch (info.m_state) {
+
+  case OpalPresenceInfo::InternalError:
+  case OpalPresenceInfo::Forbidden:
+  case OpalPresenceInfo::NoPresence:
+  case OpalPresenceInfo::Unchanged:
+  case OpalPresenceInfo::Unavailable:
+    presence = "offline";
+    break;
+
+  case OpalPresenceInfo::Available:
+  case OpalPresenceInfo::UnknownExtended:
+  case OpalPresenceInfo::Appointment:
+  case OpalPresenceInfo::Away:
+  case OpalPresenceInfo::Breakfast:
+  case OpalPresenceInfo::Busy:
+  case OpalPresenceInfo::Dinner:
+  case OpalPresenceInfo::Holiday:
+  case OpalPresenceInfo::InTransit:
+  case OpalPresenceInfo::LookingForWork:
+  case OpalPresenceInfo::Lunch:
+  case OpalPresenceInfo::Meal:
+  case OpalPresenceInfo::Meeting:
+  case OpalPresenceInfo::OnThePhone:
+  case OpalPresenceInfo::Other:
+  case OpalPresenceInfo::Performance:
+  case OpalPresenceInfo::PermanentAbsence:
+  case OpalPresenceInfo::Playing:
+  case OpalPresenceInfo::Presentation:
+  case OpalPresenceInfo:: Shopping:
+  case OpalPresenceInfo::Sleeping:
+  case OpalPresenceInfo::Spectator:
+  case OpalPresenceInfo::Steering:
+  case OpalPresenceInfo::Travel:
+  case OpalPresenceInfo::TV:
+  case OpalPresenceInfo::Vacation:
+  case OpalPresenceInfo::Working:
+  case OpalPresenceInfo:: Worship:
+    presence = "online";
+    break;
+  default:
+    presence = "offline";
+    break;
+  }
+
+  if (!info.m_note.IsEmpty ()) {
+
+    PINDEX j;
+    PCaselessString note = info.m_note;
+    if (note.Find ("Away") != P_MAX_INDEX)
+      presence = "away";
+    else if (note.Find ("On the phone") != P_MAX_INDEX)
+      presence = "inacall";
+    else if (note.Find ("Ringing") != P_MAX_INDEX)
+      presence = "ringing";
+    else if (note.Find ("dnd") != P_MAX_INDEX
+             || note.Find ("Do Not Disturb") != P_MAX_INDEX)
+      presence = "dnd";
+
+    else if (note.Find ("Free For Chat") != P_MAX_INDEX)
+      presence = "freeforchat";
+
+    if ((j = note.Find (" - ")) != P_MAX_INDEX)
+      status = (const char *) info.m_note.Mid (j + 3);
+  }
+
+  SIPURL sip_uri = SIPURL (info.m_entity);
+  sip_uri.Sanitise (SIPURL::ExternalURI);
+  std::string uri = sip_uri.AsString ();
+  std::string old_presence = presence_infos[uri].presence;
+  std::string old_status = presence_infos[uri].status;
+
+  // If first notification, and no information, then we are offline
+  if (presence == "unknown" && old_presence.empty ())
+    presence = "offline";
+
+  // If presence change, then signal it to the various components
+  // If presence is unknown (notification with empty body), and it is not the
+  // first notification, and we can conclude it is a ping back from the server
+  // to indicate the presence status did not change, hence we do nothing.
+  if (presence != "unknown" && (old_presence != presence || old_status != status)) {
+    presence_infos[uri].presence = presence;
+    presence_infos[uri].status = status;
+    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Bank::presence_status_in_main, this, uri, presence_infos[uri].presence, presence_infos[uri].status));
+  }
+}
+
+
+void
+Opal::Bank::presence_status_in_main (std::string uri,
+				     std::string presence,
+				     std::string status)
+{
+  presence_received (uri, presence);
+  status_received (uri, status);
+}
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index 28497c7..f6bf9b6 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -42,6 +42,7 @@
 #include "bank-impl.h"
 #include "opal-account.h"
 #include "services.h"
+#include "runtime.h"
 
 namespace Opal
 {
@@ -97,6 +98,12 @@ public:
 private:
     Ekiga::ServiceCore &core;
 
+    PDECLARE_PresenceChangeNotifier (Bank, OnPresenceChange);
+
+    void presence_status_in_main (std::string uri,
+				  std::string presence,
+				  std::string status);
+
     void on_new_account_form_submitted (bool submitted,
 					Ekiga::Form& form,
 					Account::Type acc_type);
@@ -111,6 +118,16 @@ private:
               unsigned timeout);
 
     void save () const;
+
+    typedef struct {
+
+      std::string presence;
+      std::string status;
+      bool requested;
+    } uri_info;
+    
+    std::map<std::string, uri_info> presence_infos;
+
   };
 
   /**
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index 27e2eec..58185f9 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -129,7 +129,6 @@ struct OPALSpark: public Ekiga::Spark
       call_manager->add_protocol_manager (sip_manager);
       contact_core->add_contact_decorator (sip_manager);
       presence_core->add_presentity_decorator (sip_manager);
-      presence_core->add_presence_fetcher (sip_manager);
 
       presence_core->add_presence_publisher (bank);
       presence_core->add_presence_fetcher (bank);
diff --git a/lib/engine/components/opal/sip-endpoint.cpp b/lib/engine/components/opal/sip-endpoint.cpp
index 41a5026..0aa77b0 100644
--- a/lib/engine/components/opal/sip-endpoint.cpp
+++ b/lib/engine/components/opal/sip-endpoint.cpp
@@ -53,8 +53,6 @@
 #include "personal-details.h"
 #include "opal-account.h"
 
-#include <ptclib/pxml.h>
-
 namespace Opal {
 
   namespace Sip {
@@ -271,34 +269,6 @@ Opal::Sip::EndPoint::menu_builder_add_actions (const std::string& fullname,
 }
 
 
-void
-Opal::Sip::EndPoint::fetch (const std::string uri)
-{
-  /* this is for the new opal presence api */
-  PSafePtr<OpalPresentity> presentity = manager.AddPresentity (uri);
-  presentity->SetPresenceChangeNotifier (PCREATE_PresenceChangeNotifier(OnPresenceChange));
-  presentity->Open ();
-
-  /* this is for the old opal presence api */
-  Subscribe (SIPSubscribe::Presence, 300, uri);
-
-  Subscribe (SIPSubscribe::Dialog, 300, uri);
-}
-
-
-void
-Opal::Sip::EndPoint::unfetch (const std::string uri)
-{
-  /* this is for the new opal presence api */
-  manager.RemovePresentity (uri);
-
-  /* this is for the old opal presence api */
-  Subscribe (SIPSubscribe::Presence, 0, uri);
-
-  Subscribe (SIPSubscribe::Dialog, 0, uri);
-}
-
-
 bool
 Opal::Sip::EndPoint::send_message (const std::string & _uri,
 				   const std::string & _message)
@@ -956,113 +926,6 @@ Opal::Sip::EndPoint::GetRegisteredPartyName (const SIPURL & aor,
   return GetDefaultRegisteredPartyName (transport);
 }
 
-void
-Opal::Sip::EndPoint::OnPresenceInfoReceived (const SIPPresenceInfo& info)
-{
-  treat_presence_info (info);
-}
-
-void
-Opal::Sip::EndPoint::OnPresenceChange (OpalPresentity& /*presentity*/,
-				       const OpalPresenceInfo& info)
-{
-  treat_presence_info (info);
-}
-
-void
-Opal::Sip::EndPoint::treat_presence_info (const OpalPresenceInfo& info)
-{
-  std::string presence = "unknown";
-  std::string status;
-
-  /* we could do something precise */
-  switch (info.m_state) {
-
-  case OpalPresenceInfo::InternalError:
-  case OpalPresenceInfo::Forbidden:
-  case OpalPresenceInfo::NoPresence:
-  case OpalPresenceInfo::Unchanged:
-  case OpalPresenceInfo::Unavailable:
-    presence = "offline";
-    break;
-
-  case OpalPresenceInfo::Available:
-  case OpalPresenceInfo::UnknownExtended:
-  case OpalPresenceInfo::Appointment:
-  case OpalPresenceInfo::Away:
-  case OpalPresenceInfo::Breakfast:
-  case OpalPresenceInfo::Busy:
-  case OpalPresenceInfo::Dinner:
-  case OpalPresenceInfo::Holiday:
-  case OpalPresenceInfo::InTransit:
-  case OpalPresenceInfo::LookingForWork:
-  case OpalPresenceInfo::Lunch:
-  case OpalPresenceInfo::Meal:
-  case OpalPresenceInfo::Meeting:
-  case OpalPresenceInfo::OnThePhone:
-  case OpalPresenceInfo::Other:
-  case OpalPresenceInfo::Performance:
-  case OpalPresenceInfo::PermanentAbsence:
-  case OpalPresenceInfo::Playing:
-  case OpalPresenceInfo::Presentation:
-  case OpalPresenceInfo:: Shopping:
-  case OpalPresenceInfo::Sleeping:
-  case OpalPresenceInfo::Spectator:
-  case OpalPresenceInfo::Steering:
-  case OpalPresenceInfo::Travel:
-  case OpalPresenceInfo::TV:
-  case OpalPresenceInfo::Vacation:
-  case OpalPresenceInfo::Working:
-  case OpalPresenceInfo:: Worship:
-    presence = "online";
-    break;
-  default:
-    presence = "offline";
-    break;
-  }
-
-  if (!info.m_note.IsEmpty ()) {
-
-    PINDEX j;
-    PCaselessString note = info.m_note;
-    if (note.Find ("Away") != P_MAX_INDEX)
-      presence = "away";
-    else if (note.Find ("On the phone") != P_MAX_INDEX)
-      presence = "inacall";
-    else if (note.Find ("Ringing") != P_MAX_INDEX)
-      presence = "ringing";
-    else if (note.Find ("dnd") != P_MAX_INDEX
-             || note.Find ("Do Not Disturb") != P_MAX_INDEX)
-      presence = "dnd";
-
-    else if (note.Find ("Free For Chat") != P_MAX_INDEX)
-      presence = "freeforchat";
-
-    if ((j = note.Find (" - ")) != P_MAX_INDEX)
-      status = (const char *) info.m_note.Mid (j + 3);
-  }
-
-  SIPURL sip_uri = SIPURL (info.m_entity);
-  sip_uri.Sanitise (SIPURL::ExternalURI);
-  std::string _uri = sip_uri.AsString ();
-  std::string old_presence = presence_infos[_uri].presence;
-  std::string old_status = presence_infos[_uri].status;
-
-  // If first notification, and no information, then we are offline
-  if (presence == "unknown" && old_presence.empty ())
-    presence = "offline";
-
-  // If presence change, then signal it to the various components
-  // If presence is unknown (notification with empty body), and it is not the
-  // first notification, and we can conclude it is a ping back from the server
-  // to indicate the presence status did not change, hence we do nothing.
-  if (presence != "unknown" && (old_presence != presence || old_status != status)) {
-    presence_infos[_uri].presence = presence;
-    presence_infos[_uri].status = status;
-    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::presence_status_in_main, this, _uri, presence_infos[_uri].presence, presence_infos[_uri].status));
-  }
-}
-
 
 void
 Opal::Sip::EndPoint::OnDialogInfoReceived (const SIPDialogNotification & info)
@@ -1099,17 +962,6 @@ Opal::Sip::EndPoint::OnDialogInfoReceived (const SIPDialogNotification & info)
   case SIPDialogNotification::Terminated:
     break;
   }
-
-  dialog_infos[uri].presence = presence;
-  dialog_infos[uri].status = status;
-
-  if (presence_infos[uri].presence.empty ())
-    presence_infos[uri].presence = "online";
-
-  if (_status)
-    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::presence_status_in_main, this, uri, dialog_infos[uri].presence, dialog_infos[uri].status));
-  else
-    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::presence_status_in_main, this, uri, presence_infos[uri].presence, presence_infos[uri].status));
 }
 
 
@@ -1167,16 +1019,6 @@ Opal::Sip::EndPoint::registration_event_in_main (const std::string aor,
     account->handle_registration_event (state, msg);
 }
 
-
-void
-Opal::Sip::EndPoint::presence_status_in_main (std::string uri,
-					      std::string presence,
-					      std::string status)
-{
-  presence_received (uri, presence);
-  status_received (uri, status);
-}
-
 void
 Opal::Sip::EndPoint::push_message_in_main (const std::string uri,
 					   const std::string name,
diff --git a/lib/engine/components/opal/sip-endpoint.h b/lib/engine/components/opal/sip-endpoint.h
index 686882a..69ddc2b 100644
--- a/lib/engine/components/opal/sip-endpoint.h
+++ b/lib/engine/components/opal/sip-endpoint.h
@@ -63,7 +63,6 @@ namespace Opal {
     class EndPoint : public SIPEndPoint,
 		     public Ekiga::Service,
 		     public Ekiga::CallProtocolManager,
-		     public Ekiga::PresenceFetcher,
 		     public Ekiga::PresentityDecorator,
 		     public Ekiga::ContactDecorator
     {
@@ -73,12 +72,6 @@ namespace Opal {
 
       typedef std::list<std::string> domain_list;
       typedef std::list<std::string>::iterator domain_list_iterator;
-      typedef struct {
-        std::string presence;
-        std::string status;
-        bool requested;
-      } uri_info;
-      typedef std::map<std::string, uri_info> uri_info_map;
 
       EndPoint (CallManager& ep,
 		Ekiga::ServiceCore& core,
@@ -107,11 +100,6 @@ namespace Opal {
                                      Ekiga::MenuBuilder & builder);
 
 
-      /* PresenceFetcher */
-      void fetch (const std::string uri);
-      void unfetch (const std::string uri);
-
-
       /* Chat subsystem */
       bool send_message (const std::string & uri,
                          const std::string & message);
@@ -174,15 +162,6 @@ namespace Opal {
                                  unsigned options,
                                  OpalConnection::StringOptions * stroptions);
 
-      /* new opal presence api -- doesn't work yet with ekiga.net */
-      PDECLARE_PresenceChangeNotifier (EndPoint, OnPresenceChange);
-
-      /* old opal presence api -- the one which works with ekiga.net */
-      void OnPresenceInfoReceived (const SIPPresenceInfo& info);
-
-      /* common function to treat presence information coming from both opal presence api */
-      void treat_presence_info (const OpalPresenceInfo& info);
-
       void OnDialogInfoReceived (const SIPDialogNotification & info);
 
       PBoolean OnReceivedINVITE (OpalTransport & transport, SIP_PDU * pdu);
@@ -249,9 +228,6 @@ namespace Opal {
       bool auto_answer_call;
 
       boost::shared_ptr<SIP::Dialect> dialect;
-
-      uri_info_map presence_infos;  // List of uri presences
-      uri_info_map dialog_infos;    // List of uri dialog informations
     };
   };
 };



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