#define USEC_TO_MSEC(x) ((double)x/1000)
#endif
-int sys_get_int(char *fname, int *val);
int sys_get_str(char *fname, char *str);
int sys_strtol(char *str);
#endif /* __CORE_COMMON_H__ */
void devices_init(void *data);
void devices_exit(void *data);
-static inline int device_start(const struct device_ops *dev)
-{
- if (dev && dev->start)
- return dev->start(NORMAL_MODE);
-
- return -EINVAL;
-}
-
-static inline int device_stop(const struct device_ops *dev)
-{
- if (dev && dev->stop)
- return dev->stop(NORMAL_MODE);
-
- return -EINVAL;
-}
-
-static inline int device_exit(const struct device_ops *dev, void *data)
-{
- if (dev && dev->exit) {
- dev->exit(data);
- return 0;
- }
-
- return -EINVAL;
-}
-
-static inline int device_execute(const struct device_ops *dev, void *data)
-{
- if (dev && dev->execute)
- return dev->execute(data);
-
- return -EINVAL;
-}
-
-static inline int device_get_status(const struct device_ops *dev)
-{
- if (dev && dev->status)
- return dev->status();
-
- return -EINVAL;
-}
-
#define DEVICE_OPS_REGISTER(dev) \
static void __CONSTRUCTOR__ module_init(void) \
{ \
void add_device(const struct device_ops *dev);
void remove_device(const struct device_ops *dev);
-
-const struct device_ops *find_device(const char *name);
-int check_default(const struct device_ops *dev);
-
-#define NOT_SUPPORT_OPS(dev) ((check_default(dev)) ? 1 : 0)
-
-#define FIND_DEVICE_INT(dev, name) do { \
- if (!dev) dev = find_device(name); if (check_default(dev)) return -ENODEV; \
-} while (0)
-
-#define FIND_DEVICE_VOID(dev, name) do { \
- if (!dev) dev = find_device(name); if (check_default(dev)) return; \
-} while (0)
-
#endif
return ret;
}
-int sys_get_int(char *fname, int *val)
-{
- char buf[BUFF_MAX];
- int ret = 0;
-
- if (sys_read_buf(fname, buf) == 0) {
- ret = sys_strtol(buf);
- if (ret < 0)
- return ret;
- *val = ret;
- } else {
- *val = -1;
- ret = -EIO;
- }
-
- return ret;
-}
-
int sys_get_str(char *fname, char *str)
{
char buf[BUFF_MAX] = {0};
long value;
value = strtol(str, (char**)NULL, 10);
- if (value > INT_MAX || value < INT_MIN) {
- _E("%s is out of range of integer\n", str);
+ if (value > INT_MAX || value < INT_MIN)
return -EINVAL;
- }
return (int)value;
}
dev_head = g_list_remove(dev_head, (gconstpointer)dev);
}
-const struct device_ops *find_device(const char *name)
-{
- GList *elem;
- const struct device_ops *dev;
-
- for (elem = dev_head; elem != NULL; elem = elem->next) {
- dev = elem->data;
- if (!strcmp(dev->name, name))
- return dev;
- }
-
- dev = &default_ops;
- return dev;
-}
-
-int check_default(const struct device_ops *dev)
-{
- return (dev == &default_ops);
-}
-
void devices_init(void *data)
{
GList *elem, *elem_n;