[ekiga] Moved the SIP component to the new chat stack organisation



commit dfb93e503c161f2d158ad13025b9ea3116e5e99f
Author: Julien Puydt <jpuydt free fr>
Date:   Sun Feb 16 08:47:08 2014 +0100

    Moved the SIP component to the new chat stack organisation

 lib/Makefile.am                                 |    4 +-
 lib/engine/components/opal/sip-conversation.cpp |   68 ++++++++++++++++
 lib/engine/components/opal/sip-conversation.h   |   95 +++++++++++++++++++++++
 lib/engine/components/opal/sip-dialect.cpp      |   56 +++++---------
 lib/engine/components/opal/sip-dialect.h        |   30 +++----
 lib/engine/components/opal/sip-endpoint.cpp     |   41 ++++++----
 lib/engine/components/opal/sip-endpoint.h       |    9 +--
 7 files changed, 224 insertions(+), 79 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 63329be..3569c84 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -437,8 +437,8 @@ libekiga_la_SOURCES += \
 endif
 
 libekiga_la_SOURCES += \
-       engine/components/opal/sip-chat-simple.h \
-       engine/components/opal/sip-chat-simple.cpp \
+       engine/components/opal/sip-conversation.h \
+       engine/components/opal/sip-conversation.cpp \
        engine/components/opal/sip-dialect.h \
        engine/components/opal/sip-dialect.cpp \
        engine/components/opal/sip-endpoint.h \
diff --git a/lib/engine/components/opal/sip-conversation.cpp b/lib/engine/components/opal/sip-conversation.cpp
new file mode 100644
index 0000000..09ca21b
--- /dev/null
+++ b/lib/engine/components/opal/sip-conversation.cpp
@@ -0,0 +1,68 @@
+
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+
+ * This program is free software; you can  redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ *                         sip-conversation.cpp -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2014 by Julien Puydt
+ *   copyright            : (c) 2014 by Julien Puydt
+ *   description          : implementation of a SIP conversation
+ *
+ */
+
+#include "sip-conversation.h"
+
+void
+SIP::Conversation::visit_messages (boost::function1<bool, const Ekiga::Message&> visitor) const
+{
+  for (std::list<Ekiga::Message>::const_iterator iter = messages.begin();
+       iter != messages.end ();
+       ++iter) {
+
+    if (!visitor(*iter))
+      break;
+  }
+}
+
+bool
+SIP::Conversation::send_message (const Ekiga::Message::payload_type& payload)
+{
+  return sender (payload);
+}
+
+void
+SIP::Conversation::reset_unread_messages_count ()
+{
+  unreads = 0;
+  updated ();
+}
+
+void
+SIP::Conversation::receive_message (const Ekiga::Message& message)
+{
+  messages.push_back (message);
+  message_received (message);
+}
diff --git a/lib/engine/components/opal/sip-conversation.h b/lib/engine/components/opal/sip-conversation.h
new file mode 100644
index 0000000..8ba9b28
--- /dev/null
+++ b/lib/engine/components/opal/sip-conversation.h
@@ -0,0 +1,95 @@
+
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+
+ * This program is free software; you can  redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ *                         sip-conversation.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2014 by Julien Puydt
+ *   copyright            : (c) 2014 by Julien Puydt
+ *   description          : declaration of a SIP conversation
+ *
+ */
+
+#ifndef __SIP_CONVERSATION_H__
+#define __SIP_CONVERSATION_H__
+
+#include "conversation.h"
+
+namespace SIP {
+
+  class Conversation: public Ekiga::Conversation
+  {
+  public:
+
+    Conversation (const std::string _uri,
+                 const std::string _name,
+                 boost::function1<bool, const Ekiga::Message::payload_type&> _sender):
+      uri(_uri), title(_name), sender(_sender)
+    {}
+
+    // generic Ekiga::Conversation api:
+
+    Ekiga::HeapPtr get_heap () const
+    { return heap; }
+
+    // FIXME: is that part of the api any good?!
+    const std::string get_title () const
+    { return title; }
+    const std::string get_topic () const
+    { return topic; }
+
+    void visit_messages (boost::function1<bool, const Ekiga::Message&> visitor) const;
+    bool send_message (const Ekiga::Message::payload_type& payload);
+
+    int get_unread_messages_count () const
+    { return unreads; }
+
+    void reset_unread_messages_count ();
+
+    bool populate_menu (Ekiga::MenuBuilder& /*builder*/)
+    { return false; /* FIXME */ }
+
+    // protocol-specific api
+    const std::string get_uri () const
+    { return uri; }
+
+    void receive_message (const Ekiga::Message& message);
+
+  private:
+
+    std::string uri;
+    std::string title;
+    boost::function1<bool, Ekiga::Message::payload_type> sender;
+    Ekiga::HeapPtr heap;
+    std::string topic;
+    int unreads;
+    std::list<Ekiga::Message> messages;
+  };
+
+  typedef typename boost::shared_ptr<Conversation> ConversationPtr;
+};
+
+#endif
diff --git a/lib/engine/components/opal/sip-dialect.cpp b/lib/engine/components/opal/sip-dialect.cpp
index 21a3863..ec879a4 100644
--- a/lib/engine/components/opal/sip-dialect.cpp
+++ b/lib/engine/components/opal/sip-dialect.cpp
@@ -1,6 +1,6 @@
 
 /* Ekiga -- A VoIP and Video-Conferencing application
- * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@
  *                         sip-dialect.cpp  -  description
  *                         --------------------------------
  *   begin                : written in july 2008 by Julien Puydt
- *   copyright            : (C) 2008 by Julien Puydt
+ *   copyright            : (C) 2014 by Julien Puydt
  *   description          : Implementation of the SIP dialect
  *
  */
