2021-10-18 14:32:41 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Io Server Interface
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#include "build.auto.h"
|
|
|
|
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/io/server.h"
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "common/memContext.h"
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Object type
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
struct IoServer
|
|
|
|
{
|
|
|
|
IoServerPub pub; // Publicly accessible variables
|
|
|
|
};
|
|
|
|
|
|
|
|
/**********************************************************************************************************************************/
|
2023-01-02 15:24:51 +07:00
|
|
|
FN_EXTERN IoServer *
|
2021-10-18 14:32:41 -04:00
|
|
|
ioServerNew(void *const driver, const IoServerInterface *const interface)
|
|
|
|
{
|
2023-01-09 14:47:57 +07:00
|
|
|
FUNCTION_LOG_BEGIN(logLevelTrace);
|
2021-10-18 14:32:41 -04:00
|
|
|
FUNCTION_LOG_PARAM_P(VOID, driver);
|
|
|
|
FUNCTION_LOG_PARAM(IO_SERVER_INTERFACE, interface);
|
|
|
|
FUNCTION_LOG_END();
|
|
|
|
|
|
|
|
ASSERT(driver != NULL);
|
|
|
|
ASSERT(interface != NULL);
|
|
|
|
ASSERT(interface->type != 0);
|
|
|
|
ASSERT(interface->name != NULL);
|
|
|
|
ASSERT(interface->accept != NULL);
|
|
|
|
ASSERT(interface->toLog != NULL);
|
|
|
|
|
2023-03-27 14:32:37 +06:00
|
|
|
OBJ_NEW_BEGIN(IoServer, .childQty = MEM_CONTEXT_QTY_MAX)
|
2021-10-18 14:32:41 -04:00
|
|
|
{
|
2023-03-27 14:32:37 +06:00
|
|
|
*this = (IoServer)
|
2021-10-18 14:32:41 -04:00
|
|
|
{
|
2023-03-27 14:32:37 +06:00
|
|
|
.pub =
|
|
|
|
{
|
|
|
|
.driver = objMoveToInterface(driver, this, memContextPrior()),
|
|
|
|
.interface = interface,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
OBJ_NEW_END();
|
2021-10-18 14:32:41 -04:00
|
|
|
|
|
|
|
FUNCTION_LOG_RETURN(IO_SERVER, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************************************************************************/
|
2023-01-12 17:14:36 +07:00
|
|
|
FN_EXTERN void
|
|
|
|
ioServerToLog(const IoServer *const this, StringStatic *const debugLog)
|
2021-10-18 14:32:41 -04:00
|
|
|
{
|
2023-01-12 17:14:36 +07:00
|
|
|
strStcCat(debugLog, "{type: ");
|
|
|
|
strStcResultSizeInc(debugLog, strIdToLog(this->pub.interface->type, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
|
|
|
|
|
|
|
|
strStcCat(debugLog, ", driver: ");
|
|
|
|
this->pub.interface->toLog(this->pub.driver, debugLog);
|
|
|
|
strStcCatChr(debugLog, '}');
|
2021-10-18 14:32:41 -04:00
|
|
|
}
|