1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Update all interfaces to use variable parameter constructors.

Fixed parameter constructors made adding new interface functions a burden, so we switched to using structs to define interfaces in the storage module at c49eaec7.

While propagating this pattern to the IO interfaces it became obvious that the existing variable parameter function pattern (begun in the storage module) was more succinct and consistent with the existing code.

So, use variable parameter functions to define all interfaces. This assumes that the non-interface parameters will be fixed, which seems reasonable for low-level code.
This commit is contained in:
David Steele 2018-09-15 21:07:00 -04:00
parent f0ed89f21f
commit 0c02481d6e
28 changed files with 384 additions and 339 deletions

View File

@ -56,6 +56,10 @@
<p>Storage refactoring. Posix file functions now differentiate between open and missing errors. Don't use negations in objects below Storage. Rename posix driver files/functions for consistency. Full abstraction of storage driver interface.</p>
</release-item>
<release-item>
<p>Update all interfaces to use variable parameter constructors.</p>
</release-item>
<release-item>
<p>Info objects now parse JSON and use specified storage.</p>
</release-item>

View File

@ -184,22 +184,22 @@ common/fork.o: common/fork.c common/debug.h common/error.auto.h common/error.h c
common/ini.o: common/ini.c common/debug.h common/error.auto.h common/error.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h
$(CC) $(CFLAGS) -c common/ini.c -o common/ini.o
common/io/bufferRead.o: common/io/bufferRead.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/bufferRead.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
common/io/bufferRead.o: common/io/bufferRead.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/bufferRead.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/read.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
$(CC) $(CFLAGS) -c common/io/bufferRead.c -o common/io/bufferRead.o
common/io/bufferWrite.o: common/io/bufferWrite.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/bufferWrite.h common/io/filter/filter.h common/io/filter/group.h common/io/write.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
common/io/bufferWrite.o: common/io/bufferWrite.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/bufferWrite.h common/io/filter/filter.h common/io/filter/group.h common/io/write.h common/io/write.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
$(CC) $(CFLAGS) -c common/io/bufferWrite.c -o common/io/bufferWrite.o
common/io/filter/buffer.o: common/io/filter/buffer.c common/debug.h common/error.auto.h common/error.h common/io/filter/buffer.h common/io/filter/filter.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
common/io/filter/buffer.o: common/io/filter/buffer.c common/debug.h common/error.auto.h common/error.h common/io/filter/buffer.h common/io/filter/filter.h common/io/filter/filter.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
$(CC) $(CFLAGS) -c common/io/filter/buffer.c -o common/io/filter/buffer.o
common/io/filter/filter.o: common/io/filter/filter.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
common/io/filter/filter.o: common/io/filter/filter.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/filter.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
$(CC) $(CFLAGS) -c common/io/filter/filter.c -o common/io/filter/filter.o
common/io/filter/group.o: common/io/filter/group.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/buffer.h common/io/filter/filter.h common/io/filter/group.h common/io/io.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/list.h common/type/string.h common/type/variant.h common/type/variantList.h
$(CC) $(CFLAGS) -c common/io/filter/group.c -o common/io/filter/group.o
common/io/filter/size.o: common/io/filter/size.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/size.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
common/io/filter/size.o: common/io/filter/size.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/filter.intern.h common/io/filter/size.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
$(CC) $(CFLAGS) -c common/io/filter/size.c -o common/io/filter/size.o
common/io/handle.o: common/io/handle.c common/debug.h common/error.auto.h common/error.h common/io/handle.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/string.h
@ -208,10 +208,10 @@ common/io/handle.o: common/io/handle.c common/debug.h common/error.auto.h common
common/io/io.o: common/io/io.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/io.h common/log.h common/logLevel.h common/stackTrace.h common/type/convert.h
$(CC) $(CFLAGS) -c common/io/io.c -o common/io/io.o
common/io/read.o: common/io/read.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/io.h common/io/read.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
common/io/read.o: common/io/read.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/io.h common/io/read.h common/io/read.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
$(CC) $(CFLAGS) -c common/io/read.c -o common/io/read.o
common/io/write.o: common/io/write.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/io.h common/io/write.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
common/io/write.o: common/io/write.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/io.h common/io/write.h common/io/write.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h
$(CC) $(CFLAGS) -c common/io/write.c -o common/io/write.o
common/lock.o: common/lock.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/handle.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h common/wait.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h storage/storage.intern.h version.h
@ -265,10 +265,10 @@ common/wait.o: common/wait.c common/debug.h common/error.auto.h common/error.h c
compress/gzip.o: compress/gzip.c common/debug.h common/error.auto.h common/error.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/convert.h compress/gzip.h
$(CC) $(CFLAGS) -c compress/gzip.c -o compress/gzip.o
compress/gzipCompress.o: compress/gzipCompress.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h compress/gzip.h compress/gzipCompress.h
compress/gzipCompress.o: compress/gzipCompress.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/filter.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h compress/gzip.h compress/gzipCompress.h
$(CC) $(CFLAGS) -c compress/gzipCompress.c -o compress/gzipCompress.o
compress/gzipDecompress.o: compress/gzipDecompress.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h compress/gzip.h compress/gzipDecompress.h
compress/gzipDecompress.o: compress/gzipDecompress.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/filter.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h compress/gzip.h compress/gzipDecompress.h
$(CC) $(CFLAGS) -c compress/gzipDecompress.c -o compress/gzipDecompress.o
config/config.o: config/config.c common/assert.h common/debug.h common/error.auto.h common/error.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.c config/config.auto.h config/config.h config/define.auto.h config/define.h
@ -289,7 +289,7 @@ crypto/cipherBlock.o: crypto/cipherBlock.c common/debug.h common/error.auto.h co
crypto/crypto.o: crypto/crypto.c common/debug.h common/log.h common/logLevel.h common/stackTrace.h common/type/convert.h crypto/crypto.h
$(CC) $(CFLAGS) -c crypto/crypto.c -o crypto/crypto.o
crypto/hash.o: crypto/hash.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h crypto/crypto.h crypto/hash.h
crypto/hash.o: crypto/hash.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/filter.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h crypto/crypto.h crypto/hash.h
$(CC) $(CFLAGS) -c crypto/hash.c -o crypto/hash.o
crypto/random.o: crypto/random.c common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/stackTrace.h common/type/convert.h crypto/random.h
@ -325,10 +325,10 @@ protocol/storage/helper.o: protocol/storage/helper.c common/debug.h common/error
storage/driver/posix/common.o: storage/driver/posix/common.c common/assert.h common/debug.h common/error.auto.h common/error.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/string.h storage/driver/posix/common.h
$(CC) $(CFLAGS) -c storage/driver/posix/common.c -o storage/driver/posix/common.o
storage/driver/posix/fileRead.o: storage/driver/posix/fileRead.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h storage/driver/posix/common.h storage/driver/posix/fileRead.h storage/driver/posix/storage.h storage/fileRead.h storage/fileRead.intern.h
storage/driver/posix/fileRead.o: storage/driver/posix/fileRead.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/read.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h storage/driver/posix/common.h storage/driver/posix/fileRead.h storage/driver/posix/storage.h storage/fileRead.h storage/fileRead.intern.h
$(CC) $(CFLAGS) -c storage/driver/posix/fileRead.c -o storage/driver/posix/fileRead.o
storage/driver/posix/fileWrite.o: storage/driver/posix/fileWrite.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/write.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h storage/driver/posix/common.h storage/driver/posix/fileWrite.h storage/driver/posix/storage.h storage/fileWrite.h storage/fileWrite.intern.h version.h
storage/driver/posix/fileWrite.o: storage/driver/posix/fileWrite.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/write.h common/io/write.intern.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h storage/driver/posix/common.h storage/driver/posix/fileWrite.h storage/driver/posix/storage.h storage/fileWrite.h storage/fileWrite.intern.h version.h
$(CC) $(CFLAGS) -c storage/driver/posix/fileWrite.c -o storage/driver/posix/fileWrite.o
storage/driver/posix/storage.o: storage/driver/posix/storage.c common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/log.h common/logLevel.h common/memContext.h common/regExp.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h storage/driver/posix/common.h storage/driver/posix/fileRead.h storage/driver/posix/fileWrite.h storage/driver/posix/storage.h storage/fileRead.h storage/fileWrite.h storage/info.h storage/storage.h storage/storage.intern.h

View File

