hunting/hal/src/Hal.c
2023-11-20 06:48:53 -08:00

56 lines
1.6 KiB
C

/*
* Copyright (c) 2023 Fancy Code.
* 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
*
* http://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.
*/
#include "Hal.h"
#include "ILog.h"
#include <stddef.h>
#include <stdlib.h>
StatusCode HalInit(IHal *hal)
{
LogInfo("Hal init.\n");
return CreateStatusCode(STATUS_CODE_OK);
}
static void HalFree(void *object)
{
LogInfo("hal instance free.\n");
if (object) {
free(object);
}
}
void HalImplInit(Hal *hal)
{
LogInfo("HalImplInit\n");
NewIHal((IHal **)&hal);
((IHal *)hal)->init = HalInit;
((IHal *)hal)->free = HalFree;
}
StatusCode NewHal(Hal **hal)
{
if (!hal) {
LogError("STATUS_CODE_INVALID_PARAMENTER\n");
return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER);
}
if (!(*hal)) {
*hal = (Hal *)malloc(sizeof(Hal));
if (*hal) {
LogInfo("NewHal succeed.\n");
HalImplInit(*hal);
return CreateStatusCode(STATUS_CODE_OK);
}
LogError("NewHal failed.\n");
return CreateStatusCode(STATUS_CODE_NOT_OK);
}
HalImplInit(*hal);
return CreateStatusCode(STATUS_CODE_OK);
}