1 /* 2 * Copyright (C) 2019 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 #pragma once 18 19 #include "CloseHandleWrapper.h" 20 21 #include <android/hardware/automotive/can/1.0/ICanBus.h> 22 #include <android/hidl/manager/1.0/IServiceNotification.h> 23 #include <utils/Mutex.h> 24 #include <VehicleBus.h> 25 26 namespace android { 27 namespace hardware { 28 namespace automotive { 29 namespace can { 30 namespace V1_0 { 31 namespace utils { 32 33 class CanClient : public ::aidl::android::hardware::automotive::vehicle::VehicleBus, 34 public hidl::manager::V1_0::IServiceNotification, 35 private ICanErrorListener, 36 private ICanMessageListener, 37 private hidl_death_recipient { 38 public: 39 virtual ~CanClient(); 40 41 virtual ::ndk::ScopedAStatus start(); 42 43 protected: 44 CanClient(const std::string& busName); 45 46 virtual void onReady(const sp<ICanBus>& canBus); 47 48 private: 49 const std::string mBusName; 50 51 CloseHandleWrapper mListenerCloseHandle; 52 CloseHandleWrapper mErrorCloseHandle; 53 54 mutable std::mutex mCanBusGuard; 55 sp<ICanBus> mCanBus GUARDED_BY(mCanBusGuard); 56 57 Return<void> onRegistration(const hidl_string&, const hidl_string& name, bool) override; 58 void serviceDied(uint64_t cookie, const wp<hidl::base::V1_0::IBase>& who) override; 59 Return<void> onError(ErrorEvent error, bool isFatal) override; 60 bool close(); 61 62 DISALLOW_COPY_AND_ASSIGN(CanClient); 63 }; 64 65 } // namespace utils 66 } // namespace V1_0 67 } // namespace can 68 } // namespace automotive 69 } // namespace hardware 70 } // namespace android 71