diff mbox series

[1/2] service: Add and leverage 'clear_error'.

Message ID 20231120215329.786768-2-gerickson@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series service: Add and Leverage 'clear_error' | expand

Commit Message

Grant Erickson Nov. 20, 2023, 9:53 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/src/service.c b/src/service.c
index 9808028637dd..b30e75b9ac13 100644
--- a/src/service.c
+++ b/src/service.c
@@ -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);