@@ -39,10 +39,9 @@
 #include "presence-core.h"
 #include "personal-details.h"
 
-SIP::Dialect::Dialect (Ekiga::ServiceCore& core,
-                      boost::function2<bool, std::string, std::string> sender_):
-  presence_core(core.get<Ekiga::PresenceCore> ("presence-core")),
-  personal_details(core.get<Ekiga::PersonalDetails> ("personal-details")),
+SIP::Dialect::Dialect (Ekiga::ServiceCore& core_,
+                      boost::function2<bool, std::string, Ekiga::Message::payload_type> sender_):
+  core(core_),
   sender(sender_)
 {
 }
@@ -53,27 +52,14 @@ SIP::Dialect::~Dialect ()
 
 void
 SIP::Dialect::push_message (const std::string uri,
-                           const std::string name,
-                           const std::string msg)
+                           const Ekiga::Message& msg)
 {
-  SimpleChatPtr chat;
+  ConversationPtr conversation;
 
-  chat = open_chat_with (uri, name, false);
+  conversation = open_chat_with (uri, msg.name, false);
 
-  if (chat)
-    chat->receive_message (msg);
-}
-
-void
-SIP::Dialect::push_notice (const std::string uri,
-                          const std::string name,
-                          const std::string msg)
-{
-  SimpleChatPtr chat;
-
-  chat = open_chat_with (uri, name, false);
-
-  chat->receive_notice (msg);
+  if (conversation)
+    conversation->receive_message (msg);
 }
 
 bool
@@ -89,29 +75,27 @@ SIP::Dialect::start_chat_with (std::string uri,
   (void)open_chat_with (uri, name, true);
 }
 
-boost::shared_ptr<SIP::SimpleChat>
+SIP::ConversationPtr
 SIP::Dialect::open_chat_with (std::string uri,
                              std::string name,
                              bool user_request)
 {
-  SimpleChatPtr result;
+  ConversationPtr result;
+  std::string display_name = name;
 
-  for (simple_iterator iter = simple_begin ();
-       iter != simple_end ();
+  for (iterator iter = begin ();
+       iter != end ();
        ++iter)
     if ((*iter)->get_uri () == uri)
       result = *iter;
 
   if ( !result) {
 
-    boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
-    boost::shared_ptr<Ekiga::PersonalDetails> details = personal_details.lock ();
-    if (pcore && details) {
-
-      result = SimpleChatPtr (new SimpleChat (pcore, details, name, uri,
-                                             boost::bind(sender, uri, _1)));
-      add_simple_chat (result);
-    }
+    // FIXME: here find a better display_name
+    result = ConversationPtr (new Conversation(uri,
+                                              display_name,
+                                              boost::bind(sender, uri, _1)));
+    add_conversation (result);
   }
 
   if (user_request && result)
diff --git a/lib/engine/components/opal/sip-dialect.h b/lib/engine/components/opal/sip-dialect.h
index 6ebcded..7da62b2 100644
--- a/lib/engine/components/opal/sip-dialect.h
+++ b/lib/engine/components/opal/sip-dialect.h
@@ -39,26 +39,22 @@
 #define __SIP_DIALECT_H__
 
 #include "dialect-impl.h"
-#include "sip-chat-simple.h"
+
+#include "presence-core.h"
+#include "sip-conversation.h"
 
 namespace SIP
 {
-  class Dialect: public Ekiga::DialectImpl<SimpleChat>
+  class Dialect: public Ekiga::DialectImpl<Conversation>
   {
   public:
     Dialect (Ekiga::ServiceCore& core_,
-            /* the strings are : uri then msg */
-            boost::function2<bool, std::string, std::string> sender_);
+            boost::function2<bool, std::string, Ekiga::Message::payload_type> sender_);
 
     ~Dialect ();
 
     void push_message (const std::string uri,
-                      const std::string name,
-                      const std::string msg);
-
-    void push_notice (const std::string uri,
-                     const std::string name,
-                     const std::string msg);
+                      const Ekiga::Message& msg);
 
     bool populate_menu (Ekiga::MenuBuilder& builder);
 
@@ -66,14 +62,12 @@ namespace SIP
                          std::string name);
 
   private:
-    boost::weak_ptr<Ekiga::PresenceCore> presence_core;
-    boost::weak_ptr<Ekiga::PersonalDetails> personal_details;
-    /* the strings are : uri then msg */
-    boost::function2<bool, std::string, std::string> sender;
-
-    SimpleChatPtr open_chat_with (std::string uri,
-                                         std::string name,
-                                         bool user_request);
+    Ekiga::ServiceCore& core;
+    boost::function2<bool, std::string, Ekiga::Message::payload_type> sender;
+
+    ConversationPtr open_chat_with (std::string uri,
+                                   std::string name,
+                                   bool user_request);
   };
 
   typedef boost::shared_ptr<Dialect> DialectPtr;
