• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 #include <cutils/log.h>
17 #include <errno.h>
18 #include <fcntl.h>
19 #include <hardware/lights.h>
20 #include <pthread.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/ioctl.h>
25 #include <sys/types.h>
26 #include <unistd.h>
27 
28 #include "guest/libs/platform_support/api_level_fixes.h"
29 
set_light(struct light_device_t * dev,struct light_state_t const * state)30 static int set_light(struct light_device_t* dev,
31                      struct light_state_t const* state) {
32   ALOGI("%s: dev %p state %p", __FUNCTION__, dev, state);
33   if (state) {
34     ALOGI("%s: state value %d\n", __FUNCTION__, state->color);
35   }
36   return 0;
37 }
38 
close_lights(struct light_device_t * dev)39 static int close_lights(struct light_device_t* dev) {
40   free(dev);
41   return 0;
42 }
43 
open_lights(const struct hw_module_t * module,char const * name __unused,struct hw_device_t ** device)44 static int open_lights(const struct hw_module_t* module,
45                        char const* name __unused, struct hw_device_t** device) {
46   struct light_device_t* dev = malloc(sizeof(struct light_device_t));
47   if (dev == NULL) {
48     return -EINVAL;
49   }
50   memset(dev, 0, sizeof(*dev));
51 
52   dev->common.tag = HARDWARE_DEVICE_TAG;
53   dev->common.version = 0;
54   dev->common.module = (struct hw_module_t*)module;
55   dev->common.close = (int (*)(struct hw_device_t*))close_lights;
56   dev->set_light = set_light;
57   *device = (struct hw_device_t*)dev;
58   return 0;
59 }
60 
61 static struct hw_module_methods_t lights_module_methods = {
62     VSOC_STATIC_INITIALIZER(open) open_lights,
63 };
64 
65 struct hw_module_t HAL_MODULE_INFO_SYM = {
66     VSOC_STATIC_INITIALIZER(tag) HARDWARE_MODULE_TAG,
67     VSOC_STATIC_INITIALIZER(version_major) 1,
68     VSOC_STATIC_INITIALIZER(version_minor) 0,
69     VSOC_STATIC_INITIALIZER(id) LIGHTS_HARDWARE_MODULE_ID,
70     VSOC_STATIC_INITIALIZER(name) "Android GCE lights Module",
71     VSOC_STATIC_INITIALIZER(author) "Google",
72     VSOC_STATIC_INITIALIZER(methods) & lights_module_methods,
73 };
74