robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
d0a262db88
master
1#pragma once 2 3#include <stdbool.h> 4#include <stdint.h> 5#include <stdlib.h> 6 7#include "nvim/autocmd_defs.h" 8#include "nvim/channel_defs.h" // IWYU pragma: keep 9#include "nvim/eval/typval_defs.h" 10#include "nvim/event/defs.h" 11#include "nvim/event/libuv_proc.h" 12#include "nvim/macros_defs.h" 13#include "nvim/map_defs.h" 14#include "nvim/msgpack_rpc/channel_defs.h" 15#include "nvim/os/pty_proc.h" 16#include "nvim/types_defs.h" 17 18struct Channel { 19uint64_t id ; 20size_t refcount ; 21MultiQueue * events ; 22 23ChannelStreamType streamtype ; 24union { 25Proc proc ; 26LibuvProc uv ; 27PtyProc pty ; 28RStream socket ; 29StdioPair stdio ; 30StderrState err ; 31InternalState internal ; 32 }stream ; 33 34bool is_rpc ; 35bool detach ;///< Prevents self-exit on channel-close. Normally, Nvim self-exits if its primary 36///< RPC channel is closed, unless detach=true. Note: currently, detach=false does 37///< not FORCE self-exit. 38RpcState rpc ; 39Terminal * term ; 40 41CallbackReader on_data ; 42CallbackReader on_stderr ; 43Callback on_exit ; 44int exit_status ;///< Process exit-code (if the channel wraps a process). 45 46bool callback_busy ; 47bool callback_scheduled ; 48bool did_close_event ; 49}; 50 51#include "channel.h.generated.h" 52#include "channel.h.inline.generated.h" 53 54static inline bool callback_reader_set (CallbackReader reader ) 55{ 56return reader .cb .type != kCallbackNone || reader .self ; 57} 58 59EXTERN PMap (uint64_t )channels INIT (= MAP_INIT ); 60 61EXTERN Callback on_print INIT (= CALLBACK_INIT ); 62 63/// @returns Channel with the id or NULL if not found 64static inline Channel * find_channel (uint64_t id ) 65{ 66return (Channel * )pmap_get (uint64_t )(& channels ,id ); 67} 68 69static inline Stream * channel_instream (Channel * chan ) 70FUNC_ATTR_NONNULL_ALL 71{ 72switch (chan -> streamtype ) { 73case kChannelStreamProc : 74return & chan -> stream .proc .in ; 75 76case kChannelStreamSocket : 77return & chan -> stream .socket .s ; 78 79case kChannelStreamStdio : 80return & chan -> stream .stdio .out ; 81 82case kChannelStreamInternal : 83case kChannelStreamStderr : 84abort (); 85 } 86abort (); 87} 88 89static inline RStream * channel_outstream (Channel * chan ) 90FUNC_ATTR_NONNULL_ALL 91{ 92switch (chan -> streamtype ) { 93case kChannelStreamProc : 94return & chan -> stream .proc .out ; 95 96case kChannelStreamSocket : 97return & chan -> stream .socket ; 98 99case kChannelStreamStdio : 100return & chan -> stream .stdio .in ; 101 102case kChannelStreamInternal : 103case kChannelStreamStderr : 104abort (); 105 } 106abort (); 107}