change c++ standard version for supporting TizenRT
authorYoungjae Shin <yj99.shin@samsung.com>
Wed, 24 Aug 2022 10:12:19 +0000 (19:12 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 15 Sep 2022 05:32:15 +0000 (14:32 +0900)
- replace make_unique
- replace getrandom which is Linux-specific.

CMakeLists.txt
modules/tcp/Module.cc
modules/tcp/samples/tcp_test.cc
modules/tcp/tests/TCPServer_test.cc
modules/tcp/tests/TCP_test.cc
modules/webrtc/WebRtcStream.cc
modules/webrtc/WebRtcStream.h
src/AITT.cc
tests/AITT_test.cc

index 3fa2dc0..bbde429 100644 (file)
@@ -3,7 +3,7 @@ SET(CMAKE_SKIP_BUILD_RPATH true)
 PROJECT(aitt VERSION 0.0.1 LANGUAGES CXX)
 SET_PROPERTY(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 0)
 SET(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
-SET(CMAKE_CXX_STANDARD 17)
+SET(CMAKE_CXX_STANDARD 11)
 SET(CMAKE_CXX_STANDARD_REQUIRED ON)
 SET(CMAKE_CXX_EXTENSIONS OFF)
 
index 929a2ee..4002b00 100644 (file)
@@ -105,7 +105,7 @@ void Module::Publish(const std::string &topic, const void *data, const size_t da
                         // The broken clientTable or subscribeTable
                     }
 
-                    std::unique_ptr<TCP> client(std::make_unique<TCP>(host, portIt->first));
+                    std::unique_ptr<TCP> client(new TCP(host, portIt->first));
 
                     // TODO:
                     // If the client gets disconnected,
@@ -155,7 +155,8 @@ void Module::SendPayload(const size_t &datalen, Module::PortMap::iterator &portI
     }
 }
 
-void Module::SendExactSize(Module::PortMap::iterator &port_iterator, const void *data, size_t data_length)
+void Module::SendExactSize(Module::PortMap::iterator &port_iterator, const void *data,
+      size_t data_length)
 {
     size_t remaining_size = data_length;
     while (0 < remaining_size) {
@@ -183,7 +184,7 @@ void *Module::Subscribe(const std::string &topic, const AittTransport::Subscribe
     std::unique_ptr<TCP::Server> tcpServer;
 
     unsigned short port = 0;
-    tcpServer = std::make_unique<TCP::Server>("0.0.0.0", port);
+    tcpServer = std::unique_ptr<TCP::Server>(new TCP::Server("0.0.0.0", port));
     TCPServerData *listen_info = new TCPServerData;
     listen_info->impl = this;
     listen_info->cb = cb;
index d319e27..f550c60 100644 (file)
@@ -36,7 +36,7 @@ __thread __aitt__tls__ __aitt;
 class AittTcpSample {
   public:
     AittTcpSample(const std::string &host, unsigned short &port)
-          : server(std::make_unique<TCP::Server>(host, port))
+          : server(new TCP::Server(host, port))
     {
     }
     virtual ~AittTcpSample(void) {}
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
               SEND_INTERVAL,
               [](gpointer data) -> gboolean {
                   Main *ctx = static_cast<Main *>(data);
-                  std::unique_ptr<TCP> client(std::make_unique<TCP>(ctx->host, ctx->port));
+                  std::unique_ptr<TCP> client(new TCP(ctx->host, ctx->port));
 
                   INFO("Assigned client port: %u", client->GetPort());
 
index e8b48b1..e3eb62e 100644 (file)
@@ -31,7 +31,7 @@
 TEST(TCPServer, Positive_Create_Anytime)
 {
     unsigned short port = TEST_SERVER_PORT;
-    std::unique_ptr<TCP::Server> tcp(std::make_unique<TCP::Server>(TEST_SERVER_ADDRESS, port));
+    std::unique_ptr<TCP::Server> tcp(new TCP::Server(TEST_SERVER_ADDRESS, port));
     ASSERT_NE(tcp, nullptr);
 }
 
@@ -40,8 +40,7 @@ TEST(TCPServer, Negative_Create_Anytime)
     try {
         unsigned short port = TEST_SERVER_PORT;
 
-        std::unique_ptr<TCP::Server> tcp(
-              std::make_unique<TCP::Server>(TEST_SERVER_INVALID_ADDRESS, port));
+        std::unique_ptr<TCP::Server> tcp(new TCP::Server(TEST_SERVER_INVALID_ADDRESS, port));
         ASSERT_EQ(tcp, nullptr);
     } catch (std::exception &e) {
         ASSERT_STREQ(e.what(), strerror(EINVAL));
@@ -51,7 +50,7 @@ TEST(TCPServer, Negative_Create_Anytime)
 TEST(TCPServer, Positive_Create_AutoPort_Anytime)
 {
     unsigned short port = TEST_SERVER_AVAILABLE_PORT;
-    std::unique_ptr<TCP::Server> tcp(std::make_unique<TCP::Server>(TEST_SERVER_ADDRESS, port));
+    std::unique_ptr<TCP::Server> tcp(new TCP::Server(TEST_SERVER_ADDRESS, port));
     ASSERT_NE(tcp, nullptr);
     ASSERT_NE(port, 0);
 }
@@ -59,7 +58,7 @@ TEST(TCPServer, Positive_Create_AutoPort_Anytime)
 TEST(TCPServer, Positive_GetPort_Anytime)
 {
     unsigned short port = TEST_SERVER_PORT;
-    std::unique_ptr<TCP::Server> tcp(std::make_unique<TCP::Server>(TEST_SERVER_ADDRESS, port));
+    std::unique_ptr<TCP::Server> tcp(new TCP::Server(TEST_SERVER_ADDRESS, port));
     ASSERT_NE(tcp, nullptr);
     ASSERT_EQ(tcp->GetPort(), TEST_SERVER_PORT);
 }
@@ -67,7 +66,7 @@ TEST(TCPServer, Positive_GetPort_Anytime)
 TEST(TCPServer, Positive_GetHandle_Anytime)
 {
     unsigned short port = TEST_SERVER_PORT;
-    std::unique_ptr<TCP::Server> tcp(std::make_unique<TCP::Server>(TEST_SERVER_ADDRESS, port));
+    std::unique_ptr<TCP::Server> tcp(new TCP::Server(TEST_SERVER_ADDRESS, port));
     ASSERT_NE(tcp, nullptr);
     ASSERT_GE(tcp->GetHandle(), 0);
 }
@@ -75,7 +74,7 @@ TEST(TCPServer, Positive_GetHandle_Anytime)
 TEST(TCPServer, Positive_GetPort_AutoPort_Anytime)
 {
     unsigned short port = TEST_SERVER_AVAILABLE_PORT;
-    std::unique_ptr<TCP::Server> tcp(std::make_unique<TCP::Server>(TEST_SERVER_ADDRESS, port));
+    std::unique_ptr<TCP::Server> tcp(new TCP::Server(TEST_SERVER_ADDRESS, port));
     ASSERT_NE(tcp, nullptr);
     ASSERT_EQ(tcp->GetPort(), port);
 }
@@ -91,8 +90,7 @@ TEST(TCPServer, Positive_AcceptPeer_Anytime)
     unsigned short serverPort = TEST_SERVER_PORT;
     std::thread serverThread(
           [serverPort, &m, &ready, &connected, &ready_cv, &connected_cv](void) mutable -> void {
-              std::unique_ptr<TCP::Server> tcp(
-                    std::make_unique<TCP::Server>(TEST_SERVER_ADDRESS, serverPort));
+              std::unique_ptr<TCP::Server> tcp(new TCP::Server(TEST_SERVER_ADDRESS, serverPort));
               {
                   std::lock_guard<std::mutex> lk(m);
                   ready = true;
@@ -110,7 +108,7 @@ TEST(TCPServer, Positive_AcceptPeer_Anytime)
     {
         std::unique_lock<std::mutex> lk(m);
         ready_cv.wait(lk, [&ready] { return ready; });
-        std::unique_ptr<TCP> tcp(std::make_unique<TCP>(TEST_SERVER_ADDRESS, serverPort));
+        std::unique_ptr<TCP> tcp(new TCP(TEST_SERVER_ADDRESS, serverPort));
         connected_cv.wait(lk, [&connected] { return connected; });
     }
 
index 604bd23..d65875c 100644 (file)
@@ -43,7 +43,7 @@ class TCPTest : public testing::Test {
         clientThread = std::thread([this](void) mutable -> void {
             std::unique_lock<std::mutex> lk(m);
             ready_cv.wait(lk, [this] { return ready; });
-            client = std::make_unique<TCP>(TEST_SERVER_ADDRESS, serverPort);
+            client = std::unique_ptr<TCP>(new TCP(TEST_SERVER_ADDRESS, serverPort));
 
             customTest();
         });
@@ -51,7 +51,7 @@ class TCPTest : public testing::Test {
 
     void RunServer(void)
     {
-        tcp = std::make_unique<TCP::Server>(TEST_SERVER_ADDRESS, serverPort);
+        tcp = std::unique_ptr<TCP::Server>(new TCP::Server(TEST_SERVER_ADDRESS, serverPort));
         {
             std::lock_guard<std::mutex> lk(m);
             ready = true;
@@ -78,8 +78,7 @@ class TCPTest : public testing::Test {
 TEST(TCP, Negative_Create_InvalidPort_Anytime)
 {
     try {
-        std::unique_ptr<TCP> tcp(
-              std::make_unique<TCP>(TEST_SERVER_ADDRESS, TEST_SERVER_AVAILABLE_PORT));
+        std::unique_ptr<TCP> tcp(new TCP(TEST_SERVER_ADDRESS, TEST_SERVER_AVAILABLE_PORT));
         ASSERT_EQ(tcp, nullptr);
     } catch (std::exception &e) {
         ASSERT_STREQ(e.what(), strerror(EINVAL));
@@ -89,8 +88,7 @@ TEST(TCP, Negative_Create_InvalidPort_Anytime)
 TEST(TCP, Negative_Create_InvalidAddress_Anytime)
 {
     try {
-        std::unique_ptr<TCP> tcp(
-              std::make_unique<TCP>(TEST_SERVER_INVALID_ADDRESS, TEST_SERVER_PORT));
+        std::unique_ptr<TCP> tcp(new TCP(TEST_SERVER_INVALID_ADDRESS, TEST_SERVER_PORT));
         ASSERT_EQ(tcp, nullptr);
     } catch (std::exception &e) {
         ASSERT_STREQ(e.what(), strerror(EINVAL));
index ef717b0..0f2ef93 100644 (file)
@@ -121,7 +121,7 @@ bool WebRtcStream::AttachCameraPreviewSource(void)
         return false;
     }
 
-    camera_handler_ = std::make_unique<CameraHandler>();
+    camera_handler_ = std::unique_ptr<CameraHandler>(new CameraHandler());
     camera_handler_->Init(OnMediaPacketPreview, this);
 
     auto ret = webrtc_add_media_source(webrtc_handle_, WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET,
index 755c1ae..b2a9ef5 100644 (file)
@@ -21,6 +21,7 @@
 #include <memory>
 #include <mutex>
 #include <string>
+#include <vector>
 
 // TODO: webrtc.h is very heavy header file.
 // I think we need to decide whether to include this or not
@@ -94,7 +95,7 @@ class WebRtcStream {
 
   private:
     webrtc_h webrtc_handle_;
-    std::shared_ptr<CameraHandler> camera_handler_;
+    std::unique_ptr<CameraHandler> camera_handler_;
     // DO we need to make is_source_overflow_ as atomic?
     bool is_source_overflow_;
     unsigned int source_id_;
index 4e2fb8b..b6e5655 100644 (file)
@@ -42,7 +42,8 @@ AITT::AITT(const std::string &id, const std::string &ip_addr, AittOption option)
     if (ip_addr.empty())
         valid_ip = "127.0.0.1";
 
-    pImpl = std::make_unique<AITT::Impl>(*this, valid_id, valid_ip, option.GetClearSession());
+    pImpl = std::unique_ptr<AITT::Impl>(
+          new AITT::Impl(*this, valid_id, valid_ip, option.GetClearSession()));
 }
 
 AITT::~AITT(void)
index b9aa8c4..8a4b771 100644 (file)
@@ -17,9 +17,8 @@
 
 #include <glib.h>
 #include <gtest/gtest.h>
-#include <sys/random.h>
 
-#include <thread>
+#include <random>
 
 #include "aitt_internal.h"
 #include "aitt_tests.h"
@@ -477,11 +476,14 @@ TEST_F(AITTTest, Positive_Subscribe_Retained_Anytime)
 TEST_F(AITTTest, TCP_Publish_Disconnect_Anytime)
 {
     try {
-        char dump_msg[204800] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
-        int dump_msg_size = getrandom(dump_msg, sizeof(dump_msg), 0);
-        if (-1 == dump_msg_size) {
-            ERR("getrandom() Fail(%d)", errno);
-            dump_msg_size = 62;
+        const char character_set[] =
+              "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+        std::mt19937 random_gen{std::random_device{}()};
+        std::uniform_int_distribution<std::string::size_type> gen(0, 61);
+
+        char dump_msg[204800] = {};
+        for (size_t i = 0; i < sizeof(dump_msg); i++) {
+            dump_msg[i] = character_set[gen(random_gen)];
         }
 
         AITT aitt(clientId, LOCAL_IP);
@@ -513,8 +515,8 @@ TEST_F(AITTTest, TCP_Publish_Disconnect_Anytime)
             sleep(SLEEP_MS);
 
             for (int i = 0; i < 10; i++) {
-                INFO("size = %d", dump_msg_size);
-                aitt1.Publish("test/stress1", dump_msg, dump_msg_size, AITT_TYPE_TCP,
+                INFO("size = %zu", sizeof(dump_msg));
+                aitt1.Publish("test/stress1", dump_msg, sizeof(dump_msg), AITT_TYPE_TCP,
                       AITT_QOS_AT_MOST_ONCE, true);
             }
             g_timeout_add(10, AittTests::ReadyCheck, static_cast<AittTests *>(this));
@@ -529,7 +531,7 @@ TEST_F(AITTTest, TCP_Publish_Disconnect_Anytime)
         ASSERT_TRUE(ready);
         ready = false;
 
-        aitt_retry.Publish("test/stress1", dump_msg, dump_msg_size, AITT_TYPE_TCP,
+        aitt_retry.Publish("test/stress1", dump_msg, sizeof(dump_msg), AITT_TYPE_TCP,
               AITT_QOS_AT_MOST_ONCE, true);
 
         g_timeout_add(10, AittTests::ReadyCheck, static_cast<AittTests *>(this));