diff options
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 + |