channel.h
Go to the documentation of this file.
1 #ifndef NVIM_CHANNEL_H
2 #define NVIM_CHANNEL_H
3 
4 #include "nvim/eval/typval.h"
6 #include "nvim/event/process.h"
7 #include "nvim/event/socket.h"
8 #include "nvim/main.h"
10 #include "nvim/os/pty_process.h"
11 
12 #define CHAN_STDIO 1
13 #define CHAN_STDERR 2
14 
15 typedef enum {
22 
23 typedef enum {
29 } ChannelPart;
30 
31 typedef enum {
35 
36 typedef struct {
39 } StdioPair;
40 
41 typedef struct {
42  bool closed;
43 } StderrState;
44 
45 typedef struct {
47  bool closed;
49 
50 typedef struct {
52  dict_T *self;
54  bool eof;
55  bool buffered;
56  const char *type;
58 
59 #define CALLBACK_READER_INIT ((CallbackReader){ .cb = CALLBACK_NONE, \
60  .self = NULL, \
61  .buffer = GA_EMPTY_INIT_VALUE, \
62  .buffered = false, \
63  .type = NULL })
64 static inline bool callback_reader_set(CallbackReader reader)
65 {
66  return reader.cb.type != kCallbackNone || reader.self;
67 }
68 
69 struct Channel {
70  uint64_t id;
71  size_t refcount;
73 
75  union {
82  InternalState internal;
83  } stream;
84 
85  bool is_rpc;
88 
93 
96 };
97 
98 EXTERN PMap(uint64_t) channels INIT(= MAP_INIT);
99 
100 EXTERN Callback on_print INIT(= CALLBACK_INIT);
101 
102 #ifdef INCLUDE_GENERATED_DECLARATIONS
103 # include "channel.h.generated.h"
104 #endif
105 
107 static inline Channel *find_channel(uint64_t id)
108 {
109  return pmap_get(uint64_t)(&channels, id);
110 }
111 
112 static inline Stream *channel_instream(Channel *chan)
114 {
115  switch (chan->streamtype) {
116  case kChannelStreamProc:
117  return &chan->stream.proc.in;
118 
120  return &chan->stream.socket;
121 
122  case kChannelStreamStdio:
123  return &chan->stream.stdio.out;
124 
127  abort();
128  }
129  abort();
130 }
131 
132 static inline Stream *channel_outstream(Channel *chan)
134 {
135  switch (chan->streamtype) {
136  case kChannelStreamProc:
137  return &chan->stream.proc.out;
138 
140  return &chan->stream.socket;
141 
142  case kChannelStreamStdio:
143  return &chan->stream.stdio.in;
144 
147  abort();
148  }
149  abort();
150 }
151 
152 
153 #endif // NVIM_CHANNEL_H
INIT
EXTERN Callback on_print INIT(=CALLBACK_INIT)
Channel
Definition: channel.h:69
Channel::events
MultiQueue * events
Definition: channel.h:72
process.h
Channel::uv
LibuvProcess uv
Definition: channel.h:77
pmap_get
#define pmap_get(T)
Definition: map.h:71
kChannelStreamSocket
@ kChannelStreamSocket
Definition: channel.h:17
kChannelPartStdout
@ kChannelPartStdout
Definition: channel.h:25
CallbackReader::cb
Callback cb
Definition: channel.h:51
kChannelPartStderr
@ kChannelPartStderr
Definition: channel.h:26
Channel::rpc
RpcState rpc
Definition: channel.h:86
Callback::type
CallbackType type
Definition: typval.h:84
pty_process
Definition: pty_process_unix.h:8
Channel::pty
PtyProcess pty
Definition: channel.h:78
ChannelStreamType
ChannelStreamType
Definition: channel.h:15
CallbackReader::buffered
bool buffered
Definition: channel.h:55
Channel::callback_busy
bool callback_busy
Definition: channel.h:94
CallbackReader::self
dict_T * self
Definition: channel.h:52
stream
Definition: stream.h:31
Channel::socket
Stream socket
Definition: channel.h:79
LuaRef
int LuaRef
Definition: types.h:23
growarray
Definition: garray.h:12
libuv_process.h
kChannelPartAll
@ kChannelPartAll
Definition: channel.h:28
InternalState::cb
LuaRef cb
Definition: channel.h:46
StderrState
Definition: channel.h:41
StdioPair::in
Stream in
Definition: channel.h:37
kChannelStreamStderr
@ kChannelStreamStderr
Definition: channel.h:19
kChannelStdinPipe
@ kChannelStdinPipe
Definition: channel.h:32
CallbackReader::buffer
garray_T buffer
Definition: channel.h:53
RpcState
Definition: channel_defs.h:29
Channel::term
Terminal * term
Definition: channel.h:87
Channel::stream
union Channel::@15 stream
FUNC_ATTR_NONNULL_ALL
#define FUNC_ATTR_NONNULL_ALL
Definition: func_attr.h:247
PMap
EXTERN PMap(uint64_t) channels INIT(
StderrState::closed
bool closed
Definition: channel.h:42
typval.h
ChannelPart
ChannelPart
Definition: channel.h:23
CallbackReader
Definition: channel.h:50
multiqueue
Definition: multiqueue.c:71
ChannelStdinMode
ChannelStdinMode
Definition: channel.h:31
kChannelStdinNull
@ kChannelStdinNull
Definition: channel.h:33
process
Definition: process.h:18
Channel::err
StderrState err
Definition: channel.h:81
EXTERN
#define EXTERN
Definition: macros.h:9
kChannelStreamStdio
@ kChannelStreamStdio
Definition: channel.h:18
kChannelStreamProc
@ kChannelStreamProc
Definition: channel.h:16
kChannelStreamInternal
@ kChannelStreamInternal
Definition: channel.h:20
StdioPair
Definition: channel.h:36
CALLBACK_INIT
#define CALLBACK_INIT
Definition: typval.h:87
main.h
pty_process.h
MAP_INIT
#define MAP_INIT
Definition: map.h:56
Channel::streamtype
ChannelStreamType streamtype
Definition: channel.h:74
Channel::is_rpc
bool is_rpc
Definition: channel.h:85
Channel::callback_scheduled
bool callback_scheduled
Definition: channel.h:95
Channel::refcount
size_t refcount
Definition: channel.h:71
socket.h
Callback
Definition: typval.h:78
kChannelPartStdin
@ kChannelPartStdin
Definition: channel.h:24
Channel::proc
Process proc
Definition: channel.h:76
Channel::on_stderr
CallbackReader on_stderr
Definition: channel.h:90
libuv_process
Definition: libuv_process.h:8
Channel::stdio
StdioPair stdio
Definition: channel.h:80
InternalState::closed
bool closed
Definition: channel.h:47
dict_T
Definition: coverity-model.c:40
Channel::id
uint64_t id
Definition: channel.h:70
InternalState
Definition: channel.h:45
StdioPair::out
Stream out
Definition: channel.h:38
CallbackReader::eof
bool eof
Definition: channel.h:54
kChannelPartRpc
@ kChannelPartRpc
Definition: channel.h:27
Channel::on_exit
Callback on_exit
Definition: channel.h:91
Channel::on_data
CallbackReader on_data
Definition: channel.h:89
id
m id
Definition: match.c:87
Channel::exit_status
int exit_status
Definition: channel.h:92
channel_defs.h
terminal
Definition: terminal.c:103
kCallbackNone
@ kCallbackNone
Definition: typval.h:72
CallbackReader::type
const char * type
Definition: channel.h:56