/* * Copyright (c) 2022, 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 CPP_VHAL_CLIENT_INCLUDE_HIDLVHALCLIENT_H_ #define CPP_VHAL_CLIENT_INCLUDE_HIDLVHALCLIENT_H_ #include "IVhalClient.h" #include #include #include #include #include // NOLINT #include namespace android { namespace frameworks { namespace automotive { namespace vhal { namespace hidl_test { class HidlVhalClientTest; } // namespace hidl_test class HidlVhalClient final : public IVhalClient { public: static std::shared_ptr create(); static std::shared_ptr tryCreate(); static std::shared_ptr tryCreate(const char* descriptor); explicit HidlVhalClient( android::sp hal); ~HidlVhalClient(); bool isAidlVhal() override; std::unique_ptr createHalPropValue(int32_t propId) override; std::unique_ptr createHalPropValue(int32_t propId, int32_t areaId) override; void getValue(const IHalPropValue& requestValue, std::shared_ptr callback) override; void setValue(const IHalPropValue& value, std::shared_ptr callback) override; // Add the callback that would be called when VHAL binder died. VhalClientResult addOnBinderDiedCallback( std::shared_ptr callback) override; // Remove a previously added OnBinderDied callback. VhalClientResult removeOnBinderDiedCallback( std::shared_ptr callback) override; VhalClientResult>> getAllPropConfigs() override; VhalClientResult>> getPropConfigs( std::vector propIds) override; std::unique_ptr getSubscriptionClient( std::shared_ptr callback) override; private: friend class hidl_test::HidlVhalClientTest; class DeathRecipient : public android::hardware::hidl_death_recipient { public: explicit DeathRecipient(HidlVhalClient* client); void serviceDied(uint64_t cookie, const android::wp& who) override; private: HidlVhalClient* mClient; }; android::sp<::android::hardware::automotive::vehicle::V2_0::IVehicle> mHal; android::sp mDeathRecipient; std::mutex mLock; std::unordered_set> mOnBinderDiedCallbacks GUARDED_BY(mLock); void onBinderDied(); }; class SubscriptionCallback; class HidlSubscriptionClient final : public ISubscriptionClient { public: ~HidlSubscriptionClient() = default; HidlSubscriptionClient(android::sp hal, std::shared_ptr callback); VhalClientResult subscribe( const std::vector& options) override; VhalClientResult unsubscribe(const std::vector& propIds) override; private: std::shared_ptr mCallback; android::sp mHal; android::sp mVhalCallback; }; class SubscriptionCallback : public android::hardware::automotive::vehicle::V2_0::IVehicleCallback { public: explicit SubscriptionCallback(std::shared_ptr callback); android::hardware::Return onPropertyEvent( const android::hardware::hidl_vec< hardware::automotive::vehicle::V2_0::VehiclePropValue>& propValues) override; android::hardware::Return onPropertySet( const android::hardware::automotive::vehicle::V2_0::VehiclePropValue& propValue) override; android::hardware::Return onPropertySetError( android::hardware::automotive::vehicle::V2_0::StatusCode status, int32_t propId, int32_t areaId) override; private: std::shared_ptr mCallback; }; } // namespace vhal } // namespace automotive } // namespace frameworks } // namespace android #endif // CPP_VHAL_CLIENT_INCLUDE_HIDLVHALCLIENT_H_