firmware  v0.1.2
Chromation Spectrometer Dev-Kit
RecordedArg.h
1 #ifndef _RECORDEDARG_H
2 #define _RECORDEDARG_H
3 #include <glib.h> // GString, GList
4 #include <stdbool.h> // bool, true, false
5 
6 //=====[ mock-c RecordedArg datatype ]=====
7 // Record arguments in a `RecordedArg` struct. See definition below.
8 typedef struct RecordedArg RecordedArg;
9 // Define function type `SetupRecordedArg`.
10 typedef void (SetupRecordedArg)(RecordedArg *self);
11 // Declare `SetupRecord_arg_t` functions for every arg type.
12 SetupRecordedArg SetupRecord_uint8_t;
13 SetupRecordedArg SetupRecord_uint16_t;
14 SetupRecordedArg SetupRecord_uint32_t;
15 SetupRecordedArg SetupRecord_GString;
16 SetupRecordedArg SetupRecord_p_uint8_t;
17 SetupRecordedArg SetupRecord_p_GString;
18 // To fake a function that takes an arg type not listed above,
19 // add it above, then in `RecordedArg.c`, define `SetupRecord_arg_t` for that
20 // `arg_t`.
21 typedef void (FreeArg)(RecordedArg *self);
22 typedef void (PrintArgToString)(GString *string, RecordedArg *self);
23 typedef bool (DoArgsMatch)(RecordedArg *arg1, RecordedArg *arg2);
24 typedef bool (CheckArg_t)(RecordedArg *argk, void const * arg);
25 typedef bool (CheckValArgPointsTo_t)(RecordedArg *argk, void const * arg);
26 // `SetupRecord_` functions allocate heap-mem for the arg.
27 // Heap-mem address is stored in `RecordedArg` struct member `pArg`.
28 // `SetupRecord_` functions define allocate heap-mem for the arg.
30 {
31  void *pArg; // ex: *((uint8_t *)record_of_arg->pArg) returns a uint8_t
32  // Store functions for working with the value on the heap pArg points to.
33  // The function pointers are assigned by a SetupRecordedArg function.
34  FreeArg *Destroy;
35  PrintArgToString *Print;
36  // Anything else needed by mock-c goes here.
37  DoArgsMatch *Match;
38  CheckArg_t *CheckArg;
39  CheckValArgPointsTo_t *CheckValArgPointsTo;
40 };
41 RecordedArg * RecordedArg_new(SetupRecordedArg SetupRecord);
42 void RecordedArg_destroy(RecordedArg *self);
43 
44 #endif // _RECORDEDARG_H