@ -4,6 +4,7 @@ Buffer IO Read
#include "common/assert.h"
#include "common/debug.h"
#include "common/io/bufferRead.h"
#include "common/io/read.intern.h"
#include "common/log.h"
#include "common/memContext.h"
@ -38,9 +39,8 @@ ioBufferReadNew(const Buffer *buffer)
{
this = memNew(sizeof(IoBufferRead));
this->memContext = memContextCurrent();
this->io = ioReadNewP(this, .eof = (IoReadInterfaceEof)ioBufferReadEof, .read = (IoReadInterfaceRead)ioBufferRead);
this->read = buffer;
this->io = ioReadNew(this, NULL, (IoReadProcess)ioBufferRead, NULL, (IoReadEof)ioBufferReadEof);
}
MEM_CONTEXT_NEW_END();

View File

@ -4,6 +4,7 @@ Buffer IO Write
#include "common/assert.h"
#include "common/debug.h"
#include "common/io/bufferWrite.h"
#include "common/io/write.intern.h"
#include "common/log.h"
#include "common/memContext.h"
@ -35,9 +36,8 @@ ioBufferWriteNew(Buffer *buffer)
{
this = memNew(sizeof(IoBufferWrite));
this->memContext = memContextCurrent();
this->io = ioWriteNewP(this, .write = (IoWriteInterfaceWrite)ioBufferWrite);
this->write = buffer;
this->io = ioWriteNew(this, NULL, (IoWriteProcess)ioBufferWrite, NULL);
}
MEM_CONTEXT_NEW_END();

View File

@ -5,6 +5,7 @@ IO Buffer Filter
#include "common/debug.h"
#include "common/io/filter/buffer.h"
#include "common/io/filter/filter.intern.h"
#include "common/log.h"
#include "common/memContext.h"
@ -40,9 +41,10 @@ ioBufferNew(void)
this = memNew(sizeof(IoBuffer));
this->memContext = memContextCurrent();
this->filter = ioFilterNew(
strNew(BUFFER_FILTER_TYPE), this, NULL, (IoFilterInputSame)ioBufferInputSame, NULL,
(IoFilterProcessInOut)ioBufferProcess, NULL);
// Create filter interface
this->filter = ioFilterNewP(
strNew(BUFFER_FILTER_TYPE), this, .inOut = (IoFilterInterfaceProcessInOut)ioBufferProcess,
.inputSame = (IoFilterInterfaceInputSame)ioBufferInputSame);
}
MEM_CONTEXT_NEW_END();

View File

@ -3,7 +3,7 @@ IO Filter Interface
***********************************************************************************************************************************/
#include "common/assert.h"
#include "common/debug.h"
#include "common/io/filter/filter.h"
#include "common/io/filter/filter.intern.h"
#include "common/log.h"
#include "common/memContext.h"
@ -14,12 +14,8 @@ struct IoFilter
{
MemContext *memContext; // Mem context of filter
const String *type; // Filter type
void *data; // Filter data
IoFilterDone done; // Done processing?
IoFilterInputSame inputSame; // Does the filter need the same input again?
IoFilterProcessIn processIn; // Process in function
IoFilterProcessInOut processInOut; // Process in/out function
IoFilterResult result; // Result function
void *driver; // Filter driver
IoFilterInterface interface; // Filter interface
};
/***********************************************************************************************************************************
@ -28,40 +24,31 @@ New object
Allocations will be in the memory context of the caller.
***********************************************************************************************************************************/
IoFilter *
ioFilterNew(
const String *type, void *data, IoFilterDone done, IoFilterInputSame inputSame, IoFilterProcessIn processIn,
IoFilterProcessInOut processInOut, IoFilterResult result)
ioFilterNew(const String *type, void *driver, IoFilterInterface interface)
{
FUNCTION_DEBUG_BEGIN(logLevelTrace);
FUNCTION_DEBUG_PARAM(STRING, type);
FUNCTION_DEBUG_PARAM(VOIDP, data);
FUNCTION_DEBUG_PARAM(FUNCTIONP, done);
FUNCTION_DEBUG_PARAM(FUNCTIONP, inputSame);
FUNCTION_DEBUG_PARAM(FUNCTIONP, processIn);
FUNCTION_DEBUG_PARAM(FUNCTIONP, processInOut);
FUNCTION_DEBUG_PARAM(FUNCTIONP, result);
FUNCTION_DEBUG_PARAM(VOIDP, driver);
FUNCTION_DEBUG_PARAM(IO_FILTER_INTERFACE, interface);
FUNCTION_TEST_ASSERT(type != NULL);
FUNCTION_TEST_ASSERT(data != NULL);
FUNCTION_TEST_ASSERT(driver != NULL);
// One of processIn or processInOut must be set
FUNCTION_TEST_ASSERT(processIn != NULL || processInOut != NULL);
FUNCTION_TEST_ASSERT(interface.in != NULL || interface.inOut != NULL);
// But not both of them
FUNCTION_TEST_ASSERT(!(processIn != NULL && processInOut != NULL));
FUNCTION_TEST_ASSERT(!(interface.in != NULL && interface.inOut != NULL));
// If the filter does not produce output then it should produce a result
FUNCTION_TEST_ASSERT(processIn == NULL || (result != NULL && done == NULL && inputSame == NULL));
FUNCTION_TEST_ASSERT(
interface.in == NULL || (interface.result != NULL && interface.done == NULL && interface.inputSame == NULL));
// Filters that produce output will not always be able to dump all their output and will need to get the same input again
FUNCTION_TEST_ASSERT(processInOut == NULL || inputSame != NULL);
FUNCTION_TEST_ASSERT(interface.inOut == NULL || interface.inputSame != NULL);
FUNCTION_DEBUG_END();
IoFilter *this = memNew(sizeof(IoFilter));
this->memContext = memContextCurrent();
this->type = type;
this->data = data;
this->done = done;
this->inputSame = inputSame;
this->processIn = processIn;
this->processInOut = processInOut;
this->result = result;
this->driver = driver;
this->interface = interface;
FUNCTION_DEBUG_RESULT(IO_FILTER, this);
}
@ -77,10 +64,10 @@ ioFilterProcessIn(IoFilter *this, const Buffer *input)
FUNCTION_TEST_PARAM(BUFFER, input);
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_ASSERT(this->processIn != NULL);
FUNCTION_TEST_ASSERT(this->interface.in != NULL);
FUNCTION_TEST_END();
this->processIn(this->data, input);
this->interface.in(this->driver, input);
FUNCTION_TEST_RESULT_VOID();
}
@ -98,10 +85,10 @@ ioFilterProcessInOut(IoFilter *this, const Buffer *input, Buffer *output)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_ASSERT(output != NULL);
FUNCTION_TEST_ASSERT(this->processInOut != NULL);
FUNCTION_TEST_ASSERT(this->interface.inOut != NULL);
FUNCTION_TEST_END();
this->processInOut(this->data, input, output);
this->interface.inOut(this->driver, input, output);
FUNCTION_TEST_RESULT_VOID();
}
@ -139,7 +126,7 @@ ioFilterDone(const IoFilter *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(BOOL, this->done != NULL ? this->done(this->data) : !ioFilterInputSame(this));
FUNCTION_TEST_RESULT(BOOL, this->interface.done != NULL ? this->interface.done(this->driver) : !ioFilterInputSame(this));
}
/***********************************************************************************************************************************
@ -156,7 +143,7 @@ ioFilterInputSame(const IoFilter *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(BOOL, this->inputSame != NULL ? this->inputSame(this->data) : false);
FUNCTION_TEST_RESULT(BOOL, this->interface.inputSame != NULL ? this->interface.inputSame(this->driver) : false);
}
/***********************************************************************************************************************************
@ -173,7 +160,7 @@ ioFilterOutput(const IoFilter *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(BOOL, this->processInOut != NULL);
FUNCTION_TEST_RESULT(BOOL, this->interface.inOut != NULL);
}
/***********************************************************************************************************************************
@ -188,7 +175,7 @@ ioFilterResult(const IoFilter *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(VARIANT, this->result ? this->result(this->data) : NULL);
FUNCTION_TEST_RESULT(VARIANT, this->interface.result ? this->interface.result(this->driver) : NULL);
}
/***********************************************************************************************************************************

View File

@ -26,22 +26,6 @@ typedef struct IoFilter IoFilter;
#include "common/type/string.h"
#include "common/type/variant.h"
/***********************************************************************************************************************************
Function pointer types
***********************************************************************************************************************************/
typedef bool (*IoFilterDone)(const void *data);
typedef bool (*IoFilterInputSame)(const void *data);
typedef void (*IoFilterProcessIn)(void *data, const Buffer *);
typedef void (*IoFilterProcessInOut)(void *data, const Buffer *, Buffer *);
typedef Variant *(*IoFilterResult)(const void *data);
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
IoFilter *ioFilterNew(
const String *type, void *data, IoFilterDone done, IoFilterInputSame input, IoFilterProcessIn processIn,
IoFilterProcessInOut processInOut, IoFilterResult result);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/

