service: Add and Leverage 'clear_error'
cover service: Add and Leverage 'clear_error'
There are a suffient number of instantiations of the following implementation pattern:
set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
to clear or reset the "Error" service property where it makes sense to embody this in a single function.
This introduces and leverages the 'clear_error' function to embody this pattern.
Grant Erickson (2):
service: Add and leverage 'clear_error'.
service: Document '{clear,set}_error'.
src/service.c | 56 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/2 service: Add and leverage 'clear_error'.
There are a suffient number of instantiations of the following implementation pattern:
set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
to clear or reset the "Error" service property where it makes sense to embody this in a single function, 'clear_error'.
This introduces and leverages the 'clear_error' function to embody this pattern.
--- src/service.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
src/service.c +13 -6
@@ -183,6 +183,8 @@ static void complete_online_check(struct connman_service *service,bool success, int err);static bool service_downgrade_online_state (struct connman_service *service); +static bool connman_service_is_default (const struct connman_service *service); +static void clear_error (struct connman_service *service);struct find_data {const char *path;
@@ -3992,7 +3994,7 @@ int __connman_service_set_passphrase(struct connman_service *service,if (service->hidden_service && service->error ==CONNMAN_SERVICE_ERROR_INVALID_KEY ) -set_error (service,CONNMAN_SERVICE_ERROR_UNKNOWN ); +clear_error (service);return 0 ; }
@@ -4374,7 +4376,7 @@ static DBusMessage *set_property(DBusConnection *conn,* have the same effect as user connecting the VPN = * clear previous error and change state to idle. */ -set_error (service,CONNMAN_SERVICE_ERROR_UNKNOWN ); +clear_error (service);if (service->state ==CONNMAN_SERVICE_STATE_FAILURE ) { service->state =CONNMAN_SERVICE_STATE_IDLE ;
@@ -4674,6 +4676,11 @@ static void set_error(struct connman_service *service, DBUS_TYPE_STRING, &str); } +static void clear_error (struct connman_service *service) +{ +set_error (service,CONNMAN_SERVICE_ERROR_UNKNOWN ); +} +static void remove_timeout (struct connman_service *service) {if (service->timeout >0 ) {
@@ -4715,7 +4722,7 @@ static DBusMessage *clear_property(DBusConnection *conn, DBUS_TYPE_INVALID);if (g_str_equal (name,"Error" )) { -set_error (service,CONNMAN_SERVICE_ERROR_UNKNOWN ); +clear_error (service);__connman_service_clear_error (service);service_complete (service);
@@ -6795,7 +6802,7 @@ static void request_input_cb(struct connman_service *service,if (err >=0 ) {/* We forget any previous error. */ -set_error (service,CONNMAN_SERVICE_ERROR_UNKNOWN ); +clear_error (service);__connman_service_connect (service,CONNMAN_SERVICE_CONNECT_REASON_USER );
@@ -7017,7 +7024,7 @@ static int service_indicate_state(struct connman_service *service)break ;case CONNMAN_SERVICE_STATE_READY : -set_error (service,CONNMAN_SERVICE_ERROR_UNKNOWN ); +clear_error (service);if (service->new_service &&__connman_stats_service_register (service) ==0 ) {
@@ -7084,7 +7091,7 @@ static int service_indicate_state(struct connman_service *service)break ;case CONNMAN_SERVICE_STATE_DISCONNECT : -set_error (service,CONNMAN_SERVICE_ERROR_UNKNOWN ); +clear_error (service);reply_pending (service,ECONNABORTED );
Signature · 1 line
2.42.0
PATCH 2/2 service: Document '{clear,set}_error'.
In reply to Grant EricksonThis adds documentation to the '{clear,set}_error' functions.
--- src/service.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
src/service.c +37 -0
@@ -4650,6 +4650,24 @@ static DBusMessage *set_property(DBusConnection *conn,return g_dbus_create_reply (msg,DBUS_TYPE_INVALID ); } +/** +* @brief +* Set the specified network service "Error" property. +* +* This sets the specified network service "Error" property to the +* provided value. +* +* @note +* This function results in a D-Bus property changed signal for the +* network service "Error" property. +* +* @param[in,out] service A pointer to the mutable network service +* for which to set the "Error" property. +* @param[in] error The error value to set. +* +* @sa clear_error +* +*/ static void set_error (struct connman_service *service,enum connman_service_error error) {
@@ -4676,6 +4694,25 @@ static void set_error(struct connman_service *service, DBUS_TYPE_STRING, &str); } +/** +* @brief +* Clear or reset the specified network service "Error" property. +* +* This sets the specified network service "Error" property to the +* initialization value of #CONNMAN_SERVICE_ERROR_UNKNOWN, +* effectively clearing or resetting the property. +* +* @note +* This function results in a D-Bus property changed signal for the +* network service "Error" property. +* +* @param[in,out] service A pointer to the mutable network service +* for which to clear or reset the "Error" +* property. +* +* @sa set_error +* +*/ static void clear_error (struct connman_service *service) {set_error (service,CONNMAN_SERVICE_ERROR_UNKNOWN );
Signature · 1 line
2.42.0
Hi Grant,
Quoted 11 lines
There are a suffient number of instantiations of the following implementation pattern:
set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);to clear or reset the "Error" service property where it makes sense to embody this in a single function.
This introduces and leverages the '
clear_error' function to embody this pattern.
Quoted 6 lines
Grant Erickson (2):
service: Add and leverage 'clear_error'.
service: Document '{clear,set}_error'.
src/service.c| 56 +++++++++++++++++++++++++++++++++++++++++++++------1 file changed, 50 insertions(+), 6 deletions(-)
both patches have been applied.
Regards
Marcel