wlmaker
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
decode.c File Reference
#include "decode.h"
#include "plist.h"
Include dependency graph for decode.c:

Classes

struct  _test_subdict_value_t
 
struct  _test_value_t
 

Macros

#define BS_VALUE_AT(_value_type, _base_ptr, _offset)    ((_value_type*)((uint8_t*)(_base_ptr) + (_offset)))
 

Functions

static bool _wlmcfg_init_defaults (const wlmcfg_desc_t *desc_ptr, void *dest_ptr)
 
static bool _wlmcfg_decode_uint64 (wlmcfg_object_t *obj_ptr, uint64_t *uint64_ptr)
 
static bool _wlmcfg_decode_int64 (wlmcfg_object_t *obj_ptr, int64_t *int64_ptr)
 
static bool _wlmcfg_decode_double (wlmcfg_object_t *obj_ptr, double *double_ptr)
 
static bool _wlmcfg_decode_argb32 (wlmcfg_object_t *obj_ptr, uint32_t *argb32_ptr)
 
static bool _wlmcfg_decode_bool (wlmcfg_object_t *obj_ptr, bool *bool_ptr)
 
static bool _wlmcfg_decode_enum (wlmcfg_object_t *obj_ptr, const wlmcfg_enum_desc_t *enum_desc_ptr, int *enum_value_ptr)
 
static bool _wlmcfg_decode_string (wlmcfg_object_t *obj_ptr, char **str_ptr_ptr)
 
static bool _wlmcfg_decode_charbuf (wlmcfg_object_t *obj_ptr, char *str_ptr, size_t len)
 
bool wlmcfg_decode_dict (wlmcfg_dict_t *dict_ptr, const wlmcfg_desc_t *desc_ptr, void *dest_ptr)
 
void wlmcfg_decoded_destroy (const wlmcfg_desc_t *desc_ptr, void *dest_ptr)
 
bool wlmcfg_enum_name_to_value (const wlmcfg_enum_desc_t *enum_desc_ptr, const char *name_ptr, int *value_ptr)
 
bool wlmcfg_enum_value_to_name (const wlmcfg_enum_desc_t *enum_desc_ptr, int value, const char **name_ptr_ptr)
 
static void test_init_defaults (bs_test_t *test_ptr)
 
static void test_enum_translate (bs_test_t *test_ptr)
 
static void test_decode_dict (bs_test_t *test_ptr)
 
static void test_decode_number (bs_test_t *test_ptr)
 
static void test_decode_argb32 (bs_test_t *test_ptr)
 
static void test_decode_bool (bs_test_t *test_ptr)
 
static void test_decode_enum (bs_test_t *test_ptr)
 
static void test_decode_string (bs_test_t *test_ptr)
 
static void test_decode_charbuf (bs_test_t *test_ptr)
 
static bool _wlmcfg_test_custom_decode (wlmcfg_object_t *o_ptr, void *dst_ptr)
 
static bool _wlmcfg_test_custom_init (void *dst_ptr)
 
static void _wlmcfg_test_custom_fini (void *dst_ptr)
 

Variables

static const wlmcfg_enum_desc_t _wlmcfg_bool_desc []
 
const bs_test_case_t wlmcfg_decode_test_cases []
 
static const wlmcfg_enum_desc_t _test_enum_desc []
 
static const wlmcfg_desc_t _wlmcfg_decode_test_subdesc []
 
static const wlmcfg_desc_t _wlmcfg_decode_test_desc []
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Configurables for wlmaker. Currently, this file lists hardcoded entities, and mainly serves as a catalog about which entities should be dynamically configurable.

Macro Definition Documentation

◆ BS_VALUE_AT

#define BS_VALUE_AT ( _value_type,
_base_ptr,
_offset )    ((_value_type*)((uint8_t*)(_base_ptr) + (_offset)))

A pointer of type value_type, at offset behind base_ptr.

Function Documentation

◆ _wlmcfg_decode_argb32()

bool _wlmcfg_decode_argb32 ( wlmcfg_object_t * obj_ptr,
uint32_t * argb32_ptr )
static

Deocdes an ARGB32 value from the config object.

◆ _wlmcfg_decode_bool()

bool _wlmcfg_decode_bool ( wlmcfg_object_t * obj_ptr,
bool * bool_ptr )
static

Translates a bool value from the string.

◆ _wlmcfg_decode_charbuf()

bool _wlmcfg_decode_charbuf ( wlmcfg_object_t * obj_ptr,
char * str_ptr,
size_t len )
static

Translates (ie. duplicates) a char buf from the plist string.

◆ _wlmcfg_decode_double()

bool _wlmcfg_decode_double ( wlmcfg_object_t * obj_ptr,
double * double_ptr )
static

Decodes a floating point number.

◆ _wlmcfg_decode_enum()

