aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/job_defs.h
blob: 340ef551bee50cc7581b2f7dd835019dde9a8691 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef NVIM_OS_JOB_DEFS_H
#define NVIM_OS_JOB_DEFS_H

#include <uv.h>
#include "nvim/os/rstream_defs.h"
#include "nvim/os/wstream_defs.h"

typedef struct job Job;

/// Function called when the job reads data
///
/// @param id The job id
/// @param data Some data associated with the job by the caller
typedef void (*job_exit_cb)(Job *job, void *data);

// Job startup options
// job_exit_cb Callback that will be invoked when the job exits
// maxmem Maximum amount of memory used by the job WStream
typedef struct {
  // Argument vector for the process. The first item is the
  // executable to run.
  // [consumed]
  char **argv;
  // Caller data that will be associated with the job
  void *data;
  // If true the job stdin will be available for writing with job_write,
  // otherwise it will be redirected to /dev/null
  bool writable;
  // Callback that will be invoked when data is available on stdout. If NULL
  // stdout will be redirected to /dev/null.
  rstream_cb stdout_cb;
  // Callback that will be invoked when data is available on stderr. If NULL
  // stderr will be redirected to /dev/null.
  rstream_cb  stderr_cb;
  // Callback that will be invoked when the job has exited and will not send
  // data
  job_exit_cb exit_cb;
  // Maximum memory used by the job's WStream
  size_t maxmem;
} JobOptions;

#define JOB_OPTIONS_INIT ((JobOptions) {                     \
    .argv = NULL,                                            \
    .data = NULL,                                            \
    .writable = true,                                        \
    .stdout_cb = NULL,                                       \
    .stderr_cb = NULL,                                       \
    .exit_cb = NULL,                                         \
    .maxmem = 0                                              \
    })
#endif  // NVIM_OS_JOB_DEFS_H