• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleCallback_H_
18 #define android_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleCallback_H_
19 
20 #include <VehicleHalTypes.h>
21 
22 #include <aidl/android/hardware/automotive/vehicle/BnVehicleCallback.h>
23 #include <android-base/thread_annotations.h>
24 
25 #include <list>
26 #include <mutex>
27 #include <optional>
28 
29 namespace android {
30 namespace hardware {
31 namespace automotive {
32 namespace vehicle {
33 
34 template <class T>
pop(std::list<T> & items)35 std::optional<T> pop(std::list<T>& items) {
36     if (items.size() > 0) {
37         auto item = std::move(items.front());
38         items.pop_front();
39         return item;
40     }
41     return std::nullopt;
42 }
43 
44 // MockVehicleCallback is a mock VehicleCallback implementation that simply stores the results.
45 class MockVehicleCallback final
46     : public aidl::android::hardware::automotive::vehicle::BnVehicleCallback {
47   public:
48     ndk::ScopedAStatus onGetValues(
49             const aidl::android::hardware::automotive::vehicle::GetValueResults& results) override;
50     ndk::ScopedAStatus onSetValues(
51             const aidl::android::hardware::automotive::vehicle::SetValueResults& results) override;
52     ndk::ScopedAStatus onPropertyEvent(
53             const aidl::android::hardware::automotive::vehicle::VehiclePropValues&,
54             int32_t) override;
55     ndk::ScopedAStatus onPropertySetError(
56             const aidl::android::hardware::automotive::vehicle::VehiclePropErrors&) override;
57 
58     // Test functions
59     std::optional<aidl::android::hardware::automotive::vehicle::GetValueResults>
60     nextGetValueResults();
61     std::optional<aidl::android::hardware::automotive::vehicle::SetValueResults>
62     nextSetValueResults();
63     std::optional<aidl::android::hardware::automotive::vehicle::VehiclePropValues>
64     nextOnPropertyEventResults();
65     size_t countOnPropertyEventResults();
66 
67   private:
68     std::mutex mLock;
69     std::list<aidl::android::hardware::automotive::vehicle::GetValueResults> mGetValueResults
70             GUARDED_BY(mLock);
71     std::list<aidl::android::hardware::automotive::vehicle::SetValueResults> mSetValueResults
72             GUARDED_BY(mLock);
73     std::list<aidl::android::hardware::automotive::vehicle::VehiclePropValues>
74             mOnPropertyEventResults GUARDED_BY(mLock);
75     int32_t mSharedMemoryFileCount GUARDED_BY(mLock);
76 };
77 
78 }  // namespace vehicle
79 }  // namespace automotive
80 }  // namespace hardware
81 }  // namespace android
82 
83 #endif  // android_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleCallback_H_
84