DSUtilSocket: add skeleton codes to control socket 96/242096/1
authorjeon <jhyuni.kang@samsung.com>
Fri, 21 Aug 2020 08:39:06 +0000 (17:39 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 24 Aug 2020 06:31:41 +0000 (15:31 +0900)
Change-Id: I1dab0ff9c770782171b54f013bd7cfeac55299ef

src/DSUtil/DSUtilSocket.cpp [new file with mode: 0644]
src/DSUtil/DSUtilSocket.h [new file with mode: 0644]
src/meson.build

diff --git a/src/DSUtil/DSUtilSocket.cpp b/src/DSUtil/DSUtilSocket.cpp
new file mode 100644 (file)
index 0000000..4307a75
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#include "DSUtilSocket.h"
+
+namespace display_server
+{
+
+/* reference count, mutex and compositor pointer for DSUtilSocket singleton */
+int DSUtilSocket::__refCount { 0 };
+std::mutex DSUtilSocket::__mutex;
+DSUtilSocket* DSUtilSocket::__utilSocket { nullptr };
+
+DSUtilSocket::DSUtilSocket()
+{
+}
+
+DSUtilSocket::~DSUtilSocket()
+{
+}
+
+/* getInstance for DSUtilSocket singleton */
+//static
+DSUtilSocket *DSUtilSocket::getInstance()
+{
+       std::lock_guard<std::mutex> tLock(__mutex);
+
+       DSLOG_INF("DSUtilSocket",
+                       "[Get] instance __refCount=%d !", __refCount);
+
+       if (!__utilSocket && (__refCount == 0))
+       {
+               __utilSocket = new DSUtilSocket();
+               DSLOG_INF("DSUtilSocket",
+                       "DSUtilSocket instance has been created !");
+       }
+
+       ++__refCount;
+       return __utilSocket;
+}
+
+/* releaseInstance for DSUtilSocket singleton */
+// static
+void DSUtilSocket::releaseInstance()
+{
+       std::lock_guard<std::mutex> tLock(__mutex);
+
+       --__refCount;
+       if (__refCount < 0)
+               __refCount = 0;
+       DSLOG_INF("DSUtilSocket",
+                       "[Release] instance __refCount=%d !", __refCount);
+
+       if ((0 == __refCount) && __utilSocket)
+       {
+               delete __utilSocket;
+               __utilSocket = nullptr;
+               DSLOG_INF("DSUtilSocket",
+                       "DSUtilSocket instance has been removed !");
+       }
+}
+
+
+}
diff --git a/src/DSUtil/DSUtilSocket.h b/src/DSUtil/DSUtilSocket.h
new file mode 100644 (file)
index 0000000..309f1ef
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef __DS_UTIL_SOCKET_H_
+#define __DS_UTIL_SOCKET_H_
+
+#include <DSCore.h>
+
+namespace display_server
+{
+
+class DSUtilSocket
+{
+public:
+       static DSUtilSocket *getInstance();
+       static void releaseInstance();
+
+private:
+       DSUtilSocket();
+       ~DSUtilSocket();
+       DSUtilSocket& operator=(const DSUtilSocket&) = delete;
+
+       static std::mutex __mutex;
+       static DSUtilSocket *__utilSocket;
+       static int __refCount;
+};
+
+}
+
+#endif
index d1731f2..6b988da 100644 (file)
@@ -76,6 +76,8 @@ libds_srcs = [
        'DSTextInput/DSTextInputPrivate.h',
        'DSTextInput/DSTextInput.h',
        'DSTextInput/DSTextInput.cpp',
+       'DSUtil/DSUtilSocket.h',
+       'DSUtil/DSUtilSocket.cpp',
        ]
 
 libds_wayland_srcs = [
@@ -235,6 +237,7 @@ libds_include_dirs = include_directories(
        './DSXkb',
        './DSTextInput',
        './DSTizenAppinfo',
+       './DSUtil',
        )
 
 libds_lib = shared_library(