From d3b112bda4869d5c47fee787c94edaf2ebc42b85 Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Thu, 18 Aug 2022 09:21:04 +0900 Subject: [PATCH] revise name and location - from AITTEx to AittException like AittTypes - cleanup names - revise location for adding custom_broker option --- CMakeLists.txt | 5 +- common/AittDiscovery.cc | 4 +- {include => common}/AittDiscovery.h | 0 common/{AITTEx.cc => AittException.cc} | 117 ++++++++++++++++---------------- {include => common}/AittTransport.h | 9 ++- common/MQ.cc | 36 +++++----- {src => common}/ModuleLoader.cc | 15 ++-- {src => common}/ModuleLoader.h | 14 ++-- {src => common}/NullTransport.cc | 0 {src => common}/NullTransport.h | 0 common/aitt_platform.h | 8 ++- include/AITT.h | 6 +- include/{AITTEx.h => AittException.h} | 14 ++-- modules/tcp/CMakeLists.txt | 2 +- modules/tcp/Module.h | 1 + modules/{main.cc => transport_entry.cc} | 14 ++-- modules/webrtc/CMakeLists.txt | 2 +- modules/webrtc/tests/WEBRTC_test.cc | 6 +- src/AITT.cc | 4 -- src/AITTImpl.cc | 17 +++-- src/AITTImpl.h | 7 +- tests/CMakeLists.txt | 4 +- tests/ModuleLoader_test.cc | 14 ++-- 23 files changed, 148 insertions(+), 151 deletions(-) rename {include => common}/AittDiscovery.h (100%) rename common/{AITTEx.cc => AittException.cc} (76%) mode change 100755 => 100644 rename {include => common}/AittTransport.h (89%) rename {src => common}/ModuleLoader.cc (89%) rename {src => common}/ModuleLoader.h (81%) rename {src => common}/NullTransport.cc (100%) rename {src => common}/NullTransport.h (100%) rename include/{AITTEx.h => AittException.h} (82%) rename modules/{main.cc => transport_entry.cc} (72%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 976ac18..3fa2dc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,10 +51,7 @@ INCLUDE_DIRECTORIES(include common) AUX_SOURCE_DIRECTORY(src AITT_SRC) -ADD_LIBRARY(M_LOADER_OBJ OBJECT src/ModuleLoader.cc src/NullTransport.cc) -LIST(REMOVE_ITEM AITT_SRC src/ModuleLoader.cc src/NullTransport.cc) - -ADD_LIBRARY(${PROJECT_NAME} SHARED ${AITT_SRC} $) +ADD_LIBRARY(${PROJECT_NAME} SHARED ${AITT_SRC}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} Threads::Threads ${CMAKE_DL_LIBS} ${AITT_COMMON}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${AITT_NEEDS_LIBRARIES}) diff --git a/common/AittDiscovery.cc b/common/AittDiscovery.cc index 8f383c0..be3b65b 100644 --- a/common/AittDiscovery.cc +++ b/common/AittDiscovery.cc @@ -19,7 +19,7 @@ #include -#include "AITTEx.h" +#include "AittException.h" #include "aitt_internal.h" namespace aitt { @@ -74,7 +74,7 @@ void AittDiscovery::RemoveDiscoveryCB(int callback_id) auto it = callbacks.find(callback_id); if (it == callbacks.end()) { ERR("Unknown callback_id(%d)", callback_id); - throw AITTEx(AITTEx::INVALID_ARG); + throw AittException(AittException::INVALID_ARG); } callbacks.erase(it); } diff --git a/include/AittDiscovery.h b/common/AittDiscovery.h similarity index 100% rename from include/AittDiscovery.h rename to common/AittDiscovery.h diff --git a/common/AITTEx.cc b/common/AittException.cc old mode 100755 new mode 100644 similarity index 76% rename from common/AITTEx.cc rename to common/AittException.cc index b99d305..c1d061a --- a/common/AITTEx.cc +++ b/common/AittException.cc @@ -1,59 +1,58 @@ -/* - * Copyright (c) 2021-2022 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "AITTEx.h" - -using namespace aitt; - -AITTEx::AITTEx(ErrCode code) : err_code(code) -{ - err_msg = getErrString(); -} - -AITTEx::AITTEx(ErrCode code, const std::string& msg) : err_code(code) -{ - err_msg = getErrString() + " : " + msg; -} - -AITTEx::ErrCode AITTEx::getErrCode() -{ - return err_code; -} - -std::string AITTEx::getErrString() const -{ - switch (err_code) { - case INVALID_ARG: - return "Invalid Argument"; - case NO_MEMORY: - return "Memory allocation failure"; - case OPERATION_FAILED: - return "Operation failure"; - case SYSTEM_ERR: - return "System failure"; - case MQTT_ERR: - return "MQTT failure"; - case NO_DATA: - return "No data found"; - default: - return "Unknown Error"; - } -} - -const char* AITTEx::what() const throw() -{ - return err_msg.c_str(); -} - +/* + * Copyright (c) 2021-2022 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "AittException.h" + +using namespace aitt; + +AittException::AittException(ErrCode code) : err_code(code) +{ + err_msg = getErrString(); +} + +AittException::AittException(ErrCode code, const std::string& msg) : err_code(code) +{ + err_msg = getErrString() + " : " + msg; +} + +AittException::ErrCode AittException::getErrCode() +{ + return err_code; +} + +std::string AittException::getErrString() const +{ + switch (err_code) { + case INVALID_ARG: + return "Invalid Argument"; + case NO_MEMORY_ERR: + return "Memory allocation failure"; + case OPERATION_FAILED: + return "Operation failure"; + case SYSTEM_ERR: + return "System failure"; + case MQTT_ERR: + return "MQTT failure"; + case NO_DATA_ERR: + return "No data found"; + default: + return "Unknown Error"; + } +} + +const char* AittException::what() const throw() +{ + return err_msg.c_str(); +} diff --git a/include/AittTransport.h b/common/AittTransport.h similarity index 89% rename from include/AittTransport.h rename to common/AittTransport.h index 6523b2e..c7d1bcf 100644 --- a/include/AittTransport.h +++ b/common/AittTransport.h @@ -21,6 +21,10 @@ #include #include +#define AITT_TRANSPORT_NEW aitt_transport_new +#define TO_STR(s) #s +#define DEFINE_TO_STR(x) TO_STR(x) + namespace aitt { class AittTransport { @@ -29,7 +33,7 @@ class AittTransport { using SubscribeCallback = std::function; - static constexpr const char *const MODULE_ENTRY_NAME = "aitt_module_entry"; + static constexpr const char *const MODULE_ENTRY_NAME = DEFINE_TO_STR(AITT_TRANSPORT_NEW); explicit AittTransport(AittDiscovery &discovery) : discovery(discovery) {} virtual ~AittTransport(void) = default; @@ -53,3 +57,6 @@ class AittTransport { }; } // namespace aitt + +#undef TO_STR +#undef DEFINE_TO_STR diff --git a/common/MQ.cc b/common/MQ.cc index 834cd27..951b9f1 100644 --- a/common/MQ.cc +++ b/common/MQ.cc @@ -24,7 +24,7 @@ #include #include -#include "AITTEx.h" +#include "AittException.h" #include "AittTypes.h" #include "aitt_internal.h" @@ -74,7 +74,7 @@ MQ::MQ(const std::string &id, bool clear_session) mosquitto_destroy(handle); mosquitto_lib_cleanup(); - throw AITTEx(AITTEx::MQTT_ERR, std::string("MQ Constructor Error")); + throw AittException(AittException::MQTT_ERR, std::string("MQ Constructor Error")); } MQ::~MQ(void) @@ -140,14 +140,14 @@ void MQ::Connect(const std::string &host, int port, const std::string &username, if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_username_pw_set(%s, %s) Fail(%s)", username.c_str(), password.c_str(), mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } } ret = mosquitto_connect(handle, host.c_str(), port, keep_alive); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_connect(%s, %d) Fail(%s)", host.c_str(), port, mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } } @@ -156,7 +156,7 @@ void MQ::SetWillInfo(const std::string &topic, const void *msg, size_t szmsg, in int ret = mosquitto_will_set(handle, topic.c_str(), szmsg, msg, qos, retain); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_will_set(%s) Fail(%s)", topic.c_str(), mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } } @@ -165,7 +165,7 @@ void MQ::Disconnect(void) int ret = mosquitto_disconnect(handle); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_disconnect() Fail(%s)", mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } mosquitto_will_clear(handle); @@ -257,7 +257,7 @@ void MQ::Publish(const std::string &topic, const void *data, const size_t datale int ret = mosquitto_publish(handle, &mid, topic.c_str(), datalen, data, qos, retain); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_publish(%s) Fail(%s)", topic.c_str(), mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } } @@ -271,19 +271,19 @@ void MQ::PublishWithReply(const std::string &topic, const void *data, const size ret = mosquitto_property_add_string(&props, MQTT_PROP_RESPONSE_TOPIC, reply_topic.c_str()); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_property_add_string(response-topic) Fail(%s)", mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } ret = mosquitto_property_add_binary(&props, MQTT_PROP_CORRELATION_DATA, correlation.c_str(), correlation.size()); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_property_add_binary(correlation) Fail(%s)", mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } ret = mosquitto_publish_v5(handle, &mid, topic.c_str(), datalen, data, qos, retain, props); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_publish_v5(%s) Fail(%s)", topic.c_str(), mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } } @@ -299,21 +299,21 @@ void MQ::SendReply(MSG *msg, const void *data, const size_t datalen, int qos, bo msg->GetCorrelation().c_str(), msg->GetCorrelation().size()); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_property_add_binary(correlation) Fail(%s)", mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } ret = mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, REPLY_SEQUENCE_NUM_KEY.c_str(), std::to_string(msg->GetSequence()).c_str()); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_property_add_string_pair(squenceNum) Fail(%s)", mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } ret = mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, REPLY_IS_END_SEQUENCE_KEY.c_str(), std::to_string(msg->IsEndSequence()).c_str()); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_property_add_string_pair(IsEndSequence) Fail(%s)", mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } ret = mosquitto_publish_v5(handle, &mId, msg->GetResponseTopic().c_str(), datalen, data, qos, @@ -321,7 +321,7 @@ void MQ::SendReply(MSG *msg, const void *data, const size_t datalen, int qos, bo if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_publish_v5(%s) Fail(%s)", msg->GetResponseTopic().c_str(), mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } } @@ -331,7 +331,7 @@ void *MQ::Subscribe(const std::string &topic, const SubscribeCallback &cb, void int ret = mosquitto_subscribe(handle, &mid, topic.c_str(), qos); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_subscribe(%s) Fail(%s)", topic.c_str(), mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } std::lock_guard lock_from_here(callback_lock); @@ -352,7 +352,7 @@ void *MQ::Unsubscribe(void *sub_handle) if (it == subscribers.end()) { ERR("No Subscription(%p)", sub_handle); - throw AITTEx(AITTEx::NO_DATA); + throw AittException(AittException::NO_DATA_ERR); } SubscribeData *data = static_cast(sub_handle); @@ -372,7 +372,7 @@ void *MQ::Unsubscribe(void *sub_handle) int ret = mosquitto_unsubscribe(handle, &mid, topic.c_str()); if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_unsubscribe(%s) Fail(%d)", topic.c_str(), ret); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } return user_data; @@ -385,7 +385,7 @@ bool MQ::CompareTopic(const std::string &left, const std::string &right) if (ret != MOSQ_ERR_SUCCESS) { ERR("mosquitto_topic_matches_sub(%s, %s) Fail(%s)", left.c_str(), right.c_str(), mosquitto_strerror(ret)); - throw AITTEx(AITTEx::MQTT_ERR); + throw AittException(AittException::MQTT_ERR); } return result; } diff --git a/src/ModuleLoader.cc b/common/ModuleLoader.cc similarity index 89% rename from src/ModuleLoader.cc rename to common/ModuleLoader.cc index 2c538c1..c62229d 100644 --- a/src/ModuleLoader.cc +++ b/common/ModuleLoader.cc @@ -18,16 +18,13 @@ #include -#include "AITTEx.h" +#include "AittException.h" +#include "MQ.h" #include "NullTransport.h" #include "aitt_internal.h" namespace aitt { -ModuleLoader::ModuleLoader(const std::string &ip) : ip(ip) -{ -} - std::string ModuleLoader::GetModuleFilename(Type type) { if (type == TYPE_TCP) @@ -53,8 +50,14 @@ ModuleLoader::ModuleHandle ModuleLoader::OpenModule(Type type) return handle; } -std::shared_ptr ModuleLoader::LoadTransport(void *handle, AittDiscovery &discovery) +std::shared_ptr ModuleLoader::LoadTransport(void *handle, const std::string &ip, + AittDiscovery &discovery) { + if (handle == nullptr) { + ERR("handle is NULL"); + return std::shared_ptr(new NullTransport(ip.c_str(), discovery)); + } + AittTransport::ModuleEntry get_instance_fn = reinterpret_cast( dlsym(handle, AittTransport::MODULE_ENTRY_NAME)); if (get_instance_fn == nullptr) { diff --git a/src/ModuleLoader.h b/common/ModuleLoader.h similarity index 81% rename from src/ModuleLoader.h rename to common/ModuleLoader.h index 647a82d..b1ecfb3 100644 --- a/src/ModuleLoader.h +++ b/common/ModuleLoader.h @@ -15,35 +15,33 @@ */ #pragma once -#include -#include - #include #include #include #include -#include "ModuleLoader.h" +#include "AittTransport.h" +#include "MQ.h" namespace aitt { class ModuleLoader { public: enum Type { - TYPE_MQTT = 0, TYPE_TCP, TYPE_WEBRTC, TYPE_RTSP, - TYPE_MAX, + TYPE_TRANSPORT_MAX, }; using ModuleHandle = std::unique_ptr; - explicit ModuleLoader(const std::string &ip); + ModuleLoader() = default; virtual ~ModuleLoader() = default; ModuleHandle OpenModule(Type type); - std::shared_ptr LoadTransport(void *handle, AittDiscovery &discovery); + std::shared_ptr LoadTransport(void *handle, const std::string &ip, + AittDiscovery &discovery); private: std::string GetModuleFilename(Type type); diff --git a/src/NullTransport.cc b/common/NullTransport.cc similarity index 100% rename from src/NullTransport.cc rename to common/NullTransport.cc diff --git a/src/NullTransport.h b/common/NullTransport.h similarity index 100% rename from src/NullTransport.h rename to common/NullTransport.h diff --git a/common/aitt_platform.h b/common/aitt_platform.h index dd13d4d..3056693 100644 --- a/common/aitt_platform.h +++ b/common/aitt_platform.h @@ -27,10 +27,12 @@ #if defined(PLATFORM) && !defined(LOG_STDOUT) -#define STR(x) #x #define PURE(x) x -#define PLATFORM_HEADER(x) STR(x) -#include PLATFORM_HEADER(PLATFORM PURE(/) PURE(aitt_platform.h)) +#define TO_STR(x) #x +#define DEFINE_TO_STR(x) TO_STR(x) +#include DEFINE_TO_STR(PLATFORM PURE(/) PURE(aitt_platform.h)) +#undef TO_STR +#undef DEFINE_TO_STR #else // PLATFORM diff --git a/include/AITT.h b/include/AITT.h index 5817662..ac8cc0c 100644 --- a/include/AITT.h +++ b/include/AITT.h @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include #include @@ -62,10 +62,6 @@ class API AITT { void SendReply(MSG *msg, const void *data, const size_t datalen, bool end = true); - // NOTE: - // Provide utility functions to developers who only be able to access the AITT class - static bool CompareTopic(const std::string &left, const std::string &right); - private: class Impl; std::unique_ptr pImpl; diff --git a/include/AITTEx.h b/include/AittException.h similarity index 82% rename from include/AITTEx.h rename to include/AittException.h index 9657dc3..6d9d302 100644 --- a/include/AITTEx.h +++ b/include/AittException.h @@ -21,19 +21,19 @@ namespace aitt { -class AITTEx : public std::exception { +class AittException : public std::exception { public: - typedef enum { + enum ErrCode { INVALID_ARG, - NO_MEMORY, + NO_MEMORY_ERR, OPERATION_FAILED, SYSTEM_ERR, MQTT_ERR, - NO_DATA - } ErrCode; + NO_DATA_ERR, + }; - AITTEx(ErrCode err_code); - AITTEx(ErrCode err_code, const std::string& custom_err_msg); + AittException(ErrCode err_code); + AittException(ErrCode err_code, const std::string& custom_err_msg); ErrCode getErrCode(); virtual const char* what() const throw() override; diff --git a/modules/tcp/CMakeLists.txt b/modules/tcp/CMakeLists.txt index edac2fd..3872f68 100644 --- a/modules/tcp/CMakeLists.txt +++ b/modules/tcp/CMakeLists.txt @@ -3,7 +3,7 @@ SET(AITT_TCP aitt-transport-tcp) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_LIBRARY(TCP_OBJ OBJECT TCP.cc TCPServer.cc) -ADD_LIBRARY(${AITT_TCP} SHARED ../main.cc Module.cc $) +ADD_LIBRARY(${AITT_TCP} SHARED ../transport_entry.cc Module.cc $) TARGET_LINK_LIBRARIES(${AITT_TCP} ${AITT_TCP_NEEDS_LIBRARIES} Threads::Threads ${AITT_COMMON}) INSTALL(TARGETS ${AITT_TCP} DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/modules/tcp/Module.h b/modules/tcp/Module.h index 4011980..5cfc476 100644 --- a/modules/tcp/Module.h +++ b/modules/tcp/Module.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "TCPServer.h" diff --git a/modules/main.cc b/modules/transport_entry.cc similarity index 72% rename from modules/main.cc rename to modules/transport_entry.cc index 86e9c36..8892a56 100644 --- a/modules/main.cc +++ b/modules/transport_entry.cc @@ -15,26 +15,26 @@ */ #include +#include + #include "Module.h" #include "aitt_internal_definitions.h" extern "C" { -// Function name Should be same with aitt::AittTransport::MODULE_ENTRY_NAME -API void *aitt_module_entry(const char *ip, AittDiscovery &discovery) +API void *AITT_TRANSPORT_NEW(const char *ip, AittDiscovery &discovery) { - assert(!strcmp(__func__, aitt::AittTransport::MODULE_ENTRY_NAME) + assert(STR_EQ == strcmp(__func__, aitt::AittTransport::MODULE_ENTRY_NAME) && "Entry point name is not matched"); std::string ip_address(ip); Module *module = new Module(ip_address, discovery); - AittTransport *tModule = dynamic_cast(module); - // NOTE: // validate that the module creates valid object (which inherits AittTransport) - assert(tModule && "Transport Module is not created"); + AittTransport *transport_module = dynamic_cast(module); + assert(transport_module && "Transport Module is not created"); - return tModule; + return transport_module; } } // extern "C" diff --git a/modules/webrtc/CMakeLists.txt b/modules/webrtc/CMakeLists.txt index 9452b2b..1e9ed81 100644 --- a/modules/webrtc/CMakeLists.txt +++ b/modules/webrtc/CMakeLists.txt @@ -13,7 +13,7 @@ LINK_DIRECTORIES(${AITT_WEBRTC_NEEDS_LIBRARY_DIRS}) FILE(GLOB AITT_WEBRTC_SRC *.cc) list(REMOVE_ITEM AITT_WEBRTC_SRC ${CMAKE_CURRENT_SOURCE_DIR}/Module.cc) ADD_LIBRARY(WEBRTC_OBJ OBJECT ${AITT_WEBRTC_SRC}) -ADD_LIBRARY(${AITT_WEBRTC} SHARED $ ../main.cc Module.cc) +ADD_LIBRARY(${AITT_WEBRTC} SHARED $ ../transport_entry.cc Module.cc) TARGET_LINK_LIBRARIES(${AITT_WEBRTC} ${AITT_WEBRTC_NEEDS_LIBRARIES} ${AITT_COMMON}) TARGET_COMPILE_OPTIONS(${AITT_WEBRTC} PUBLIC ${AITT_WEBRTC_NEEDS_CFLAGS_OTHER}) diff --git a/modules/webrtc/tests/WEBRTC_test.cc b/modules/webrtc/tests/WEBRTC_test.cc index 5ee42c1..17726c5 100644 --- a/modules/webrtc/tests/WEBRTC_test.cc +++ b/modules/webrtc/tests/WEBRTC_test.cc @@ -21,7 +21,7 @@ #include #include -#include "AITTEx.h" +#include "AittException.h" #include "Config.h" #include "MqttServer.h" #include "aitt_internal.h" @@ -156,12 +156,12 @@ TEST_F(MqttServerTest, Negative_Disconnect_Anytime) server.Disconnect(); g_main_loop_run(loop_); - } catch (const aitt::AITTEx &e) { + } catch (const aitt::AittException &e) { // and this tests that it has the correct message throw; } }, - aitt::AITTEx); + aitt::AittException); } TEST_F(MqttServerTest, Positive_Disconnect_Anytime) diff --git a/src/AITT.cc b/src/AITT.cc index c50332d..0c9b08d 100644 --- a/src/AITT.cc +++ b/src/AITT.cc @@ -129,9 +129,5 @@ void AITT::SendReply(MSG *msg, const void *data, size_t datalen, bool end) return pImpl->SendReply(msg, data, datalen, end); } -bool AITT::CompareTopic(const std::string &left, const std::string &right) -{ - return MQ::CompareTopic(left, right); -} } // namespace aitt diff --git a/src/AITTImpl.cc b/src/AITTImpl.cc index f5ea893..1cca42e 100644 --- a/src/AITTImpl.cc +++ b/src/AITTImpl.cc @@ -30,20 +30,19 @@ namespace aitt { -AITT::Impl::Impl(AITT &parent, const std::string &id, const std::string &ipAddr, bool clearSession) - : public_api(parent), id_(id), mq(id, clearSession), discovery(id), reply_id(0) +AITT::Impl::Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session) + : public_api(parent), id_(id), mq(id, clear_session), discovery(id), reply_id(0), modules{0} { - // TODO: - // Validate ipAddr - ModuleLoader loader(ipAddr); - for (ModuleLoader::Type i = ModuleLoader::TYPE_MQTT; i < ModuleLoader::TYPE_MAX; + // TODO: Validate my_ip + ModuleLoader loader; + for (ModuleLoader::Type i = ModuleLoader::TYPE_TCP; i < ModuleLoader::TYPE_TRANSPORT_MAX; i = ModuleLoader::Type(i + 1)) { ModuleLoader::ModuleHandle handle = loader.OpenModule(i); if (handle == nullptr) ERR("OpenModule() Fail"); - modules[i] = - new ModuleObj(std::move(handle), loader.LoadTransport(handle.get(), discovery)); + modules[i] = new ModuleObj(std::move(handle), + loader.LoadTransport(handle.get(), my_ip, discovery)); } aittThread = std::thread(&AITT::Impl::ThreadMain, this); } @@ -61,7 +60,7 @@ AITT::Impl::~Impl(void) if (aittThread.joinable()) aittThread.join(); - for (ModuleLoader::Type i = ModuleLoader::TYPE_MQTT; i < ModuleLoader::TYPE_MAX; + for (ModuleLoader::Type i = ModuleLoader::TYPE_TCP; i < ModuleLoader::TYPE_TRANSPORT_MAX; i = ModuleLoader::Type(i + 1)) { delete modules[i]; } diff --git a/src/AITTImpl.h b/src/AITTImpl.h index b39fdb2..f31c662 100644 --- a/src/AITTImpl.h +++ b/src/AITTImpl.h @@ -34,7 +34,7 @@ namespace aitt { class AITT::Impl { public: - Impl(AITT &parent, const std::string &id, const std::string &ipAddr, bool clearSession); + Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session); virtual ~Impl(void); void SetWillInfo(const std::string &topic, const void *data, const size_t datalen, AittQoS qos, @@ -49,18 +49,15 @@ class AITT::Impl { void Publish(const std::string &topic, const void *data, const size_t datalen, AittProtocol protocols, AittQoS qos, bool retain); - int PublishWithReply(const std::string &topic, const void *data, const size_t datalen, AittProtocol protocol, AittQoS qos, bool retain, const AITT::SubscribeCallback &cb, void *cbdata, const std::string &correlation); - int PublishWithReplySync(const std::string &topic, const void *data, const size_t datalen, AittProtocol protocol, AittQoS qos, bool retain, const SubscribeCallback &cb, void *cbdata, const std::string &correlation, int timeout_ms); AittSubscribeID Subscribe(const std::string &topic, const AITT::SubscribeCallback &cb, void *cbdata, AittProtocol protocols, AittQoS qos); - void *Unsubscribe(AittSubscribeID handle); void SendReply(MSG *msg, const void *data, const int datalen, bool end); @@ -94,7 +91,7 @@ class AITT::Impl { MQ mq; AittDiscovery discovery; unsigned short reply_id; - ModuleObj *modules[ModuleLoader::TYPE_MAX]; + ModuleObj *modules[ModuleLoader::TYPE_TRANSPORT_MAX]; MainLoopHandler main_loop; void ThreadMain(void); std::thread aittThread; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 37d00cb..96dda23 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,7 +33,7 @@ INSTALL(TARGETS ${AITT_UT}_manual DESTINATION ${AITT_TEST_BINDIR}) AUX_SOURCE_DIRECTORY(../mock MOCK_SRC) ADD_EXECUTABLE(${AITT_UT}_mq MQ_mocktest.cc ${MOCK_SRC}) TARGET_LINK_LIBRARIES(${AITT_UT}_mq ${UT_NEEDS_LIBRARIES} Threads::Threads ${AITT_NEEDS_LIBRARIES} ${AITT_COMMON}) -TARGET_INCLUDE_DIRECTORIES(${AITT_UT}_mq PRIVATE ../src ../mock) +TARGET_INCLUDE_DIRECTORIES(${AITT_UT}_mq PRIVATE ../mock) INSTALL(TARGETS ${AITT_UT}_mq DESTINATION ${AITT_TEST_BINDIR}) ADD_TEST( @@ -46,7 +46,7 @@ ADD_TEST( ) ########################################################################### -ADD_EXECUTABLE(${AITT_UT}_module ModuleLoader_test.cc $) +ADD_EXECUTABLE(${AITT_UT}_module ModuleLoader_test.cc) TARGET_LINK_LIBRARIES(${AITT_UT}_module ${UT_NEEDS_LIBRARIES} ${AITT_NEEDS_LIBRARIES} ${CMAKE_DL_LIBS} ${AITT_COMMON}) TARGET_INCLUDE_DIRECTORIES(${AITT_UT}_module PRIVATE ../src) diff --git a/tests/ModuleLoader_test.cc b/tests/ModuleLoader_test.cc index 37f8aee..f693401 100644 --- a/tests/ModuleLoader_test.cc +++ b/tests/ModuleLoader_test.cc @@ -20,12 +20,13 @@ #include "AittTransport.h" #include "aitt_internal.h" +#include "aitt_tests.h" using ModuleLoader = aitt::ModuleLoader; class ModuleLoaderTest : public testing::Test { public: - ModuleLoaderTest(void) : discovery("test"), loader("127.0.0.1") {} + ModuleLoaderTest(void) : discovery("test") {} protected: void SetUp() override {} @@ -35,20 +36,21 @@ class ModuleLoaderTest : public testing::Test { aitt::ModuleLoader loader; }; -TEST_F(ModuleLoaderTest, Positive_LoadTransport_Anytime) +TEST_F(ModuleLoaderTest, LoadTransport_P_Anytime) { ModuleLoader::ModuleHandle handle = loader.OpenModule(ModuleLoader::TYPE_TCP); ASSERT_NE(handle, nullptr); - std::shared_ptr module = loader.LoadTransport(handle.get(), discovery); + std::shared_ptr module = + loader.LoadTransport(handle.get(), LOCAL_IP, discovery); ASSERT_NE(module, nullptr); } -TEST_F(ModuleLoaderTest, Negative_LoadTransport_Anytime) +TEST_F(ModuleLoaderTest, LoadTransport_N_Anytime) { - ModuleLoader::ModuleHandle handle = loader.OpenModule(ModuleLoader::TYPE_MQTT); + ModuleLoader::ModuleHandle handle = loader.OpenModule(ModuleLoader::TYPE_TRANSPORT_MAX); ASSERT_EQ(handle.get(), nullptr); - auto module = loader.LoadTransport(handle.get(), discovery); + auto module = loader.LoadTransport(handle.get(), LOCAL_IP, discovery); ASSERT_NE(module, nullptr); } -- 2.7.4