bool _wlmcfg_decode_enum ( wlmcfg_object_t * obj_ptr,
const wlmcfg_enum_desc_t * enum_desc_ptr,
int * enum_value_ptr )
static

Translates a enum value from the string, using the provided descriptor.

◆ _wlmcfg_decode_int64()

bool _wlmcfg_decode_int64 ( wlmcfg_object_t * obj_ptr,
int64_t * int64_ptr )
static

Decodes a signed number, using int64_t as carry-all.

◆ _wlmcfg_decode_string()

bool _wlmcfg_decode_string ( wlmcfg_object_t * obj_ptr,
char ** str_ptr_ptr )
static

Translates (ie. duplicates) a string value from the plist string.

◆ _wlmcfg_decode_uint64()

bool _wlmcfg_decode_uint64 ( wlmcfg_object_t * obj_ptr,
uint64_t * uint64_ptr )
static

Decodes an unsigned number, using uint64_t as carry-all.

◆ _wlmcfg_init_defaults()

bool _wlmcfg_init_defaults ( const wlmcfg_desc_t * desc_ptr,
void * dest_ptr )
static

Initializes default values at the destination, as described.

Parameters
desc_ptr
dest_ptr

◆ _wlmcfg_test_custom_decode()

bool _wlmcfg_test_custom_decode ( wlmcfg_object_t * o_ptr,
void * dst_ptr )
static

A custom decoding function. Here: just decode a string.

◆ _wlmcfg_test_custom_fini()

void _wlmcfg_test_custom_fini ( void * dst_ptr)
static

A custom decoding cleanup method. Frees the string.

◆ _wlmcfg_test_custom_init()

bool _wlmcfg_test_custom_init ( void * dst_ptr)
static

A custom decoding initializer. Here: Just create a string.

◆ test_decode_argb32()

void test_decode_argb32 ( bs_test_t * test_ptr)
static

Tests argb32 decoding.

◆ test_decode_bool()

void test_decode_bool ( bs_test_t * test_ptr)
static

Tests bool decoding.

◆ test_decode_charbuf()

void test_decode_charbuf ( bs_test_t * test_ptr)
static

Tests string decoding into a char buf.

◆ test_decode_dict()

void test_decode_dict ( bs_test_t * test_ptr)
static

Tests dict decoding.

◆ test_decode_enum()

void test_decode_enum ( bs_test_t * test_ptr)
static

Tests enum decoding.

◆ test_decode_number()

void test_decode_number ( bs_test_t * test_ptr)
static

Tests number decoding.

◆ test_decode_string()

void test_decode_string ( bs_test_t * test_ptr)
static

Tests string decoding.

◆ test_enum_translate()

void test_enum_translate ( bs_test_t * test_ptr)
static

◆ test_init_defaults()

void test_init_defaults ( bs_test_t * test_ptr)
static

Tests initialization of default values.

◆ wlmcfg_decode_dict()

bool wlmcfg_decode_dict ( wlmcfg_dict_t * dict_ptr,
const wlmcfg_desc_t * desc_ptr,
void * dest_ptr )

Decodes the plist dict_ptr into dest_ptr as described.

Parameters
dict_ptr
desc_ptr
dest_ptr
Returns
true on success.

◆ wlmcfg_decoded_destroy()

void wlmcfg_decoded_destroy ( const wlmcfg_desc_t * desc_ptr,
void * dest_ptr )

Destroys resources that were allocated during wlmcfg_decode_dict.

Parameters
desc_ptr
dest_ptr

◆ wlmcfg_enum_name_to_value()

bool wlmcfg_enum_name_to_value ( const wlmcfg_enum_desc_t * enum_desc_ptr,
const char * name_ptr,
int * value_ptr )

Translates from the given name of an enum to it's value.

Parameters
enum_desc_ptr
name_ptr
value_ptr
Returns
true if name_ptr was a valid enum name.

◆ wlmcfg_enum_value_to_name()

bool wlmcfg_enum_value_to_name ( const wlmcfg_enum_desc_t * enum_desc_ptr,
int value,
const char ** name_ptr_ptr )

Translates from the given value of an enum to it's name.

Parameters
enum_desc_ptr
value
name_ptr_ptr
Returns
true if name_ptr was a valid enum name.

Variable Documentation

◆ _test_enum_desc

const wlmcfg_enum_desc_t _test_enum_desc[]
static
Initial value:
= {
WLMCFG_ENUM("enum1", 1),
WLMCFG_ENUM("enum2", 2),
}
#define WLMCFG_ENUM(_name, _value)
Definition decode.h:52

An enum descriptor.

◆ _wlmcfg_bool_desc

const wlmcfg_enum_desc_t _wlmcfg_bool_desc[]
static
Initial value:
= {
WLMCFG_ENUM("True", true),
WLMCFG_ENUM("False", false),
WLMCFG_ENUM("Yes", true),
WLMCFG_ENUM("No", false),
WLMCFG_ENUM("Enabled", true),
WLMCFG_ENUM("Disabled", false),
WLMCFG_ENUM("On", true),
WLMCFG_ENUM("Off", false),
}

