process.h
Go to the documentation of this file.
1 #ifndef NVIM_EVENT_PROCESS_H
2 #define NVIM_EVENT_PROCESS_H
3 
4 #include "nvim/event/loop.h"
5 #include "nvim/event/rstream.h"
6 #include "nvim/event/wstream.h"
7 
8 typedef enum {
11 } ProcessType;
12 
13 typedef struct process Process;
14 typedef void (*process_exit_cb)(Process *proc, int status, void *data);
15 typedef void (*internal_process_cb)(Process *proc);
16 
17 struct process {
20  void *data;
22  uint8_t exit_signal; // Signal used when killing (on Windows).
23  uint64_t stopped_time; // process_stop() timestamp
24  const char *cwd;
25  char **argv;
29  bool closed, detach;
31 };
32 
33 
34 static inline Process process_init(Loop *loop, ProcessType type, void *data)
35 {
36  return (Process) {
37  .type = type,
38  .data = data,
39  .loop = loop,
40  .events = NULL,
41  .pid = 0,
42  .status = -1,
43  .refcount = 0,
44  .stopped_time = 0,
45  .cwd = NULL,
46  .argv = NULL,
47  .in = { .closed = false },
48  .out = { .closed = false },
49  .err = { .closed = false },
50  .cb = NULL,
51  .closed = false,
52  .internal_close_cb = NULL,
53  .internal_exit_cb = NULL,
54  .detach = false
55  };
56 }
57 
58 static inline bool process_is_stopped(Process *proc)
59 {
60  bool exited = (proc->status >= 0);
61  return exited || (proc->stopped_time != 0);
62 }
63 
64 #ifdef INCLUDE_GENERATED_DECLARATIONS
65 # include "event/process.h.generated.h"
66 #endif
67 #endif // NVIM_EVENT_PROCESS_H
Definition: process.h:17
process_exit_cb cb
Definition: process.h:27
bool closed
Definition: process.h:29
ProcessType
Definition: process.h:8
Stream in
Definition: process.h:26
internal_process_cb internal_exit_cb
Definition: process.h:28
internal_process_cb internal_close_cb
Definition: process.h:28
uint8_t exit_signal
Definition: process.h:22
return NULL
Definition: eval.c:23776
void * data
Definition: process.h:20
Definition: process.h:10
char ** argv
Definition: process.h:25
void(* internal_process_cb)(Process *proc)
Definition: process.h:15
void(* process_exit_cb)(Process *proc, int status, void *data)
Definition: process.h:14
const char * cwd
Definition: process.h:24
int status
Definition: process.h:21
uint64_t stopped_time
Definition: process.h:23
bool detach
Definition: process.h:29
Stream err
Definition: process.h:26
Stream out
Definition: process.h:26
Definition: stream.h:32
Definition: loop.h:17
Definition: process.h:9
Loop * loop
Definition: process.h:19
int refcount
Definition: process.h:21
MultiQueue * events
Definition: process.h:30
Definition: multiqueue.c:73
MultiQueue * events
Definition: loop.h:19
ProcessType type
Definition: process.h:18
int pid
Definition: process.h:21