- For applying global option in AITT instance.
};
AittNativeInterface::AittNativeInterface(std::string &mqId, std::string &ip, bool clearSession)
- : cbObject(nullptr), aitt(mqId, ip, clearSession)
+ : cbObject(nullptr), aitt(mqId, ip, AittOption(clearSession, false))
{
}
namespace aitt {
-AittDiscovery::AittDiscovery(const std::string &id)
+AittDiscovery::AittDiscovery(const std::string &id, bool custom_broker)
: id_(id), discovery_mq(id + "d", true), callback_handle(nullptr)
{
}
using DiscoveryCallback = std::function<void(const std::string &clientId,
const std::string &status, const void *msg, const int szmsg)>;
- explicit AittDiscovery(const std::string &id);
+ explicit AittDiscovery(const std::string &id, bool custom_broker);
void Start(const std::string &host, int port, const std::string &username,
const std::string &password);
void Stop();
#pragma once
#include <AittException.h>
+#include <AittOption.h>
#include <AittTypes.h>
#include <MSG.h>
std::function<void(MSG *msg, const void *data, const size_t datalen, void *user_data)>;
using ConnectionCallback = std::function<void(AITT &, int, void *user_data)>;
- explicit AITT(const std::string &id, const std::string &ip_addr, bool clear_session = false);
+ explicit AITT(const std::string &id, const std::string &ip_addr,
+ AittOption option = AittOption(false, false));
virtual ~AITT(void);
void SetWillInfo(const std::string &topic, const void *data, const size_t datalen, AittQoS qos,
--- /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 <AittTypes.h>
+
+class API AittOption {
+ public:
+ AittOption();
+ explicit AittOption(bool clear_session, bool use_custom_broker);
+ ~AittOption() = default;
+
+ void SetClearSession(bool val);
+ bool GetClearSession();
+ void SetUseCustomMqttBroker(bool val);
+ bool GetUseCustomMqttBroker();
+
+ private:
+ bool clear_session_;
+ bool use_custom_broker_;
+};
/**
* @brief @a aitt_h is an opaque data structure to represent AITT service handle.
- * @since_tizen 7.0
*/
typedef struct aitt_handle *aitt_h;
/**
+ * @brief @a aitt_option_h is an opaque data structure to represent AITT option handle.
+ * The option handle is used at aitt_new()
+ * @see aitt_new()
+ */
+typedef struct aitt_option *aitt_option_h;
+
+/**
* @brief @a aitt_msg_h is an opaque data structure to represent AITT message handle.
- * @since_tizen 7.0
* @see aitt_sub_fn
* @see aitt_msg_get_topic()
*/
/**
* @brief @a aitt_sub_h is an opaque data structure to represent AITT subscribe ID.
- * @since_tizen 7.0
* @see aitt_subscribe(), aitt_unsubscribe()
*/
typedef AittSubscribeID aitt_sub_h;
/**
* @brief Enumeration for protocol.
- * @since_tizen 7.0
*/
typedef enum AittProtocol aitt_protocol_e;
/**
* @brief Enumeration for MQTT QoS.
* It only works with the AITT_TYPE_MQTT
- * @since_tizen 7.0
*/
typedef enum AittQoS aitt_qos_e;
/**
* @brief Enumeration for AITT error code.
- * @since_tizen 7.0
*/
typedef enum AittError aitt_error_e;
/**
* @brief Specify the type of function passed to aitt_subscribe().
* @details When the aitt get message, it is called, immediately.
- * @since_tizen 7.0
* @param[in] msg_handle aitt message handle. The handle has topic name and so on. @c aitt_msg_h
* @param[in] msg pointer to the data received
* @param[in] msg_len the size of the @c msg (bytes)
* @brief Create a new AITT service instance.
* @detail If id is NULL or empty string, id will be generated automatically.
* If my_ip is NULL or empty string, my_ip will be set as 127.0.0.1.
- * @since_tizen 7.0
* @privlevel public
* @param[in] id Unique identifier in local network
- * @param[in] my_ip Own device ip address for connecting by others
* @return @c handle of AITT service
* otherwise NULL value on failure
* @see aitt_destroy()
*/
-aitt_h aitt_new(const char *id, const char *my_ip);
+aitt_h aitt_new(const char *id, aitt_option_h option);
+
+/**
+ * @brief Release memory of the AITT service instance.
+ * @privlevel public
+ * @param[in] handle Handle of AITT service;
+ * @see aitt_new()
+ */
+void aitt_destroy(aitt_h handle);
+
+/**
+ * @brief Create a new AITT option instance.
+ * @detail Create AITT option which is used in aitt_new()
+ * @privlevel public
+ * @return @c handle of AITT option
+ * otherwise NULL value on failure
+ * @see aitt_option_destroy()
+ */
+aitt_option_h aitt_option_new();
+
+/**
+ * @brief Release memory of the AITT option instance.
+ * @privlevel public
+ * @param[in] handle Handle of AITT option;
+ * @see aitt_option_new()
+ */
+void aitt_option_destroy(aitt_option_h handle);
/**
* @brief Enumeration for option.
- * @since_tizen 7.0
+ * @remarks The boolean value is case-insensitive @c true or @c false
+ * and NULL is handled as @c false
*/
typedef enum {
- AITT_OPT_UNKNOWN, /**< Unknown */
+ AITT_OPT_UNKNOWN, /**< Unknown */
+ AITT_OPT_MY_IP, /**< Own device ip address for connecting by others */
+ AITT_OPT_CLEAN_SESSION, /**< A Boolean value whether broker clean all message and subscriptions
+ on disconnect */
+ AITT_OPT_CUSTOM_BROKER, /**< A Boolean value whether AITT uses a custom broker. */
} aitt_option_e;
/**
* @brief Set the contents of a @c handle related with @c option to @c value
* @detail The @c value can be NULL for removing the content
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] option value of @a aitt_option_e.
*
* @see aitt_get_option()
*/
-int aitt_set_option(aitt_h handle, aitt_option_e option, const char *value);
+int aitt_option_set(aitt_option_h handle, aitt_option_e option, const char *value);
/**
* @brief Returns the string value of a @c handle related with @c option
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] option value of @a aitt_option_e.
*
* @see aitt_set_option()
*/
-const char *aitt_get_option(aitt_h handle, aitt_option_e option);
+const char *aitt_option_get(aitt_option_h handle, aitt_option_e option);
/**
* @brief Configure will information for a aitt instance.
* @detail By default, clients do not have a will. This must be called before calling aitt_connect()
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] topic the topic on which to publish the will.
aitt_qos_e qos, bool retain);
/**
- * @brief Release memory of the AITT service instance.
- * @since_tizen 7.0
- * @privlevel public
- * @param[in] handle Handle of AITT service;
- * @see aitt_new()
- */
-void aitt_destroy(aitt_h handle);
-
-/**
* @brief Connect to mqtt broker.
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] broker_ip IP address of the broker to connect to
/**
* @brief Connect to mqtt broker as aitt_connect(), but takes username and password.
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] broker_ip IP address of the broker to connect to
/**
* @brief Disconnect from the broker.
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @return @c 0 on success
/**
* @brief Publish a message on a given topic using MQTT, QoS0(At most once).
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] topic null terminated string of the topic to publish to.
/**
* @brief Publish a message on a given topic as aitt_publish(), but takes protocols and qos.
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] topic null terminated string of the topic to publish to.
/**
* @brief Publish a message on a given topic as aitt_publish_full(),
* but takes reply topic and callback for the reply.
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] topic null terminated string of the topic to publish to.
/**
* @brief Send reply message to regarding topic.
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] msg_handle Handle of published message(to reply).
/**
* @brief Get topic name from @c handle
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle aitt message handle
* @return topic name on success otherwise NULL value on failure
/**
* @brief Subscribe to a topic on MQTT with QoS0(at most once).
* @details Sets a function to be called when the aitt get messages related with @c topic
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] topic null terminated string of the topic to subscribe to.
/**
* @brief Subscribe to a topic, but takes protocols and qos.
* @details Sets a function to be called when the aitt get messages related with @c topic
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] topic null terminated string of the topic to subscribe to.
/**
* @brief Unsubscribe from a topic.
* @details Removes the subscription of changes with given ID.
- * @since_tizen 7.0
* @privlevel public
* @param[in] handle Handle of AITT service
* @param[in] sub_handle Handle of subscribed topic
void UnsetRoomMessageArrivedCb(void) { room_message_arrived_cb_ = nullptr; }
private:
- static void MessageCallback(mosquitto *handle, void *mqtt_server, const mosquitto_message *msg,
- const mosquitto_property *props);
void OnConnect();
void OnDisconnect();
void ConnectCallBack(int status);
namespace aitt {
-AITT::AITT(const std::string &id, const std::string &ip_addr, bool clear_session)
+AITT::AITT(const std::string &id, const std::string &ip_addr, AittOption option)
{
std::string valid_id = id;
std::string valid_ip = ip_addr;
if (ip_addr.empty())
valid_ip = "127.0.0.1";
- pImpl = std::make_unique<AITT::Impl>(*this, valid_id, valid_ip, clear_session);
+ pImpl = std::make_unique<AITT::Impl>(*this, valid_id, valid_ip, option.GetClearSession());
}
AITT::~AITT(void)
return pImpl->SendReply(msg, data, datalen, end);
}
-
} // namespace aitt
namespace aitt {
-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}
+AITT::Impl::Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session,
+ bool custom_broker)
+ : public_api(parent),
+ id_(id),
+ mq(id, clear_session),
+ discovery(id, custom_broker),
+ reply_id(0),
+ modules{0}
{
// TODO: Validate my_ip
ModuleLoader loader;
class AITT::Impl {
public:
- Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session);
+ explicit Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session,
+ bool custom_broker = false);
virtual ~Impl(void);
void SetWillInfo(const std::string &topic, const void *data, const size_t datalen, AittQoS qos,
--- /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_;
+}
bool connected;
};
-API aitt_h aitt_new(const char *id, const char *my_ip)
+struct aitt_option {
+ const char *my_ip;
+ bool clear_session;
+ bool custom_broker;
+};
+
+API aitt_h aitt_new(const char *id, aitt_option_h option)
{
aitt_h handle = nullptr;
try {
std::string valid_id;
std::string valid_ip;
+ AittOption aitt_option;
if (id)
valid_id = id;
- if (my_ip)
- valid_ip = my_ip;
-
- DBG("id(%s), ip(%s)", valid_id.c_str(), valid_ip.c_str());
+ if (option) {
+ if (option->my_ip)
+ valid_ip = option->my_ip;
+ aitt_option.SetClearSession(option->clear_session);
+ aitt_option.SetUseCustomMqttBroker(option->custom_broker);
+ }
handle = new aitt_handle();
- handle->aitt = new AITT(valid_id, valid_ip, true);
+ handle->aitt = new AITT(valid_id, valid_ip, aitt_option);
handle->connected = false;
} catch (std::exception &e) {
ERR("new() Fail(%s)", e.what());
return handle;
}
-API int aitt_set_option(aitt_h handle, aitt_option_e option, const char *value)
+API void aitt_destroy(aitt_h handle)
+{
+ if (handle == nullptr) {
+ ERR("handle is NULL");
+ return;
+ }
+
+ try {
+ delete handle->aitt;
+ delete handle;
+ } catch (std::exception &e) {
+ ERR("delete() Fail(%s)", e.what());
+ }
+}
+
+API aitt_option_h aitt_option_new()
+{
+ aitt_option_h handle = nullptr;
+
+ try {
+ handle = new aitt_option();
+ handle->my_ip = nullptr;
+ handle->clear_session = false;
+ handle->custom_broker = false;
+ } catch (std::exception &e) {
+ ERR("new() Fail(%s)", e.what());
+ }
+
+ return handle;
+}
+
+void aitt_option_destroy(aitt_option_h handle)
+{
+ if (handle == nullptr) {
+ ERR("handle is NULL");
+ return;
+ }
+
+ try {
+ delete handle;
+ } catch (std::exception &e) {
+ ERR("delete() Fail(%s)", e.what());
+ }
+}
+
+static int _option_set_bool(const char *value, bool &dest)
+{
+ if (value) {
+ dest = (STR_EQ == strcasecmp(value, "true"));
+ if (false == dest && STR_EQ != strcasecmp(value, "false")) {
+ ERR("Unknown value(%s)", value);
+ return AITT_ERROR_INVALID_PARAMETER;
+ }
+ } else {
+ dest = false;
+ }
+ return AITT_ERROR_NONE;
+}
+
+API int aitt_option_set(aitt_option_h handle, aitt_option_e option, const char *value)
{
RETV_IF(handle == nullptr, AITT_ERROR_INVALID_PARAMETER);
switch (option) {
- case AITT_OPT_UNKNOWN:
+ case AITT_OPT_MY_IP:
try {
- // something to do
+ handle->my_ip = value;
} catch (std::exception &e) {
ERR("string() Fail(%s)", e.what());
return AITT_ERROR_SYSTEM;
}
break;
+ case AITT_OPT_CLEAN_SESSION:
+ return _option_set_bool(value, handle->clear_session);
+ case AITT_OPT_CUSTOM_BROKER:
+ return _option_set_bool(value, handle->custom_broker);
default:
ERR("Unknown option(%d)", option);
return AITT_ERROR_INVALID_PARAMETER;
return AITT_ERROR_NONE;
}
-API const char *aitt_get_option(aitt_h handle, aitt_option_e option)
+API const char *aitt_option_get(aitt_option_h handle, aitt_option_e option)
{
RETV_IF(handle == nullptr, nullptr);
switch (option) {
- case AITT_OPT_UNKNOWN:
- return "Unknown";
+ case AITT_OPT_MY_IP:
+ return handle->my_ip;
+ case AITT_OPT_CLEAN_SESSION:
+ return (handle->clear_session) ? "true" : "false";
+ case AITT_OPT_CUSTOM_BROKER:
+ return (handle->custom_broker) ? "true" : "false";
default:
ERR("Unknown option(%d)", option);
}
return AITT_ERROR_NONE;
}
-API void aitt_destroy(aitt_h handle)
-{
- if (handle == nullptr) {
- ERR("handle is NULL");
- return;
- }
-
- try {
- delete handle->aitt;
- delete handle;
- } catch (std::exception &e) {
- ERR("delete() Fail(%s)", e.what());
- }
-}
-
static bool is_valid_ip(const char *ip)
{
RETV_IF(ip == nullptr, false);
TEST_F(AITTManualTest, WillSet_P)
{
try {
- AITT aitt("", LOCAL_IP, true);
+ AITT aitt("", LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Subscribe(
"test/AITT_will",
int pid = fork();
if (pid == 0) {
- AITT aitt_will("test_will_AITT", LOCAL_IP, true);
+ AITT aitt_will("test_will_AITT", LOCAL_IP, AittOption(true, false));
aitt_will.SetWillInfo("test/AITT_will", TEST_MSG, sizeof(TEST_MSG),
AITT_QOS_AT_LEAST_ONCE, false);
aitt_will.Connect();
void pubsub_template(const char *test_msg, AittProtocol protocol)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Subscribe(
testTopic,
TEST_F(AITTTest, Positive_Create_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
} catch (std::exception &e) {
FAIL() << "Unexpected exception: " << e.what();
}
TEST_F(AITTTest, SetConnectionCallback_P_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.SetConnectionCallback(
[&](AITT &handle, int status, void *user_data) {
AITTTest *test = static_cast<AITTTest *>(user_data);
TEST_F(AITTTest, UnsetConnectionCallback_P_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.SetConnectionCallback(
[&](AITT &handle, int status, void *user_data) {
AITTTest *test = static_cast<AITTTest *>(user_data);
TEST_F(AITTTest, Positive_Connect_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
} catch (std::exception &e) {
FAIL() << "Unexpected exception: " << e.what();
TEST_F(AITTTest, Positive_Disconnect_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Disconnect();
} catch (std::exception &e) {
TEST_F(AITTTest, Positive_Connect_twice_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Disconnect();
aitt.Connect();
TEST_F(AITTTest, Positive_Publish_MQTT_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Publish(testTopic, TEST_MSG, sizeof(TEST_MSG));
} catch (std::exception &e) {
TEST_F(AITTTest, Positive_Publish_TCP_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Publish(testTopic, TEST_MSG, sizeof(TEST_MSG), AITT_TYPE_TCP);
} catch (std::exception &e) {
TEST_F(AITTTest, Positive_Publish_Multiple_Protocols_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Publish(testTopic, TEST_MSG, sizeof(TEST_MSG),
(AittProtocol)(AITT_TYPE_MQTT | AITT_TYPE_TCP));
TEST_F(AITTTest, Positive_Subscribe_WebRTC_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Subscribe(
testTopic,
TEST_F(AITTTest, Positive_Unsubscribe_MQTT_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
subscribeHandle = aitt.Subscribe(
testTopic,
TEST_F(AITTTest, Positive_Unsubscribe_TCP_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
subscribeHandle = aitt.Subscribe(
testTopic,
TEST_F(AITTTest, Positve_Unsubscribe_in_Subscribe_MQTT_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
subscribeHandle = aitt.Subscribe(
testTopic,
TEST_F(AITTTest, Positve_Subscribe_in_Subscribe_MQTT_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
subscribeHandle = aitt.Subscribe(
testTopic,
TEST_F(AITTTest, Positve_PublishSubscribe_Multiple_Protocols_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Subscribe(
testTopic,
{
EXPECT_THROW(
{
- AITT aitt_will("", LOCAL_IP, true);
+ AITT aitt_will("", LOCAL_IP, AittOption(true, false));
aitt_will.SetWillInfo("+", "will msg", 8, AITT_QOS_AT_MOST_ONCE, false);
aitt_will.Connect();
aitt_will.Disconnect();
class ModuleLoaderTest : public testing::Test {
public:
- ModuleLoaderTest(void) : discovery("test") {}
+ ModuleLoaderTest(void) : discovery("test", false) {}
protected:
void SetUp() override {}
bool reply_ok[2];
sub_ok = reply_ok[0] = reply_ok[1] = false;
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Subscribe(rr_topic.c_str(),
bool sub_ok, reply1_ok, reply2_ok;
sub_ok = reply1_ok = reply2_ok = false;
- AITT sub_aitt(clientId + "sub", LOCAL_IP, true);
+ AITT sub_aitt(clientId + "sub", LOCAL_IP, AittOption(true, false));
INFO("Constructor Success");
sub_aitt.Connect();
sub_ok = true;
});
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
using namespace std::placeholders;
sub_ok = reply_ok = false;
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Subscribe(rr_topic.c_str(),
sub_ok = reply_ok = false;
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Subscribe(rr_topic.c_str(),
sub_ok = reply1_ok = false;
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
aitt.Subscribe(rr_topic.c_str(),
TEST_F(AITTRRTest, RequestResponse_timeout_P_Anytime)
{
try {
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
int ret = aitt.PublishWithReplySync(
sub_ok = reply_ok = false;
try {
- AITT sub_aitt(clientId + "sub", LOCAL_IP, true);
+ AITT sub_aitt(clientId + "sub", LOCAL_IP, AittOption(true, false));
sub_aitt.Connect();
sub_aitt.Subscribe(rr_topic.c_str(),
[&](aitt::MSG *msg, const void *data, const size_t datalen, void *cbdata) {
sub_ok = true;
});
- AITT aitt(clientId, LOCAL_IP, true);
+ AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
aitt.Connect();
int ret = aitt.PublishWithReplySync(
TEST(AITT_C_MANUAL, will_set_P)
{
int ret;
- aitt_h handle = aitt_new("test14", LOCAL_IP);
+ aitt_h handle = aitt_new("test14", nullptr);
ASSERT_NE(handle, nullptr);
ret = aitt_connect(handle, LOCAL_IP, 1883);
int pid = fork();
if (pid == 0) {
- aitt_h handle_will = aitt_new("test_will", LOCAL_IP);
+ aitt_h handle_will = aitt_new("test_will", nullptr);
ASSERT_NE(handle_will, nullptr);
ret = aitt_will_set(handle_will, "test/topic_will", TEST_C_MSG, strlen(TEST_C_MSG),
// Set user/passwd in mosquitto.conf before testing
TEST(AITT_C_MANUAL, connect_id_passwd_P)
{
- aitt_h handle = aitt_new("test15", LOCAL_IP);
+ aitt_h handle = aitt_new("test15", nullptr);
ASSERT_NE(handle, nullptr);
int ret = aitt_connect_full(handle, LOCAL_IP, 1883, "testID", "testPasswd");
TEST(AITT_C_INTERFACE, new_P_Anytime)
{
- aitt_h handle = aitt_new("test1", LOCAL_IP);
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ aitt_h handle = aitt_new("test1", option);
+ aitt_option_destroy(option);
EXPECT_TRUE(handle != nullptr);
aitt_destroy(handle);
EXPECT_TRUE(handle != nullptr);
aitt_destroy(handle);
- handle = aitt_new("", "");
+ handle = aitt_new("", nullptr);
EXPECT_TRUE(handle != nullptr);
aitt_destroy(handle);
}
TEST(AITT_C_INTERFACE, destroy_P_Anytime)
{
- aitt_h handle = aitt_new("test2", LOCAL_IP);
+ aitt_h handle = aitt_new("test2", nullptr);
ASSERT_NE(handle, nullptr);
aitt_destroy(handle);
aitt_destroy(nullptr);
}
-// TODO:: Not yet Support
-/*
TEST(AITT_C_INTERFACE, option_P_Anytime)
{
- aitt_h handle = aitt_new("test3");
- ASSERT_NE(handle, nullptr);
+ int ret;
+
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
- int ret = aitt_set_option(handle, AITT_OPT_MY_IP, LOCAL_IP);
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
EXPECT_EQ(ret, AITT_ERROR_NONE);
- EXPECT_STREQ(LOCAL_IP, aitt_get_option(handle, AITT_OPT_MY_IP));
+ EXPECT_STREQ(LOCAL_IP, aitt_option_get(option, AITT_OPT_MY_IP));
- ret = aitt_set_option(handle, AITT_OPT_MY_IP, NULL);
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, nullptr);
EXPECT_EQ(ret, AITT_ERROR_NONE);
- EXPECT_EQ(NULL, aitt_get_option(handle, AITT_OPT_MY_IP));
+ EXPECT_STREQ(nullptr, aitt_option_get(option, AITT_OPT_MY_IP));
- aitt_destroy(handle);
+ ret = aitt_option_set(option, AITT_OPT_CLEAN_SESSION, "TRUE");
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+ EXPECT_STREQ("true", aitt_option_get(option, AITT_OPT_CLEAN_SESSION));
+
+ ret = aitt_option_set(option, AITT_OPT_CLEAN_SESSION, nullptr);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+ EXPECT_STREQ("false", aitt_option_get(option, AITT_OPT_CLEAN_SESSION));
+
+ ret = aitt_option_set(option, AITT_OPT_CUSTOM_BROKER, "TRUE");
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+ EXPECT_STREQ("true", aitt_option_get(option, AITT_OPT_CUSTOM_BROKER));
+
+ ret = aitt_option_set(option, AITT_OPT_CUSTOM_BROKER, nullptr);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+ EXPECT_STREQ("false", aitt_option_get(option, AITT_OPT_CUSTOM_BROKER));
+
+ aitt_option_destroy(option);
}
TEST(AITT_C_INTERFACE, option_N_Anytime)
{
- aitt_h handle = aitt_new("test4");
- ASSERT_NE(handle, nullptr);
+ int ret;
- int ret = aitt_set_option(handle, AITT_OPT_UNKNOWN, LOCAL_IP);
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ ret = aitt_option_set(option, AITT_OPT_UNKNOWN, LOCAL_IP);
EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
- ret = aitt_set_option(nullptr, AITT_OPT_MY_IP, LOCAL_IP);
+ ret = aitt_option_set(option, AITT_OPT_CLEAN_SESSION, "OFF");
EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
- aitt_destroy(handle);
+ ret = aitt_option_set(option, AITT_OPT_CUSTOM_BROKER, "Off");
+ EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
+
+ ret = aitt_option_set(nullptr, AITT_OPT_MY_IP, LOCAL_IP);
+ EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
+
+ aitt_option_destroy(option);
}
-*/
TEST(AITT_C_INTERFACE, connect_disconnect_P_Anytime)
{
- aitt_h handle = aitt_new("test5", LOCAL_IP);
+ int ret;
+
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+ aitt_h handle = aitt_new("test5", option);
+ aitt_option_destroy(option);
ASSERT_NE(handle, nullptr);
- int ret = aitt_connect(handle, LOCAL_IP, 1883);
+ ret = aitt_connect(handle, LOCAL_IP, 1883);
ASSERT_EQ(ret, AITT_ERROR_NONE);
ret = aitt_disconnect(handle);
TEST(AITT_C_INTERFACE, connect_N_Anytime)
{
- aitt_h handle = aitt_new("test6", LOCAL_IP);
+ int ret;
+
+ aitt_h handle = aitt_new("test6", nullptr);
ASSERT_NE(handle, nullptr);
aitt_h invalid_handle = nullptr;
- int ret = aitt_connect(invalid_handle, LOCAL_IP, 1883);
+ ret = aitt_connect(invalid_handle, LOCAL_IP, 1883);
EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
const char *invalid_ip = "1.2.3";
TEST(AITT_C_INTERFACE, disconnect_N_Anytime)
{
- int ret = aitt_disconnect(nullptr);
+ int ret;
+
+ ret = aitt_disconnect(nullptr);
EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
- aitt_h handle = aitt_new("test7", LOCAL_IP);
+ aitt_h handle = aitt_new("test7", nullptr);
ASSERT_NE(handle, nullptr);
ret = aitt_disconnect(handle);
TEST(AITT_C_INTERFACE, pub_sub_P_Anytime)
{
- aitt_h handle = aitt_new("test8", LOCAL_IP);
+ int ret;
+
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+ aitt_h handle = aitt_new("test8", option);
+ aitt_option_destroy(option);
ASSERT_NE(handle, nullptr);
- int ret = aitt_connect(handle, LOCAL_IP, 1883);
+ ret = aitt_connect(handle, LOCAL_IP, 1883);
ASSERT_EQ(ret, AITT_ERROR_NONE);
GMainLoop *loop = g_main_loop_new(nullptr, FALSE);
TEST(AITT_C_INTERFACE, pub_N_Anytime)
{
- aitt_h handle = aitt_new("test9", LOCAL_IP);
+ int ret;
+
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+ aitt_h handle = aitt_new("test9", option);
+ aitt_option_destroy(option);
ASSERT_NE(handle, nullptr);
- int ret = aitt_connect(handle, nullptr, 1883);
+ ret = aitt_connect(handle, nullptr, 1883);
EXPECT_NE(ret, AITT_ERROR_NONE);
ret = aitt_publish(handle, TEST_C_TOPIC, TEST_C_MSG, strlen(TEST_C_MSG));
TEST(AITT_C_INTERFACE, sub_N_Anytime)
{
- aitt_h handle = aitt_new("test10", LOCAL_IP);
+ int ret;
+
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+ aitt_h handle = aitt_new("test10", option);
+ aitt_option_destroy(option);
aitt_sub_h sub_handle = nullptr;
ASSERT_NE(handle, nullptr);
- int ret = aitt_connect(handle, nullptr, 1883);
+ ret = aitt_connect(handle, nullptr, 1883);
EXPECT_NE(ret, AITT_ERROR_NONE);
ret = aitt_subscribe(
TEST(AITT_C_INTERFACE, pub_with_reply_send_reply_P_Anytime)
{
- aitt_h handle = aitt_new("test11", LOCAL_IP);
+ int ret;
+
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+ aitt_h handle = aitt_new("test11", option);
+ aitt_option_destroy(option);
ASSERT_NE(handle, nullptr);
- int ret = aitt_connect(handle, LOCAL_IP, 1883);
+ ret = aitt_connect(handle, LOCAL_IP, 1883);
ASSERT_EQ(ret, AITT_ERROR_NONE);
GMainLoop *loop = g_main_loop_new(nullptr, FALSE);
TEST(AITT_C_INTERFACE, pub_with_reply_N_Anytime)
{
- aitt_h handle = aitt_new("test12", LOCAL_IP);
+ int ret;
+
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+ aitt_h handle = aitt_new("test12", option);
+ aitt_option_destroy(option);
ASSERT_NE(handle, nullptr);
- int ret = aitt_connect(handle, LOCAL_IP, 1883);
+ ret = aitt_connect(handle, LOCAL_IP, 1883);
ASSERT_EQ(ret, AITT_ERROR_NONE);
ret = aitt_publish_with_reply(
TEST(AITT_C_INTERFACE, sub_unsub_P_Anytime)
{
- aitt_h handle = aitt_new("test13", LOCAL_IP);
+ int ret;
+
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+ aitt_h handle = aitt_new("test13", option);
+ aitt_option_destroy(option);
ASSERT_NE(handle, nullptr);
- int ret = aitt_connect(handle, LOCAL_IP, 1883);
+ ret = aitt_connect(handle, LOCAL_IP, 1883);
ASSERT_EQ(ret, AITT_ERROR_NONE);
static unsigned int sub_call_count = 0;
TEST(AITT_C_INTERFACE, will_set_N_Anytime)
{
- int ret = aitt_will_set(nullptr, "test/will_topic", "test", 4, AITT_QOS_AT_MOST_ONCE, false);
+ int ret;
+
+ ret = aitt_will_set(nullptr, "test/will_topic", "test", 4, AITT_QOS_AT_MOST_ONCE, false);
EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
}