Improve hal module.

This commit is contained in:
xiaojiazhu 2023-08-13 01:38:14 -07:00
parent 5b3152355e
commit 6d886d26eb
5 changed files with 15 additions and 12 deletions

View File

@ -33,5 +33,6 @@ RETURN_CODE_C new_i_hal(IHal **object)
}
void reset_hal_impl(IHal *impl)
{
hal_instance->free(hal_instance);
hal_instance = impl;
}

View File

@ -22,15 +22,12 @@ extern "C"
{
return get_hal_instance()->init(get_hal_instance());
}
static inline void i_hal_free(void)
{
return get_hal_instance()->free(get_hal_instance());
}
static inline RETURN_CODE_C i_hal_un_init(void)
{
return get_hal_instance()->un_init(get_hal_instance());
}
RETURN_CODE_C create_hal_module(void);
RETURN_CODE_C destroy_hal_module(void);
#ifdef __cplusplus
}
#endif

View File

@ -6,17 +6,22 @@
#include <stdlib.h>
RETURN_CODE_C create_hal_module(void)
{
IHal *hal = NULL;
Hal *hal = NULL;
RETURN_CODE_C code = create_hal_instance(&hal);
if (C_RETURN_CODE_OK == code.mCode)
{
LogInfo("Create hal instance ok.\n");
reset_hal_impl(hal);
reset_hal_impl((IHal *)hal);
return code;
}
return CreateReturnCode(C_RETURN_CODE_NOT_OK);
}
static RETURN_CODE_C create_hal_instance_ptr(HalMakePtr *object, IHal **hal)
RETURN_CODE_C destroy_hal_module(void)
{
reset_hal_impl(NULL);
return CreateReturnCode(C_RETURN_CODE_OK);
}
static RETURN_CODE_C create_hal_instance_ptr(HalMakePtr *object, Hal **hal)
{
return new_hal(hal);
}

View File

@ -1,7 +1,7 @@
#ifndef HAL_MAKE_PTR_H
#define HAL_MAKE_PTR_H
#include "ReturnCode.h"
#include "i_hal.h"
#include "hal.h"
/*
** Make sure we can call this stuff from C++.
*/
@ -13,7 +13,7 @@ extern "C"
typedef struct hal_make_ptr
{
RETURN_CODE_C (*init)(HalMakePtr *);
RETURN_CODE_C (*create_hal_instance)(HalMakePtr *, IHal **);
RETURN_CODE_C (*create_hal_instance)(HalMakePtr *, Hal **);
void (*free)(HalMakePtr *);
RETURN_CODE_C (*un_init)(HalMakePtr *);
} HalMakePtr;
@ -28,7 +28,7 @@ extern "C"
{
return get_hal_make_ptr_instance()->un_init(get_hal_make_ptr_instance());
}
static inline RETURN_CODE_C create_hal_instance(IHal **hal)
static inline RETURN_CODE_C create_hal_instance(Hal **hal)
{
return get_hal_make_ptr_instance()->create_hal_instance(get_hal_make_ptr_instance(), hal);
}

View File

@ -9,10 +9,10 @@ namespace IHalTest
TEST(IHalTest, Demo)
{
InitLog(LOG_EASYLOGGING, nullptr);
// create_hal_module();
create_hal_module();
i_hal_init();
i_hal_un_init();
i_hal_free();
destroy_hal_module();
UnInitLog();
}
}