Enum descriptor for decoding bool.

◆ _wlmcfg_decode_test_desc

const wlmcfg_desc_t _wlmcfg_decode_test_desc[]
static
Initial value:
= {
WLMCFG_DESC_UINT64("u64", true, _test_value_t, v_uint64, 1234),
WLMCFG_DESC_INT64("i64", true, _test_value_t, v_int64, -1234),
WLMCFG_DESC_DOUBLE("d", true, _test_value_t, v_double, 3.14),
WLMCFG_DESC_ARGB32("argb32", true, _test_value_t, v_argb32, 0x01020304),
WLMCFG_DESC_BOOL("bool", true, _test_value_t, v_bool, true),
WLMCFG_DESC_ENUM("enum", true, _test_value_t, v_enum, 3, _test_enum_desc),
WLMCFG_DESC_STRING("string", true, _test_value_t, v_string, "The String"),
WLMCFG_DESC_CHARBUF("charbuf", true, _test_value_t, v_charbuf, 10, "CharBuf"),
WLMCFG_DESC_DICT("subdict", true, _test_value_t, subdict,
WLMCFG_DESC_CUSTOM("custom", true, _test_value_t, v_custom_ptr,
}
static void _wlmcfg_test_custom_fini(void *dst_ptr)
Definition decode.c:585
static const wlmcfg_enum_desc_t _test_enum_desc[]
Definition decode.c:526
static const wlmcfg_desc_t _wlmcfg_decode_test_subdesc[]
Definition decode.c:533
static bool _wlmcfg_test_custom_init(void *dst_ptr)
Definition decode.c:575
static bool _wlmcfg_test_custom_decode(wlmcfg_object_t *o_ptr, void *dst_ptr)
Definition decode.c:561
#define WLMCFG_DESC_STRING(_key, _required, _base, _field, _default)
Definition decode.h:215
#define WLMCFG_DESC_SENTINEL()
Definition decode.h:156
#define WLMCFG_DESC_CHARBUF(_key, _required, _base, _field, _len, _default)
Definition decode.h:224
#define WLMCFG_DESC_ENUM(_key, _required, _base, _field, _default, _desc_ptr)
Definition decode.h:204
#define WLMCFG_DESC_INT64(_key, _required, _base, _field, _default)
Definition decode.h:168
#define WLMCFG_DESC_DOUBLE(_key, _required, _base, _field, _default)
Definition decode.h:177
#define WLMCFG_DESC_ARGB32(_key, _required, _base, _field, _default)
Definition decode.h:186
#define WLMCFG_DESC_UINT64(_key, _required, _base, _field, _default)
Definition decode.h:159
#define WLMCFG_DESC_BOOL(_key, _required, _base, _field, _default)
Definition decode.h:195
#define WLMCFG_DESC_DICT(_key, _required, _base, _field, _desc)
Definition decode.h:234
#define WLMCFG_DESC_CUSTOM(_key, _required, _base, _field, _d,_i, _f)
Definition decode.h:243
Definition decode.c:510

Test descriptor.

◆ _wlmcfg_decode_test_subdesc

const wlmcfg_desc_t _wlmcfg_decode_test_subdesc[]
static
Initial value:
= {
WLMCFG_DESC_STRING("string", true, _test_subdict_value_t, value,
"Other String"),
}
Definition decode.c:503

Descriptor of a contained dict.

◆ wlmcfg_decode_test_cases

const bs_test_case_t wlmcfg_decode_test_cases[]
Initial value:
= {
{ 1, "init_defaults", test_init_defaults },
{ 1, "enum_translate", test_enum_translate },
{ 1, "dict", test_decode_dict },
{ 1, "number", test_decode_number },
{ 1, "argb32", test_decode_argb32 },
{ 1, "bool", test_decode_bool },
{ 1, "enum", test_decode_enum },
{ 1, "string", test_decode_string },
{ 1, "charbuf", test_decode_charbuf },
{ 0, NULL, NULL },
}
static void test_decode_dict(bs_test_t *test_ptr)
Definition decode.c:638
static void test_decode_number(bs_test_t *test_ptr)
Definition decode.c:683
static void test_init_defaults(bs_test_t *test_ptr)
Definition decode.c:596
static void test_decode_string(bs_test_t *test_ptr)
Definition decode.c:801
static void test_decode_charbuf(bs_test_t *test_ptr)
Definition decode.c:831
static void test_decode_enum(bs_test_t *test_ptr)
Definition decode.c:770
static void test_enum_translate(bs_test_t *test_ptr)
Definition decode.c:615
static void test_decode_argb32(bs_test_t *test_ptr)
Definition decode.c:722
static void test_decode_bool(bs_test_t *test_ptr)
Definition decode.c:750

Unit tests.