hunting/hal/abstract/IHal.cpp
xiaojiazhu a80a8f7cee 1.Add clang-tidy in CMakeList.txt.
2.Add clang-tidy tools.
2023-09-02 04:26:30 -07:00

40 lines
887 B
C++

#include "IHal.h"
#include "IHalCpp.h"
#include "StatusCode.h"
// #include <stddef.h>
#include <string.h>
static StatusCode IHalInit(IHal *object)
{
return IHalCpp::GetInstance()->Init();
}
static void IHalFree(IHal *object)
{
}
static StatusCode IHalUnInit(IHal *object)
{
return IHalCpp::GetInstance()->UnInit();
}
static IHal default_hal = {
.init = IHalInit,
.free = IHalFree,
.un_init = IHalUnInit,
};
static IHal *hal_instance = &default_hal;
IHal *GetHalIntance(void)
{
return hal_instance;
}
StatusCode NewIHal(IHal **object)
{
if (!object || !(*object))
{
return CreateStatusCode(STATUS_CODE_NOT_OK);
}
memcpy(*object, &default_hal, sizeof(IHal));
return CreateStatusCode(STATUS_CODE_OK);
}
void ResetHalImpl(IHal *impl)
{
hal_instance->free(hal_instance);
hal_instance = impl;
}