add AittUtil for separating CompareTopic()
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 18 Aug 2022 05:51:47 +0000 (14:51 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 15 Sep 2022 05:25:35 +0000 (14:25 +0900)
common/AittUtil.cc [new file with mode: 0644]
common/AittUtil.h [new file with mode: 0644]
modules/tcp/Module.cc

diff --git a/common/AittUtil.cc b/common/AittUtil.cc
new file mode 100644 (file)
index 0000000..c26dd47
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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;
+}
diff --git a/common/AittUtil.h b/common/AittUtil.h
new file mode 100644 (file)
index 0000000..4859fd6
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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
index bc50d7d..b9b6774 100644 (file)
@@ -15,7 +15,7 @@
  */
 #include "Module.h"
 
-#include <MQ.h>
+#include <AittUtil.h>
 #include <flatbuffers/flexbuffers.h>
 #include <unistd.h>
 
@@ -77,7 +77,7 @@ void Module::Publish(const std::string &topic, const void *data, const size_t da
     for (PublishMap::iterator it = publishTable.begin(); it != publishTable.end(); ++it) {
         // NOTE:
         // Find entries that have matched with the given topic
-        if (!aitt::MQ::CompareTopic(it->first, topic))
+        if (!aitt::AittUtil::CompareTopic(it->first, topic))
             continue;
 
         // NOTE: