1 /***********************************************************************************************************************************
2 Io Client Interface
3 ***********************************************************************************************************************************/
4 #include "build.auto.h"
5 
6 #include "common/debug.h"
7 #include "common/io/client.h"
8 #include "common/log.h"
9 #include "common/memContext.h"
10 
11 /***********************************************************************************************************************************
12 Object type
13 ***********************************************************************************************************************************/
14 struct IoClient
15 {
16     IoClientPub pub;                                                // Publicly accessible variables
17 };
18 
19 /**********************************************************************************************************************************/
20 IoClient *
ioClientNew(void * driver,const IoClientInterface * interface)21 ioClientNew(void *driver, const IoClientInterface *interface)
22 {
23     FUNCTION_LOG_BEGIN(logLevelTrace)
24         FUNCTION_LOG_PARAM_P(VOID, driver);
25         FUNCTION_LOG_PARAM(IO_CLIENT_INTERFACE, interface);
26     FUNCTION_LOG_END();
27 
28     ASSERT(driver != NULL);
29     ASSERT(interface != NULL);
30     ASSERT(interface->type != 0);
31     ASSERT(interface->name != NULL);
32     ASSERT(interface->open != NULL);
33     ASSERT(interface->toLog != NULL);
34 
35     IoClient *this = memNew(sizeof(IoClient));
36 
37     *this = (IoClient)
38     {
39         .pub =
40         {
41             .memContext = memContextCurrent(),
42             .driver = driver,
43             .interface = interface,
44         },
45     };
46 
47     FUNCTION_LOG_RETURN(IO_CLIENT, this);
48 }
49 
50 /**********************************************************************************************************************************/
51 String *
ioClientToLog(const IoClient * this)52 ioClientToLog(const IoClient *this)
53 {
54     return strNewFmt(
55         "{type: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(this->pub.interface->toLog(this->pub.driver)));
56 }
57