View File

@ -0,0 +1,40 @@
/***********************************************************************************************************************************
IO Filter Interface Internal
***********************************************************************************************************************************/
#ifndef COMMON_IO_FILTER_FILTER_INTERN_H
#define COMMON_IO_FILTER_FILTER_INTERN_H
#include "common/io/filter/filter.h"
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
typedef bool (*IoFilterInterfaceDone)(const void *driver);
typedef void (*IoFilterInterfaceProcessIn)(void *driver, const Buffer *);
typedef void (*IoFilterInterfaceProcessInOut)(void *driver, const Buffer *, Buffer *);
typedef bool (*IoFilterInterfaceInputSame)(const void *driver);
typedef Variant *(*IoFilterInterfaceResult)(const void *driver);
typedef struct IoFilterInterface
{
IoFilterInterfaceDone done;
IoFilterInterfaceProcessIn in;
IoFilterInterfaceProcessInOut inOut;
IoFilterInterfaceInputSame inputSame;
IoFilterInterfaceResult result;
} IoFilterInterface;
#define ioFilterNewP(type, driver, ...) \
ioFilterNew(type, driver, (IoFilterInterface){__VA_ARGS__})
IoFilter *ioFilterNew(const String *type, void *driver, IoFilterInterface);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
#define FUNCTION_DEBUG_IO_FILTER_INTERFACE_TYPE \
IoFilterInterface *
#define FUNCTION_DEBUG_IO_FILTER_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoFilterInterface", buffer, bufferSize)
#endif

View File

@ -4,6 +4,7 @@ IO Size Filter
#include <stdio.h>
#include "common/debug.h"
#include "common/io/filter/filter.intern.h"
#include "common/io/filter/size.h"
#include "common/log.h"
#include "common/memContext.h"
@ -39,8 +40,10 @@ ioSizeNew(void)
this = memNew(sizeof(IoSize));
this->memContext = memContextCurrent();
this->filter = ioFilterNew(
strNew(SIZE_FILTER_TYPE), this, NULL, NULL, (IoFilterProcessIn)ioSizeProcess, NULL, (IoFilterResult)ioSizeResult);
// Create filter interface
this->filter = ioFilterNewP(
strNew(SIZE_FILTER_TYPE), this, .in = (IoFilterInterfaceProcessIn)ioSizeProcess,
.result = (IoFilterInterfaceResult)ioSizeResult);
}
MEM_CONTEXT_NEW_END();

View File

@ -3,7 +3,7 @@ IO Read Interface
***********************************************************************************************************************************/
#include "common/debug.h"
#include "common/io/io.h"
#include "common/io/read.h"
#include "common/io/read.intern.h"
#include "common/log.h"
#include "common/memContext.h"
@ -14,14 +14,10 @@ struct IoRead
{
MemContext *memContext; // Mem context of driver
void *driver; // Driver object
IoReadInterface interface; // Driver interface
IoFilterGroup *filterGroup; // IO filters
Buffer *input; // Input buffer
IoReadOpen open; // Driver open
IoReadProcess read; // Driver read
IoReadClose close; // Driver close
IoReadEof eof; // Driver eof
bool eofAll; // Is the read done (read and filters complete)?
#ifdef DEBUG
@ -36,28 +32,21 @@ New object
Allocations will be in the memory context of the caller.
***********************************************************************************************************************************/
IoRead *
ioReadNew(void *driver, IoReadOpen open, IoReadProcess read, IoReadClose close, IoReadEof eof)
ioReadNew(void *driver, IoReadInterface interface)
{
FUNCTION_DEBUG_BEGIN(logLevelTrace);
FUNCTION_DEBUG_PARAM(VOIDP, driver);
FUNCTION_DEBUG_PARAM(FUNCTIONP, open);
FUNCTION_DEBUG_PARAM(FUNCTIONP, read);
FUNCTION_DEBUG_PARAM(FUNCTIONP, close);
FUNCTION_DEBUG_PARAM(FUNCTIONP, eof);
FUNCTION_DEBUG_PARAM(IO_READ_INTERFACE, interface);
FUNCTION_TEST_ASSERT(driver != NULL);
FUNCTION_TEST_ASSERT(read != NULL);
FUNCTION_TEST_ASSERT(interface.read != NULL);
FUNCTION_DEBUG_END();
IoRead *this = memNew(sizeof(IoRead));
this->memContext = memContextCurrent();
this->input = bufNew(ioBufferSize());
this->driver = driver;
this->open = open;
this->read = read;
this->close = close;
this->eof = eof;
this->interface = interface;
this->input = bufNew(ioBufferSize());
FUNCTION_DEBUG_RESULT(IO_READ, this);
}
@ -76,7 +65,7 @@ ioReadOpen(IoRead *this)
FUNCTION_DEBUG_END();
// Open if the driver has an open function
bool result = this->open != NULL ? this->open(this->driver) : true;
bool result = this->interface.open != NULL ? this->interface.open(this->driver) : true;
// Only open the filter group if the read was opened
if (result)
@ -110,7 +99,7 @@ ioReadEofDriver(const IoRead *this)
FUNCTION_TEST_ASSERT(this->opened && !this->closed);
FUNCTION_DEBUG_END();
FUNCTION_DEBUG_RESULT(BOOL, this->eof != NULL ? this->eof(this->driver) : false);
FUNCTION_DEBUG_RESULT(BOOL, this->interface.eof != NULL ? this->interface.eof(this->driver) : false);
}
/***********************************************************************************************************************************
@ -144,7 +133,7 @@ ioRead(IoRead *this, Buffer *buffer)
if (!ioReadEofDriver(this))
{
bufUsedZero(this->input);
this->read(this->driver, this->input);
this->interface.read(this->driver, this->input);
}
// Set input to NULL and flush (no need to actually free the buffer here as it will be freed with the mem context)
else
@ -178,8 +167,8 @@ ioReadClose(IoRead *this)
ioFilterGroupClose(this->filterGroup);
// Close the driver if there is a close function
if (this->close != NULL)
this->close(this->driver);
if (this->interface.close != NULL)
this->interface.close(this->driver);
#ifdef DEBUG
this->closed = true;

View File

@ -17,19 +17,6 @@ typedef struct IoRead IoRead;
#include "common/io/filter/group.h"
#include "common/type/buffer.h"
/***********************************************************************************************************************************
Function pointer types
***********************************************************************************************************************************/
typedef bool (*IoReadOpen)(void *driver);
typedef size_t (*IoReadProcess)(void *driver, Buffer *buffer);
typedef void (*IoReadClose)(void *driver);
typedef bool (*IoReadEof)(void *driver);
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
IoRead *ioReadNew(void *driver, IoReadOpen open, IoReadProcess read, IoReadClose close, IoReadEof eof);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/

View File

@ -0,0 +1,38 @@
/***********************************************************************************************************************************
IO Read Interface Internal
***********************************************************************************************************************************/
#ifndef COMMON_IO_READ_INTERN_H
#define COMMON_IO_READ_INTERN_H
#include "common/io/read.h"
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
typedef bool (*IoReadInterfaceEof)(void *driver);
typedef void (*IoReadInterfaceClose)(void *driver);
typedef bool (*IoReadInterfaceOpen)(void *driver);
typedef size_t (*IoReadInterfaceRead)(void *driver, Buffer *buffer);
typedef struct IoReadInterface
{
IoReadInterfaceEof eof;
IoReadInterfaceClose close;
IoReadInterfaceOpen open;
IoReadInterfaceRead read;
} IoReadInterface;
#define ioReadNewP(driver, ...) \
ioReadNew(driver, (IoReadInterface){__VA_ARGS__})
IoRead *ioReadNew(void *driver, IoReadInterface interface);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
#define FUNCTION_DEBUG_IO_READ_INTERFACE_TYPE \
IoReadInterface
#define FUNCTION_DEBUG_IO_READ_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoReadInterface", buffer, bufferSize)
#endif

View File

