hunting/hal/abstract/IHal.cpp
xiaojiazhu 080c1f6c64 1.Delete hal.
2.Add new hal.
2023-08-17 08:23:22 -07:00

41 lines
1011 B
C++

#include "IHal.h"
#include "IHalCpp.h"
#include <stddef.h>
#include <string.h>
static RETURN_CODE_C hal_init(IHal *object)
{
// return CreateReturnCode(C_RETURN_CODE_VIRTUAL_FUNCTION);
return IHalCpp::GetInstance()->Init();
}
static void hal_free(IHal *object)
{
}
static RETURN_CODE_C hal_un_init(IHal *object)
{
// return CreateReturnCode(C_RETURN_CODE_VIRTUAL_FUNCTION);
return IHalCpp::GetInstance()->UnInit();
}
static IHal default_hal = {
.init = hal_init,
.free = hal_free,
.un_init = hal_un_init,
};
static IHal *hal_instance = &default_hal;
IHal *get_hal_instance(void)
{
return hal_instance;
}
RETURN_CODE_C new_i_hal(IHal **object)
{
if (!object || !(*object))
{
return CreateReturnCode(C_RETURN_CODE_NOT_OK);
}
memcpy(*object, &default_hal, sizeof(IHal));
return CreateReturnCode(C_RETURN_CODE_OK);
}
void reset_hal_impl(IHal *impl)
{
hal_instance->free(hal_instance);
hal_instance = impl;
}