Refactoring: replace ffs_service to is_functionfs
[platform/core/system/libdevice-node.git] / hw / usb_cfs_client_common.c
index 6d3595f..39dfca2 100644 (file)
@@ -497,7 +497,7 @@ static bool cfs_is_function_supported(struct usb_client *usb,
        bool res;
        int ret;
 
-       if (!func->ffs_service) {
+       if (!func->is_functionfs) {
                ret = usbg_lookup_function_type(func->name);
                res = ret >= 0;
        } else {
@@ -730,7 +730,7 @@ static int cfs_set_gadget_config(struct cfs_client *cfs_client,
                int type;
                usbg_function *func;
 
-               if (!usb_func->ffs_service) {
+               if (!usb_func->is_functionfs) {
                        type = usbg_lookup_function_type(usb_func->name);
                        if (strlen(usb_func->instance) >= MAX_INSTANCE_LEN)
                                return -ENAMETOOLONG;
@@ -760,11 +760,11 @@ static int cfs_set_gadget_config(struct cfs_client *cfs_client,
                        if (usbg_get_function_type(func) == USBG_F_RNDIS)
                                (void)cfs_set_rndis_mac_addr(cfs_client->gadget, func); /* A random value is used if fails */
 
-                       if (usb_func->ffs_service) {
+                       if (usb_func->is_functionfs) {
                                ret = cfs_prep_ffs_service(usb_func->name,
                                                        usb_func->instance,
                                                        instance,
-                                                       usb_func->ffs_service);
+                                                       usb_func->service);
                                if (ret)
                                        return ret;
                        }
@@ -863,10 +863,9 @@ static int cfs_enable(struct usb_client *usb)
                if (func->handler)
                        func->handler(1);
 
-               if (func->service)
+               /* functionfs service is automatically started by socket activation */
+               if (!func->is_functionfs && func->service)
                        (void)systemd_start_unit_wait_started(func->service, ".service", -1);
-
-               /* func->ffs_service is automatically started by socket activation */
        }
 
        cfs_free_gadget(gadget);
@@ -892,7 +891,7 @@ static int cfs_disable(struct usb_client *usb)
        for (i = 0; gadget->funcs[i]; ++i) {
                func = gadget->funcs[i];
 
-               if (func->service)
+               if (!func->is_functionfs && func->service)
                        (void)systemd_stop_unit_wait_stopped(func->service, ".service", -1);
 
                if (func->handler)
@@ -903,15 +902,15 @@ static int cfs_disable(struct usb_client *usb)
        ret = usbg_disable_gadget(cfs_client->gadget); /* ignore error checking */
 
        /*
-        * Since ffs_service works with socket activation, you must stop it after disabling gadget.
-        * If usb data may come in after stopping ffs_service and before disabling gadget,
-        * ffs_service wakes up again by socket activation.
+        * Since functionfs service works with socket activation, you must stop it after disabling gadget.
+        * If usb data may come in after stopping functionfs service and before disabling gadget,
+        * functionfs service wakes up again by socket activation.
         */
        for (i = 0; gadget->funcs[i]; ++i) {
                func = gadget->funcs[i];
 
-               if (func->ffs_service)
-                       (void)systemd_stop_unit_wait_stopped(func->ffs_service, ".service", -1);
+               if (func->is_functionfs && func->service)
+                       (void)systemd_stop_unit_wait_stopped(func->service, ".service", -1);
        }
 
        cfs_free_gadget(gadget);
@@ -994,9 +993,10 @@ int hw_cfs_gadget_close(struct hw_common *common)
                        continue;
 
                usb_func = _available_funcs[ret];
-               if (usb_func->ffs_service) {
-                       systemd_stop_unit_wait_stopped(usb_func->ffs_service, ".socket", -1);
-                       systemd_stop_unit_wait_stopped(usb_func->ffs_service, ".service", -1);
+
+               if (usb_func->is_functionfs && usb_func->service) {
+                       (void)systemd_stop_unit_wait_stopped(usb_func->service, ".socket", -1);
+                       (void)systemd_stop_unit_wait_stopped(usb_func->service, ".service", -1);
                }
        }