• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/channel_parcelable.h>
8 #include <pdx/file_handle.h>
9 #include <pdx/status.h>
10 
11 struct iovec;
12 
13 namespace android {
14 namespace pdx {
15 
16 class ClientChannel {
17  public:
18   virtual ~ClientChannel() = default;
19 
20   // Returns a tag that uniquely identifies a specific underlying IPC transport.
21   virtual uint32_t GetIpcTag() const = 0;
22 
23   virtual int event_fd() const = 0;
24   virtual Status<int> GetEventMask(int events) = 0;
25 
26   struct EventSource {
27     int event_fd;
28     int event_mask;
29   };
30 
31   // Returns a set of event-generating fds with and event mask for each. These
32   // fds are owned by the ClientChannel and must never be closed by the caller.
33   virtual std::vector<EventSource> GetEventSources() const = 0;
34 
35   virtual LocalChannelHandle& GetChannelHandle() = 0;
36   virtual const LocalChannelHandle& GetChannelHandle() const = 0;
37   virtual void* AllocateTransactionState() = 0;
38   virtual void FreeTransactionState(void* state) = 0;
39 
40   virtual Status<void> SendImpulse(int opcode, const void* buffer,
41                                    size_t length) = 0;
42 
43   virtual Status<int> SendWithInt(void* transaction_state, int opcode,
44                                   const iovec* send_vector, size_t send_count,
45                                   const iovec* receive_vector,
46                                   size_t receive_count) = 0;
47   virtual Status<LocalHandle> SendWithFileHandle(
48       void* transaction_state, int opcode, const iovec* send_vector,
49       size_t send_count, const iovec* receive_vector, size_t receive_count) = 0;
50   virtual Status<LocalChannelHandle> SendWithChannelHandle(
51       void* transaction_state, int opcode, const iovec* send_vector,
52       size_t send_count, const iovec* receive_vector, size_t receive_count) = 0;
53 
54   virtual FileReference PushFileHandle(void* transaction_state,
55                                        const LocalHandle& handle) = 0;
56   virtual FileReference PushFileHandle(void* transaction_state,
57                                        const BorrowedHandle& handle) = 0;
58   virtual ChannelReference PushChannelHandle(
59       void* transaction_state, const LocalChannelHandle& handle) = 0;
60   virtual ChannelReference PushChannelHandle(
61       void* transaction_state, const BorrowedChannelHandle& handle) = 0;
62   virtual bool GetFileHandle(void* transaction_state, FileReference ref,
63                              LocalHandle* handle) const = 0;
64   virtual bool GetChannelHandle(void* transaction_state, ChannelReference ref,
65                                 LocalChannelHandle* handle) const = 0;
66 
67   // Returns the internal state of the channel as a parcelable object. The
68   // ClientChannel is invalidated however, the channel is kept alive by the
69   // parcelable object and may be transferred to another process.
70   virtual std::unique_ptr<ChannelParcelable> TakeChannelParcelable() = 0;
71 };
72 
73 }  // namespace pdx
74 }  // namespace android
75 
76 #endif  // ANDROID_PDX_CLIENT_CHANNEL_H_
77