return dev->type->check_state(dev);
}
-int init_device(struct device *dev, const struct device_type *type, const char *ifname)
+void init_virtual_device(struct device *dev, const struct device_type *type, const char *name)
{
- int ret;
-
assert(dev);
assert(type);
- if (ifname)
- strncpy(dev->ifname, ifname, IFNAMSIZ);
+ fprintf(stderr, "Initialize interface '%s'\n", dev->ifname);
+ INIT_LIST_HEAD(&dev->users);
+ dev->type = type;
+
+ if (name)
+ strncpy(dev->ifname, name, IFNAMSIZ);
+}
+
+int init_device(struct device *dev, const struct device_type *type, const char *ifname)
+{
+ int ret;
+
+ init_virtual_device(dev, type, ifname);
if (!dev->set_state)
dev->set_state = set_device_state;
- fprintf(stderr, "Initialize interface '%s'\n", dev->ifname);
- INIT_LIST_HEAD(&dev->users);
dev->avl.key = dev->ifname;
- dev->type = type;
ret = avl_insert(&devices, &dev->avl);
if (ret < 0)
return ret;
check_device_state(dev);
+
return 0;
}
dep->cb(dep, DEV_EVENT_REMOVE);
}
- avl_delete(&devices, &dev->avl);
+ if (dev->avl.key)
+ avl_delete(&devices, &dev->avl);
}
void set_device_present(struct device *dev, bool state)
int (*del)(struct device *main, struct device *member);
};
+void init_virtual_device(struct device *dev, const struct device_type *type, const char *name);
int init_device(struct device *iface, const struct device_type *type, const char *ifname);
void cleanup_device(struct device *iface);
struct device *get_device(const char *name, bool create);