diff options
author | Peng Xu <pengxu@google.com> | 2017-01-20 14:24:39 -0800 |
---|---|---|
committer | Peng Xu <pengxu@google.com> | 2017-03-07 20:50:56 -0800 |
commit | 57d8af7f5ecbdbadb043b05ac5874989ef33fdad (patch) | |
tree | a315a9abcecd5d6adb6603e22efb2ead32ee6262 /modules/sensors/dynamic_sensor/BaseSensorObject.cpp | |
parent | 2e643b42ad6fea21d0be2adf21f4d6832205528a (diff) |
Dynamic sensor manager module - framework
Library to handle dynamic sensor connection. There are two way to use
this: as hal extension or standalone hal module.
In hal extension mode: add libdynamic_sensor_ext in dependency of hal,
instantiate DynamicSensorManager with appropriate parameters. Then
for all sensor requests, if the handle is owned by dynamic sensor
manager, forward the request.
In standalone mode, add sensor.dynamic_sensor_hal into device make
file. Usually, this also means multihal is necessary. Add
sensor.dynamic_sensor_hal into multihal configuration file.
This CL implements the dynamic sensor manager framework. Sensor daemon
will be added in follow up CL.
Test: test compile (functionality test done in a follow up CL)
Change-Id: I3b96ee135d8dbe3e199af01bed4b61637358803e
Diffstat (limited to 'modules/sensors/dynamic_sensor/BaseSensorObject.cpp')
-rw-r--r-- | modules/sensors/dynamic_sensor/BaseSensorObject.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/modules/sensors/dynamic_sensor/BaseSensorObject.cpp b/modules/sensors/dynamic_sensor/BaseSensorObject.cpp new file mode 100644 index 00000000..189e87fa --- /dev/null +++ b/modules/sensors/dynamic_sensor/BaseSensorObject.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "BaseSensorObject.h" +#include "SensorEventCallback.h" + +#include <utils/Log.h> +#include <cstring> + +namespace android { +namespace SensorHalExt { + +BaseSensorObject::BaseSensorObject() : mCallback(nullptr) { +} + +bool BaseSensorObject::setEventCallback(SensorEventCallback* callback) { + if (mCallback != nullptr) { + ALOGE("callback is already assigned, cannot change."); + return false; + } + mCallback = callback; + return true; +} + +void BaseSensorObject::getUuid(uint8_t* uuid) const { + // default uuid denoting uuid feature is not supported on this sensor. + memset(uuid, 0, 16); +} + +int BaseSensorObject::flush() { + static const sensors_event_t event = { + .type = SENSOR_TYPE_META_DATA, + .timestamp = TIMESTAMP_AUTO_FILL // timestamp will be filled at dispatcher + }; + generateEvent(event); + return 0; +} + +void BaseSensorObject::generateEvent(const sensors_event_t &e) { + if (mCallback) { + mCallback->submitEvent(this, e); + } +} + +} // namespace SensorHalExt +} // namespace android + |