/* * 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 "UartDevice.h" #include "ILog.h" #include "StatusCode.h" #include "UartDeviceImpl.h" void *CreateUartDevice(const UartInfo info) { return NewUartDeviceImpl(info); } const StatusCode IUartOpen(void *object) { if (nullptr == object) { LogError("nullptr object!\n"); return CreateStatusCode(STATUS_CODE_NOT_OK); } if (*((const char **)(((char *)object) - sizeof(UartDeviceHeader))) != GetUartDeviceModuleName()) { LogError("Illegal object!\n"); return CreateStatusCode(STATUS_CODE_NOT_OK); } return ((UartDevice *)object)->mOpen((UartDevice *)object); } const ssize_t IUartSend(void *object, const void *buff, const size_t buffLength) { if (nullptr == object) { LogError("nullptr object!\n"); return 0; } if (*((const char **)(((char *)object) - sizeof(UartDeviceHeader))) != GetUartDeviceModuleName()) { LogError("Illegal object!\n"); return 0; } return ((UartDevice *)object)->mSend((UartDevice *)object, buff, buffLength); } const ssize_t IUartRecv(void *object, void *buff, const size_t buffLength, const unsigned int timeoutMs) { if (nullptr == object) { LogError("nullptr object!\n"); return 0; } if (*((const char **)(((char *)object) - sizeof(UartDeviceHeader))) != GetUartDeviceModuleName()) { LogError("Illegal object!\n"); return 0; } return ((UartDevice *)object)->mRecv((UartDevice *)object, buff, buffLength, timeoutMs); } void IUartTcflush(void *object) { if (nullptr == object) { LogError("nullptr object!\n"); return; } if (*((const char **)(((char *)object) - sizeof(UartDeviceHeader))) != GetUartDeviceModuleName()) { LogError("Illegal object!\n"); return; } ((UartDevice *)object)->mTcflush((UartDevice *)object); } void IUartDeviceFree(void *object) { if (nullptr == object) { LogError("nullptr object!\n"); return; } if (*((const char **)(((char *)object) - sizeof(UartDeviceHeader))) != GetUartDeviceModuleName()) { LogError("Illegal object!\n"); return; } ((UartDevice *)object)->mFree((UartDevice *)object); }