diff options
author | Brian Stack <bstack@google.com> | 2018-09-26 16:17:33 -0700 |
---|---|---|
committer | Brian Stack <bstack@google.com> | 2018-10-05 10:03:43 -0700 |
commit | bc5a39bd249b46d6d6528e4489761ef0d8644aef (patch) | |
tree | 960b29716e971e2bd28bf2f0401febd17031a33b /sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp | |
parent | f0dbf813b22624375727f1f50d8d7df6c5dc5a8a (diff) |
Create SensorsHidlEnvironmentBase
Move common parts of SensorsHidlEnvironment into a base class so they
can be reused with other versions of sensors tests.
Bug: 111070257
Test: Builds
Change-Id: I1e04e734d00308adff35b9c16de1499573a84b03
Diffstat (limited to 'sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp')
-rw-r--r-- | sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp b/sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp new file mode 100644 index 0000000000..21c08d297c --- /dev/null +++ b/sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 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 "SensorsHidlEnvironmentBase.h" + +void SensorsHidlEnvironmentBase::HidlSetUp() { + ASSERT_TRUE(resetHal()) << "could not get hidl service"; + + collectionEnabled = false; + startPollingThread(); + + // In case framework just stopped for test and there is sensor events in the pipe, + // wait some time for those events to be cleared to avoid them messing up the test. + std::this_thread::sleep_for(std::chrono::seconds(3)); +} + +void SensorsHidlEnvironmentBase::HidlTearDown() { + stopThread = true; + pollThread.detach(); +} + +void SensorsHidlEnvironmentBase::catEvents(std::vector<Event>* output) { + std::lock_guard<std::mutex> lock(events_mutex); + if (output) { + output->insert(output->end(), events.begin(), events.end()); + } + events.clear(); +} + +void SensorsHidlEnvironmentBase::setCollection(bool enable) { + std::lock_guard<std::mutex> lock(events_mutex); + collectionEnabled = enable; +} + +void SensorsHidlEnvironmentBase::addEvent(const Event& ev) { + std::lock_guard<std::mutex> lock(events_mutex); + if (collectionEnabled) { + events.push_back(ev); + } +} |