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