channel.h
Go to the documentation of this file.
1 #ifndef NVIM_CHANNEL_H
2 #define NVIM_CHANNEL_H
3 
4 #include "nvim/main.h"
5 #include "nvim/event/socket.h"
6 #include "nvim/event/process.h"
7 #include "nvim/os/pty_process.h"
9 #include "nvim/eval/typval.h"
11 
12 #define CHAN_STDIO 1
13 #define CHAN_STDERR 2
14 
15 typedef enum {
22 
23 typedef enum {
29 } ChannelPart;
30 
31 
32 typedef struct {
35 } StdioPair;
36 
37 typedef struct {
38  bool closed;
39 } StderrState;
40 
41 typedef struct {
43  dict_T *self;
45  bool buffered;
47 
48 #define CALLBACK_READER_INIT ((CallbackReader){ .cb = CALLBACK_NONE, \
49  .self = NULL, \
50  .buffer = GA_EMPTY_INIT_VALUE, \
51  .buffered = false })
52 static inline bool callback_reader_set(CallbackReader reader)
53 {
54  return reader.cb.type != kCallbackNone || reader.self;
55 }
56 
57 struct Channel {
58  uint64_t id;
59  size_t refcount;
61 
63  union {
70  } stream;
71 
72  bool is_rpc;
75 
79 };
80 
81 EXTERN PMap(uint64_t) *channels;
82 
83 #ifdef INCLUDE_GENERATED_DECLARATIONS
84 # include "channel.h.generated.h"
85 #endif
86 
88 static inline Channel *find_channel(uint64_t id)
89 {
90  return pmap_get(uint64_t)(channels, id);
91 }
92 
93 static inline Stream *channel_instream(Channel *chan)
95 {
96  switch (chan->streamtype) {
97  case kChannelStreamProc:
98  return &chan->stream.proc.in;
99 
101  return &chan->stream.socket;
102 
103  case kChannelStreamStdio:
104  return &chan->stream.stdio.out;
105 
108  abort();
109  }
110  abort();
111 }
112 
113 static inline Stream *channel_outstream(Channel *chan)
115 {
116  switch (chan->streamtype) {
117  case kChannelStreamProc:
118  return &chan->stream.proc.out;
119 
121  return &chan->stream.socket;
122 
123  case kChannelStreamStdio:
124  return &chan->stream.stdio.in;
125 
128  abort();
129  }
130  abort();
131 }
132 
133 
134 #endif // NVIM_CHANNEL_H
Definition: channel.h:17
Definition: process.h:17
Definition: channel.h:28
Stream in
Definition: process.h:25
garray_T buffer
Definition: channel.h:44
Terminal * term
Definition: channel.h:74
Definition: channel.h:57
CallbackReader on_stderr
Definition: channel.h:77
union Channel::@5 stream
EXTERN PMap(uint64_t)*channels
Definition: channel.c:18
bool is_rpc
Definition: channel.h:72
Definition: channel.h:27
MultiQueue * events
Definition: channel.h:60
LibuvProcess uv
Definition: channel.h:65
ChannelStreamType
Definition: channel.h:15
StdioPair stdio
Definition: channel.h:68
RpcState rpc
Definition: channel.h:73
Definition: channel.h:18
ChannelStreamType streamtype
Definition: channel.h:62
#define pmap_get(T)
Definition: map.h:58
uint64_t id
Definition: channel.h:58
size_t refcount
Definition: channel.h:59
#define EXTERN
Definition: macros.h:7
Definition: channel_defs.h:28
Process proc
Definition: channel.h:64
ChannelPart
Definition: channel.h:23
dict_T * self
Definition: channel.h:43
Definition: pty_process_unix.h:8
Stream out
Definition: process.h:25
Definition: coverity-model.c:40
Definition: channel.h:19
Definition: garray.h:12
Callback on_exit
Definition: channel.h:78
Definition: libuv_process.h:8
Definition: channel.h:24
CallbackReader on_stdout
Definition: channel.h:76
Definition: stream.h:32
Stream out
Definition: channel.h:34
Definition: typval.h:78
Definition: channel.h:37
Stream in
Definition: channel.h:33
PtyProcess pty
Definition: channel.h:66
Definition: channel.h:41
Definition: channel.h:20
Definition: channel.h:26
bool closed
Definition: channel.h:38
Stream socket
Definition: channel.h:67
Definition: channel.h:16
StderrState err
Definition: channel.h:69
Definition: channel.h:25
CallbackType type
Definition: typval.h:83
bool buffered
Definition: channel.h:45
#define FUNC_ATTR_NONNULL_ALL
Definition: func_attr.h:238
Definition: terminal.c:104
Callback cb
Definition: channel.h:42
Definition: multiqueue.c:73
Definition: channel.h:32
Definition: typval.h:73