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 eof;
46  bool buffered;
47  const char *type;
49 
50 #define CALLBACK_READER_INIT ((CallbackReader){ .cb = CALLBACK_NONE, \
51  .self = NULL, \
52  .buffer = GA_EMPTY_INIT_VALUE, \
53  .buffered = false, \
54  .type = NULL })
55 static inline bool callback_reader_set(CallbackReader reader)
56 {
57  return reader.cb.type != kCallbackNone || reader.self;
58 }
59 
60 struct Channel {
61  uint64_t id;
62  size_t refcount;
64 
66  union {
73  } stream;
74 
75  bool is_rpc;
78 
83 
86 };
87 
88 EXTERN PMap(uint64_t) *channels;
89 
90 #ifdef INCLUDE_GENERATED_DECLARATIONS
91 # include "channel.h.generated.h"
92 #endif
93 
95 static inline Channel *find_channel(uint64_t id)
96 {
97  return pmap_get(uint64_t)(channels, id);
98 }
99 
100 static inline Stream *channel_instream(Channel *chan)
102 {
103  switch (chan->streamtype) {
104  case kChannelStreamProc:
105  return &chan->stream.proc.in;
106 
108  return &chan->stream.socket;
109 
110  case kChannelStreamStdio:
111  return &chan->stream.stdio.out;
112 
115  abort();
116  }
117  abort();
118 }
119 
120 static inline Stream *channel_outstream(Channel *chan)
122 {
123  switch (chan->streamtype) {
124  case kChannelStreamProc:
125  return &chan->stream.proc.out;
126 
128  return &chan->stream.socket;
129 
130  case kChannelStreamStdio:
131  return &chan->stream.stdio.in;
132 
135  abort();
136  }
137  abort();
138 }
139 
140 
141 #endif // NVIM_CHANNEL_H
Definition: channel.h:17
Definition: process.h:17
Definition: channel.h:28
Stream in
Definition: process.h:26
bool callback_scheduled
Definition: channel.h:85
garray_T buffer
Definition: channel.h:44
Terminal * term
Definition: channel.h:77
Definition: channel.h:60
union Channel::@4 stream
CallbackReader on_stderr
Definition: channel.h:80
EXTERN PMap(uint64_t)*channels
Teardown the module.
Definition: channel.c:18
bool is_rpc
Definition: channel.h:75
Definition: channel.h:27
MultiQueue * events
Definition: channel.h:63
LibuvProcess uv
Definition: channel.h:68
ChannelStreamType
Definition: channel.h:15
StdioPair stdio
Definition: channel.h:71
RpcState rpc
Definition: channel.h:76
const char * type
Definition: channel.h:47
Definition: channel.h:18
ChannelStreamType streamtype
Definition: channel.h:65
#define pmap_get(T)
Definition: map.h:58
uint64_t id
Definition: channel.h:61
size_t refcount
Definition: channel.h:62
#define EXTERN
Definition: macros.h:7
Definition: channel_defs.h:29
Process proc
Definition: channel.h:67
int exit_status
Definition: channel.h:82
ChannelPart
Definition: channel.h:23
dict_T * self
Definition: channel.h:43
Definition: pty_process_unix.h:8
Stream out
Definition: process.h:26
Definition: coverity-model.c:40
Definition: channel.h:19
Definition: garray.h:12
Callback on_exit
Definition: channel.h:81
Definition: libuv_process.h:8
CallbackReader on_data
Definition: channel.h:79
Definition: channel.h:24
Definition: stream.h:32
Stream out
Definition: channel.h:34
Definition: typval.h:76
Definition: channel.h:37
bool callback_busy
Definition: channel.h:84
Stream in
Definition: channel.h:33
PtyProcess pty
Definition: channel.h:69
Definition: channel.h:41
Definition: channel.h:20
Definition: channel.h:26
bool closed
Definition: channel.h:38
Stream socket
Definition: channel.h:70
bool eof
Definition: channel.h:45
Definition: channel.h:16
StderrState err
Definition: channel.h:72
Definition: channel.h:25
CallbackType type
Definition: typval.h:81
bool buffered
Definition: channel.h:46
#define FUNC_ATTR_NONNULL_ALL
Definition: func_attr.h:243
Definition: terminal.c:105
Callback cb
Definition: channel.h:42
Definition: multiqueue.c:73
Definition: channel.h:32
Definition: typval.h:71