1#ifndef ANDROID_PDX_CLIENT_CHANNEL_H_
2#define ANDROID_PDX_CLIENT_CHANNEL_H_
3
4#include <vector>
5
6#include <pdx/channel_handle.h>
7#include <pdx/file_handle.h>
8#include <pdx/status.h>
9
10struct iovec;
11
12namespace android {
13namespace pdx {
14
15class ClientChannel {
16 public:
17  virtual ~ClientChannel() = default;
18
19  // Returns a tag that uniquely identifies a specific underlying IPC transport.
20  virtual uint32_t GetIpcTag() const = 0;
21
22  virtual int event_fd() const = 0;
23  virtual Status<int> GetEventMask(int events) = 0;
24
25  struct EventSource {
26    int event_fd;
27    int event_mask;
28  };
29
30  // Returns a set of event-generating fds with and event mask for each. These
31  // fds are owned by the ClientChannel and must never be closed by the caller.
32  virtual std::vector<EventSource> GetEventSources() const = 0;
33
34  virtual LocalChannelHandle& GetChannelHandle() = 0;
35  virtual void* AllocateTransactionState() = 0;
36  virtual void FreeTransactionState(void* state) = 0;
37
38  virtual Status<void> SendImpulse(int opcode, const void* buffer,
39                                   size_t length) = 0;
40
41  virtual Status<int> SendWithInt(void* transaction_state, int opcode,
42                                  const iovec* send_vector, size_t send_count,
43                                  const iovec* receive_vector,
44                                  size_t receive_count) = 0;
45  virtual Status<LocalHandle> SendWithFileHandle(
46      void* transaction_state, int opcode, const iovec* send_vector,
47      size_t send_count, const iovec* receive_vector, size_t receive_count) = 0;
48  virtual Status<LocalChannelHandle> SendWithChannelHandle(
49      void* transaction_state, int opcode, const iovec* send_vector,
50      size_t send_count, const iovec* receive_vector, size_t receive_count) = 0;
51
52  virtual FileReference PushFileHandle(void* transaction_state,
53                                       const LocalHandle& handle) = 0;
54  virtual FileReference PushFileHandle(void* transaction_state,
55                                       const BorrowedHandle& handle) = 0;
56  virtual ChannelReference PushChannelHandle(
57      void* transaction_state, const LocalChannelHandle& handle) = 0;
58  virtual ChannelReference PushChannelHandle(
59      void* transaction_state, const BorrowedChannelHandle& handle) = 0;
60  virtual bool GetFileHandle(void* transaction_state, FileReference ref,
61                             LocalHandle* handle) const = 0;
62  virtual bool GetChannelHandle(void* transaction_state, ChannelReference ref,
63                                LocalChannelHandle* handle) const = 0;
64};
65
66}  // namespace pdx
67}  // namespace android
68
69#endif  // ANDROID_PDX_CLIENT_CHANNEL_H_
70