From e8bf175eea4d1a843b658b8aba8bb91f0f06249a Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Fri, 27 Sep 2024 20:42:12 +0200 Subject: [PATCH] Add OC_API annotations to oc_network_monitor.h --- api/cloud/oc_cloud.c | 5 +- api/oc_session_events.c | 1 - .../device-provisioning-client/plgd_dps.c | 7 +++ .../plgd_dps_manager.c | 1 - api/plgd/unittest/plgdtimetest.cpp | 1 - include/oc_network_monitor.h | 58 +------------------ include/oc_session_events.h | 55 ++++++++++++++++++ port/android/ipadapter.c | 5 +- port/esp32/adapter/src/ipadapter.c | 3 + port/linux/ipadapter.c | 5 +- port/unittest/connectivitytest.cpp | 2 +- port/windows/ipadapter.c | 4 +- swig/swig_interfaces/oc_session_events.i | 1 + 13 files changed, 84 insertions(+), 64 deletions(-) diff --git a/api/cloud/oc_cloud.c b/api/cloud/oc_cloud.c index f951cf7fb2..008bb1a91c 100644 --- a/api/cloud/oc_cloud.c +++ b/api/cloud/oc_cloud.c @@ -35,12 +35,15 @@ #include "oc_api.h" #include "oc_collection.h" #include "oc_core_res.h" -#include "oc_network_monitor.h" #include "port/oc_assert.h" #include "util/oc_endpoint_address_internal.h" #include "util/oc_mmem_internal.h" #include "util/oc_secure_string_internal.h" +#ifdef OC_NETWORK_MONITOR +#include "oc_network_monitor.h" +#endif /* OC_NETWORK_MONITOR */ + #ifdef OC_SECURITY #include "security/oc_tls_internal.h" #endif /* OC_SECURITY */ diff --git a/api/oc_session_events.c b/api/oc_session_events.c index 53caffd914..8623604b00 100644 --- a/api/oc_session_events.c +++ b/api/oc_session_events.c @@ -22,7 +22,6 @@ #include "api/oc_session_events_internal.h" #include "oc_api.h" #include "oc_buffer.h" -#include "oc_network_monitor.h" #include "oc_session_events.h" #include "oc_signal_event_loop.h" #include "port/oc_connectivity_internal.h" diff --git a/api/plgd/device-provisioning-client/plgd_dps.c b/api/plgd/device-provisioning-client/plgd_dps.c index 6d2db25a2b..3345817ada 100644 --- a/api/plgd/device-provisioning-client/plgd_dps.c +++ b/api/plgd/device-provisioning-client/plgd_dps.c @@ -30,7 +30,10 @@ #include "api/oc_tcp_internal.h" #include "oc_certs.h" #include "oc_core_res.h" + +#ifdef OC_NETWORK_MONITOR #include "oc_network_monitor.h" +#endif /* OC_NETWORK_MONITOR */ #include #include @@ -226,13 +229,17 @@ plgd_dps_session_callbacks_deinit(plgd_dps_context_t *ctx) void plgd_dps_interface_callbacks_init(void) { +#ifdef OC_NETWORK_MONITOR oc_add_network_interface_event_callback(dps_interface_event_handler); +#endif /* OC_NETWORK_MONITOR */ } void plgd_dps_interface_callbacks_deinit(void) { +#ifdef OC_NETWORK_MONITOR oc_remove_network_interface_event_callback(dps_interface_event_handler); +#endif /* OC_NETWORK_MONITOR */ } #endif /* OC_SESSION_EVENTS */ diff --git a/api/plgd/device-provisioning-client/plgd_dps_manager.c b/api/plgd/device-provisioning-client/plgd_dps_manager.c index 06c9afebfa..8b51e8346a 100644 --- a/api/plgd/device-provisioning-client/plgd_dps_manager.c +++ b/api/plgd/device-provisioning-client/plgd_dps_manager.c @@ -30,7 +30,6 @@ #include "plgd_dps_internal.h" #include "oc_cred.h" -#include "oc_network_monitor.h" #include "security/oc_cred_util_internal.h" #include "util/oc_list.h" diff --git a/api/plgd/unittest/plgdtimetest.cpp b/api/plgd/unittest/plgdtimetest.cpp index d800004374..d625e3c864 100644 --- a/api/plgd/unittest/plgdtimetest.cpp +++ b/api/plgd/unittest/plgdtimetest.cpp @@ -35,7 +35,6 @@ #include "messaging/coap/transactions_internal.h" #include "oc_acl.h" #include "oc_core_res.h" -#include "oc_network_monitor.h" #include "oc_ri.h" #include "port/oc_log_internal.h" #include "port/oc_network_event_handler_internal.h" diff --git a/include/oc_network_monitor.h b/include/oc_network_monitor.h index 2a291dd360..df986e21ed 100644 --- a/include/oc_network_monitor.h +++ b/include/oc_network_monitor.h @@ -23,8 +23,6 @@ #include "oc_export.h" #include "oc_network_events.h" -#include "oc_session_events.h" -#include "util/oc_compiler.h" #ifdef __cplusplus extern "C" { @@ -37,6 +35,7 @@ extern "C" { * @return 0 on success * @return -1 on error */ +OC_API int oc_add_network_interface_event_callback(interface_event_handler_t cb); /** @@ -46,61 +45,8 @@ int oc_add_network_interface_event_callback(interface_event_handler_t cb); * @return 0 on success * @return -1 on error */ -int oc_remove_network_interface_event_callback(interface_event_handler_t cb); - -/** - * @brief Add the callback to receive session event notifications. - * - * @param cb The callback to be added. Must not be NULL. - * @return 0 on success - * @return -1 on error - * - * @deprecated replaced by oc_add_session_event_callback_v1 in v2.2.5.4 - */ -OC_API -int oc_add_session_event_callback(session_event_handler_t cb) - OC_DEPRECATED("replaced by oc_add_session_event_callback_v1 in v2.2.5.4"); - -/** - * @brief Add the callback to receive session event notifications. - * - * @param cb The callback to be added (cannot be NULL). - * @param user_data user data passed to the callback when invoked - * @return 0 on success - * @return -1 on error - */ -OC_API -int oc_add_session_event_callback_v1(session_event_handler_v1_t cb, - void *user_data); - -/** - * @brief Remove the callback to receive session event notifications. - * @param cb The callback to be removed. Must not be NULL. - * @return 0 on success - * @return -1 on error - * - * @deprecated replaced by oc_remove_session_event_callback_v1 in v2.2.5.4 - */ OC_API -int oc_remove_session_event_callback(session_event_handler_t cb) - OC_DEPRECATED("replaced by oc_remove_session_event_callback_v1 in v2.2.5.4"); - -/** - * @brief Remove the callback with to receive session event notifications. - * - * @param cb The callback to be removed. - * @param user_data user data provided to the callback by - oc_add_session_event_callback_v1 - * @param ignore_user_data ignore user_data and match only the function pointer - * @return 0 on success - * @return OC_ERR_SESSION_EVENT_HANDLER_NOT_FOUND when no match was found - * @return -1 other errors - * - * @see oc_add_session_event_callback_v1 - */ -OC_API -int oc_remove_session_event_callback_v1(session_event_handler_v1_t cb, - void *user_data, bool ignore_user_data); +int oc_remove_network_interface_event_callback(interface_event_handler_t cb); #ifdef __cplusplus } diff --git a/include/oc_session_events.h b/include/oc_session_events.h index e142b45705..8f4daded33 100644 --- a/include/oc_session_events.h +++ b/include/oc_session_events.h @@ -27,6 +27,7 @@ #include "oc_export.h" #include "oc_endpoint.h" +#include "util/oc_compiler.h" #ifdef __cplusplus extern "C" { @@ -76,6 +77,60 @@ typedef void (*session_event_handler_v1_t)(const oc_endpoint_t *endpoint, OC_API void oc_session_events_set_event_delay(int secs); +/** + * @brief Add the callback to receive session event notifications. + * + * @param cb The callback to be added. Must not be NULL. + * @return 0 on success + * @return -1 on error + * + * @deprecated replaced by oc_add_session_event_callback_v1 in v2.2.5.4 + */ +OC_API +int oc_add_session_event_callback(session_event_handler_t cb) + OC_DEPRECATED("replaced by oc_add_session_event_callback_v1 in v2.2.5.4"); + +/** + * @brief Add the callback to receive session event notifications. + * + * @param cb The callback to be added (cannot be NULL). + * @param user_data user data passed to the callback when invoked + * @return 0 on success + * @return -1 on error + */ +OC_API +int oc_add_session_event_callback_v1(session_event_handler_v1_t cb, + void *user_data); + +/** + * @brief Remove the callback to receive session event notifications. + * @param cb The callback to be removed. Must not be NULL. + * @return 0 on success + * @return -1 on error + * + * @deprecated replaced by oc_remove_session_event_callback_v1 in v2.2.5.4 + */ +OC_API +int oc_remove_session_event_callback(session_event_handler_t cb) + OC_DEPRECATED("replaced by oc_remove_session_event_callback_v1 in v2.2.5.4"); + +/** + * @brief Remove the callback with to receive session event notifications. + * + * @param cb The callback to be removed. + * @param user_data user data provided to the callback by + oc_add_session_event_callback_v1 + * @param ignore_user_data ignore user_data and match only the function pointer + * @return 0 on success + * @return OC_ERR_SESSION_EVENT_HANDLER_NOT_FOUND when no match was found + * @return -1 other errors + * + * @see oc_add_session_event_callback_v1 + */ +OC_API +int oc_remove_session_event_callback_v1(session_event_handler_v1_t cb, + void *user_data, bool ignore_user_data); + #ifdef __cplusplus } #endif diff --git a/port/android/ipadapter.c b/port/android/ipadapter.c index 6c68151c64..930820ea3e 100644 --- a/port/android/ipadapter.c +++ b/port/android/ipadapter.c @@ -31,7 +31,6 @@ #include "oc_buffer.h" #include "oc_core_res.h" #include "oc_endpoint.h" -#include "oc_network_monitor.h" #include "port/common/posix/oc_socket_internal.h" #include "port/oc_assert.h" #include "port/oc_connectivity.h" @@ -41,6 +40,10 @@ #include "port/oc_random.h" #include "util/oc_macros_internal.h" +#ifdef OC_NETWORK_MONITOR +#include "oc_network_monitor.h" +#endif /* OC_NETWORK_MONITOR */ + #ifdef OC_SESSION_EVENTS #include "api/oc_session_events_internal.h" #endif /* OC_SESSION_EVENTS */ diff --git a/port/esp32/adapter/src/ipadapter.c b/port/esp32/adapter/src/ipadapter.c index 7f1e72ffb3..76ba3699f4 100644 --- a/port/esp32/adapter/src/ipadapter.c +++ b/port/esp32/adapter/src/ipadapter.c @@ -32,7 +32,10 @@ #include "oc_buffer.h" #include "oc_core_res.h" #include "oc_endpoint.h" + +#ifdef OC_NETWORK_MONITOR #include "oc_network_monitor.h" +#endif /* OC_NETWORK_MONITOR */ #ifdef OC_SESSION_EVENTS #include "api/oc_session_events_internal.h" diff --git a/port/linux/ipadapter.c b/port/linux/ipadapter.c index 1293346540..c4f3d3a0d4 100644 --- a/port/linux/ipadapter.c +++ b/port/linux/ipadapter.c @@ -27,7 +27,6 @@ #include "oc_buffer.h" #include "oc_core_res.h" #include "oc_endpoint.h" -#include "oc_network_monitor.h" #include "port/common/posix/oc_socket_internal.h" #include "port/oc_assert.h" #include "port/oc_clock.h" @@ -41,6 +40,10 @@ #include "util/oc_features.h" #include "util/oc_macros_internal.h" +#ifdef OC_NETWORK_MONITOR +#include "oc_network_monitor.h" +#endif /* OC_NETWORK_MONITOR */ + #ifdef OC_SESSION_EVENTS #include "api/oc_session_events_internal.h" #endif /* OC_SESSION_EVENTS */ diff --git a/port/unittest/connectivitytest.cpp b/port/unittest/connectivitytest.cpp index 18226d632f..fee6b3ff8e 100644 --- a/port/unittest/connectivitytest.cpp +++ b/port/unittest/connectivitytest.cpp @@ -157,6 +157,7 @@ TEST(TestConnectivity_wakeup, WakeupInvalidDevice) } #endif /* OC_DYNAMIC_ALLOCATION */ +#ifdef OC_NETWORK_MONITOR static void interface_event_handler(oc_interface_event_t event) { @@ -183,7 +184,6 @@ TEST_F(TestConnectivity, oc_remove_network_interface_event_callback_fail) -1, oc_remove_network_interface_event_callback(interface_event_handler)); } -#ifdef OC_NETWORK_MONITOR TEST_F(TestConnectivity, handle_network_interface_event_callback) { oc_add_network_interface_event_callback(interface_event_handler); diff --git a/port/windows/ipadapter.c b/port/windows/ipadapter.c index dc18eba180..fa6470add9 100644 --- a/port/windows/ipadapter.c +++ b/port/windows/ipadapter.c @@ -26,7 +26,6 @@ #include "oc_buffer.h" #include "oc_core_res.h" #include "oc_endpoint.h" -#include "oc_network_monitor.h" #include "port/common/posix/oc_socket_internal.h" #include "port/oc_assert.h" #include "port/oc_connectivity.h" @@ -36,6 +35,9 @@ #include "util/oc_list.h" #include "util/oc_memb.h" +#ifdef OC_NETWORK_MONITOR +#include "oc_network_monitor.h" +#endif /* OC_NETWORK_MONITOR */ #ifdef OC_TCP #include "tcpadapter.h" #endif /* OC_TCP */ diff --git a/swig/swig_interfaces/oc_session_events.i b/swig/swig_interfaces/oc_session_events.i index 662b92a7b9..cf788c88f7 100644 --- a/swig/swig_interfaces/oc_session_events.i +++ b/swig/swig_interfaces/oc_session_events.i @@ -39,4 +39,5 @@ void jni_session_events_set_event_delay(int secs) } %} #define OC_API +#define OC_DEPRECATED(...) %include "oc_session_events.h"