1 #ifndef ANDROID_PDX_UDS_CLIENT_CHANNEL_H_ 2 #define ANDROID_PDX_UDS_CLIENT_CHANNEL_H_ 3 4 #include <pdx/client_channel.h> 5 6 #include <mutex> 7 8 #include <uds/channel_event_set.h> 9 #include <uds/channel_manager.h> 10 #include <uds/service_endpoint.h> 11 12 namespace android { 13 namespace pdx { 14 namespace uds { 15 16 class ClientChannel : public pdx::ClientChannel { 17 public: 18 ~ClientChannel() override; 19 20 static std::unique_ptr<pdx::ClientChannel> Create( 21 LocalChannelHandle channel_handle); 22 GetIpcTag()23 uint32_t GetIpcTag() const override { return Endpoint::kIpcTag; } 24 event_fd()25 int event_fd() const override { 26 return channel_data_ ? channel_data_->event_fd().Get() : -1; 27 } 28 GetEventSources()29 std::vector<EventSource> GetEventSources() const override { 30 if (channel_data_) 31 return channel_data_->GetEventSources(); 32 else 33 return {}; 34 } 35 GetEventMask(int)36 Status<int> GetEventMask(int /*events*/) override { 37 if (channel_data_) 38 return channel_data_->GetPendingEvents(); 39 else 40 return ErrorStatus(EINVAL); 41 } 42 GetChannelHandle()43 LocalChannelHandle& GetChannelHandle() override { return channel_handle_; } GetChannelHandle()44 const LocalChannelHandle& GetChannelHandle() const override { 45 return channel_handle_; 46 } 47 void* AllocateTransactionState() override; 48 void FreeTransactionState(void* state) override; 49 50 Status<void> SendImpulse(int opcode, const void* buffer, 51 size_t length) override; 52 53 Status<int> SendWithInt(void* transaction_state, int opcode, 54 const iovec* send_vector, size_t send_count, 55 const iovec* receive_vector, 56 size_t receive_count) override; 57 Status<LocalHandle> SendWithFileHandle(void* transaction_state, int opcode, 58 const iovec* send_vector, 59 size_t send_count, 60 const iovec* receive_vector, 61 size_t receive_count) override; 62 Status<LocalChannelHandle> SendWithChannelHandle( 63 void* transaction_state, int opcode, const iovec* send_vector, 64 size_t send_count, const iovec* receive_vector, 65 size_t receive_count) override; 66 67 FileReference PushFileHandle(void* transaction_state, 68 const LocalHandle& handle) override; 69 FileReference PushFileHandle(void* transaction_state, 70 const BorrowedHandle& handle) override; 71 ChannelReference PushChannelHandle(void* transaction_state, 72 const LocalChannelHandle& handle) override; 73 ChannelReference PushChannelHandle( 74 void* transaction_state, const BorrowedChannelHandle& handle) override; 75 bool GetFileHandle(void* transaction_state, FileReference ref, 76 LocalHandle* handle) const override; 77 bool GetChannelHandle(void* transaction_state, ChannelReference ref, 78 LocalChannelHandle* handle) const override; 79 80 std::unique_ptr<pdx::ChannelParcelable> TakeChannelParcelable() override; 81 82 private: 83 explicit ClientChannel(LocalChannelHandle channel_handle); 84 85 Status<int> SendAndReceive(void* transaction_state, int opcode, 86 const iovec* send_vector, size_t send_count, 87 const iovec* receive_vector, size_t receive_count); 88 89 LocalChannelHandle channel_handle_; 90 ChannelEventReceiver* channel_data_; 91 std::mutex socket_mutex_; 92 }; 93 94 } // namespace uds 95 } // namespace pdx 96 } // namespace android 97 98 #endif // ANDROID_PDX_UDS_CLIENT_CHANNEL_H_ 99