Check initialized before calling DBus method 29/242429/1
authorYu <jiung.yu@samsung.com>
Thu, 27 Aug 2020 01:38:28 +0000 (10:38 +0900)
committerYu <jiung.yu@samsung.com>
Thu, 27 Aug 2020 01:38:37 +0000 (10:38 +0900)
Change-Id: I5cbf2ecfa61c2eef40da9bb2b8a2d0bbb84127c2
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
include/uwb.h
src/uwb-private.h
src/uwb.c

index 6619057..c3724e7 100755 (executable)
@@ -37,7 +37,9 @@ typedef enum {
        UWB_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
        UWB_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
        UWB_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
-       UWB_ERROR_OPERATION_FAILED = TIZEN_ERROR_UWB | 0x01
+       UWB_ERROR_OPERATION_FAILED = TIZEN_ERROR_UWB | 0x01, /**< Operation failed */
+       UWB_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_UWB | 0x02, /**< already initialized */
+       UWB_ERROR_NOT_INITIALIZED = TIZEN_ERROR_UWB | 0x03, /**< Not initialized */
 } uwb_error_e;
 
 typedef void *uwb_network_h; /**< Device handle */
index b317bb9..117dff3 100755 (executable)
 
 #define UWB_FEATURE "http://tizen.org/feature/network.uwb"
 
+#define CHECK_ALREADY_INITIALIZED()                  \
+       if (uwb_ctx.manager_proxy != NULL) {                          \
+               _WARN("Alread initialized"); \
+               return UWB_ERROR_ALREADY_INITIALIZED; \
+       }
+
+#define CHECK_NOT_INITIALIZED()                  \
+       if (uwb_ctx.manager_proxy == NULL) {                          \
+               _WARN("Not initialized"); \
+               return UWB_ERROR_NOT_INITIALIZED; \
+       }
+
 #define CHECK_INPUT_PARAMETER(arg)                  \
        if (arg == NULL) {                          \
                _WARN("INVALID_PARAMETER"); \
index b5bac02..adf2530 100755 (executable)
--- a/src/uwb.c
+++ b/src/uwb.c
@@ -39,7 +39,7 @@ static struct _uwb_ctx {
        void *position_changed_user_data;
        uwb_network_get_finished_cb network_get_finished_cb;
        uwb_network_foreach_remote_node_cb foreach_remote_node_cb;
-} uwb_ctx;
+} uwb_ctx = {NULL,};
 
 static inline void __handle_error(GError *error, int *ret)
 {
@@ -140,6 +140,7 @@ static int manager_proxy_init()
 static void manager_proxy_deinit()
 {
        g_object_unref(uwb_ctx.manager_proxy);
+       uwb_ctx.manager_proxy = NULL;
 }
 
 EXPORT_API int uwb_initialize()
@@ -147,6 +148,7 @@ EXPORT_API int uwb_initialize()
        int ret = UWB_ERROR_NONE;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_ALREADY_INITIALIZED();
 
        _BEGIN();
 
@@ -162,6 +164,7 @@ EXPORT_API int uwb_deinitialize()
        int ret = UWB_ERROR_NONE;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -178,6 +181,7 @@ EXPORT_API int uwb_reset()
        GError *error = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -197,6 +201,7 @@ EXPORT_API int uwb_factory_reset()
        GError *error = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -282,6 +287,7 @@ EXPORT_API int uwb_get_own_node(uwb_node_h *own_node)
        uwb_node_s **_own_node = (uwb_node_s **)own_node;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -365,6 +371,7 @@ EXPORT_API int uwb_network_get(uwb_network_get_finished_cb finished_cb, void *us
        int ret = UWB_ERROR_NONE;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -624,6 +631,7 @@ EXPORT_API int uwb_node_set_position(uwb_node_h node, int x, int y, int z)
        GError *error = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -662,6 +670,7 @@ EXPORT_API int uwb_node_send_message(const unsigned char *message, int len)
        GError *error = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -688,6 +697,7 @@ EXPORT_API int uwb_node_send_message_to(uwb_node_h node, const unsigned char *me
        GError *error = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -732,6 +742,7 @@ EXPORT_API int uwb_node_get_configuration_int32(uwb_node_h node, char *key, int3
        GVariant *value_va = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -755,6 +766,7 @@ EXPORT_API int uwb_node_get_configuration_int64(uwb_node_h node, char *key, int6
        GVariant *value_va = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -778,6 +790,7 @@ EXPORT_API int uwb_node_get_configuration_string(uwb_node_h node, char *key, con
        GVariant *value_va = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -830,6 +843,7 @@ EXPORT_API int uwb_node_set_configuration_int32(uwb_node_h node, char *key, int3
        GVariant *configuration = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -850,6 +864,7 @@ EXPORT_API int uwb_node_set_configuration_int64(uwb_node_h node, char *key, int6
        GVariant *configuration = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
@@ -870,6 +885,7 @@ EXPORT_API int uwb_node_set_configuration_string(uwb_node_h node, char *key, con
        GVariant *configuration = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();