| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef __GPIOD_TEST_SIM_H__ |
| 5 |
#define __GPIOD_TEST_SIM_H__ |
| 6 |
|
| 7 |
#include <gio/gio.h> |
| 8 |
#include <glib.h> |
| 9 |
#include <glib-object.h> |
| 10 |
|
| 11 |
G_BEGIN_DECLS |
| 12 |
|
| 13 |
typedef enum { |
| 14 |
G_GPIOSIM_VALUE_ERROR = -1, |
| 15 |
G_GPIOSIM_VALUE_INACTIVE = 0, |
| 16 |
G_GPIOSIM_VALUE_ACTIVE = 1, |
| 17 |
} GPIOSimValue; |
| 18 |
|
| 19 |
typedef enum { |
| 20 |
G_GPIOSIM_PULL_UP = 1, |
| 21 |
G_GPIOSIM_PULL_DOWN, |
| 22 |
} GPIOSimPull; |
| 23 |
|
| 24 |
typedef enum { |
| 25 |
G_GPIOSIM_DIRECTION_INPUT = 1, |
| 26 |
G_GPIOSIM_DIRECTION_OUTPUT_HIGH, |
| 27 |
G_GPIOSIM_DIRECTION_OUTPUT_LOW, |
| 28 |
} GPIOSimDirection; |
| 29 |
|
| 30 |
#define G_GPIOSIM_ERROR g_gpiosim_error_quark() |
| 31 |
|
| 32 |
typedef enum { |
| 33 |
G_GPIOSIM_ERR_CTX_INIT_FAILED = 1, |
| 34 |
G_GPIOSIM_ERR_CHIP_INIT_FAILED, |
| 35 |
G_GPIOSIM_ERR_CHIP_ENABLE_FAILED, |
| 36 |
G_GPIOSIM_ERR_GET_VALUE_FAILED, |
| 37 |
} GPIOSimError; |
| 38 |
|
| 39 |
GQuark g_gpiosim_error_quark(void); |
| 40 |
|
| 41 |
G_DECLARE_FINAL_TYPE(GPIOSimChip, g_gpiosim_chip, G_GPIOSIM, CHIP, GObject); |
| 42 |
|
| 43 |
#define G_GPIOSIM_CHIP_TYPE (g_gpiosim_chip_get_type()) |
| 44 |
#define G_GPIOSIM_CHIP_OBJ(obj) \ |
| 45 |
(G_TYPE_CHECK_INSTANCE_CAST((obj), G_GPIOSIM_CHIP_TYPE, GPIOSimChip)) |
| 46 |
|
| 47 |
#define g_gpiosim_chip_new(...) \ |
| 48 |
({ \ |
| 49 |
g_autoptr(GError) _err = NULL; \ |
| 50 |
GPIOSimChip *_chip = G_GPIOSIM_CHIP_OBJ( \ |
| 51 |
g_initable_new(G_GPIOSIM_CHIP_TYPE, \ |
| 52 |
NULL, &_err, \ |
| 53 |
__VA_ARGS__)); \ |
| 54 |
g_assert_no_error(_err); \ |
| 55 |
if (g_test_failed()) \ |
| 56 |
return; \ |
| 57 |
_chip; \ |
| 58 |
}) |
| 59 |
|
| 60 |
const gchar *g_gpiosim_chip_get_dev_path(GPIOSimChip *self); |
| 61 |
const gchar *g_gpiosim_chip_get_name(GPIOSimChip *self); |
| 62 |
|
| 63 |
GPIOSimValue |
| 64 |
_g_gpiosim_chip_get_value(GPIOSimChip *self, guint offset, GError **err); |
| 65 |
void g_gpiosim_chip_set_pull(GPIOSimChip *self, guint offset, GPIOSimPull pull); |
| 66 |
|
| 67 |
#define g_gpiosim_chip_get_value(self, offset) \ |
| 68 |
({ \ |
| 69 |
g_autoptr(GError) _err = NULL; \ |
| 70 |
gint _val = _g_gpiosim_chip_get_value(self, offset, &_err); \ |
| 71 |
g_assert_no_error(_err); \ |
| 72 |
if (g_test_failed()) \ |
| 73 |
return; \ |
| 74 |
_val; \ |
| 75 |
}) |
| 76 |
|
| 77 |
typedef struct { |
| 78 |
guint offset; |
| 79 |
const gchar *name; |
| 80 |
} GPIOSimLineName; |
| 81 |
|
| 82 |
typedef struct { |
| 83 |
guint offset; |
| 84 |
const gchar *name; |
| 85 |
GPIOSimDirection direction; |
| 86 |
} GPIOSimHog; |
| 87 |
|
| 88 |
GVariant *g_gpiosim_package_line_names(const GPIOSimLineName *names); |
| 89 |
GVariant *g_gpiosim_package_hogs(const GPIOSimHog *hogs); |
| 90 |
|
| 91 |
G_END_DECLS |
| 92 |
|
| 93 |
#endif |