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_; } 44 void* AllocateTransactionState() override; 45 void FreeTransactionState(void* state) override; 46 47 Status<void> SendImpulse(int opcode, const void* buffer, 48 size_t length) override; 49 50 Status<int> SendWithInt(void* transaction_state, int opcode, 51 const iovec* send_vector, size_t send_count, 52 const iovec* receive_vector, 53 size_t receive_count) override; 54 Status<LocalHandle> SendWithFileHandle(void* transaction_state, int opcode, 55 const iovec* send_vector, 56 size_t send_count, 57 const iovec* receive_vector, 58 size_t receive_count) override; 59 Status<LocalChannelHandle> SendWithChannelHandle( 60 void* transaction_state, int opcode, const iovec* send_vector, 61 size_t send_count, const iovec* receive_vector, 62 size_t receive_count) override; 63 64 FileReference PushFileHandle(void* transaction_state, 65 const LocalHandle& handle) override; 66 FileReference PushFileHandle(void* transaction_state, 67 const BorrowedHandle& handle) override; 68 ChannelReference PushChannelHandle(void* transaction_state, 69 const LocalChannelHandle& handle) override; 70 ChannelReference PushChannelHandle( 71 void* transaction_state, const BorrowedChannelHandle& handle) override; 72 bool GetFileHandle(void* transaction_state, FileReference ref, 73 LocalHandle* handle) const override; 74 bool GetChannelHandle(void* transaction_state, ChannelReference ref, 75 LocalChannelHandle* handle) const override; 76 77 private: 78 explicit ClientChannel(LocalChannelHandle channel_handle); 79 80 Status<int> SendAndReceive(void* transaction_state, int opcode, 81 const iovec* send_vector, size_t send_count, 82 const iovec* receive_vector, size_t receive_count); 83 84 LocalChannelHandle channel_handle_; 85 ChannelEventReceiver* channel_data_; 86 std::mutex socket_mutex_; 87 }; 88 89 } // namespace uds 90 } // namespace pdx 91 } // namespace android 92 93 #endif // ANDROID_PDX_UDS_CLIENT_CHANNEL_H_ 94