blob: f0e979e8f8cecd7bb53051a0e5c3b40124419d10 [file] [log] [blame]
Mike Lockwood07908322013-10-17 08:05:00 -07001/*
2 * Copyright (C) 2013 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 <hardware/sensors.h>
18#include <fcntl.h>
19#include <errno.h>
20#include <dirent.h>
21#include <math.h>
22#include <poll.h>
23#include <pthread.h>
24#include <linux/input.h>
25#include <cutils/atomic.h>
26#include <cutils/log.h>
27
28#include <vector>
29#include <map>
30
31#include <stdio.h>
32#include <dlfcn.h>
Aaron Whyte92863c12013-10-28 17:18:06 -070033#include <SensorEventQueue.h>
Mike Lockwood07908322013-10-17 08:05:00 -070034
35// comment out to disable debug-level logging
36#define LOG_NDEBUG 0
37
38static const char* CONFIG_FILENAME = "/system/etc/sensors/hals.conf";
39static const char* LEGAL_SUBHAL_PATH_PREFIX = "/system/lib/hw/";
40static const int MAX_CONF_LINE_LENGTH = 1024;
41
42static pthread_mutex_t init_modules_mutex = PTHREAD_MUTEX_INITIALIZER;
43static pthread_mutex_t init_sensors_mutex = PTHREAD_MUTEX_INITIALIZER;
44
Aaron Whyte92863c12013-10-28 17:18:06 -070045// This mutex is shared by all queues
46static pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER;
47
48// Used to pause the multihal poll(). Broadcasted by sub-polling tasks if waiting_for_data.
49static pthread_cond_t data_available_cond = PTHREAD_COND_INITIALIZER;
50bool waiting_for_data = false;
51
Mike Lockwood07908322013-10-17 08:05:00 -070052/*
53 * Vector of sub modules, whose indexes are referred to ni this file as module_index.
54 */
55static std::vector<hw_module_t *> *sub_hw_modules = NULL;
56
57/*
58 * Comparable class that globally identifies a sensor, by module index and local handle.
59 * A module index is the module's index in sub_hw_modules.
60 * A local handle is the handle the sub-module assigns to a sensor.
61 */
62struct FullHandle {
63 int moduleIndex;
64 int localHandle;
65
66 bool operator<(const FullHandle &that) const {
67 if (moduleIndex < that.moduleIndex) {
68 return true;
69 }
70 if (moduleIndex > that.moduleIndex) {
71 return false;
72 }
73 return localHandle < that.localHandle;
74 }
75
Aaron Whyte92863c12013-10-28 17:18:06 -070076 bool operator==(const FullHandle &that) const {
Mike Lockwood07908322013-10-17 08:05:00 -070077 return moduleIndex == that.moduleIndex && localHandle == that.localHandle;
78 }
79};
80
81std::map<int, FullHandle> global_to_full;
82std::map<FullHandle, int> full_to_global;
83int next_global_handle = 1;
84
85static int assign_global_handle(int module_index, int local_handle) {
Mike Lockwood07908322013-10-17 08:05:00 -070086 int global_handle = next_global_handle++;
Aaron Whyte92863c12013-10-28 17:18:06 -070087 FullHandle full_handle;
88 full_handle.moduleIndex = module_index;
89 full_handle.localHandle = local_handle;
90 full_to_global[full_handle] = global_handle;
91 global_to_full[global_handle] = full_handle;
Mike Lockwood07908322013-10-17 08:05:00 -070092 return global_handle;
93}
94
95static int get_local_handle(int global_handle) {
96 return global_to_full[global_handle].localHandle;
97}
98
99static int get_module_index(int global_handle) {
Mike Lockwood07908322013-10-17 08:05:00 -0700100 FullHandle f = global_to_full[global_handle];
Aaron Whytec69f3a72013-10-29 15:17:01 -0700101 ALOGD("FullHandle for global_handle %d: moduleIndex %d, localHandle %d",
102 global_handle, f.moduleIndex, f.localHandle);
Mike Lockwood07908322013-10-17 08:05:00 -0700103 return f.moduleIndex;
104}
105
Aaron Whyte92863c12013-10-28 17:18:06 -0700106static const int SENSOR_EVENT_QUEUE_CAPACITY = 20;
107
108struct TaskContext {
109 sensors_poll_device_t* device;
110 SensorEventQueue* queue;
111};
112
113void *writerTask(void* ptr) {
114 ALOGD("writerTask STARTS");
115 TaskContext* ctx = (TaskContext*)ptr;
116 sensors_poll_device_t* device = ctx->device;
117 SensorEventQueue* queue = ctx->queue;
118 sensors_event_t* buffer;
119 int eventsPolled;
120 while (1) {
Aaron Whyte92863c12013-10-28 17:18:06 -0700121 pthread_mutex_lock(&queue_mutex);
Aaron Whytec69f3a72013-10-29 15:17:01 -0700122 if (queue->waitForSpace(&queue_mutex)) {
123 ALOGD("writerTask waited for space");
124 }
Aaron Whyte92863c12013-10-28 17:18:06 -0700125 int bufferSize = queue->getWritableRegion(SENSOR_EVENT_QUEUE_CAPACITY, &buffer);
126 // Do blocking poll outside of lock
127 pthread_mutex_unlock(&queue_mutex);
128
129 ALOGD("writerTask before poll() - bufferSize = %d", bufferSize);
130 eventsPolled = device->poll(device, buffer, bufferSize);
131 ALOGD("writerTask poll() got %d events.", eventsPolled);
Aaron Whytec69f3a72013-10-29 15:17:01 -0700132 if (eventsPolled == 0) {
133 continue;
134 }
Aaron Whyte92863c12013-10-28 17:18:06 -0700135 pthread_mutex_lock(&queue_mutex);
136 queue->markAsWritten(eventsPolled);
137 ALOGD("writerTask wrote %d events", eventsPolled);
138 if (waiting_for_data) {
139 ALOGD("writerTask - broadcast data_available_cond");
140 pthread_cond_broadcast(&data_available_cond);
141 }
142 pthread_mutex_unlock(&queue_mutex);
143 }
144 // never actually returns
145 return NULL;
146}
Mike Lockwood07908322013-10-17 08:05:00 -0700147
148/*
149 * Cache of all sensors, with original handles replaced by global handles.
150 * This will be handled to get_sensors_list() callers.
151 */
152static struct sensor_t const* global_sensors_list = NULL;
153static int global_sensors_count = -1;
154
155/*
156 * Extends a sensors_poll_device_1 by including all the sub-module's devices.
157 */
158struct sensors_poll_context_t {
159 /*
160 * This is the device that SensorDevice.cpp uses to make API calls
161 * to the multihal, which fans them out to sub-HALs.
162 */
163 sensors_poll_device_1 proxy_device; // must be first
164
165 void addSubHwDevice(struct hw_device_t*);
166
167 int activate(int handle, int enabled);
168 int setDelay(int handle, int64_t ns);
169 int poll(sensors_event_t* data, int count);
170 int batch(int handle, int flags, int64_t period_ns, int64_t timeout);
171 int flush(int handle);
172 int close();
173
174 std::vector<hw_device_t*> sub_hw_devices;
Aaron Whyte92863c12013-10-28 17:18:06 -0700175 std::vector<SensorEventQueue*> queues;
176 std::vector<pthread_t> threads;
177 int nextReadIndex;
Mike Lockwood07908322013-10-17 08:05:00 -0700178
179 sensors_poll_device_t* get_v0_device_by_handle(int global_handle);
180 sensors_poll_device_1_t* get_v1_device_by_handle(int global_handle);
181 int get_device_version_by_handle(int global_handle);
Aaron Whyte92863c12013-10-28 17:18:06 -0700182
183 void copy_event_remap_handle(sensors_event_t* src, sensors_event_t* dest, int sub_index);
Mike Lockwood07908322013-10-17 08:05:00 -0700184};
185
186void sensors_poll_context_t::addSubHwDevice(struct hw_device_t* sub_hw_device) {
187 ALOGD("addSubHwDevice");
188 this->sub_hw_devices.push_back(sub_hw_device);
Aaron Whyte92863c12013-10-28 17:18:06 -0700189
190 SensorEventQueue *queue = new SensorEventQueue(SENSOR_EVENT_QUEUE_CAPACITY);
191 this->queues.push_back(queue);
192
193 TaskContext* taskContext = new TaskContext();
194 taskContext->device = (sensors_poll_device_t*) sub_hw_device;
195 taskContext->queue = queue;
196
197 pthread_t writerThread;
198 pthread_create(&writerThread, NULL, writerTask, taskContext);
199 this->threads.push_back(writerThread);
Mike Lockwood07908322013-10-17 08:05:00 -0700200}
201
202sensors_poll_device_t* sensors_poll_context_t::get_v0_device_by_handle(int handle) {
Mike Lockwood07908322013-10-17 08:05:00 -0700203 int sub_index = get_module_index(handle);
Mike Lockwood07908322013-10-17 08:05:00 -0700204 return (sensors_poll_device_t*) this->sub_hw_devices[sub_index];
205}
206
207sensors_poll_device_1_t* sensors_poll_context_t::get_v1_device_by_handle(int handle) {
208 int sub_index = get_module_index(handle);
209 return (sensors_poll_device_1_t*) this->sub_hw_devices[sub_index];
210}
211
212int sensors_poll_context_t::get_device_version_by_handle(int handle) {
213 sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle);
214 return v0->common.version;
215}
216
217int sensors_poll_context_t::activate(int handle, int enabled) {
218 ALOGD("activate");
219 sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle);
220 int retval = v0->activate(v0, get_local_handle(handle), enabled);
221 ALOGD("retval %d", retval);
222 return retval;
223}
224
225int sensors_poll_context_t::setDelay(int handle, int64_t ns) {
226 ALOGD("setDelay");
227 sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle);
228 int retval = v0->setDelay(v0, get_local_handle(handle), ns);
229 ALOGD("retval %d", retval);
230 return retval;
231}
232
Aaron Whyte92863c12013-10-28 17:18:06 -0700233void sensors_poll_context_t::copy_event_remap_handle(sensors_event_t* dest, sensors_event_t* src,
234 int sub_index) {
235 memcpy(dest, src, sizeof(struct sensors_event_t));
236 // A normal event's "sensor" field is a local handle. Convert it to a global handle.
Mike Lockwood07908322013-10-17 08:05:00 -0700237 // A meta-data event must have its sensor set to 0, but it has a nested event
238 // with a local handle that needs to be converted to a global handle.
239 FullHandle full_handle;
240 full_handle.moduleIndex = sub_index;
Aaron Whyte92863c12013-10-28 17:18:06 -0700241 // If it's a metadata event, rewrite the inner payload, not the sensor field.
242 if (dest->type == SENSOR_TYPE_META_DATA) {
243 full_handle.localHandle = dest->meta_data.sensor;
244 dest->meta_data.sensor = full_to_global[full_handle];
245 } else {
246 full_handle.localHandle = dest->sensor;
247 dest->sensor = full_to_global[full_handle];
248 }
249}
250
251int sensors_poll_context_t::poll(sensors_event_t *data, int maxReads) {
252 ALOGD("poll");
253 int empties = 0;
254 int queueCount = (int)this->queues.size();
255 int eventsRead = 0;
256
257 pthread_mutex_lock(&queue_mutex);
258 while (eventsRead == 0) {
259 while (empties < queueCount && eventsRead < maxReads) {
260 SensorEventQueue* queue = this->queues.at(this->nextReadIndex);
Aaron Whyte92863c12013-10-28 17:18:06 -0700261 sensors_event_t* event = queue->peek();
262 if (event == NULL) {
263 empties++;
264 } else {
265 empties = 0;
266 this->copy_event_remap_handle(&data[eventsRead++], event, nextReadIndex);
267 queue->dequeue();
268 }
269 this->nextReadIndex = (this->nextReadIndex + 1) % queueCount;
270 }
271 if (eventsRead == 0) {
Aaron Whytec69f3a72013-10-29 15:17:01 -0700272 // The queues have been scanned and none contain data, so wait.
Aaron Whyte92863c12013-10-28 17:18:06 -0700273 ALOGD("poll stopping to wait for data");
274 waiting_for_data = true;
275 pthread_cond_wait(&data_available_cond, &queue_mutex);
276 waiting_for_data = false;
277 empties = 0;
Mike Lockwood07908322013-10-17 08:05:00 -0700278 }
279 }
Aaron Whyte92863c12013-10-28 17:18:06 -0700280 pthread_mutex_unlock(&queue_mutex);
Aaron Whytec69f3a72013-10-29 15:17:01 -0700281 ALOGD("poll returning %d events.", eventsRead);
Aaron Whyte92863c12013-10-28 17:18:06 -0700282
283 return eventsRead;
Mike Lockwood07908322013-10-17 08:05:00 -0700284}
285
286int sensors_poll_context_t::batch(int handle, int flags, int64_t period_ns, int64_t timeout) {
287 ALOGD("batch");
288 int retval = -EINVAL;
289 int version = this->get_device_version_by_handle(handle);
290 if (version >= SENSORS_DEVICE_API_VERSION_1_0) {
291 sensors_poll_device_1_t* v1 = this->get_v1_device_by_handle(handle);
292 retval = v1->batch(v1, get_local_handle(handle), flags, period_ns, timeout);
293 }
294 ALOGD("retval %d", retval);
295 return retval;
296}
297
298int sensors_poll_context_t::flush(int handle) {
299 ALOGD("flush");
300 int retval = -EINVAL;
301 int version = this->get_device_version_by_handle(handle);
302 if (version >= SENSORS_DEVICE_API_VERSION_1_0) {
303 sensors_poll_device_1_t* v1 = this->get_v1_device_by_handle(handle);
304 retval = v1->flush(v1, get_local_handle(handle));
305 }
306 ALOGD("retval %d", retval);
307 return retval;
308}
309
310int sensors_poll_context_t::close() {
311 ALOGD("close");
312 for (std::vector<hw_device_t*>::iterator it = this->sub_hw_devices.begin();
313 it != this->sub_hw_devices.end(); it++) {
314 hw_device_t* dev = *it;
315 int retval = dev->close(dev);
316 ALOGD("retval %d", retval);
317 }
318 return 0;
319}
320
321
322static int device__close(struct hw_device_t *dev) {
323 sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev;
324 if (ctx != NULL) {
325 int retval = ctx->close();
326 delete ctx;
327 }
328 return 0;
329}
330
331static int device__activate(struct sensors_poll_device_t *dev, int handle,
332 int enabled) {
333 sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev;
334 return ctx->activate(handle, enabled);
335}
336
337static int device__setDelay(struct sensors_poll_device_t *dev, int handle,
338 int64_t ns) {
339 sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev;
340 return ctx->setDelay(handle, ns);
341}
342
343static int device__poll(struct sensors_poll_device_t *dev, sensors_event_t* data,
344 int count) {
345 sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev;
346 return ctx->poll(data, count);
347}
348
349static int device__batch(struct sensors_poll_device_1 *dev, int handle,
350 int flags, int64_t period_ns, int64_t timeout) {
351 sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev;
352 return ctx->batch(handle, flags, period_ns, timeout);
353}
354
355static int device__flush(struct sensors_poll_device_1 *dev, int handle) {
356 sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev;
357 return ctx->flush(handle);
358}
359
360static int open_sensors(const struct hw_module_t* module, const char* name,
361 struct hw_device_t** device);
362
363static bool starts_with(const char* s, const char* prefix) {
364 if (s == NULL || prefix == NULL) {
365 return false;
366 }
367 size_t s_size = strlen(s);
368 size_t prefix_size = strlen(prefix);
369 return s_size >= prefix_size && strncmp(s, prefix, prefix_size) == 0;
370}
371
372/*
373 * Adds valid paths from the config file to the vector passed in.
374 * The vector must not be null.
375 */
376static void get_so_paths(std::vector<char*> *so_paths) {
377 FILE *conf_file = fopen(CONFIG_FILENAME, "r");
378 if (conf_file == NULL) {
379 ALOGD("No multihal config file found at %s", CONFIG_FILENAME);
380 return;
381 }
382 ALOGD("Multihal config file found at %s", CONFIG_FILENAME);
383 char *line = NULL;
384 size_t len = 0;
385 int line_count = 0;
386 while (getline(&line, &len, conf_file) != -1) {
387 // overwrite trailing eoln with null char
388 char* pch = strchr(line, '\n');
389 if (pch != NULL) {
390 *pch = '\0';
391 }
392 ALOGD("config file line #%d: '%s'", ++line_count, line);
393 char *real_path = realpath(line, NULL);
394 if (starts_with(real_path, LEGAL_SUBHAL_PATH_PREFIX)) {
395 ALOGD("accepting valid path '%s'", real_path);
396 char* compact_line = new char[strlen(real_path) + 1];
397 strcpy(compact_line, real_path);
398 so_paths->push_back(compact_line);
399 } else {
400 ALOGD("rejecting path '%s' because it does not start with '%s'",
401 real_path, LEGAL_SUBHAL_PATH_PREFIX);
402 }
403 free(real_path);
404 }
405 free(line);
406 fclose(conf_file);
407 ALOGD("hals.conf contained %d lines", line_count);
408}
409
410/*
411 * Ensures that the sub-module array is initialized.
412 * This can be first called from get_sensors_list or from open_sensors.
413 */
414static void lazy_init_modules() {
415 pthread_mutex_lock(&init_modules_mutex);
416 if (sub_hw_modules != NULL) {
417 pthread_mutex_unlock(&init_modules_mutex);
418 return;
419 }
420 std::vector<char*> *so_paths = new std::vector<char*>();
421 get_so_paths(so_paths);
422
423 // dlopen the module files and cache their module symbols in sub_hw_modules
424 sub_hw_modules = new std::vector<hw_module_t *>();
425 dlerror(); // clear any old errors
426 const char* sym = HAL_MODULE_INFO_SYM_AS_STR;
427 for (std::vector<char*>::iterator it = so_paths->begin(); it != so_paths->end(); it++) {
428 char* path = *it;
429 void* lib_handle = dlopen(path, RTLD_LAZY);
430 if (lib_handle == NULL) {
431 ALOGD("dlerror(): %s", dlerror());
432 } else {
433 ALOGD("hal lib was loaded: %s", path);
434 ALOGD("Opening symbol \"%s\"", sym);
435 // clear old errors
436 dlerror();
437 struct hw_module_t* module = (hw_module_t*) dlsym(lib_handle, sym);
438 const char* error;
439 if ((error = dlerror()) != NULL) {
440 ALOGD("Error calling dlsym: %s", error);
441 } else if (module == NULL) {
442 ALOGD("module == NULL");
443 } else {
444 ALOGD("OK, dlsym()'ed \"%s\"", sym);
445 sub_hw_modules->push_back(module);
446 }
447 }
448 }
449 pthread_mutex_unlock(&init_modules_mutex);
450}
451
452/*
453 * Lazy-initializes global_sensors_count, global_sensors_list, and module_sensor_handles.
454 */
455static void lazy_init_sensors_list() {
456 ALOGD("lazy_init_sensors_list");
457 pthread_mutex_lock(&init_sensors_mutex);
458 if (global_sensors_list != NULL) {
459 // already initialized
460 pthread_mutex_unlock(&init_sensors_mutex);
461 ALOGD("lazy_init_sensors_list - early return");
462 return;
463 }
464
465 ALOGD("lazy_init_sensors_list needs to do work");
466 lazy_init_modules();
467
468 // Count all the sensors, then allocate an array of blanks.
469 global_sensors_count = 0;
470 const struct sensor_t *subhal_sensors_list;
471 for (std::vector<hw_module_t*>::iterator it = sub_hw_modules->begin();
472 it != sub_hw_modules->end(); it++) {
473 struct sensors_module_t *module = (struct sensors_module_t*) *it;
474 global_sensors_count += module->get_sensors_list(module, &subhal_sensors_list);
475 ALOGD("increased global_sensors_count to %d", global_sensors_count);
476 }
477
478 // The global_sensors_list is full of consts.
479 // Manipulate this non-const list, and point the const one to it when we're done.
480 sensor_t* mutable_sensor_list = new sensor_t[global_sensors_count];
481
482 // index of the next sensor to set in mutable_sensor_list
483 int mutable_sensor_index = 0;
484 int module_index = 0;
485
486 for (std::vector<hw_module_t*>::iterator it = sub_hw_modules->begin();
487 it != sub_hw_modules->end(); it++) {
488 hw_module_t *hw_module = *it;
489 ALOGD("examine one module");
490 // Read the sub-module's sensor list.
491 struct sensors_module_t *module = (struct sensors_module_t*) hw_module;
492 int module_sensor_count = module->get_sensors_list(module, &subhal_sensors_list);
493 ALOGD("the module has %d sensors", module_sensor_count);
494
495 // Copy the HAL's sensor list into global_sensors_list,
496 // with the handle changed to be a global handle.
497 for (int i = 0; i < module_sensor_count; i++) {
498 ALOGD("examining one sensor");
499 const struct sensor_t *local_sensor = &subhal_sensors_list[i];
500 int local_handle = local_sensor->handle;
501 memcpy(&mutable_sensor_list[mutable_sensor_index], local_sensor,
502 sizeof(struct sensor_t));
503
504 // Overwrite the global version's handle with a global handle.
505 int global_handle = assign_global_handle(module_index, local_handle);
506
507 mutable_sensor_list[mutable_sensor_index].handle = global_handle;
508 ALOGD("module_index %d, local_handle %d, global_handle %d",
509 module_index, local_handle, global_handle);
510
511 mutable_sensor_index++;
512 }
513 module_index++;
514 }
515 // Set the const static global_sensors_list to the mutable one allocated by this function.
516 global_sensors_list = mutable_sensor_list;
517
518 pthread_mutex_unlock(&init_sensors_mutex);
519 ALOGD("end lazy_init_sensors_list");
520}
521
522static int module__get_sensors_list(struct sensors_module_t* module,
523 struct sensor_t const** list) {
Aaron Whyte92863c12013-10-28 17:18:06 -0700524 ALOGD("module__get_sensors_list start");
Mike Lockwood07908322013-10-17 08:05:00 -0700525 lazy_init_sensors_list();
526 *list = global_sensors_list;
Aaron Whyte92863c12013-10-28 17:18:06 -0700527 ALOGD("global_sensors_count: %d", global_sensors_count);
528 for (int i = 0; i < global_sensors_count; i++) {
529 ALOGD("sensor type: %d", global_sensors_list[i].type);
530 }
Mike Lockwood07908322013-10-17 08:05:00 -0700531 return global_sensors_count;
532}
533
534static struct hw_module_methods_t sensors_module_methods = {
535 open : open_sensors
536};
537
538struct sensors_module_t HAL_MODULE_INFO_SYM = {
539 common :{
540 tag : HARDWARE_MODULE_TAG,
541 version_major : 1,
542 version_minor : 0,
543 id : SENSORS_HARDWARE_MODULE_ID,
544 name : "MultiHal Sensor Module",
545 author : "Google, Inc",
546 methods : &sensors_module_methods,
547 dso : NULL,
548 reserved : {0},
549 },
550 get_sensors_list : module__get_sensors_list
551};
552
553static int open_sensors(const struct hw_module_t* hw_module, const char* name,
554 struct hw_device_t** hw_device_out) {
555 ALOGD("open_sensors begin...");
556
557 lazy_init_modules();
558
559 // Create proxy device, to return later.
560 sensors_poll_context_t *dev = new sensors_poll_context_t();
561 memset(dev, 0, sizeof(sensors_poll_device_1_t));
562 dev->proxy_device.common.tag = HARDWARE_DEVICE_TAG;
563 dev->proxy_device.common.version = SENSORS_DEVICE_API_VERSION_1_0;
564 dev->proxy_device.common.module = const_cast<hw_module_t*>(hw_module);
565 dev->proxy_device.common.close = device__close;
566 dev->proxy_device.activate = device__activate;
567 dev->proxy_device.setDelay = device__setDelay;
568 dev->proxy_device.poll = device__poll;
569 dev->proxy_device.batch = device__batch;
570 dev->proxy_device.flush = device__flush;
571
Aaron Whyte92863c12013-10-28 17:18:06 -0700572 dev->nextReadIndex = 0;
573
Mike Lockwood07908322013-10-17 08:05:00 -0700574 // Open() the subhal modules. Remember their devices in a vector parallel to sub_hw_modules.
575 for (std::vector<hw_module_t*>::iterator it = sub_hw_modules->begin();
576 it != sub_hw_modules->end(); it++) {
577 sensors_module_t *sensors_module = (sensors_module_t*) *it;
578 struct hw_device_t* sub_hw_device;
579 int sub_open_result = sensors_module->common.methods->open(*it, name, &sub_hw_device);
580 dev->addSubHwDevice(sub_hw_device);
581 }
582
583 // Prepare the output param and return
584 *hw_device_out = &dev->proxy_device.common;
585 ALOGD("...open_sensors end");
586 return 0;
587}