Incremental commit for event dispatching.
authorOssama Othman <ossama.othman@intel.com>
Mon, 7 Oct 2013 06:57:40 +0000 (23:57 -0700)
committerOssama Othman <ossama.othman@intel.com>
Mon, 7 Oct 2013 06:57:40 +0000 (23:57 -0700)
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
lib/manager.cpp
lib/manager.hpp
src/websocket_server.cpp

index 8fd64b0..45539bd 100644 (file)
@@ -126,7 +126,7 @@ ivi::settings::manager::load_settings(std::string const & dir)
 
 void
 ivi::settings::manager::dispatch(std::string request,
-                                 struct libwebsocket * wsi)
+                                 libwebsocket * wsi)
 {
   if (request.empty()) {
     response_callback response(wsi, std::string(), std::string());
@@ -186,6 +186,21 @@ ivi::settings::manager::dispatch(std::string request,
   }
 }
 
+void
+ivi::settings::manager::subscribe_client(libwebsocket * wsi)
+{
+  clients_.push_back(wsi);
+}
+
+void
+ivi::settings::manager::unsubscribe_client(libwebsocket * wsi)
+{
+  auto const end = clients_.end();
+  for (auto i = clients_.begin; i != end; ++i)
+    if (*i == wsi)
+      clients_.erase(i);
+}
+
 
 // Local Variables:
 // mode:c++
index e768deb..0d644aa 100644 (file)
@@ -81,6 +81,18 @@ namespace ivi
        */
       void dispatch(std::string request, libwebsocket * wsi);
 
+      /**
+       * Subscribe client on the other side of the WebSocket @a wsi to
+       * events created by settings plugins.
+       */
+      void subscribe_client(libwebsocket * wsi);
+
+      /**
+       * Unsubscribe client on the other side of the WebSocket @a wsi
+       * from receiving further settings plugin events.
+       */
+      void unsubscribe_client(libwebsocket * wsi);
+
     private:
 
       /**
@@ -125,6 +137,12 @@ namespace ivi
       /// Map of settings name to @c settings instance.
       map_type settings_;
 
+      /**
+       * List of client WebSockets to be used for sending events to
+       * the client.
+       */
+      std::vector<libwebsocket *> clients_;
+
     };
 
   }
index 69fbfeb..eab3698 100644 (file)
@@ -55,8 +55,14 @@ namespace
     switch(reason) {
     case LWS_CALLBACK_ESTABLISHED:
       // Enable event dispatching to client.
-      
+      manager->subscribe_client(wsi);
       break;
+
+    case LWS_CALLBACK_CLOSED:
+      // Disable event dispatching to client.
+      manager->unsubscribe_client(wsi);
+      break;
+
     case LWS_CALLBACK_RECEIVE:
       // Request has come in from Settings app.  Pass it on to the
       // settings manager.