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 {
48 
49 typedef struct {
51  dict_T *self;
53  bool eof;
54  bool buffered;
55  const char *type;
57 
58 #define CALLBACK_READER_INIT ((CallbackReader){ .cb = CALLBACK_NONE, \
59  .self = NULL, \
60  .buffer = GA_EMPTY_INIT_VALUE, \
61  .buffered = false, \
62  .type = NULL })
63 static inline bool callback_reader_set(CallbackReader reader)
64 {
65  return reader.cb.type != kCallbackNone || reader.self;
66 }
67 
68 struct Channel {
69  uint64_t id;
70  size_t refcount;
72 
74  union {
81  InternalState internal;
82  } stream;
83 
84  bool is_rpc;
87 
92 
95 };
96 
97 EXTERN PMap(uint64_t) channels INIT(= MAP_INIT);
98 
99 #ifdef INCLUDE_GENERATED_DECLARATIONS
100 # include "channel.h.generated.h"
101 #endif
102 
104 static inline Channel *find_channel(uint64_t id)
105 {
106  return pmap_get(uint64_t)(&channels, id);
107 }
108 
109 static inline Stream *channel_instream(Channel *chan)
111 {
112  switch (chan->streamtype) {
113  case kChannelStreamProc:
114  return &chan->stream.proc.in;
115 
117  return &chan->stream.socket;
118 
119  case kChannelStreamStdio:
120  return &chan->stream.stdio.out;
121 
124  abort();
125  }
126  abort();
127 }
128 
129 static inline Stream *channel_outstream(Channel *chan)
131 {
132  switch (chan->streamtype) {
133  case kChannelStreamProc:
134  return &chan->stream.proc.out;
135 
137  return &chan->stream.socket;
138 
139  case kChannelStreamStdio:
140  return &chan->stream.stdio.in;
141 
144  abort();
145  }
146  abort();
147 }
148 
149 
150 #endif // NVIM_CHANNEL_H
Channel
Definition: channel.h:68
Channel::events
MultiQueue * events
Definition: channel.h:71
process.h
Channel::uv
LibuvProcess uv
Definition: channel.h:76
pmap_get
#define pmap_get(T)
Definition: map.h:75
INIT
EXTERN MultiQueue *ch_before_blocking_events INIT(=NULL)
kChannelStreamSocket
@ kChannelStreamSocket
Definition: channel.h:17
kChannelPartStdout
@ kChannelPartStdout
Definition: channel.h:25
CallbackReader::cb
Callback cb
Definition: channel.h:50
kChannelPartStderr
@ kChannelPartStderr
Definition: channel.h:26
Channel::rpc
RpcState rpc
Definition: channel.h:85
Callback::type
CallbackType type
Definition: typval.h:82
pty_process
Definition: pty_process_unix.h:8
Channel::pty
PtyProcess pty
Definition: channel.h:77
ChannelStreamType
ChannelStreamType
Definition: channel.h:15
Channel::stream
union Channel::@14 stream
CallbackReader::buffered
bool buffered
Definition: channel.h:54
Channel::callback_busy
bool callback_busy
Definition: channel.h:93
id
thislist id
Definition: regexp_nfa.c:5138
CallbackReader::self
dict_T * self
Definition: channel.h:51
stream
Definition: stream.h:31
Channel::socket
Stream socket
Definition: channel.h:78
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:52
RpcState
Definition: channel_defs.h:29
Channel::term
Terminal * term
Definition: channel.h:86
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:49
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:80
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
main.h
pty_process.h
MAP_INIT
#define MAP_INIT
Definition: map.h:60
Channel::streamtype
ChannelStreamType streamtype
Definition: channel.h:73
Channel::is_rpc
bool is_rpc
Definition: channel.h:84
Channel::callback_scheduled
bool callback_scheduled
Definition: channel.h:94
Channel::refcount
size_t refcount
Definition: channel.h:70
socket.h
Callback
Definition: typval.h:77
kChannelPartStdin
@ kChannelPartStdin
Definition: channel.h:24
Channel::proc
Process proc
Definition: channel.h:75
Channel::on_stderr
CallbackReader on_stderr
Definition: channel.h:89
libuv_process
Definition: libuv_process.h:8
Channel::stdio
StdioPair stdio
Definition: channel.h:79
dict_T
Definition: coverity-model.c:40
Channel::id
uint64_t id
Definition: channel.h:69
InternalState
Definition: channel.h:45
StdioPair::out
Stream out
Definition: channel.h:38
CallbackReader::eof
bool eof
Definition: channel.h:53
kChannelPartRpc
@ kChannelPartRpc
Definition: channel.h:27
Channel::on_exit
Callback on_exit
Definition: channel.h:90
Channel::on_data
CallbackReader on_data
Definition: channel.h:88
Channel::exit_status
int exit_status
Definition: channel.h:91
channel_defs.h
terminal
Definition: terminal.c:103
kCallbackNone
@ kCallbackNone
Definition: typval.h:72
CallbackReader::type
const char * type
Definition: channel.h:55