/* * Copyright (C) 2021 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. */ #ifndef android_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleHardware_H_ #define android_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleHardware_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace android { namespace hardware { namespace automotive { namespace vehicle { class MockVehicleHardware final : public IVehicleHardware { public: MockVehicleHardware(); ~MockVehicleHardware(); std::vector getAllPropertyConfigs() const override; aidl::android::hardware::automotive::vehicle::StatusCode setValues( std::shared_ptr callback, const std::vector& requests) override; aidl::android::hardware::automotive::vehicle::StatusCode getValues( std::shared_ptr callback, const std::vector& requests) const override; DumpResult dump(const std::vector&) override; aidl::android::hardware::automotive::vehicle::StatusCode checkHealth() override; void registerOnPropertyChangeEvent( std::unique_ptr callback) override; void registerOnPropertySetErrorEvent(std::unique_ptr) override; aidl::android::hardware::automotive::vehicle::StatusCode subscribe( aidl::android::hardware::automotive::vehicle::SubscribeOptions options) override; aidl::android::hardware::automotive::vehicle::StatusCode unsubscribe(int32_t propId, int32_t areaId) override; std::chrono::nanoseconds getPropertyOnChangeEventBatchingWindow() override; // Test functions. void setPropertyConfigs( const std::vector& configs); void addGetValueResponses( const std::vector& responses); void addSetValueResponses( const std::vector& responses); void setGetValueResponder( std::function, const std::vector< aidl::android::hardware::automotive::vehicle::GetValueRequest>&)>&& responder); std::vector nextGetValueRequests(); std::vector nextSetValueRequests(); void setStatus(const char* functionName, aidl::android::hardware::automotive::vehicle::StatusCode status); void setSleepTime(int64_t timeInNano); void setDumpResult(DumpResult result); void sendOnPropertySetErrorEvent(const std::vector& errorEvents); void setPropertyOnChangeEventBatchingWindow(std::chrono::nanoseconds window); std::set> getSubscribedOnChangePropIdAreaIds(); std::set> getSubscribedContinuousPropIdAreaIds(); std::vector getSubscribeOptions(); void clearSubscribeOptions(); private: mutable std::mutex mLock; mutable std::condition_variable mCv; mutable std::atomic mThreadCount; std::vector mPropertyConfigs GUARDED_BY(mLock); mutable std::list> mGetValueRequests GUARDED_BY(mLock); mutable std::list> mGetValueResponses GUARDED_BY(mLock); mutable std::list> mSetValueRequests GUARDED_BY(mLock); mutable std::list> mSetValueResponses GUARDED_BY(mLock); std::unordered_map mStatusByFunctions GUARDED_BY(mLock); int64_t mSleepTime GUARDED_BY(mLock) = 0; std::unique_ptr mPropertyChangeCallback GUARDED_BY(mLock); std::unique_ptr mPropertySetErrorCallback GUARDED_BY(mLock); std::function, const std::vector&)> mGetValueResponder GUARDED_BY(mLock); std::chrono::nanoseconds mEventBatchingWindow GUARDED_BY(mLock) = std::chrono::nanoseconds(0); std::set> mSubOnChangePropIdAreaIds GUARDED_BY(mLock); std::vector mSubscribeOptions GUARDED_BY(mLock); template aidl::android::hardware::automotive::vehicle::StatusCode returnResponse( std::shared_ptr)>> callback, std::list>* storedResponses) const; template aidl::android::hardware::automotive::vehicle::StatusCode handleRequestsLocked( const char* functionName, std::shared_ptr)>> callback, const std::vector& requests, std::list>* storedRequests, std::list>* storedResponses) const REQUIRES(mLock); aidl::android::hardware::automotive::vehicle::StatusCode subscribePropIdAreaId( int32_t propId, int32_t areaId, float sampleRateHz); DumpResult mDumpResult; // RecurrentTimer is thread-safe. std::shared_ptr mRecurrentTimer; std::unordered_map>>> mRecurrentActions GUARDED_BY(mLock); }; } // namespace vehicle } // namespace automotive } // namespace hardware } // namespace android #endif // android_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleHardware_H_