@ -3,7 +3,7 @@ IO Write Interface
***********************************************************************************************************************************/
#include "common/debug.h"
#include "common/io/io.h"
#include "common/io/write.h"
#include "common/io/write.intern.h"
#include "common/log.h"
#include "common/memContext.h"
@ -14,13 +14,10 @@ struct IoWrite
{
MemContext *memContext; // Mem context of driver
void *driver; // Driver object
IoWriteInterface interface; // Driver interface
IoFilterGroup *filterGroup; // IO filters
Buffer *output; // Output buffer
IoWriteOpen open; // Driver open
IoWriteProcess write; // Driver write
IoWriteClose close; // Driver close
#ifdef DEBUG
bool opened; // Has the io been opened?
bool closed; // Has the io been closed?
@ -33,26 +30,21 @@ New object
Allocations will be in the memory context of the caller.
***********************************************************************************************************************************/
IoWrite *
ioWriteNew(void *driver, IoWriteOpen open, IoWriteProcess write, IoWriteClose close)
ioWriteNew(void *driver, IoWriteInterface interface)
{
FUNCTION_DEBUG_BEGIN(logLevelTrace);
FUNCTION_DEBUG_PARAM(VOIDP, driver);
FUNCTION_DEBUG_PARAM(FUNCTIONP, open);
FUNCTION_DEBUG_PARAM(FUNCTIONP, write);
FUNCTION_DEBUG_PARAM(FUNCTIONP, close);
FUNCTION_DEBUG_PARAM(IO_WRITE_INTERFACE, interface);
FUNCTION_TEST_ASSERT(driver != NULL);
FUNCTION_TEST_ASSERT(write != NULL);
FUNCTION_TEST_ASSERT(interface.write != NULL);
FUNCTION_DEBUG_END();
IoWrite *this = memNew(sizeof(IoWrite));
this->memContext = memContextCurrent();
this->output = bufNew(ioBufferSize());
this->driver = driver;
this->open = open;
this->write = write;
this->close = close;
this->interface = interface;
this->output = bufNew(ioBufferSize());
FUNCTION_DEBUG_RESULT(IO_WRITE, this);
}
@ -70,8 +62,8 @@ ioWriteOpen(IoWrite *this)
FUNCTION_TEST_ASSERT(!this->opened && !this->closed);
FUNCTION_DEBUG_END();
if (this->open != NULL)
this->open(this->driver);
if (this->interface.open != NULL)
this->interface.open(this->driver);
// If no filter group exists create one to do buffering
if (this->filterGroup == NULL)
@ -110,7 +102,7 @@ ioWrite(IoWrite *this, const Buffer *buffer)
// Write data if the buffer is full
if (bufRemains(this->output) == 0)
{
this->write(this->driver, this->output);
this->interface.write(this->driver, this->output);
bufUsedZero(this->output);
}
}
@ -141,7 +133,7 @@ ioWriteClose(IoWrite *this)
// Write data if the buffer is full or if this is the last buffer to be written
if (bufRemains(this->output) == 0 || (ioFilterGroupDone(this->filterGroup) && bufUsed(this->output) > 0))
{
this->write(this->driver, this->output);
this->interface.write(this->driver, this->output);
bufUsedZero(this->output);
}
}
@ -151,8 +143,8 @@ ioWriteClose(IoWrite *this)
ioFilterGroupClose(this->filterGroup);
// Close the driver if there is a close function
if (this->close != NULL)
this->close(this->driver);
if (this->interface.close != NULL)
this->interface.close(this->driver);
#ifdef DEBUG
this->closed = true;

View File

@ -16,18 +16,6 @@ typedef struct IoWrite IoWrite;
#include "common/io/filter/group.h"
#include "common/type/buffer.h"
/***********************************************************************************************************************************
Function pointer types
***********************************************************************************************************************************/
typedef void (*IoWriteOpen)(void *driver);
typedef void (*IoWriteProcess)(void *driver, const Buffer *buffer);
typedef void (*IoWriteClose)(void *driver);
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
IoWrite *ioWriteNew(void *driver, IoWriteOpen open, IoWriteProcess write, IoWriteClose close);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/

View File

@ -0,0 +1,36 @@
/***********************************************************************************************************************************
IO Write Interface Internal
***********************************************************************************************************************************/
#ifndef COMMON_IO_WRITE_INTERN_H
#define COMMON_IO_WRITE_INTERN_H
#include "common/io/write.h"
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
typedef void (*IoWriteInterfaceClose)(void *driver);
typedef void (*IoWriteInterfaceOpen)(void *driver);
typedef void (*IoWriteInterfaceWrite)(void *driver, const Buffer *buffer);
typedef struct IoWriteInterface
{
IoWriteInterfaceClose close;
IoWriteInterfaceOpen open;
IoWriteInterfaceWrite write;
} IoWriteInterface;
#define ioWriteNewP(driver, ...) \
ioWriteNew(driver, (IoWriteInterface){__VA_ARGS__})
IoWrite *ioWriteNew(void *driver, IoWriteInterface interface);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
#define FUNCTION_DEBUG_IO_WRITE_INTERFACE_TYPE \
IoWriteInterface
#define FUNCTION_DEBUG_IO_WRITE_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoWriteInterface", buffer, bufferSize)
#endif

View File

@ -6,6 +6,7 @@ Gzip Compress
#include "common/assert.h"
#include "common/debug.h"
#include "common/io/filter/filter.intern.h"
#include "common/log.h"
#include "common/memContext.h"
#include "compress/gzip.h"
@ -64,9 +65,10 @@ gzipCompressNew(int level, bool raw)
memContextCallback(this->memContext, (MemContextCallback)gzipCompressFree, this);
// Create filter interface
this->filter = ioFilterNew(
strNew(GZIP_COMPRESS_FILTER_TYPE), this, (IoFilterDone)gzipCompressDone, (IoFilterInputSame)gzipCompressInputSame,
NULL, (IoFilterProcessInOut)gzipCompressProcess, NULL);
this->filter = ioFilterNewP(
strNew(GZIP_COMPRESS_FILTER_TYPE), this, .done = (IoFilterInterfaceDone)gzipCompressDone,
.inOut = (IoFilterInterfaceProcessInOut)gzipCompressProcess,
.inputSame = (IoFilterInterfaceInputSame)gzipCompressInputSame);
}
MEM_CONTEXT_NEW_END();

View File

@ -5,6 +5,7 @@ Gzip Decompress
#include <zlib.h>
#include "common/debug.h"
#include "common/io/filter/filter.intern.h"
#include "common/log.h"
#include "common/memContext.h"
#include "compress/gzip.h"
@ -55,9 +56,10 @@ gzipDecompressNew(bool raw)
memContextCallback(this->memContext, (MemContextCallback)gzipDecompressFree, this);
// Create filter interface
this->filter = ioFilterNew(
strNew(GZIP_DECOMPRESS_FILTER_TYPE), this, (IoFilterDone)gzipDecompressDone, (IoFilterInputSame)gzipDecompressInputSame,
NULL, (IoFilterProcessInOut)gzipDecompressProcess, NULL);
this->filter = ioFilterNewP(
strNew(GZIP_DECOMPRESS_FILTER_TYPE), this, .done = (IoFilterInterfaceDone)gzipDecompressDone,
.inOut = (IoFilterInterfaceProcessInOut)gzipDecompressProcess,
.inputSame = (IoFilterInterfaceInputSame)gzipDecompressInputSame);
}
MEM_CONTEXT_NEW_END();

View File

@ -7,6 +7,7 @@ Cryptographic Hash
#include <openssl/err.h>
#include "common/debug.h"
#include "common/io/filter/filter.intern.h"
#include "common/log.h"
#include "common/memContext.h"
#include "crypto/crypto.h"
@ -69,9 +70,9 @@ cryptoHashNew(const String *type)
memContextCallback(this->memContext, (MemContextCallback)cryptoHashFree, this);
// Create filter interface
this->filter = ioFilterNew(
strNew(CRYPTO_HASH_FILTER_TYPE), this, NULL, NULL, (IoFilterProcessIn)cryptoHashProcess, NULL,
(IoFilterResult)cryptoHashResult);
this->filter = ioFilterNewP(
strNew(CRYPTO_HASH_FILTER_TYPE), this, .in = (IoFilterInterfaceProcessIn)cryptoHashProcess,
.result = (IoFilterInterfaceResult)cryptoHashResult);
}
MEM_CONTEXT_NEW_END();

View File

