blob: 4e429146ebbdbf2b69d0a4bcc0606a1cea2072dc [file] [log] [blame]
Peng Xu1a00e2d2017-09-27 23:08:30 -07001/*
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#ifndef ANDROID_SENSOR_DEVICE_UTIL
18#define ANDROID_SENSOR_DEVICE_UTIL
19
20#include <android/hidl/manager/1.0/IServiceNotification.h>
21
22#include <condition_variable>
23#include <thread>
24
25using ::android::hardware::hidl_string;
26using ::android::hardware::Return;
27using ::android::hidl::manager::V1_0::IServiceNotification;
28
29namespace android {
30namespace SensorDeviceUtils {
31
32class HidlServiceRegistrationWaiter : public IServiceNotification {
33public:
34
35 HidlServiceRegistrationWaiter();
36
37 Return<void> onRegistration(const hidl_string &fqName,
38 const hidl_string &name,
39 bool preexisting) override;
40
41 void reset();
42
43 /**
44 * Wait for service restart
45 *
46 * @return true if service is restart since last reset(); false otherwise.
47 */
48 bool wait();
49private:
Martijn Coenenb41e87a2017-11-02 14:00:41 +010050 bool mRegistered;
Peng Xu1a00e2d2017-09-27 23:08:30 -070051
52 std::mutex mLock;
53 std::condition_variable mCondition;
54 bool mRestartObserved;
55};
56
57} // namespace SensorDeviceUtils
58} // namespace android;
59
60#endif // ANDROID_SENSOR_SERVICE_UTIL