diff --git a/examples/server_example_basic_io/server_example_basic_io.c b/examples/server_example_basic_io/server_example_basic_io.c index 218a7466..b77b814c 100644 --- a/examples/server_example_basic_io/server_example_basic_io.c +++ b/examples/server_example_basic_io/server_example_basic_io.c @@ -3,6 +3,7 @@ * * - How to use simple control models * - How to serve analog measurement data + * - Using the IedServerConfig object to configure stack features */ #include "iec61850_server.h" @@ -89,16 +90,15 @@ main(int argc, char** argv) /* Set buffer size for buffered report control blocks to 200000 bytes */ IedServerConfig_setReportBufferSize(config, 200000); + /* Set the base path for the MMS file services */ + IedServerConfig_setFileServiceBasePath(config, "./vmd-filestore/"); + /* Create a new IEC 61850 server instance */ iedServer = IedServer_createWithConfig(&iedModel, NULL, config); /* configuration object is no longer required */ IedServerConfig_destroy(config); - /* Set the base path for the MMS file services */ - MmsServer mmsServer = IedServer_getMmsServer(iedServer); - MmsServer_setFilestoreBasepath(mmsServer, "./vmd-filestore/"); - /* Install handler for operate command */ IedServer_setControlHandler(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO1, (ControlHandler) controlHandlerForBinaryOutput, diff --git a/src/iec61850/inc/iec61850_server.h b/src/iec61850/inc/iec61850_server.h index 30f57201..39589a64 100644 --- a/src/iec61850/inc/iec61850_server.h +++ b/src/iec61850/inc/iec61850_server.h @@ -50,6 +50,9 @@ struct sIedServerConfig { /** size of the report buffer associated with a buffered report control block */ int reportBufferSize; + + /** Base path (directory where the file service serves files */ + char* fileServiceBasepath; }; /** @@ -82,6 +85,20 @@ IedServerConfig_setReportBufferSize(IedServerConfig self, int reportBufferSize); int IedServerConfig_getReportBufferSize(IedServerConfig self); +/** + * \brief Set the basepath of the file services + * + * \param basepath new file service base path + */ +void +IedServerConfig_setFileServiceBasePath(IedServerConfig self, const char* basepath); + +/** + * \brief Get the basepath of the file services + */ +const char* +IedServerConfig_getFileServiceBasePath(IedServerConfig self); + /** diff --git a/src/iec61850/server/impl/ied_server.c b/src/iec61850/server/impl/ied_server.c index 28081980..8fa94f6e 100644 --- a/src/iec61850/server/impl/ied_server.c +++ b/src/iec61850/server/impl/ied_server.c @@ -421,6 +421,9 @@ IedServer_createWithConfig(IedModel* dataModel, TLSConfiguration tlsConfiguratio self->mmsServer = MmsServer_create(self->mmsDevice, tlsConfiguration); + if (serverConfiguration) + MmsServer_setFilestoreBasepath(self->mmsServer, serverConfiguration->fileServiceBasepath); + MmsMapping_setMmsServer(self->mmsMapping, self->mmsServer); MmsMapping_installHandlers(self->mmsMapping); diff --git a/src/iec61850/server/impl/ied_server_config.c b/src/iec61850/server/impl/ied_server_config.c index 4f0f5072..2fa5065a 100644 --- a/src/iec61850/server/impl/ied_server_config.c +++ b/src/iec61850/server/impl/ied_server_config.c @@ -31,6 +31,7 @@ IedServerConfig_create() if (self) { self->reportBufferSize = CONFIG_REPORTING_DEFAULT_REPORT_BUFFER_SIZE; + self->fileServiceBasepath = StringUtils_copyString(CONFIG_VIRTUAL_FILESTORE_BASEPATH); } return self; @@ -39,6 +40,7 @@ IedServerConfig_create() void IedServerConfig_destroy(IedServerConfig self) { + GLOBAL_FREEMEM(self->fileServiceBasepath); GLOBAL_FREEMEM(self); } @@ -53,3 +55,21 @@ IedServerConfig_getReportBufferSize(IedServerConfig self) { return self->reportBufferSize; } + +void +IedServerConfig_setFileServiceBasePath(IedServerConfig self, const char* basepath) +{ +#if (CONFIG_SET_FILESTORE_BASEPATH_AT_RUNTIME == 1) + GLOBAL_FREEMEM(self->fileServiceBasepath); + self->fileServiceBasepath = StringUtils_copyString(basepath); +#else + if (DEBUG_IED_SERVER) + printf("IED_SERVER_CONFIG: Cannot set file service basepath (enable CONFIG_SET_FILESTORE_BASEPATH_AT_RUNTIME)!\n"); +#endif +} + +const char* +IedServerConfig_getFileServiceBasePath(IedServerConfig self) +{ + return self->fileServiceBasepath; +} diff --git a/src/vs/libiec61850-wo-goose.def b/src/vs/libiec61850-wo-goose.def index 7c866d42..3df65ab0 100644 --- a/src/vs/libiec61850-wo-goose.def +++ b/src/vs/libiec61850-wo-goose.def @@ -585,4 +585,6 @@ EXPORTS IedServerConfig_destroy IedServerConfig_setReportBufferSize IedServerConfig_getReportBufferSize - IedServer_createWithConfig \ No newline at end of file + IedServer_createWithConfig + IedServerConfig_setFileServiceBasePath + IedServerConfig_getFileServiceBasePath diff --git a/src/vs/libiec61850.def b/src/vs/libiec61850.def index c9190c50..1f7fe8ce 100644 --- a/src/vs/libiec61850.def +++ b/src/vs/libiec61850.def @@ -712,4 +712,6 @@ EXPORTS IedServerConfig_destroy IedServerConfig_setReportBufferSize IedServerConfig_getReportBufferSize - IedServer_createWithConfig \ No newline at end of file + IedServer_createWithConfig + IedServerConfig_setFileServiceBasePath + IedServerConfig_getFileServiceBasePath