#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
Go to the source code of this file.
Defines | |
#define | CT_ASSERT(e) extern char (*CT_ASSERT(void)) [sizeof(char[1 - 2*!(e)])] |
#define | NELEMS(x) (sizeof(x) / sizeof(x[0])) |
#define | LOG_ERR(fmt,...) |
#define | VALIDATE_VTABLE_FN(obj_h, private_h, vtable, fn, rc) |
#define | INHERIT_VTABLE_FN(parent_vtable, child_vtable, fn, do_null_check, rc) |
Typedefs | |
typedef enum my_rc_e_ | my_rc_e |
Enumerations | |
enum | my_rc_e_ { MY_RC_E_INVALID, MY_RC_E_SUCCESS, MY_RC_E_EINVAL, MY_RC_E_ENOMEM, MY_RC_E_MAX } |
Functions | |
bool | my_rc_e_is_notok (my_rc_e rc) |
bool | my_rc_e_is_ok (my_rc_e rc) |
bool | my_rc_e_is_valid (my_rc_e rc) |
const char * | my_rc_e_get_string (my_rc_e rc) |
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
This is an interface for some common declarations.
Definition in file common.h.
#define CT_ASSERT | ( | e | ) | extern char (*CT_ASSERT(void)) [sizeof(char[1 - 2*!(e)])] |
Compile time assert macro from: http://www.pixelbeat.org/programming/gcc/static_assert.html
#define INHERIT_VTABLE_FN | ( | parent_vtable, | |
child_vtable, | |||
fn, | |||
do_null_check, | |||
rc | |||
) |
do { \ if (NULL == child_vtable->fn) { \ child_vtable->fn = parent_vtable->fn; \ if (do_null_check && (NULL == child_vtable->fn)) { \ LOG_ERR("Invalid input, " #fn "(%p)", child_vtable->fn); \ rc = MY_RC_E_EINVAL; \ goto err_exit; \ } \ } \ } while (0)
If the function in the child's table is NULL, then inherit the function from the parent table. In do_null_check is true, then it is considered an error condition if the function is NULL after inheritance (e.g., when the base class is setting the vtable, all functions should be non-NULL). If the error condition is reached, we set the rc and goto an err_exit label.
#define LOG_ERR | ( | fmt, | |
... | |||
) |
#define NELEMS | ( | x | ) | (sizeof(x) / sizeof(x[0])) |
#define VALIDATE_VTABLE_FN | ( | obj_h, | |
private_h, | |||
vtable, | |||
fn, | |||
rc | |||
) |
do { \ if (NULL == obj_h) { \ LOG_ERR("Invalid input, " #obj_h "(%p)", obj_h); \ rc = MY_RC_E_EINVAL; \ break; \ } \ \ if (NULL == obj_h->private_h) { \ LOG_ERR("Invalid input, " #obj_h "(%p) " #private_h "(%p)", obj_h, \ obj_h->private_h); \ rc = MY_RC_E_EINVAL; \ break; \ } \ \ if (NULL == obj_h->private_h->vtable) { \ LOG_ERR("Invalid input, " #obj_h "(%p) " #private_h "(%p) " #vtable \ "(%p)", obj_h, obj_h->private_h, obj_h->private_h->vtable); \ rc = MY_RC_E_EINVAL; \ break; \ } \ \ if (NULL == obj_h->private_h->vtable->fn) { \ LOG_ERR("Invalid input, " #obj_h "(%p) " #private_h "(%p) " #vtable \ "(%p) " #fn "(%p)", obj_h, obj_h->private_h, \ obj_h->private_h->vtable, obj_h->private_h->vtable->fn); \ rc = MY_RC_E_EINVAL; \ break; \ } \ } while (0)
Validate that a function in an object's virtual table exists. If not, set the return code. Callers should set the return code to MY_RC_E_SUCCESS prior to calling the macro and check it after the macro is executed to make sure it is not an error return code.
enum my_rc_e_ |
Return codes used to indicate whether a function call was successful.
const char* my_rc_e_get_string | ( | my_rc_e | rc | ) |
bool my_rc_e_is_notok | ( | my_rc_e | rc | ) |
bool my_rc_e_is_ok | ( | my_rc_e | rc | ) |