blob: bdb47ca1508a66d798ad656728dd14a70f228b0e [file] [log] [blame]
Wonsik Kim0b78afb2014-03-03 11:33:08 +09001/*
2 * Copyright 2014 The Android Open Source Project
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 <fcntl.h>
18#include <errno.h>
19
20#include <cutils/log.h>
21#include <cutils/native_handle.h>
22
23#include <hardware/tv_input.h>
24
25/*****************************************************************************/
26
27typedef struct tv_input_private {
28 tv_input_device_t device;
29
30 // Callback related data
31 const tv_input_callback_ops_t* callback;
32 void* callback_data;
33} tv_input_private_t;
34
35static int tv_input_device_open(const struct hw_module_t* module,
36 const char* name, struct hw_device_t** device);
37
38static struct hw_module_methods_t tv_input_module_methods = {
39 open: tv_input_device_open
40};
41
42tv_input_module_t HAL_MODULE_INFO_SYM = {
43 common: {
44 tag: HARDWARE_MODULE_TAG,
45 version_major: 0,
46 version_minor: 1,
47 id: TV_INPUT_HARDWARE_MODULE_ID,
48 name: "Sample TV input module",
49 author: "The Android Open Source Project",
50 methods: &tv_input_module_methods,
51 }
52};
53
54/*****************************************************************************/
55
56static int tv_input_initialize(struct tv_input_device* dev,
57 const tv_input_callback_ops_t* callback, void* data)
58{
59 if (dev == NULL || callback == NULL) {
60 return -EINVAL;
61 }
62 tv_input_private_t* priv = (tv_input_private_t*)dev;
63 if (priv->callback != NULL) {
64 return -EEXIST;
65 }
66
67 priv->callback = callback;
68 priv->callback_data = data;
69
70 return 0;
71}
72
73static int tv_input_get_stream_configurations(
74 const struct tv_input_device*, int, int*, const tv_stream_config_t**)
75{
76 return -EINVAL;
77}
78
79static int tv_input_open_stream(struct tv_input_device*, int, tv_stream_t*)
80{
81 return -EINVAL;
82}
83
84static int tv_input_close_stream(struct tv_input_device*, int, int)
85{
86 return -EINVAL;
87}
88
89/*****************************************************************************/
90
91static int tv_input_device_close(struct hw_device_t *dev)
92{
93 tv_input_private_t* priv = (tv_input_private_t*)dev;
94 if (priv) {
95 free(priv);
96 }
97 return 0;
98}
99
100/*****************************************************************************/
101
102static int tv_input_device_open(const struct hw_module_t* module,
103 const char* name, struct hw_device_t** device)
104{
105 int status = -EINVAL;
106 if (!strcmp(name, TV_INPUT_DEFAULT_DEVICE)) {
107 tv_input_private_t* dev = (tv_input_private_t*)malloc(sizeof(*dev));
108
109 /* initialize our state here */
110 memset(dev, 0, sizeof(*dev));
111
112 /* initialize the procs */
113 dev->device.common.tag = HARDWARE_DEVICE_TAG;
114 dev->device.common.version = TV_INPUT_DEVICE_API_VERSION_0_1;
115 dev->device.common.module = const_cast<hw_module_t*>(module);
116 dev->device.common.close = tv_input_device_close;
117
118 dev->device.initialize = tv_input_initialize;
119 dev->device.get_stream_configurations =
120 tv_input_get_stream_configurations;
121 dev->device.open_stream = tv_input_open_stream;
122 dev->device.close_stream = tv_input_close_stream;
123
124 *device = &dev->device.common;
125 status = 0;
126 }
127 return status;
128}