@ -6,6 +6,7 @@ Posix Storage File Read Driver
#include "common/assert.h"
#include "common/debug.h"
#include "common/io/read.intern.h"
#include "common/log.h"
#include "common/memContext.h"
#include "storage/driver/posix/common.h"
@ -28,16 +29,6 @@ struct StorageDriverPosixFileRead
bool eof;
};
/***********************************************************************************************************************************
Interface definition
***********************************************************************************************************************************/
static const StorageFileReadInterface storageFileReadInterface =
{
.ignoreMissing = (StorageFileReadIgnoreMissing)storageDriverPosixFileReadIgnoreMissing,
.io = (StorageFileReadIo)storageDriverPosixFileReadIo,
.name = (StorageFileReadName)storageDriverPosixFileReadName,
};
/***********************************************************************************************************************************
Create a new file
***********************************************************************************************************************************/
@ -64,10 +55,16 @@ storageDriverPosixFileReadNew(const StorageDriverPosix *storage, const String *n
this->handle = -1;
this->interface = storageFileReadNew(strNew(STORAGE_DRIVER_POSIX_TYPE), this, &storageFileReadInterface);
this->io = ioReadNew(
this, (IoReadOpen)storageDriverPosixFileReadOpen, (IoReadProcess)storageDriverPosixFileRead,
(IoReadClose)storageDriverPosixFileReadClose, (IoReadEof)storageDriverPosixFileReadEof);
this->interface = storageFileReadNewP(
strNew(STORAGE_DRIVER_POSIX_TYPE), this,
.ignoreMissing = (StorageFileReadInterfaceIgnoreMissing)storageDriverPosixFileReadIgnoreMissing,
.io = (StorageFileReadInterfaceIo)storageDriverPosixFileReadIo,
.name = (StorageFileReadInterfaceName)storageDriverPosixFileReadName);
this->io = ioReadNewP(
this, .eof = (IoReadInterfaceEof)storageDriverPosixFileReadEof,
.close = (IoReadInterfaceClose)storageDriverPosixFileReadClose,
.open = (IoReadInterfaceOpen)storageDriverPosixFileReadOpen, .read = (IoReadInterfaceRead)storageDriverPosixFileRead);
}
MEM_CONTEXT_NEW_END();

View File

@ -7,6 +7,7 @@ Posix Storage File Write Driver
#include "common/assert.h"
#include "common/debug.h"
#include "common/io/write.intern.h"
#include "common/log.h"
#include "common/memContext.h"
#include "storage/driver/posix/common.h"
@ -36,21 +37,6 @@ struct StorageDriverPosixFileWrite
int handle;
};
/***********************************************************************************************************************************
Interface definition
***********************************************************************************************************************************/
static const StorageFileWriteInterface storageFileWriteInterface =
{
.atomic = (StorageFileWriteAtomic)storageDriverPosixFileWriteAtomic,
.createPath = (StorageFileWriteCreatePath)storageDriverPosixFileWriteCreatePath,
.io = (StorageFileWriteIo)storageDriverPosixFileWriteIo,
.modeFile = (StorageFileWriteModeFile)storageDriverPosixFileWriteModeFile,
.modePath = (StorageFileWriteModePath)storageDriverPosixFileWriteModePath,
.name = (StorageFileWriteName)storageDriverPosixFileWriteName,
.syncFile = (StorageFileWriteSyncFile)storageDriverPosixFileWriteSyncFile,
.syncPath = (StorageFileWriteSyncPath)storageDriverPosixFileWriteSyncPath,
};
/***********************************************************************************************************************************
File open constants
@ -88,12 +74,22 @@ storageDriverPosixFileWriteNew(
{
this = memNew(sizeof(StorageDriverPosixFileWrite));
this->memContext = MEM_CONTEXT_NEW();
this->storage = storage;
this->interface = storageFileWriteNew(strNew(STORAGE_DRIVER_POSIX_TYPE), this, &storageFileWriteInterface);
this->io = ioWriteNew(
this, (IoWriteOpen)storageDriverPosixFileWriteOpen, (IoWriteProcess)storageDriverPosixFileWrite,
(IoWriteClose)storageDriverPosixFileWriteClose);
this->interface = storageFileWriteNewP(
strNew(STORAGE_DRIVER_POSIX_TYPE), this, .atomic = (StorageFileWriteInterfaceAtomic)storageDriverPosixFileWriteAtomic,
.createPath = (StorageFileWriteInterfaceCreatePath)storageDriverPosixFileWriteCreatePath,
.io = (StorageFileWriteInterfaceIo)storageDriverPosixFileWriteIo,
.modeFile = (StorageFileWriteInterfaceModeFile)storageDriverPosixFileWriteModeFile,
.modePath = (StorageFileWriteInterfaceModePath)storageDriverPosixFileWriteModePath,
.name = (StorageFileWriteInterfaceName)storageDriverPosixFileWriteName,
.syncFile = (StorageFileWriteInterfaceSyncFile)storageDriverPosixFileWriteSyncFile,
.syncPath = (StorageFileWriteInterfaceSyncPath)storageDriverPosixFileWriteSyncPath);
this->io = ioWriteNewP(
this, .close = (IoWriteInterfaceClose)storageDriverPosixFileWriteClose,
.open = (IoWriteInterfaceOpen)storageDriverPosixFileWriteOpen,
.write = (IoWriteInterfaceWrite)storageDriverPosixFileWrite);
this->path = strPath(name);
this->name = strDup(name);

View File

@ -29,23 +29,6 @@ struct StorageDriverPosix
Storage *interface; // Driver interface
};
/***********************************************************************************************************************************
Interface definition
***********************************************************************************************************************************/
static const StorageInterface storageInterface =
{
.exists = (StorageExistsFn)storageDriverPosixExists,
.info = (StorageInfoFn)storageDriverPosixInfo,
.list = (StorageListFn)storageDriverPosixList,
.move = (StorageMoveFn)storageDriverPosixMove,
.newRead = (StorageNewReadFn)storageDriverPosixNewRead,
.newWrite = (StorageNewWriteFn)storageDriverPosixNewWrite,
.pathCreate = (StoragePathCreateFn)storageDriverPosixPathCreate,
.pathRemove = (StoragePathRemoveFn)storageDriverPosixPathRemove,
.pathSync = (StoragePathSyncFn)storageDriverPosixPathSync,
.remove = (StorageRemoveFn)storageDriverPosixRemove,
};
/***********************************************************************************************************************************
New object
***********************************************************************************************************************************/
@ -71,8 +54,16 @@ storageDriverPosixNew(
this = memNew(sizeof(StorageDriverPosix));
this->memContext = MEM_CONTEXT_NEW();
this->interface = storageNew(
strNew(STORAGE_DRIVER_POSIX_TYPE), path, modeFile, modePath, write, pathExpressionFunction, this, &storageInterface);
this->interface = storageNewP(
strNew(STORAGE_DRIVER_POSIX_TYPE), path, modeFile, modePath, write, pathExpressionFunction, this,
.exists = (StorageInterfaceExists)storageDriverPosixExists, .info = (StorageInterfaceInfo)storageDriverPosixInfo,
.list = (StorageInterfaceList)storageDriverPosixList, .move = (StorageInterfaceMove)storageDriverPosixMove,
.newRead = (StorageInterfaceNewRead)storageDriverPosixNewRead,
.newWrite = (StorageInterfaceNewWrite)storageDriverPosixNewWrite,
.pathCreate = (StorageInterfacePathCreate)storageDriverPosixPathCreate,
.pathRemove = (StorageInterfacePathRemove)storageDriverPosixPathRemove,
.pathSync = (StorageInterfacePathSync)storageDriverPosixPathSync,
.remove = (StorageInterfaceRemove)storageDriverPosixRemove);
}
MEM_CONTEXT_NEW_END();

View File

