1 /***********************************************************************************************************************************
2 Buffer IO Write
3 ***********************************************************************************************************************************/
4 #include "build.auto.h"
5
6 #include "common/debug.h"
7 #include "common/io/bufferWrite.h"
8 #include "common/io/write.h"
9 #include "common/log.h"
10 #include "common/memContext.h"
11 #include "common/type/object.h"
12
13 /***********************************************************************************************************************************
14 Object type
15 ***********************************************************************************************************************************/
16 typedef struct IoBufferWrite
17 {
18 MemContext *memContext; // Object memory context
19 Buffer *write; // Buffer to write into
20 } IoBufferWrite;
21
22 /***********************************************************************************************************************************
23 Macros for function logging
24 ***********************************************************************************************************************************/
25 #define FUNCTION_LOG_IO_BUFFER_WRITE_TYPE \
26 IoBufferWrite *
27 #define FUNCTION_LOG_IO_BUFFER_WRITE_FORMAT(value, buffer, bufferSize) \
28 objToLog(value, "IoBufferWrite", buffer, bufferSize)
29
30 /***********************************************************************************************************************************
31 Write to the buffer
32 ***********************************************************************************************************************************/
33 static void
ioBufferWrite(THIS_VOID,const Buffer * buffer)34 ioBufferWrite(THIS_VOID, const Buffer *buffer)
35 {
36 THIS(IoBufferWrite);
37
38 FUNCTION_LOG_BEGIN(logLevelTrace);
39 FUNCTION_LOG_PARAM(IO_BUFFER_WRITE, this);
40 FUNCTION_LOG_PARAM(BUFFER, buffer);
41 FUNCTION_LOG_END();
42
43 ASSERT(this != NULL);
44 ASSERT(buffer != NULL);
45
46 bufCat(this->write, buffer);
47
48 FUNCTION_LOG_RETURN_VOID();
49 }
50
51 /**********************************************************************************************************************************/
52 IoWrite *
ioBufferWriteNew(Buffer * buffer)53 ioBufferWriteNew(Buffer *buffer)
54 {
55 FUNCTION_LOG_BEGIN(logLevelTrace);
56 FUNCTION_LOG_PARAM(BUFFER, buffer);
57 FUNCTION_LOG_END();
58
59 ASSERT(buffer != NULL);
60
61 IoWrite *this = NULL;
62
63 MEM_CONTEXT_NEW_BEGIN("IoBufferWrite")
64 {
65 IoBufferWrite *driver = memNew(sizeof(IoBufferWrite));
66
67 *driver = (IoBufferWrite)
68 {
69 .memContext = memContextCurrent(),
70 .write = buffer,
71 };
72
73 this = ioWriteNewP(driver, .write = ioBufferWrite);
74 }
75 MEM_CONTEXT_NEW_END();
76
77 FUNCTION_LOG_RETURN(IO_WRITE, this);
78 }
79