Add default Smack manifest for devman.spec
[platform/core/system/devman.git] / src / if_generic.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 <string.h>
24 #include <errno.h>
25
26 #include "devman_error.h"
27 #include "devlog.h"
28 #include "device_engine.h"
29
30 API int device_get_property(devtype_t devtype, int property, int *value)
31 {
32         struct device *dev = NULL;
33         int ret = -1;
34
35  retry:
36         if (dev != NULL) {
37                 dev = dev->next;
38                 if (dev == NULL) {
39                         DBG("devtype cannot find");
40                         errno = EPERM;
41                         return DEVMAN_ERROR_OPERATION_FAILED;
42                 }
43         }
44
45         dev = find_device(dev, devtype);
46         if (dev == NULL) {
47                 DBG("devtype cannot find");
48                 errno = EPERM;
49                 return DEVMAN_ERROR_OPERATION_FAILED;
50         }
51         if (dev->get_int == NULL) {
52                 DBG("get_int of %s is null", dev->devname);
53                 goto retry;
54         }
55
56         ret = dev->get_int(property, value);
57         if (ret == -ENODEV) {
58                 DBG("not support driver");
59                 errno = ENODEV;
60                 return DEVMAN_ERROR_NOT_SUPPORTED;
61         }
62         if (ret == -1) {
63                 DBG("get_int of %s return fails", dev->devname);
64                 goto retry;
65         }
66
67         errno = 0;
68         return ret;
69 }
70
71 API int device_set_property(devtype_t devtype, int property, int value)
72 {
73         struct device *dev = NULL;
74         int ret = -1;
75
76  retry:
77         if (dev != NULL) {
78                 dev = dev->next;
79                 if (dev == NULL) {
80                         DBG("devtype cannot find");
81                         errno = EPERM;
82                         return DEVMAN_ERROR_OPERATION_FAILED;
83                 }
84         }
85
86         dev = find_device(dev, devtype);
87         if (dev == NULL) {
88                 DBG("devtype cannot find");
89                 errno = EPERM;
90                 return DEVMAN_ERROR_OPERATION_FAILED;
91         }
92         if (dev->set_int == NULL) {
93                 DBG("set_int of %s is null", dev->devname);
94                 goto retry;
95         }
96
97         ret = dev->set_int(property, value);
98         if (ret == -ENODEV) {
99                 DBG("not support driver");
100                 errno = ENODEV;
101                 return DEVMAN_ERROR_NOT_SUPPORTED;
102         }
103         if (ret == -1) {
104                 DBG("set_int of %s return fails", dev->devname);
105                 goto retry;
106         }
107
108         errno = 0;
109         return ret;
110 }