DSWaylandCompositor: add client created handler 15/241615/1
authorSung-Jin Park <sj76.park@samsung.com>
Mon, 13 Jul 2020 12:38:43 +0000 (21:38 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 09:53:45 +0000 (18:53 +0900)
Change-Id: Id03e8f7ef21ed93cef4327f9d6e85e03465089b8
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/DSWaylandServer/DSWaylandCompositor.cpp
src/DSWaylandServer/DSWaylandCompositorPrivate.h

index 9832e50..49e1eac 100644 (file)
@@ -1,5 +1,6 @@
 #include "DSWaylandCompositor.h"
 #include "DSWaylandCompositorPrivate.h"
+#include "DSWaylandClient.h"
 #include "DSDebugLog.h"
 
 namespace display_server
@@ -26,15 +27,16 @@ DSWaylandCompositorPrivate::DSWaylandCompositorPrivate(DSWaylandCompositor *comp
        _display = wl_display_create();
        DS_ASSERT(_display != nullptr);
 
-       //TODO : add listener for client creation using wl_display_add_client_created_listener()
-       //TODO : leave log (log system needed)
-       //TODO
+       m_clientCreatedListener.notify = DSWaylandCompositorPrivate::client_created_callback;
+       m_clientCreatedListener.parent = this;
+       wl_display_add_client_created_listener(_display, &m_clientCreatedListener);
 }
 
 DSWaylandCompositorPrivate::~DSWaylandCompositorPrivate()
 {
        //TODO : destroy all allocated resources
-       //TODO : remove listener link (installed for checking client creation)
+
+       wl_list_remove(&m_clientCreatedListener.link);
 
        _clients.clear();
        _seats.clear();
@@ -62,6 +64,24 @@ DSWaylandCompositorPrivate::~DSWaylandCompositorPrivate()
        ecore_shutdown();
 }
 
+void DSWaylandCompositorPrivate::client_created_callback(struct ::wl_listener *listener, void *data)
+{
+       struct ::wl_client *wlClient = (struct ::wl_client *)data;
+       DS_ASSERT(wlClient != nullptr);
+
+       DSWaylandClient *client = nullptr;
+       DSWaylandCompositorPrivate *compPriv = reinterpret_cast<ClientCreatedListener *>(listener)->parent;
+
+       if (compPriv != nullptr)
+       {
+               client = new DSWaylandClient(compPriv->_compositor, wlClient);
+               DS_ASSERT(client != nullptr);
+
+               DSLOG_INF("DSWaylandCompositorPrivate", "Client created ! (pid:%d, uid:%d, gid:%d)",
+                                       client->pid(), client->uid(), client->gid());
+       }
+}
+
 void DSWaylandCompositorPrivate::initSocket(std::string sName, std::string sDir)
 {
        std::string socketPath = std::move(sDir);
index e55529d..0cce28d 100644 (file)
@@ -4,7 +4,10 @@
 #include "DSCore.h"
 #include "DSObjectPrivate.h"
 #include "dswayland-server-wayland.h"
+#include "DSWaylandClient.h"
+#include "DSDebugLog.h"
 
+#include <wayland-server-core.h>
 #include <Ecore.h>
 
 namespace display_server
@@ -27,8 +30,11 @@ public:
     inline void addSeat(DSWaylandSeat *seat);
     inline void removeSeat(DSWaylandSeat *seat);
 
-    //TODO : add listener for client created event
-    //TODO
+    static void client_created_callback(struct ::wl_listener *listener, void *data);
+    struct ClientCreatedListener : ::wl_listener {
+        DSWaylandCompositorPrivate *parent;
+    };
+    ClientCreatedListener m_clientCreatedListener;
 
 protected:
     //virtual Resource *compositor_allocate();
@@ -59,17 +65,19 @@ private:
 void DSWaylandCompositorPrivate::addClient(DSWaylandClient *client)
 {
     DS_ASSERT(client != nullptr);
-    
+
     //TODO : check if the client is in clients already ?
     _clients.push_back(client);
+    DSLOG_INF("DSWaylandCompositorPrivate", "Client(%p, PID:%d) has been added.", client, client->pid());
 }
 
 void DSWaylandCompositorPrivate::removeClient(DSWaylandClient *client)
 {
     DS_ASSERT(client != nullptr);
-    
+
     //TODO : check if the client is in clients already ?
     _clients.remove(client);
+    DSLOG_INF("DSWaylandCompositorPrivate", "Client(%p, PID:%d) has been removed.", client, client->pid());
 }
 
 void DSWaylandCompositorPrivate::addSeat(DSWaylandSeat *seat)