namespace aitt {
AittDiscovery::AittDiscovery(const std::string &id, bool custom_broker)
- : id_(id), discovery_mq(new MQProxy(id + "d", true, custom_broker)), callback_handle(nullptr)
+ : id_(id),
+ discovery_mq(new MQProxy(id + "d", AittOption(true, custom_broker))),
+ callback_handle(nullptr)
{
}
--- /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 "AittOption.h"
+
+#include "aitt_internal.h"
+
+AittOption::AittOption() : clear_session_(false), use_custom_broker(false)
+{
+}
+
+AittOption::AittOption(bool clear_session, bool use_custom_mqtt_broker)
+ : clear_session_(clear_session), use_custom_broker(use_custom_mqtt_broker)
+{
+}
+
+void AittOption::SetClearSession(bool val)
+{
+ clear_session_ = val;
+}
+
+bool AittOption::GetClearSession() const
+{
+ return clear_session_;
+}
+
+void AittOption::SetUseCustomMqttBroker(bool val)
+{
+ use_custom_broker = val;
+}
+
+bool AittOption::GetUseCustomMqttBroker() const
+{
+ return use_custom_broker;
+}
+
+void AittOption::SetServiceID(const std::string& id)
+{
+ RET_IF(false == use_custom_broker);
+ service_id = id;
+}
+
+const char* AittOption::GetServiceID() const
+{
+ return service_id.c_str();
+}
+
+void AittOption::SetLocationID(const std::string& id)
+{
+ RET_IF(false == use_custom_broker);
+ location_id = id;
+}
+
+const char* AittOption::GetLocationID() const
+{
+ return location_id.c_str();
+}
+
+void AittOption::SetRootCA(const std::string& ca)
+{
+ RET_IF(false == use_custom_broker);
+ root_ca = ca;
+}
+
+const char* AittOption::GetRootCA() const
+{
+ return root_ca.c_str();
+}
+
+void AittOption::SetCustomRWFile(const std::string& file)
+{
+ RET_IF(false == use_custom_broker);
+ custom_rw_file = file;
+}
+
+const char* AittOption::GetCustomRWFile() const
+{
+ return custom_rw_file.c_str();
+}
namespace aitt {
-MQProxy::MQProxy(const std::string &id, bool clear_session, bool is_custom_broker)
- : handle(nullptr, nullptr)
+MQProxy::MQProxy(const std::string &id, const AittOption &option) : handle(nullptr, nullptr)
{
- if (is_custom_broker) {
+ if (option.GetUseCustomMqttBroker()) {
ModuleLoader loader;
handle = loader.OpenModule(ModuleLoader::TYPE_CUSTOM_MQTT);
- mq = loader.LoadMqttClient(handle.get(), "test", true);
+ mq = loader.LoadMqttClient(handle.get(), "test", option);
} else {
- mq = std::unique_ptr<MQ>(new MosquittoMQ(id, clear_session));
+ mq = std::unique_ptr<MQ>(new MosquittoMQ(id, option.GetClearSession()));
}
}
class MQProxy : public MQ {
public:
- explicit MQProxy(const std::string &id, bool clear_session, bool custom_broker);
+ explicit MQProxy(const std::string &id, const AittOption &option);
virtual ~MQProxy() = default;
void SetConnectionCallback(const MQConnectionCallback &cb);
}
std::unique_ptr<MQ> ModuleLoader::LoadMqttClient(void *handle, const std::string &id,
- bool clear_session)
+ const AittOption &option)
{
MQ::ModuleEntry get_instance_fn =
reinterpret_cast<MQ::ModuleEntry>(dlsym(handle, MQ::MODULE_ENTRY_NAME));
throw AittException(AittException::SYSTEM_ERR);
}
- std::unique_ptr<MQ> instance(static_cast<MQ *>(get_instance_fn(id.c_str(), clear_session)));
+ std::unique_ptr<MQ> instance(static_cast<MQ *>(get_instance_fn(id.c_str(), option)));
if (instance == nullptr) {
ERR("get_instance_fn(MQ) Fail");
throw AittException(AittException::SYSTEM_ERR);
ModuleHandle OpenModule(Type type);
std::unique_ptr<AittTransport> LoadTransport(void *handle, const std::string &ip,
AittDiscovery &discovery);
- std::unique_ptr<MQ> LoadMqttClient(void *handle, const std::string &id, bool clear_session);
+ std::unique_ptr<MQ> LoadMqttClient(void *handle, const std::string &id,
+ const AittOption &option);
private:
std::string GetModuleFilename(Type type);
#include <AittTypes.h>
+#include <string>
+
class API AittOption {
public:
AittOption();
~AittOption() = default;
void SetClearSession(bool val);
- bool GetClearSession();
+ bool GetClearSession() const;
void SetUseCustomMqttBroker(bool val);
- bool GetUseCustomMqttBroker();
+ bool GetUseCustomMqttBroker() const;
+ void SetServiceID(const std::string &id);
+ const char *GetServiceID() const;
+ void SetLocationID(const std::string &id);
+ const char *GetLocationID() const;
+ void SetRootCA(const std::string &ca);
+ const char *GetRootCA() const;
+ void SetCustomRWFile(const std::string &file);
+ const char *GetCustomRWFile() const;
private:
bool clear_session_;
- bool use_custom_broker_;
+ bool use_custom_broker;
+ std::string service_id;
+ std::string location_id;
+ std::string root_ca;
+ std::string custom_rw_file;
};
*/
#pragma once
+#include <AittOption.h>
#include <MSG.h>
#include <functional>
class MQ {
public:
- typedef void *(*ModuleEntry)(const char *id, bool clear_session);
+ typedef void *(*ModuleEntry)(const char *id, const AittOption &option);
using SubscribeCallback = std::function<void(MSG *msg, const std::string &topic,
const void *data, const size_t datalen, void *user_data)>;
#define MQTT_HANDLER_MGMT_QOS 2
MqttServer::MqttServer(const Config &config)
- : mq(new aitt::MQProxy(config.GetLocalId(), true, false))
+ : mq(new aitt::MQProxy(config.GetLocalId(), AittOption(true, false)))
{
broker_ip_ = config.GetBrokerIp();
broker_port_ = config.GetBrokerPort();
bool custom_broker)
: public_api(parent),
id_(id),
- mq(new MQProxy(id, clear_session, custom_broker)),
+ mq(new MQProxy(id, AittOption(clear_session, custom_broker))),
discovery(id, custom_broker),
reply_id(0),
transports{0}
+++ /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 "AittOption.h"
-
-AittOption::AittOption() : clear_session_(false), use_custom_broker_(false)
-{
-}
-
-AittOption::AittOption(bool clear_session, bool use_custom_mqtt_broker)
- : clear_session_(clear_session), use_custom_broker_(use_custom_mqtt_broker)
-{
-}
-
-void AittOption::SetClearSession(bool val)
-{
- clear_session_ = val;
-}
-
-bool AittOption::GetClearSession()
-{
- return clear_session_;
-}
-
-void AittOption::SetUseCustomMqttBroker(bool val)
-{
- use_custom_broker_ = val;
-}
-
-bool AittOption::GetUseCustomMqttBroker()
-{
- return use_custom_broker_;
-}
ModuleLoader::ModuleHandle handle = loader.OpenModule(ModuleLoader::TYPE_CUSTOM_MQTT);
if (handle) {
EXPECT_NO_THROW({
- auto module = loader.LoadMqttClient(handle.get(), "test", false);
+ auto module = loader.LoadMqttClient(handle.get(), "test", AittOption(false, true));
ASSERT_NE(module, nullptr);
});
}
{
EXPECT_THROW(
{
- loader.LoadMqttClient(nullptr, "test", false);
+ loader.LoadMqttClient(nullptr, "test", AittOption(false, true));
FAIL() << "Should not be called";
},
aitt::AittException);