AUX_SOURCE_DIRECTORY(src AITT_SRC)
-SET(MODULE_MAN_SRC src/ModuleManager.cc src/NullTransport.cc)
-ADD_LIBRARY(MODULE_MANAGER OBJECT ${MODULE_MAN_SRC})
-list(REMOVE_ITEM AITT_SRC ${MODULE_MAN_SRC})
+SET(AITT_INTERNAL_SRC src/ModuleManager.cc src/NullTransport.cc src/MosquittoMQ.cc)
+ADD_LIBRARY(INTERNAL_OBJ OBJECT ${AITT_INTERNAL_SRC})
+list(REMOVE_ITEM AITT_SRC ${AITT_INTERNAL_SRC})
-ADD_LIBRARY(${PROJECT_NAME} SHARED ${AITT_SRC} $<TARGET_OBJECTS:MODULE_MANAGER>)
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${AITT_SRC} $<TARGET_OBJECTS:INTERNAL_OBJ>)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} Threads::Threads ${CMAKE_DL_LIBS} ${AITT_COMMON})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${AITT_NEEDS_LIBRARIES})
callbacks.erase(it);
}
+bool AittDiscovery::CompareTopic(const std::string &left, const std::string &right)
+{
+ return discovery_mq->CompareTopic(left, right);
+}
+
void AittDiscovery::DiscoveryMessageCallback(MSG *mq, const std::string &topic, const void *msg,
const int szmsg, void *user_data)
{
void UpdateDiscoveryMsg(AittProtocol protocol, const void *msg, size_t length);
int AddDiscoveryCB(AittProtocol protocol, const DiscoveryCallback &cb);
void RemoveDiscoveryCB(int callback_id);
+ bool CompareTopic(const std::string &left, const std::string &right);
private:
struct DiscoveryBlob {
+++ /dev/null
-/*
- * Copyright (c) 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 "AittUtil.h"
-
-#include <mosquitto.h>
-
-#include "AittException.h"
-#include "aitt_internal.h"
-
-bool aitt::AittUtil::CompareTopic(const std::string& left, const std::string& right)
-{
- bool result = false;
- int ret = mosquitto_topic_matches_sub(left.c_str(), right.c_str(), &result);
- if (ret != MOSQ_ERR_SUCCESS) {
- ERR("mosquitto_topic_matches_sub(%s, %s) Fail(%s)", left.c_str(), right.c_str(),
- mosquitto_strerror(ret));
- throw AittException(AittException::MQTT_ERR);
- }
- return result;
-}
+++ /dev/null
-/*
- * Copyright (c) 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.
- */
-#pragma once
-
-#include <string>
-
-namespace aitt {
-
-class AittUtil {
- public:
- AittUtil() = default;
- ~AittUtil() = default;
-
- static bool CompareTopic(const std::string &left, const std::string &right);
-};
-
-} // namespace aitt
virtual void *Subscribe(const std::string &topic, const SubscribeCallback &cb,
void *user_data = nullptr, int qos = 0) = 0;
virtual void *Unsubscribe(void *handle) = 0;
+ virtual bool CompareTopic(const std::string &left, const std::string &right) = 0;
};
} // namespace aitt
*/
#include "Module.h"
-#include <AittUtil.h>
#include <flatbuffers/flexbuffers.h>
#include <unistd.h>
std::lock_guard<std::mutex> auto_lock_publish(publishTableLock);
for (PublishMap::iterator it = publishTable.begin(); it != publishTable.end(); ++it) {
// NOTE: Find entries that have matched with the given topic
- if (!aitt::AittUtil::CompareTopic(it->first, topic))
+ if (!discovery.CompareTopic(it->first, topic))
continue;
for (HostMap::iterator hostIt = it->second.begin(); hostIt != it->second.end(); ++hostIt) {
SET(AITT_WEBRTC aitt-transport-webrtc)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
PKG_CHECK_MODULES(AITT_WEBRTC_NEEDS REQUIRED
capi-media-camera
INCLUDE_DIRECTORIES(${AITT_WEBRTC_NEEDS_INCLUDE_DIRS})
LINK_DIRECTORIES(${AITT_WEBRTC_NEEDS_LIBRARY_DIRS})
-FILE(GLOB AITT_WEBRTC_SRC *.cc)
+FILE(GLOB AITT_WEBRTC_SRC *.cc ${CMAKE_SOURCE_DIR}/src/MosquittoMQ.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 ../transport_entry.cc Module.cc $<TARGET_OBJECTS:WEBRTC_OBJ>)
#include "AittException.h"
#include "AittTypes.h"
-#include "AittUtil.h"
#include "aitt_internal.h"
namespace aitt {
RET_IF(obj == nullptr);
MosquittoMQ *mq = static_cast<MosquittoMQ *>(obj);
- std::lock_guard<std::recursive_mutex> auto_lock(mq->callback_lock);
- mq->subscribers_iterating = true;
- mq->subscriber_iterator = mq->subscribers.begin();
- while (mq->subscriber_iterator != mq->subscribers.end()) {
- auto subscribe_data = *(mq->subscriber_iterator);
+ mq->MessageCB(msg, props);
+}
+
+void MosquittoMQ::MessageCB(const mosquitto_message *msg, const mosquitto_property *props)
+{
+ std::lock_guard<std::recursive_mutex> auto_lock(callback_lock);
+ subscribers_iterating = true;
+ subscriber_iterator = subscribers.begin();
+ while (subscriber_iterator != subscribers.end()) {
+ auto subscribe_data = *(subscriber_iterator);
if (nullptr == subscribe_data) {
ERR("Invalid subscribe data");
- mq->subscriber_iterator++;
+ ++subscriber_iterator;
continue;
}
- bool result = AittUtil::CompareTopic(subscribe_data->topic.c_str(), msg->topic);
- if (result)
- mq->InvokeCallback(*mq->subscriber_iterator, msg, props);
+ if (CompareTopic(subscribe_data->topic.c_str(), msg->topic))
+ InvokeCallback(*subscriber_iterator, msg, props);
- if (!mq->subscriber_iterator_updated)
- mq->subscriber_iterator++;
+ if (!subscriber_iterator_updated)
+ ++subscriber_iterator;
else
- mq->subscriber_iterator_updated = false;
+ subscriber_iterator_updated = false;
}
- mq->subscribers_iterating = false;
- mq->subscribers.insert(mq->subscribers.end(), mq->new_subscribers.begin(),
- mq->new_subscribers.end());
- mq->new_subscribers.clear();
+ subscribers_iterating = false;
+ subscribers.insert(subscribers.end(), new_subscribers.begin(), new_subscribers.end());
+ new_subscribers.clear();
}
void MosquittoMQ::InvokeCallback(SubscribeData *subscriber, const mosquitto_message *msg,
return user_data;
}
+bool MosquittoMQ::CompareTopic(const std::string &left, const std::string &right)
+{
+ bool result = false;
+ int ret = mosquitto_topic_matches_sub(left.c_str(), right.c_str(), &result);
+ if (ret != MOSQ_ERR_SUCCESS) {
+ ERR("mosquitto_topic_matches_sub(%s, %s) Fail(%s)", left.c_str(), right.c_str(),
+ mosquitto_strerror(ret));
+ return false;
+ }
+ return result;
+}
+
MosquittoMQ::SubscribeData::SubscribeData(const std::string &in_topic,
const SubscribeCallback &in_cb, void *in_user_data)
: topic(in_topic), cb(in_cb), user_data(in_user_data)
void *Subscribe(const std::string &topic, const SubscribeCallback &cb,
void *user_data = nullptr, int qos = 0);
void *Unsubscribe(void *handle);
+ bool CompareTopic(const std::string &left, const std::string &right);
private:
struct SubscribeData {
const mosquitto_property *props);
static void MessageCallback(mosquitto *, void *, const mosquitto_message *,
const mosquitto_property *);
+ void MessageCB(const mosquitto_message *msg, const mosquitto_property *props);
void InvokeCallback(SubscribeData *subscriber, const mosquitto_message *msg,
const mosquitto_property *props);
ADD_DEFINITIONS(-DLOG_STDOUT)
PKG_CHECK_MODULES(UT_NEEDS REQUIRED gmock_main)
-INCLUDE_DIRECTORIES(${UT_NEEDS_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(${UT_NEEDS_INCLUDE_DIRS} ../src)
LINK_DIRECTORIES(${UT_NEEDS_LIBRARY_DIRS})
###########################################################################
-SET(AITT_UT_SRC AITT_test.cc RequestResponse_test.cc MainLoopHandler_test.cc aitt_c_test.cc AITT_TCP_test.cc MosquittoMQ_test.cc)
+SET(AITT_UT_SRC AITT_test.cc RequestResponse_test.cc MainLoopHandler_test.cc aitt_c_test.cc AITT_TCP_test.cc)
ADD_EXECUTABLE(${AITT_UT} ${AITT_UT_SRC})
TARGET_LINK_LIBRARIES(${AITT_UT} Threads::Threads ${UT_NEEDS_LIBRARIES} ${PROJECT_NAME})
###########################################################################
AUX_SOURCE_DIRECTORY(../mock MOCK_SRC)
-ADD_EXECUTABLE(${AITT_UT}_mq MosquittoMQ_mocktest.cc ${MOCK_SRC})
-TARGET_LINK_LIBRARIES(${AITT_UT}_mq ${UT_NEEDS_LIBRARIES} Threads::Threads ${AITT_COMMON})
+ADD_EXECUTABLE(${AITT_UT}_mq MosquittoMQ_mocktest.cc ${MOCK_SRC} $<TARGET_OBJECTS:INTERNAL_OBJ>)
+TARGET_LINK_LIBRARIES(${AITT_UT}_mq ${UT_NEEDS_LIBRARIES} Threads::Threads ${CMAKE_DL_LIBS} ${AITT_COMMON})
TARGET_INCLUDE_DIRECTORIES(${AITT_UT}_mq PRIVATE ../mock)
INSTALL(TARGETS ${AITT_UT}_mq DESTINATION ${AITT_TEST_BINDIR})
)
###########################################################################
-ADD_EXECUTABLE(${AITT_UT}_module ModuleLoader_test.cc $<TARGET_OBJECTS:MODULE_MANAGER>)
-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)
+ADD_EXECUTABLE(${AITT_UT}_local ModuleLoader_test.cc MosquittoMQ_test.cc $<TARGET_OBJECTS:INTERNAL_OBJ>)
+TARGET_LINK_LIBRARIES(${AITT_UT}_local ${UT_NEEDS_LIBRARIES} ${AITT_NEEDS_LIBRARIES} ${CMAKE_DL_LIBS} ${AITT_COMMON})
-INSTALL(TARGETS ${AITT_UT}_module DESTINATION ${AITT_TEST_BINDIR})
+INSTALL(TARGETS ${AITT_UT}_local DESTINATION ${AITT_TEST_BINDIR})
ADD_TEST(
NAME
- ${AITT_UT}_module
+ ${AITT_UT}_local
COMMAND
${CMAKE_COMMAND} -E env
- LD_LIBRARY_PATH=../modules/webrtc/:../modules/tcp/:../:../common/:$ENV{LD_LIBRARY_PATH}
- ${CMAKE_CURRENT_BINARY_DIR}/${AITT_UT}_module --gtest_filter=*_Anytime
+ LD_LIBRARY_PATH=../modules/tcp/:../modules/webrtc/:../:../common/:$ENV{LD_LIBRARY_PATH}
+ ${CMAKE_CURRENT_BINARY_DIR}/${AITT_UT}_local --gtest_filter=*_Anytime
)
###########################################################################
ADD_EXECUTABLE(${AITT_UT}_stream AITT_Stream_test.cc)