Initialize Tizen 2.3
[framework/system/deviced.git] / src / core / devices.h
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #ifndef __DEVICES_H__
21 #define __DEVICES_H__
22
23 #include <errno.h>
24 #include "common.h"
25
26 enum device_priority {
27         DEVICE_PRIORITY_NORMAL = 0,
28         DEVICE_PRIORITY_HIGH,
29 };
30
31 struct device_ops {
32         enum device_priority priority;
33         char *name;
34         void (*init) (void *data);
35         void (*exit) (void *data);
36         int (*start) (void);
37         int (*stop) (void);
38         int (*status) (void);
39 };
40
41 enum device_ops_status {
42         DEVICE_OPS_STATUS_UNINIT,
43         DEVICE_OPS_STATUS_START,
44         DEVICE_OPS_STATUS_STOP,
45         DEVICE_OPS_STATUS_MAX,
46 };
47
48 void devices_init(void *data);
49 void devices_exit(void *data);
50
51 static inline int device_start(const struct device_ops *dev)
52 {
53         if (dev && dev->start)
54                 return dev->start();
55
56         return -EINVAL;
57 }
58
59 static inline int device_stop(const struct device_ops *dev)
60 {
61         if (dev && dev->stop)
62                 return dev->stop();
63
64         return -EINVAL;
65 }
66
67 static inline int device_get_status(const struct device_ops *dev)
68 {
69         if (dev && dev->status)
70                 return dev->status();
71
72         return -EINVAL;
73 }
74
75 #define DEVICE_OPS_REGISTER(dev)        \
76 static void __CONSTRUCTOR__ module_init(void)   \
77 {       \
78         add_device(dev);        \
79 }       \
80 static void __DESTRUCTOR__ module_exit(void)    \
81 {       \
82         remove_device(dev);     \
83 }
84
85 void add_device(const struct device_ops *dev);
86 void remove_device(const struct device_ops *dev);
87 const struct device_ops *find_device(const char *name);
88
89 #endif