From: hyunuk.tak Date: Wed, 30 Mar 2022 06:00:31 +0000 (+0900) Subject: Add a conditional statement to check operational network set X-Git-Tag: accepted/tizen/unified/20220914.164046~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3bcf0f24ebbd0a022487a3eb009ba370dcd3370d;p=platform%2Fcore%2Fapi%2Fthread.git Add a conditional statement to check operational network set Change-Id: Ifffc42f29ce339dd9425b06e971cbd14e9d4752c Signed-off-by: hyunuk.tak --- diff --git a/include/thread-private.h b/include/thread-private.h index c6ae2e1..ccc9062 100755 --- a/include/thread-private.h +++ b/include/thread-private.h @@ -195,6 +195,7 @@ typedef struct { */ typedef struct { bool is_network_active; + bool is_operational_network_set; char name[THREAD_NETWORK_NAME_MAX + 1]; char key[THREAD_NETWORK_KEY_STRING_MAX + 1]; char pskc[THREAD_NETWORK_PSKC_STRING_MAX + 1]; diff --git a/src/thread-network.c b/src/thread-network.c index da5b674..888fda9 100644 --- a/src/thread-network.c +++ b/src/thread-network.c @@ -68,6 +68,7 @@ int thread_network_create(thread_network_h *network) } new_network->is_network_active = FALSE; + new_network->is_operational_network_set = FALSE; (void)g_strlcpy(new_network->name, THREAD_NETWORK_DEFAULT_NAME, THREAD_NETWORK_NAME_MAX + 1); (void)g_strlcpy(new_network->key, @@ -92,10 +93,15 @@ int thread_network_destroy(thread_network_h network) thread_network_s *current_network = network; + if (current_network->is_operational_network_set) { + THREAD_DBG("Thread operational network set, can't be destroyed:: \ + first unset the operational network"); + return THREAD_ERROR_OPERATION_FAILED; + } + if (current_network->is_network_active) { THREAD_DBG("Thread network active, can't be destroyed:: \ - First Reset the Network"); - FUNC_EXIT; + first reset the network"); return THREAD_ERROR_OPERATION_FAILED; } @@ -223,7 +229,9 @@ int thread_set_operational_network(thread_instance_h instance, thread_network_h THREAD_VALIDATE_INPUT_PARAMETER(network); thread_instance_s *current_instance = instance; + thread_network_s *current_network = network; current_instance->network = network; + current_network->is_operational_network_set = TRUE; FUNC_EXIT; return THREAD_ERROR_NONE; @@ -237,8 +245,21 @@ int thread_unset_operational_network(thread_instance_h instance) THREAD_VALIDATE_INPUT_PARAMETER(instance); thread_instance_s *current_instance = instance; + thread_network_s *current_network = current_instance->network; + + if (!current_network) + goto exit; + + if (current_network->is_network_active) { + THREAD_DBG("Thread network active, can't be destroyed:: \ + first reset the network"); + return THREAD_ERROR_OPERATION_FAILED; + } + + current_network->is_operational_network_set = FALSE; current_instance->network = NULL; +exit: FUNC_EXIT; return THREAD_ERROR_NONE; } diff --git a/tests/unittest/thread-unittest-network.cpp b/tests/unittest/thread-unittest-network.cpp index bf2550b..dbe3e14 100644 --- a/tests/unittest/thread-unittest-network.cpp +++ b/tests/unittest/thread-unittest-network.cpp @@ -79,8 +79,8 @@ protected: { if (network) { - thread_network_destroy(network); thread_unset_operational_network(instance); + thread_network_destroy(network); } thread_disable(instance); } @@ -479,5 +479,7 @@ TEST_F(ThreadNetworkTest, UnsetOperationalNetworkErrorNone) EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance)); EXPECT_EQ(THREAD_ERROR_NONE, thread_network_create(&network)); EXPECT_EQ(THREAD_ERROR_NONE, + thread_set_operational_network(instance, network)); + EXPECT_EQ(THREAD_ERROR_NONE, thread_unset_operational_network(instance)); } \ No newline at end of file