summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoungjae Shin <yj99.shin@samsung.com>2023-09-13 11:33:14 +0900
committerYoungjae Shin <yj99.shin@samsung.com>2023-09-13 11:45:58 +0900
commit49875fa0d5af84be577712fd9631a9af7ad52e9f (patch)
treef0b362d82316610ce69b8b3b92844bcfb003ff8c
parentbf03c07fdd3ae9981d663bb7ab99796d39f81df7 (diff)
downloadaitt-accepted/tizen_7.0_unified.tar.gz
aitt-accepted/tizen_7.0_unified.tar.bz2
aitt-accepted/tizen_7.0_unified.zip
AITT_OPT_SERVICE_ID, AITT_OPT_LOCATION_ID, AITT_OPT_ROOT_CA, AITT_OPT_CUSTOM_RW_FILE
-rw-r--r--common/AittOption.cc22
-rw-r--r--include/AittOption.h8
-rw-r--r--include/aitt_c.h8
-rw-r--r--src/aitt_c.cc23
-rw-r--r--tests/aitt_c_test.cc31
5 files changed, 80 insertions, 12 deletions
diff --git a/common/AittOption.cc b/common/AittOption.cc
index ea92351..f20bc98 100644
--- a/common/AittOption.cc
+++ b/common/AittOption.cc
@@ -46,10 +46,13 @@ bool AittOption::GetUseCustomMqttBroker() const
return use_custom_broker;
}
-void AittOption::SetServiceID(const std::string& id)
+int AittOption::SetServiceID(const std::string& id)
{
- RET_IF(false == use_custom_broker);
+ RETV_IF(false == use_custom_broker, AITT_ERROR_NOT_SUPPORTED);
+
service_id = id;
+
+ return AITT_ERROR_NONE;
}
const char* AittOption::GetServiceID() const
@@ -57,10 +60,11 @@ const char* AittOption::GetServiceID() const
return service_id.c_str();
}
-void AittOption::SetLocationID(const std::string& id)
+int AittOption::SetLocationID(const std::string& id)
{
- RET_IF(false == use_custom_broker);
+ RETV_IF(false == use_custom_broker, AITT_ERROR_NOT_SUPPORTED);
location_id = id;
+ return AITT_ERROR_NONE;
}
const char* AittOption::GetLocationID() const
@@ -68,10 +72,11 @@ const char* AittOption::GetLocationID() const
return location_id.c_str();
}
-void AittOption::SetRootCA(const std::string& ca)
+int AittOption::SetRootCA(const std::string& ca)
{
- RET_IF(false == use_custom_broker);
+ RETV_IF(false == use_custom_broker, AITT_ERROR_NOT_SUPPORTED);
root_ca = ca;
+ return AITT_ERROR_NONE;
}
const char* AittOption::GetRootCA() const
@@ -79,10 +84,11 @@ const char* AittOption::GetRootCA() const
return root_ca.c_str();
}
-void AittOption::SetCustomRWFile(const std::string& file)
+int AittOption::SetCustomRWFile(const std::string& file)
{
- RET_IF(false == use_custom_broker);
+ RETV_IF(false == use_custom_broker, AITT_ERROR_NOT_SUPPORTED);
custom_rw_file = file;
+ return AITT_ERROR_NONE;
}
const char* AittOption::GetCustomRWFile() const
diff --git a/include/AittOption.h b/include/AittOption.h
index 2916d00..95fb28a 100644
--- a/include/AittOption.h
+++ b/include/AittOption.h
@@ -29,13 +29,13 @@ class API AittOption {
bool GetCleanSession() const;
void SetUseCustomMqttBroker(bool val);
bool GetUseCustomMqttBroker() const;
- void SetServiceID(const std::string &id);
+ int SetServiceID(const std::string &id);
const char *GetServiceID() const;
- void SetLocationID(const std::string &id);
+ int SetLocationID(const std::string &id);
const char *GetLocationID() const;
- void SetRootCA(const std::string &ca);
+ int SetRootCA(const std::string &ca);
const char *GetRootCA() const;
- void SetCustomRWFile(const std::string &file);
+ int SetCustomRWFile(const std::string &file);
const char *GetCustomRWFile() const;
private:
diff --git a/include/aitt_c.h b/include/aitt_c.h
index 92e61c9..3425aef 100644
--- a/include/aitt_c.h
+++ b/include/aitt_c.h
@@ -146,6 +146,14 @@ typedef enum {
AITT_OPT_CLEAN_SESSION = 2, /**< A Boolean value whether broker clean all message and
subscriptions on disconnect */
AITT_OPT_CUSTOM_BROKER = 3, /**< A Boolean value whether AITT uses a custom broker. */
+ AITT_OPT_SERVICE_ID =
+ 4, /**< Service ID of Custom broker. Must set after @a AITT_OPT_CUSTOM_BROKER */
+ AITT_OPT_LOCATION_ID =
+ 5, /**< Location ID of Custom broker. Must set after @a AITT_OPT_CUSTOM_BROKER */
+ AITT_OPT_ROOT_CA = 6, /**< Root CA of Custom broker. Must set after @a AITT_OPT_CUSTOM_BROKER */
+ AITT_OPT_CUSTOM_RW_FILE =
+ 7, /**< Custom read/write file path. Must set after @a AITT_OPT_CUSTOM_BROKER */
+
} aitt_option_e;
/**
diff --git a/src/aitt_c.cc b/src/aitt_c.cc
index f8c2c75..6733db8 100644
--- a/src/aitt_c.cc
+++ b/src/aitt_c.cc
@@ -123,16 +123,31 @@ API int aitt_option_set(aitt_option_h handle, aitt_option_e option, const char *
case AITT_OPT_MY_IP:
handle->my_ip = value;
break;
+
case AITT_OPT_CLEAN_SESSION:
ret = _to_boolean(value, bool_val);
if (ret == AITT_ERROR_NONE)
handle->option.SetCleanSession(bool_val);
return ret;
+
case AITT_OPT_CUSTOM_BROKER:
ret = _to_boolean(value, bool_val);
if (ret == AITT_ERROR_NONE)
handle->option.SetUseCustomMqttBroker(bool_val);
return ret;
+
+ case AITT_OPT_SERVICE_ID:
+ return handle->option.SetServiceID(value);
+
+ case AITT_OPT_LOCATION_ID:
+ return handle->option.SetLocationID(value);
+
+ case AITT_OPT_ROOT_CA:
+ return handle->option.SetRootCA(value);
+
+ case AITT_OPT_CUSTOM_RW_FILE:
+ return handle->option.SetCustomRWFile(value);
+
default:
ERR("Unknown option(%d)", option);
return AITT_ERROR_INVALID_PARAMETER;
@@ -152,6 +167,14 @@ API const char *aitt_option_get(aitt_option_h handle, aitt_option_e option)
return (handle->option.GetCleanSession()) ? "true" : "false";
case AITT_OPT_CUSTOM_BROKER:
return (handle->option.GetUseCustomMqttBroker()) ? "true" : "false";
+ case AITT_OPT_SERVICE_ID:
+ return handle->option.GetServiceID();
+ case AITT_OPT_LOCATION_ID:
+ return handle->option.GetLocationID();
+ case AITT_OPT_ROOT_CA:
+ return handle->option.GetRootCA();
+ case AITT_OPT_CUSTOM_RW_FILE:
+ return handle->option.GetCustomRWFile();
default:
ERR("Unknown option(%d)", option);
}
diff --git a/tests/aitt_c_test.cc b/tests/aitt_c_test.cc
index 815de29..ba03e20 100644
--- a/tests/aitt_c_test.cc
+++ b/tests/aitt_c_test.cc
@@ -98,6 +98,22 @@ TEST(AITT_C_INTERFACE, option_P_Anytime)
EXPECT_EQ(ret, AITT_ERROR_NONE);
EXPECT_STREQ("true", aitt_option_get(option, AITT_OPT_CUSTOM_BROKER));
+ ret = aitt_option_set(option, AITT_OPT_SERVICE_ID, "service_id");
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+ EXPECT_STREQ("service_id", aitt_option_get(option, AITT_OPT_SERVICE_ID));
+
+ ret = aitt_option_set(option, AITT_OPT_LOCATION_ID, "location_id");
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+ EXPECT_STREQ("location_id", aitt_option_get(option, AITT_OPT_LOCATION_ID));
+
+ ret = aitt_option_set(option, AITT_OPT_ROOT_CA, "root_ca");
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+ EXPECT_STREQ("root_ca", aitt_option_get(option, AITT_OPT_ROOT_CA));
+
+ ret = aitt_option_set(option, AITT_OPT_CUSTOM_RW_FILE, "custom_rw_file");
+ EXPECT_EQ(ret, AITT_ERROR_NONE);
+ EXPECT_STREQ("custom_rw_file", aitt_option_get(option, AITT_OPT_CUSTOM_RW_FILE));
+
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));
@@ -140,6 +156,21 @@ TEST(AITT_C_INTERFACE, option_No_set_N_Anytime)
aitt_option_destroy(option);
}
+TEST(AITT_C_INTERFACE, option_set_Without_Custom_Anytime)
+{
+ aitt_option_h option = aitt_option_new();
+ ASSERT_NE(option, nullptr);
+
+ EXPECT_EQ(AITT_ERROR_NOT_SUPPORTED, aitt_option_set(option, AITT_OPT_SERVICE_ID, "service_id"));
+ EXPECT_EQ(AITT_ERROR_NOT_SUPPORTED,
+ aitt_option_set(option, AITT_OPT_LOCATION_ID, "location_id"));
+ EXPECT_EQ(AITT_ERROR_NOT_SUPPORTED, aitt_option_set(option, AITT_OPT_ROOT_CA, "root_ca"));
+ EXPECT_EQ(AITT_ERROR_NOT_SUPPORTED,
+ aitt_option_set(option, AITT_OPT_CUSTOM_RW_FILE, "custom_rw_file"));
+
+ aitt_option_destroy(option);
+}
+
TEST(AITT_C_INTERFACE, connect_disconnect_P_Anytime)
{
int ret;