diff --git a/lib/engine/components/opal/sip-endpoint.cpp b/lib/engine/components/opal/sip-endpoint.cpp
index 9b35600..0f440b9 100644
--- a/lib/engine/components/opal/sip-endpoint.cpp
+++ b/lib/engine/components/opal/sip-endpoint.cpp
@@ -193,13 +193,15 @@ Opal::Sip::EndPoint::populate_menu (const std::string& fullname,
 
 bool
 Opal::Sip::EndPoint::send_message (const std::string & _uri,
-                                  const std::string & _message)
+                                  const Ekiga::Message::payload_type payload)
 {
-  if (!_uri.empty () && (_uri.find ("sip:") == 0 || _uri.find (':') == string::npos) && !_message.empty ()) {
+  // FIXME: here we should check which kind of payload we have
+  Ekiga::Message::payload_type::const_iterator iter = payload.find("bare");
+  if (!_uri.empty () && (_uri.find ("sip:") == 0 || _uri.find (':') == string::npos) && iter != payload.end 
()) {
     OpalIM im;
     im.m_to = PURL (_uri);
     im.m_mimeType = "text/plain;charset=UTF-8";
-    im.m_body = _message;
+    im.m_body = iter->second;
     Message (im);
     return true;
   }
@@ -811,8 +813,16 @@ Opal::Sip::EndPoint::OnReceivedMESSAGE (OpalTransport & transport,
   std::string display_name = (const char *) uri.GetDisplayName ();
   std::string message_uri = (const char *) uri.AsString ();
   std::string _message = (const char *) pdu.GetEntityBody ();
+  Ekiga::Message::payload_type payload;
+  // FIXME: we push as 'bare' without really knowing
+  payload.insert (std::make_pair ("bare", _message));
+  GTimeVal current;
+  g_get_current_time (&current);
+  gchar* time = g_time_val_to_iso8601 (&current);
+  Ekiga::Message msg = {time, display_name, payload };
+  g_free (time);
 
-  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::push_message_in_main, this, message_uri, 
display_name, _message));
+  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::push_message_in_main, this, message_uri, 
msg));
 
   return SIPEndPoint::OnReceivedMESSAGE (transport, pdu);
 }
@@ -838,8 +848,16 @@ Opal::Sip::EndPoint::OnMESSAGECompleted (const SIPMessage::Params & params,
     reason_shown += _("user offline");
   else
     reason_shown += SIP_PDU::GetStatusCodeDescription (reason);  // too many to translate them with _()...
+  Ekiga::Message::payload_type payload;
+  // FIXME: we push as 'bare' without really knowing...
+  payload.insert (std::make_pair ("bare", reason_shown));
+  GTimeVal current;
+  g_get_current_time (&current);
+  gchar* time = g_time_val_to_iso8601 (&current);
+  Ekiga::Message msg = {time, "" /* it's a notice */, payload };
+  g_free (time);
 
-  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::push_notice_in_main, this, uri, 
display_name, reason_shown));
+  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::push_message_in_main, this, uri, msg));
 }
 
 
@@ -919,18 +937,9 @@ void Opal::Sip::EndPoint::on_transfer (std::string uri)
 
 void
 Opal::Sip::EndPoint::push_message_in_main (const std::string uri,
-                                          const std::string name,
-                                          const std::string msg)
+                                          const Ekiga::Message msg)
 {
-  dialect->push_message (uri, name, msg);
-}
-
-void
-Opal::Sip::EndPoint::push_notice_in_main (const std::string uri,
-                                         const std::string name,
-                                         const std::string msg)
-{
-  dialect->push_notice (uri, name, msg);
+  dialect->push_message (uri, msg);
 }
 
 void
diff --git a/lib/engine/components/opal/sip-endpoint.h b/lib/engine/components/opal/sip-endpoint.h
index b6b806a..2850260 100644
--- a/lib/engine/components/opal/sip-endpoint.h
+++ b/lib/engine/components/opal/sip-endpoint.h
@@ -92,7 +92,7 @@ namespace Opal {
 
       /* Chat subsystem */
       bool send_message (const std::string & uri,
-                         const std::string & message);
+                         const Ekiga::Message::payload_type payload);
 
 
       /* CallProtocolManager */
@@ -175,12 +175,7 @@ namespace Opal {
       void on_transfer (std::string uri);
 
       void push_message_in_main (const std::string uri,
-                                const std::string name,
-                                const std::string msg);
-
-      void push_notice_in_main (const std::string uri,
-                               const std::string name,
-                               const std::string msg);
+                                const Ekiga::Message msg);
 
       PMutex aorMutex;
       std::map<std::string, std::string> accounts;


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