aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/args_parser.h
blob: 9e388ec1a61f703f2d9352cecbbd7a4c08821868 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef GSR_ARGS_PARSER_H
#define GSR_ARGS_PARSER_H

#include <stdbool.h>
#include <stdint.h>
#include "defs.h"
#include "vec2.h"
#include "recorder/settings.h"

typedef struct gsr_egl gsr_egl;

#define NUM_ARGS 38

typedef enum {
    GSR_CAPTURE_SOURCE_TYPE_WINDOW,
    GSR_CAPTURE_SOURCE_TYPE_FOCUSED_WINDOW,
    GSR_CAPTURE_SOURCE_TYPE_MONITOR,
    GSR_CAPTURE_SOURCE_TYPE_REGION,
    GSR_CAPTURE_SOURCE_TYPE_PORTAL,
    GSR_CAPTURE_SOURCE_TYPE_V4L2
} CaptureSourceType;

typedef enum {
    ARG_TYPE_STRING,
    ARG_TYPE_BOOLEAN,
    ARG_TYPE_ENUM,
    ARG_TYPE_I64,
    ARG_TYPE_DOUBLE,
} ArgType;

typedef struct {
    const char *name;
    int value;
} ArgEnum;

typedef struct {
    ArgType type;
    const char **values;
    int capacity_num_values;
    int num_values;

    const char *key;
    bool optional;
    bool list;

    const ArgEnum *enum_values;
    int num_enum_values;

    int64_t integer_value_min;
    int64_t integer_value_max;

    union {
        bool boolean;
        int enum_value;
        int64_t i64_value;
        double d_value;
    } typed_value;
} Arg;

typedef struct {
    void (*version)(void *userdata);
    void (*info)(void *userdata);
    void (*list_audio_devices)(void *userdata);
    void (*list_application_audio)(void *userdata);
    void (*list_v4l2_devices)(void *userdata);
    void (*list_capture_options)(const char *card_path, void *userdata);
    void (*list_monitors)(void *userdata);
} args_handlers;

typedef struct {
    Arg args[NUM_ARGS];
    gsr_recorder_settings settings;
} args_parser;

/* |argv| is stored as a reference */
bool args_parser_parse(args_parser *self, int argc, char **argv, const args_handlers *args_handlers, void *userdata);
void args_parser_deinit(args_parser *self);

bool args_parser_validate_with_gl_info(args_parser *self, gsr_egl *egl);
void args_parser_print_usage(void);
Arg* args_parser_get_arg(args_parser *self, const char *arg_name);

#endif /* GSR_ARGS_PARSER_H */