blob: 68c16616114fd4a802a1b2c4a49f985b557e3089 [file] [log] [blame]
Peng Xueb4d6282015-12-10 18:02:41 -08001/*
2 * Copyright (C) 2010 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#ifndef ANDROID_MOST_RECENT_EVENT_LOGGER_H
18#define ANDROID_MOST_RECENT_EVENT_LOGGER_H
19
20#include "SensorService.h"
21
22namespace android {
23
24class SensorService;
25
26// A circular buffer of TrimmedSensorEvents. The size of this buffer is typically 10. The last N
27// events generated from the sensor are stored in this buffer. The buffer is NOT cleared when the
28// sensor unregisters and as a result very old data in the dumpsys output can be seen, which is an
29// intended behavior.
30class SensorService::MostRecentEventLogger {
31public:
32 MostRecentEventLogger(int sensorType);
33 void addEvent(const sensors_event_t& event);
34 void printBuffer(String8& buffer) const;
35 bool populateLastEvent(sensors_event_t *event);
36 ~MostRecentEventLogger();
37
38private:
39 // sensor_event_t with only the data and the timestamp.
40 static const size_t LOG_SIZE = 10;
41 static const size_t LOG_SIZE_LARGE = 50;
42
43 struct TrimmedSensorEvent {
44 union {
45 float *mData;
46 uint64_t mStepCounter;
47 };
48 // Timestamp from the sensors_event_t.
49 int64_t mTimestamp;
50 // HH:MM:SS local time at which this sensor event is read at SensorService. Useful
51 // for debugging.
52 int32_t mHour, mMin, mSec;
53
54 TrimmedSensorEvent(int sensorType);
55 static bool isSentinel(const TrimmedSensorEvent& event);
56
57 ~TrimmedSensorEvent() {
58 delete [] mData;
59 }
60 };
61
62 int mNextInd;
63 int mSensorType;
64 int mBufSize;
65 TrimmedSensorEvent ** mTrimmedSensorEventArr;
66};
67
68} // namespace android;
69
70#endif // ANDROID_MOST_RECENT_EVENT_LOGGER_H
71