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 
17 #include "BaseSensorObject.h"
18 #include "SensorEventCallback.h"
19 #include "Utils.h"
20 
21 #include <cstring>
22 
23 namespace android {
24 namespace SensorHalExt {
25 
BaseSensorObject()26 BaseSensorObject::BaseSensorObject() : mCallback(nullptr) {
27 }
28 
setEventCallback(SensorEventCallback * callback)29 bool BaseSensorObject::setEventCallback(SensorEventCallback* callback) {
30     if (mCallback != nullptr) {
31         return false;
32     }
33     mCallback = callback;
34     return true;
35 }
36 
getUuid(uint8_t * uuid) const37 void BaseSensorObject::getUuid(uint8_t* uuid) const {
38     // default uuid denoting uuid feature is not supported on this sensor.
39     memset(uuid, 0, 16);
40 }
41 
flush()42 int BaseSensorObject::flush() {
43     static const sensors_event_t event = {
44         .type = SENSOR_TYPE_META_DATA,
45         .meta_data.what = META_DATA_FLUSH_COMPLETE,
46         .timestamp = TIMESTAMP_AUTO_FILL  // timestamp will be filled at dispatcher
47     };
48     generateEvent(event);
49     return 0;
50 }
51 
generateEvent(const sensors_event_t & e)52 void BaseSensorObject::generateEvent(const sensors_event_t &e) {
53     if (mCallback) {
54         mCallback->submitEvent(SP_THIS, e);
55     }
56 }
57 
58 } // namespace SensorHalExt
59 } // namespace android
60 
61