Add default Smack manifest for devman.spec
[platform/core/system/devman.git] / device_engine.c
1 /*
2  *  devman
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: DongGi Jang <dg0402.jang@samsung.com>
7  * 
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20 */ 
21
22
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <dirent.h>
30 #include <unistd.h>
31 #include <sys/stat.h>
32
33 #include "device_engine.h"
34
35 #define BUFF_MAX 255
36
37 struct device *dev_head = NULL;
38
39 void add_dev(struct device *dev)
40 {
41         dev->next = dev_head;
42         dev_head = dev;
43 }
44
45 void print_devices()
46 {
47         struct device *dev;
48         dev = dev_head;
49
50         while (dev) {
51                 DBG("%s - %d", dev->devname, dev->devtype);
52                 dev = dev->next;
53         }
54 }
55
56 void reset_devtype()
57 {
58         struct device *dev;
59         dev = dev_head;
60
61         while (dev) {
62                 dev->devtype = -1;
63                 dev = dev->next;
64         }
65 }
66
67 struct device *find_device(struct device *root_dev, devtype_t devtype)
68 {
69         struct device *dev;
70
71         if (devtype == -1)
72                 return NULL;
73
74         if (root_dev == NULL)
75                 dev = dev_head;
76         else
77                 dev = root_dev;
78
79         while (dev) {
80                 DBG("devname = %s %d %d", dev->devname, dev->devtype, devtype);
81                 if (dev->devtype == devtype)
82                         return dev;
83                 dev = dev->next;
84         }
85
86         return NULL;
87 }
88
89 int set_devtype(char *devname, devtype_t devtype)
90 {
91         int ret;
92         struct device *dev;
93         dev = dev_head;
94
95         while (dev) {
96                 if (strstr(dev->devname, devname)) {
97                         if ((strstr(dev->devname, "auto") != NULL) &&
98                                         (dev->probe != NULL)) {
99                                 ret = dev->probe();
100                                 if (ret < 0) {
101                                         DBG("auto probe failed");
102                                         return -1;
103                                 }
104                         }
105
106                         dev->devtype = devtype;
107                         return 0;
108                 }
109                 dev = dev->next;
110         }
111
112         return -1;
113 }