add aitt_option types accepted/tizen_7.0_unified accepted/tizen_8.0_unified tizen_7.0 tizen_8.0 accepted/tizen/7.0/unified/20230913.174316 accepted/tizen/8.0/unified/20231005.093403 accepted/tizen/unified/20230913.172615 tizen_8.0_m2_release
authorYoungjae Shin <yj99.shin@samsung.com>
Wed, 13 Sep 2023 02:33:14 +0000 (11:33 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 13 Sep 2023 02:45:58 +0000 (11:45 +0900)
AITT_OPT_SERVICE_ID, AITT_OPT_LOCATION_ID, AITT_OPT_ROOT_CA, AITT_OPT_CUSTOM_RW_FILE

common/AittOption.cc
include/AittOption.h
include/aitt_c.h
src/aitt_c.cc
tests/aitt_c_test.cc

index ea92351..f20bc98 100644 (file)
@@ -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
index 2916d00..95fb28a 100644 (file)
@@ -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:
index 92e61c9..3425aef 100644 (file)
@@ -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;
 
 /**
index f8c2c75..6733db8 100644 (file)
@@ -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);
     }
index 815de29..ba03e20 100644 (file)
@@ -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;