battery: convert info.online value to standard one
[platform/hal/backend/emulator/device-emulator.git] / hw / usb_gadget / usb_gadget.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <errno.h>
18 #include <stdlib.h>
19
20 #include <hal/hal-common-interface.h>
21 #include <hal/device/hal-usb_gadget-interface.h>
22
23 #include </hal/include/device/hal-backend-common-usb_gadget.h>
24 #include </hal/include/device/hal-backend-common.h>
25
26 static int dummy_enable(void)
27 {
28         return 0;
29 }
30
31 static int dummy_disable(void)
32 {
33         return 0;
34 }
35
36 static int dummy_reconfigure_gadget(struct usb_gadget *gadget)
37 {
38         return 0;
39 }
40
41 static int usb_gadget_init(void **data)
42 {
43         hal_backend_usb_gadget_funcs *usb_gadget_funcs;
44
45         if (!data)
46                 return -EINVAL;
47
48         usb_gadget_funcs = calloc(1, sizeof(hal_backend_usb_gadget_funcs));
49         if (!usb_gadget_funcs)
50                 return -ENOMEM;
51
52         // usb_gadget_translator
53         if (simple_translator_open(usb_gadget_funcs)) {
54                 _E("No USB gadget translator");
55                 goto error_translator_open;
56         }
57
58         usb_gadget_funcs->enable = dummy_enable;
59         usb_gadget_funcs->disable = dummy_disable;
60         usb_gadget_funcs->reconfigure_gadget = dummy_reconfigure_gadget;
61
62         *data = (void *)usb_gadget_funcs;
63
64         return 0;
65
66 error_translator_open:
67         free(usb_gadget_funcs);
68
69         return -ENODEV;
70 }
71
72 static int usb_gadget_exit(void *data)
73 {
74         hal_backend_usb_gadget_funcs *usb_gadget_funcs = (hal_backend_usb_gadget_funcs *)data;
75
76         if (usb_gadget_funcs) {
77                 simple_translator_close(usb_gadget_funcs);
78                 free(usb_gadget_funcs);
79         }
80
81         return 0;
82 }
83
84 hal_backend EXPORT hal_backend_device_usb_gadget_data = {
85         .name = "usb_gadget",
86         .vendor = "RPI",
87         .abi_version = HAL_ABI_VERSION_TIZEN_7_0,
88         .init = usb_gadget_init,
89         .exit = usb_gadget_exit,
90 };