@ -14,19 +14,15 @@ struct StorageFileRead
{
MemContext *memContext;
const String *type;
const StorageFileReadInterface *interface;
void *driver;
StorageFileReadIgnoreMissing ignoreMissing;
StorageFileReadIo io;
StorageFileReadName name;
StorageFileReadInterface interface;
};
/***********************************************************************************************************************************
Create a new storage file
***********************************************************************************************************************************/
StorageFileRead *
storageFileReadNew(const String *type, void *driver, const StorageFileReadInterface *interface)
storageFileReadNew(const String *type, void *driver, StorageFileReadInterface interface)
{
FUNCTION_DEBUG_BEGIN(logLevelTrace);
FUNCTION_DEBUG_PARAM(STRING, type);
@ -35,9 +31,9 @@ storageFileReadNew(const String *type, void *driver, const StorageFileReadInterf
FUNCTION_TEST_ASSERT(type != NULL);
FUNCTION_TEST_ASSERT(driver != NULL);
FUNCTION_TEST_ASSERT(interface->ignoreMissing != NULL);
FUNCTION_TEST_ASSERT(interface->io != NULL);
FUNCTION_TEST_ASSERT(interface->name != NULL);
FUNCTION_TEST_ASSERT(interface.ignoreMissing != NULL);
FUNCTION_TEST_ASSERT(interface.io != NULL);
FUNCTION_TEST_ASSERT(interface.name != NULL);
FUNCTION_DEBUG_END();
StorageFileRead *this = NULL;
@ -97,7 +93,7 @@ storageFileReadIgnoreMissing(const StorageFileRead *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(BOOL, this->interface->ignoreMissing(this->driver));
FUNCTION_TEST_RESULT(BOOL, this->interface.ignoreMissing(this->driver));
}
/***********************************************************************************************************************************
@ -112,7 +108,7 @@ storageFileReadIo(const StorageFileRead *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(IO_READ, this->interface->io(this->driver));
FUNCTION_TEST_RESULT(IO_READ, this->interface.io(this->driver));
}
/***********************************************************************************************************************************
@ -127,7 +123,7 @@ storageFileReadName(const StorageFileRead *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(CONST_STRING, this->interface->name(this->driver));
FUNCTION_TEST_RESULT(CONST_STRING, this->interface.name(this->driver));
}
/***********************************************************************************************************************************

View File

@ -7,30 +7,30 @@ Storage File Read Interface Internal
#include "storage/fileRead.h"
/***********************************************************************************************************************************
Interface
Constructor
***********************************************************************************************************************************/
typedef bool (*StorageFileReadIgnoreMissing)(const void *driver);
typedef IoRead *(*StorageFileReadIo)(const void *driver);
typedef const String *(*StorageFileReadName)(const void *driver);
typedef bool (*StorageFileReadInterfaceIgnoreMissing)(const void *driver);
typedef IoRead *(*StorageFileReadInterfaceIo)(const void *driver);
typedef const String *(*StorageFileReadInterfaceName)(const void *driver);
typedef struct StorageFileReadInterface
{
StorageFileReadIgnoreMissing ignoreMissing;
StorageFileReadIo io;
StorageFileReadName name;
StorageFileReadInterfaceIgnoreMissing ignoreMissing;
StorageFileReadInterfaceIo io;
StorageFileReadInterfaceName name;
} StorageFileReadInterface;
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
StorageFileRead *storageFileReadNew(const String *type, void *driver, const StorageFileReadInterface *interface);
#define storageFileReadNewP(type, driver, ...) \
storageFileReadNew(type, driver, (StorageFileReadInterface){__VA_ARGS__})
StorageFileRead *storageFileReadNew(const String *type, void *driver, StorageFileReadInterface interface);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
#define FUNCTION_DEBUG_STORAGE_FILE_READ_INTERFACE_TYPE \
StorageFileReadInterface *
StorageFileReadInterface
#define FUNCTION_DEBUG_STORAGE_FILE_READ_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "StorageFileReadInterface", buffer, bufferSize)
objToLog(&value, "StorageFileReadInterface", buffer, bufferSize)
#endif

View File

@ -15,7 +15,7 @@ struct StorageFileWrite
MemContext *memContext;
const String *type;
void *driver;
const StorageFileWriteInterface *interface;
StorageFileWriteInterface interface;
};
/***********************************************************************************************************************************
@ -25,7 +25,7 @@ This object expects its context to be created in advance. This is so the callin
required multiple functions and contexts to make it safe.
***********************************************************************************************************************************/
StorageFileWrite *
storageFileWriteNew(const String *type, void *driver, const StorageFileWriteInterface *interface)
storageFileWriteNew(const String *type, void *driver, StorageFileWriteInterface interface)
{
FUNCTION_DEBUG_BEGIN(logLevelTrace);
FUNCTION_DEBUG_PARAM(STRING, type);
@ -34,15 +34,14 @@ storageFileWriteNew(const String *type, void *driver, const StorageFileWriteInte
FUNCTION_TEST_ASSERT(type != NULL);
FUNCTION_TEST_ASSERT(driver != NULL);
FUNCTION_TEST_ASSERT(interface != NULL);
FUNCTION_TEST_ASSERT(interface->atomic != NULL);
FUNCTION_TEST_ASSERT(interface->createPath != NULL);
FUNCTION_TEST_ASSERT(interface->io != NULL);
FUNCTION_TEST_ASSERT(interface->modeFile != NULL);
FUNCTION_TEST_ASSERT(interface->modePath != NULL);
FUNCTION_TEST_ASSERT(interface->name != NULL);
FUNCTION_TEST_ASSERT(interface->syncFile != NULL);
FUNCTION_TEST_ASSERT(interface->syncPath != NULL);
FUNCTION_TEST_ASSERT(interface.atomic != NULL);
FUNCTION_TEST_ASSERT(interface.createPath != NULL);
FUNCTION_TEST_ASSERT(interface.io != NULL);
FUNCTION_TEST_ASSERT(interface.modeFile != NULL);
FUNCTION_TEST_ASSERT(interface.modePath != NULL);
FUNCTION_TEST_ASSERT(interface.name != NULL);
FUNCTION_TEST_ASSERT(interface.syncFile != NULL);
FUNCTION_TEST_ASSERT(interface.syncPath != NULL);
FUNCTION_DEBUG_END();
StorageFileWrite *this = memNew(sizeof(StorageFileWrite));
@ -88,7 +87,7 @@ storageFileWriteAtomic(const StorageFileWrite *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(BOOL, this->interface->atomic(this->driver));
FUNCTION_TEST_RESULT(BOOL, this->interface.atomic(this->driver));
}
/***********************************************************************************************************************************
@ -103,7 +102,7 @@ storageFileWriteCreatePath(const StorageFileWrite *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(BOOL, this->interface->createPath(this->driver));
FUNCTION_TEST_RESULT(BOOL, this->interface.createPath(this->driver));
}
/***********************************************************************************************************************************
@ -133,7 +132,7 @@ storageFileWriteIo(const StorageFileWrite *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(IO_WRITE, this->interface->io(this->driver));
FUNCTION_TEST_RESULT(IO_WRITE, this->interface.io(this->driver));
}
/***********************************************************************************************************************************
@ -148,7 +147,7 @@ storageFileWriteModeFile(const StorageFileWrite *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(MODE, this->interface->modeFile(this->driver));
FUNCTION_TEST_RESULT(MODE, this->interface.modeFile(this->driver));
}
/***********************************************************************************************************************************
@ -163,7 +162,7 @@ storageFileWriteModePath(const StorageFileWrite *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(MODE, this->interface->modePath(this->driver));
FUNCTION_TEST_RESULT(MODE, this->interface.modePath(this->driver));
}
/***********************************************************************************************************************************
@ -178,7 +177,7 @@ storageFileWriteName(const StorageFileWrite *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(CONST_STRING, this->interface->name(this->driver));
FUNCTION_TEST_RESULT(CONST_STRING, this->interface.name(this->driver));
}
/***********************************************************************************************************************************
@ -193,7 +192,7 @@ storageFileWriteSyncFile(const StorageFileWrite *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(BOOL, this->interface->syncFile(this->driver));
FUNCTION_TEST_RESULT(BOOL, this->interface.syncFile(this->driver));
}
/***********************************************************************************************************************************
@ -208,7 +207,7 @@ storageFileWriteSyncPath(const StorageFileWrite *this)
FUNCTION_TEST_ASSERT(this != NULL);
FUNCTION_TEST_END();
FUNCTION_TEST_RESULT(BOOL, this->interface->syncPath(this->driver));
FUNCTION_TEST_RESULT(BOOL, this->interface.syncPath(this->driver));
}
/***********************************************************************************************************************************

View File

@ -13,40 +13,40 @@ Temporary file extension
#define STORAGE_FILE_TEMP_EXT PGBACKREST_BIN ".tmp"
/***********************************************************************************************************************************
Interface
Constructor
***********************************************************************************************************************************/
typedef bool (*StorageFileWriteAtomic)(const void *data);
typedef bool (*StorageFileWriteCreatePath)(const void *data);
typedef IoWrite *(*StorageFileWriteIo)(const void *data);
typedef mode_t (*StorageFileWriteModeFile)(const void *data);
typedef mode_t (*StorageFileWriteModePath)(const void *data);
typedef const String *(*StorageFileWriteName)(const void *data);
typedef bool (*StorageFileWriteSyncFile)(const void *data);
typedef bool (*StorageFileWriteSyncPath)(const void *data);
typedef bool (*StorageFileWriteInterfaceAtomic)(const void *data);
typedef bool (*StorageFileWriteInterfaceCreatePath)(const void *data);
typedef IoWrite *(*StorageFileWriteInterfaceIo)(const void *data);
typedef mode_t (*StorageFileWriteInterfaceModeFile)(const void *data);
typedef mode_t (*StorageFileWriteInterfaceModePath)(const void *data);
typedef const String *(*StorageFileWriteInterfaceName)(const void *data);
typedef bool (*StorageFileWriteInterfaceSyncFile)(const void *data);
typedef bool (*StorageFileWriteInterfaceSyncPath)(const void *data);
typedef struct StorageFileWriteInterface
{
StorageFileWriteAtomic atomic;
StorageFileWriteCreatePath createPath;
StorageFileWriteIo io;
StorageFileWriteModeFile modeFile;
StorageFileWriteModePath modePath;
StorageFileWriteName name;
StorageFileWriteSyncFile syncFile;
StorageFileWriteSyncPath syncPath;
StorageFileWriteInterfaceAtomic atomic;
StorageFileWriteInterfaceCreatePath createPath;
StorageFileWriteInterfaceIo io;
StorageFileWriteInterfaceModeFile modeFile;
StorageFileWriteInterfaceModePath modePath;
StorageFileWriteInterfaceName name;
StorageFileWriteInterfaceSyncFile syncFile;
StorageFileWriteInterfaceSyncPath syncPath;
} StorageFileWriteInterface;
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
StorageFileWrite *storageFileWriteNew(const String *type, void *driver, const StorageFileWriteInterface *interface);
#define storageFileWriteNewP(type, driver, ...) \
storageFileWriteNew(type, driver, (StorageFileWriteInterface){__VA_ARGS__})
StorageFileWrite *storageFileWriteNew(const String *type, void *driver, StorageFileWriteInterface interface);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
#define FUNCTION_DEBUG_STORAGE_FILE_WRITE_INTERFACE_TYPE \
StorageFileWriteInterface *
StorageFileWriteInterface
#define FUNCTION_DEBUG_STORAGE_FILE_WRITE_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "StorageFileWriteInterface", buffer, bufferSize)
objToLog(&value, "StorageFileWriteInterface", buffer, bufferSize)
#endif

View File

@ -19,7 +19,7 @@ struct Storage
{
MemContext *memContext;
const void *driver;
const StorageInterface *interface;
StorageInterface interface;
const String *type;
const String *path;
@ -35,7 +35,7 @@ New storage object
Storage *
storageNew(
const String *type, const String *path, mode_t modeFile, mode_t modePath, bool write,
StoragePathExpressionCallback pathExpressionFunction, const void *driver, const StorageInterface *interface)
StoragePathExpressionCallback pathExpressionFunction, const void *driver, StorageInterface interface)
{
FUNCTION_DEBUG_BEGIN(logLevelTrace);
FUNCTION_DEBUG_PARAM(STRING, type);
@ -50,17 +50,16 @@ storageNew(
FUNCTION_TEST_ASSERT(type != NULL);
FUNCTION_TEST_ASSERT(path != NULL);
FUNCTION_TEST_ASSERT(driver != NULL);
FUNCTION_TEST_ASSERT(interface != NULL);
FUNCTION_TEST_ASSERT(interface->exists != NULL);
FUNCTION_TEST_ASSERT(interface->info != NULL);
FUNCTION_TEST_ASSERT(interface->list != NULL);
FUNCTION_TEST_ASSERT(interface->move != NULL);
FUNCTION_TEST_ASSERT(interface->newRead != NULL);
FUNCTION_TEST_ASSERT(interface->newWrite != NULL);
FUNCTION_TEST_ASSERT(interface->pathCreate != NULL);
FUNCTION_TEST_ASSERT(interface->pathRemove != NULL);
FUNCTION_TEST_ASSERT(interface->pathSync != NULL);
FUNCTION_TEST_ASSERT(interface->remove != NULL);
FUNCTION_TEST_ASSERT(interface.exists != NULL);
FUNCTION_TEST_ASSERT(interface.info != NULL);
FUNCTION_TEST_ASSERT(interface.list != NULL);
FUNCTION_TEST_ASSERT(interface.move != NULL);
FUNCTION_TEST_ASSERT(interface.newRead != NULL);
FUNCTION_TEST_ASSERT(interface.newWrite != NULL);
FUNCTION_TEST_ASSERT(interface.pathCreate != NULL);
FUNCTION_TEST_ASSERT(interface.pathRemove != NULL);
FUNCTION_TEST_ASSERT(interface.pathSync != NULL);
FUNCTION_TEST_ASSERT(interface.remove != NULL);
FUNCTION_DEBUG_END();
Storage *this = NULL;
@ -156,7 +155,7 @@ storageExists(const Storage *this, const String *pathExp, StorageExistsParam par
do
{
// Call driver function
result = this->interface->exists(this->driver, path);
result = this->interface.exists(this->driver, path);
}
while (!result && wait != NULL && waitMore(wait));
}
@ -249,7 +248,7 @@ storageInfo(const Storage *this, const String *fileExp, StorageInfoParam param)
String *file = storagePathNP(this, fileExp);
// Call driver function
result = this->interface->info(this->driver, file, param.ignoreMissing);
result = this->interface.info(this->driver, file, param.ignoreMissing);
}
MEM_CONTEXT_TEMP_END();
@ -279,7 +278,7 @@ storageList(const Storage *this, const String *pathExp, StorageListParam param)
String *path = storagePathNP(this, pathExp);
// Move list up to the old context
result = strLstMove(this->interface->list(this->driver, path, param.errorOnMissing, param.expression), MEM_CONTEXT_OLD());
result = strLstMove(this->interface.list(this->driver, path, param.errorOnMissing, param.expression), MEM_CONTEXT_OLD());
}
MEM_CONTEXT_TEMP_END();
@ -306,19 +305,19 @@ storageMove(const Storage *this, StorageFileRead *source, StorageFileWrite *dest
MEM_CONTEXT_TEMP_BEGIN()
{
// If the file can't be moved it will need to be copied
if (!this->interface->move(this->driver, storageFileReadDriver(source), storageFileWriteFileDriver(destination)))
if (!this->interface.move(this->driver, storageFileReadDriver(source), storageFileWriteFileDriver(destination)))
{
// Perform the copy
storageCopyNP(source, destination);
// Remove the source file
this->interface->remove(this->driver, storageFileReadName(source), false);
this->interface.remove(this->driver, storageFileReadName(source), false);
// Sync source path if the destination path was synced. We know the source and destination paths are different because
// the move did not succeed. This will need updating when drivers other than Posix/CIFS are implemented becaue there's
// no way to get coverage on it now.
if (storageFileWriteSyncPath(destination))
this->interface->pathSync(this->driver, strPath(storageFileReadName(source)), false);
this->interface.pathSync(this->driver, strPath(storageFileReadName(source)), false);
}
}
MEM_CONTEXT_TEMP_END();
@ -345,7 +344,7 @@ storageNewRead(const Storage *this, const String *fileExp, StorageNewReadParam p
MEM_CONTEXT_TEMP_BEGIN()
{
result = this->interface->newRead(this->driver, storagePathNP(this, fileExp), param.ignoreMissing);
result = this->interface.newRead(this->driver, storagePathNP(this, fileExp), param.ignoreMissing);
if (param.filterGroup != NULL)
ioReadFilterGroupSet(storageFileReadIo(result), param.filterGroup);
@ -382,7 +381,7 @@ storageNewWrite(const Storage *this, const String *fileExp, StorageNewWriteParam
MEM_CONTEXT_TEMP_BEGIN()
{
result = this->interface->newWrite(
result = this->interface.newWrite(
this->driver, storagePathNP(this, fileExp), param.modeFile != 0 ? param.modeFile : this->modeFile,
param.modePath != 0 ? param.modePath : this->modePath, !param.noCreatePath, !param.noSyncFile, !param.noSyncPath,
!param.noAtomic);
@ -527,7 +526,7 @@ storagePathCreate(const Storage *this, const String *pathExp, StoragePathCreateP
String *path = storagePathNP(this, pathExp);
// Call driver function
this->interface->pathCreate(
this->interface.pathCreate(
this->driver, path, param.errorOnExists, param.noParentCreate, param.mode != 0 ? param.mode : this->modePath);
}
MEM_CONTEXT_TEMP_END();
@ -557,7 +556,7 @@ storagePathRemove(const Storage *this, const String *pathExp, StoragePathRemoveP
String *path = storagePathNP(this, pathExp);
// Call driver function
this->interface->pathRemove(this->driver, path, param.errorOnMissing, param.recurse);
this->interface.pathRemove(this->driver, path, param.errorOnMissing, param.recurse);
}
MEM_CONTEXT_TEMP_END();
@ -584,7 +583,7 @@ void storagePathSync(const Storage *this, const String *pathExp, StoragePathSync
String *path = storagePathNP(this, pathExp);
// Call driver function
this->interface->pathSync(this->driver, path, param.ignoreMissing);
this->interface.pathSync(this->driver, path, param.ignoreMissing);
}
MEM_CONTEXT_TEMP_END();
@ -632,7 +631,7 @@ storageRemove(const Storage *this, const String *fileExp, StorageRemoveParam par
String *file = storagePathNP(this, fileExp);
// Call driver function
this->interface->remove(this->driver, file, param.errorOnMissing);
this->interface.remove(this->driver, file, param.errorOnMissing);
}
MEM_CONTEXT_TEMP_END();

View File

@ -12,36 +12,6 @@ Default file and path modes
#define STORAGE_MODE_FILE_DEFAULT 0640
#define STORAGE_MODE_PATH_DEFAULT 0750
/***********************************************************************************************************************************
Interface
***********************************************************************************************************************************/
typedef bool (*StorageExistsFn)(const void *driver, const String *path);
typedef StorageInfo (*StorageInfoFn)(const void *driver, const String *file, bool ignoreMissing);
typedef StringList *(*StorageListFn)(const void *driver, const String *path, bool errorOnMissing, const String *expression);
typedef bool (*StorageMoveFn)(const void *driver, void *source, void *destination);
typedef StorageFileRead *(*StorageNewReadFn)(const void *driver, const String *file, bool ignoreMissing);
typedef StorageFileWrite *(*StorageNewWriteFn)(
const void *driver, const String *file, mode_t modeFile, mode_t modePath, bool createPath, bool syncFile, bool syncPath,
bool atomic);
typedef void (*StoragePathCreateFn)(const void *driver, const String *path, bool errorOnExists, bool noParentCreate, mode_t mode);
typedef void (*StoragePathRemoveFn)(const void *driver, const String *path, bool errorOnMissing, bool recurse);
typedef void (*StoragePathSyncFn)(const void *driver, const String *path, bool ignoreMissing);
typedef void (*StorageRemoveFn)(const void *driver, const String *file, bool errorOnMissing);
typedef struct StorageInterface
{
StorageExistsFn exists;
StorageInfoFn info;
StorageListFn list;
StorageMoveFn move;
StorageNewReadFn newRead;
StorageNewWriteFn newWrite;
StoragePathCreateFn pathCreate;
StoragePathRemoveFn pathRemove;
StoragePathSyncFn pathSync;
StorageRemoveFn remove;
} StorageInterface;
/***********************************************************************************************************************************
Path expression callback function type - used to modify paths based on expressions enclosed in <>
***********************************************************************************************************************************/
@ -50,16 +20,47 @@ typedef String *(*StoragePathExpressionCallback)(const String *expression, const
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
typedef bool (*StorageInterfaceExists)(const void *driver, const String *path);
typedef StorageInfo (*StorageInterfaceInfo)(const void *driver, const String *file, bool ignoreMissing);
typedef StringList *(*StorageInterfaceList)(const void *driver, const String *path, bool errorOnMissing, const String *expression);
typedef bool (*StorageInterfaceMove)(const void *driver, void *source, void *destination);
typedef StorageFileRead *(*StorageInterfaceNewRead)(const void *driver, const String *file, bool ignoreMissing);
typedef StorageFileWrite *(*StorageInterfaceNewWrite)(
const void *driver, const String *file, mode_t modeFile, mode_t modePath, bool createPath, bool syncFile, bool syncPath,
bool atomic);
typedef void (*StorageInterfacePathCreate)(
const void *driver, const String *path, bool errorOnExists, bool noParentCreate, mode_t mode);
typedef void (*StorageInterfacePathRemove)(const void *driver, const String *path, bool errorOnMissing, bool recurse);
typedef void (*StorageInterfacePathSync)(const void *driver, const String *path, bool ignoreMissing);
typedef void (*StorageInterfaceRemove)(const void *driver, const String *file, bool errorOnMissing);
typedef struct StorageInterface
{
StorageInterfaceExists exists;
StorageInterfaceInfo info;
StorageInterfaceList list;
StorageInterfaceMove move;
StorageInterfaceNewRead newRead;
StorageInterfaceNewWrite newWrite;
StorageInterfacePathCreate pathCreate;
StorageInterfacePathRemove pathRemove;
StorageInterfacePathSync pathSync;
StorageInterfaceRemove remove;
} StorageInterface;
#define storageNewP(type, path, modeFile, modePath, write, pathExpressionFunction, driver, ...) \
storageNew(type, path, modeFile, modePath, write, pathExpressionFunction, driver, (StorageInterface){__VA_ARGS__})
Storage *storageNew(
const String *type, const String *path, mode_t modeFile, mode_t modePath, bool write,
StoragePathExpressionCallback pathExpressionFunction, const void *driver, const StorageInterface *interface);
StoragePathExpressionCallback pathExpressionFunction, const void *driver, StorageInterface interface);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
#define FUNCTION_DEBUG_STORAGE_INTERFACE_TYPE \
StorageInterface *
StorageInterface
#define FUNCTION_DEBUG_STORAGE_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "StorageInterface", buffer, bufferSize)
objToLog(&value, "StorageInterface", buffer, bufferSize)
#endif

View File

@ -18,7 +18,7 @@ testIoReadOpen(void *driver)
}
static size_t
testIoReadProcess(void *driver, Buffer *buffer)
testIoRead(void *driver, Buffer *buffer)
{
ASSERT(driver == (void *)999);
bufCat(buffer, bufNewStr(strNew("Z")));
@ -47,7 +47,7 @@ testIoWriteOpen(void *driver)
}
static void
testIoWriteProcess(void *driver, const Buffer *buffer)
testIoWrite(void *driver, const Buffer *buffer)
{
ASSERT(driver == (void *)999);
ASSERT(strEq(strNewBuf(buffer), strNew("ABC")));
@ -106,9 +106,9 @@ ioTestFilterSizeNew(const char *type)
this = memNew(sizeof(IoTestFilterSize));
this->memContext = MEM_CONTEXT_NEW();
this->filter = ioFilterNew(
strNew(type), this, NULL, NULL, (IoFilterProcessIn)ioTestFilterSizeProcess, NULL,
(IoFilterResult)ioTestFilterSizeResult);
this->filter = ioFilterNewP(
strNew(type), this, .in = (IoFilterInterfaceProcessIn)ioTestFilterSizeProcess,
.result = (IoFilterInterfaceResult)ioTestFilterSizeResult);
}
MEM_CONTEXT_NEW_END();
@ -194,9 +194,10 @@ ioTestFilterDoubleNew(const char *type, unsigned int flushTotal)
this->bufferFilter = ioBufferFilter(ioBufferNew());
this->flushTotal = flushTotal;
this->filter = ioFilterNew(
strNew(type), this, (IoFilterDone)ioTestFilterDoubleDone, (IoFilterInputSame)ioTestFilterDoubleInputSame, NULL,
(IoFilterProcessInOut)ioTestFilterDoubleProcess, NULL);
this->filter = ioFilterNewP(
strNew(type), this, .done = (IoFilterInterfaceDone)ioTestFilterDoubleDone,
.inOut = (IoFilterInterfaceProcessInOut)ioTestFilterDoubleProcess,
.inputSame = (IoFilterInterfaceInputSame)ioTestFilterDoubleInputSame);
}
MEM_CONTEXT_NEW_END();
@ -227,12 +228,18 @@ testRun(void)
ioBufferSizeSet(2);
TEST_ASSIGN(
read, ioReadNew((void *)998, testIoReadOpen, testIoReadProcess, testIoReadClose, NULL), "create io read object");
read,
ioReadNewP((void *)998, .close = (IoReadInterfaceClose)testIoReadClose, .open = (IoReadInterfaceOpen)testIoReadOpen,
.read = (IoReadInterfaceRead)testIoRead),
"create io read object");
TEST_RESULT_BOOL(ioReadOpen(read), false, " open io object");
TEST_ASSIGN(
read, ioReadNew((void *)999, testIoReadOpen, testIoReadProcess, testIoReadClose, NULL), "create io read object");
read,
ioReadNewP((void *)999, .close = (IoReadInterfaceClose)testIoReadClose, .open = (IoReadInterfaceOpen)testIoReadOpen,
.read = (IoReadInterfaceRead)testIoRead),
"create io read object");
TEST_RESULT_BOOL(ioReadOpen(read), true, " open io object");
TEST_RESULT_SIZE(ioRead(read, buffer), 2, " read 2 bytes");
@ -317,7 +324,11 @@ testRun(void)
ioBufferSizeSet(3);
TEST_ASSIGN(
write, ioWriteNew((void *)999, testIoWriteOpen, testIoWriteProcess, testIoWriteClose), "create io write object");
write,
ioWriteNewP(
(void *)999, .close = (IoWriteInterfaceClose)testIoWriteClose, .open = (IoWriteInterfaceOpen)testIoWriteOpen,
.write = (IoWriteInterfaceWrite)testIoWrite),
"create io write object");
TEST_RESULT_VOID(ioWriteOpen(write), " open io object");
TEST_RESULT_BOOL(testIoWriteOpenCalled, true, " check io object open");