diff --git a/src/drivers/dandroid/src/dandroid.cpp b/src/drivers/dandroid/src/dandroid.cpp index e322e9f4..3c5af00a 100644 --- a/src/drivers/dandroid/src/dandroid.cpp +++ b/src/drivers/dandroid/src/dandroid.cpp @@ -82,11 +82,22 @@ extern "C" int moduleWelcome(const tModWelcomeIn * welcomeIn, // Save module name and loadDir, and determine module XML file pathname. setRobotName(welcomeIn->name); - // Filehandle for robot's xml-file - void* pRobotSettings = GfParmReadFileLocal(pathBuffer, GFPARM_RMODE_STD); - PLogDANDROID = GfLogger::instance("DANDROID"); + std::string dirstr = std::string(GfLocalDir()) + "drivers/dandroid"; + const char *dir = dirstr.c_str(); + + if (GfDirCreate(dir) != GF_DIR_CREATED) + { + PLogDANDROID->error("GfDirCreate %s failed\n", dir); + return -1; + } + + int ret = 0; + // Filehandle for robot's xml-file + void* pRobotSettings = GfParmReadFileLocal(pathBuffer, + GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); + // Loop over all possible drivers, clear all buffers, // save defined driver names and descriptions. driver.clear(); @@ -94,22 +105,15 @@ extern "C" int moduleWelcome(const tModWelcomeIn * welcomeIn, if (pRobotSettings) // robot settings XML could be read { - char SectionBuffer[BUFSIZE]; - snprintf(SectionBuffer, BUFSIZE, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, 0); - - // Try to get first driver from index 0 - string sDriverName = GfParmGetStrNC(pRobotSettings, - SectionBuffer, - ROB_ATTR_NAME, - const_cast(sUndefined)); - int n = GfParmGetEltNb(pRobotSettings, ROB_SECT_ROBOTS "/" ROB_LIST_INDEX); for (int i = 0; i < n; i++) { + char SectionBuffer[BUFSIZE]; + snprintf(SectionBuffer, BUFSIZE, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, i); - sDriverName = GfParmGetStr(pRobotSettings, SectionBuffer, + std::string sDriverName = GfParmGetStr(pRobotSettings, SectionBuffer, ROB_ATTR_NAME, sUndefined); string sDriverDesc = GfParmGetStr(pRobotSettings, SectionBuffer, @@ -118,6 +122,12 @@ extern "C" int moduleWelcome(const tModWelcomeIn * welcomeIn, driver.push_back(TDriver(i)); } // for i + if (GfParmWriteFile(nullptr, pRobotSettings, "dandroid")) + { + PLogDANDROID->error("GfParmWriteFile failed\n"); + ret = -1; + } + GfParmReleaseHandle(pRobotSettings); } else @@ -128,7 +138,7 @@ extern "C" int moduleWelcome(const tModWelcomeIn * welcomeIn, // Set max nb of interfaces to return. welcomeOut->maxNbItf = driver.size(); - return 0; + return ret; } // Module entry point (new fixed name scheme). @@ -167,18 +177,24 @@ extern "C" int moduleTerminate() // Module entry point extern "C" int dandroid(tModInfo * modInfo) { + std::string dirstr = std::string(GfLocalDir()) + "drivers/dandroid"; + const char *dir = dirstr.c_str(); + + if (GfDirCreate(dir) != GF_DIR_CREATED) + return -1; + driver.clear(); Drivers.clear(); nameBuffer = "dandroid"; // Filehandle for robot's xml-file void* pRobotSettings = GfParmReadFileLocal("drivers/dandroid/dandroid.xml", - GFPARM_RMODE_STD); + GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); if (pRobotSettings) { // Let's look what we have to provide here char SectionBuffer[BUFSIZE]; - int n = GfParmGetEltNb(pRobotSettings, ROB_SECT_ROBOTS); + int ret = 0, n = GfParmGetEltNb(pRobotSettings, ROB_SECT_ROBOTS); for (int i = 0; i < n; i++) { @@ -188,7 +204,14 @@ extern "C" int dandroid(tModInfo * modInfo) Drivers.push_back(make_pair(sDriverName, sDriverDesc)); driver.push_back(TDriver(i)); } + + if (GfParmWriteFile(nullptr, pRobotSettings, "usr")) + ret = -1; + GfParmReleaseHandle(pRobotSettings); + + if (ret) + return ret; } return moduleInitialize(modInfo); diff --git a/src/drivers/shadow/src/Shadow.cpp b/src/drivers/shadow/src/Shadow.cpp index 20e0f266..4a90c1d0 100644 --- a/src/drivers/shadow/src/Shadow.cpp +++ b/src/drivers/shadow/src/Shadow.cpp @@ -122,23 +122,24 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* wel { // Save module name and loadDir, and determine module XML file pathname. setRobotName(welcomeIn->name); - - // Filehandle for robot's xml-file - void *pRobotSettings = GfParmReadFileLocal(pathBuffer, GFPARM_RMODE_STD); - PLogSHADOW = GfLogger::instance("SHADOW"); + std::string dirstr = std::string(GfLocalDir()) + "drivers/shadow"; + const char *dir = dirstr.c_str(); + + if (GfDirCreate(dir) != GF_DIR_CREATED) + { + PLogSHADOW->error("GfDirCreate %s failed\n", dir); + return -1; + } + + int ret = 0; + // Filehandle for robot's xml-file + void *pRobotSettings = GfParmReadFileLocal(pathBuffer, + GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); + if (pRobotSettings) // robot settings XML could be read { - char SectionBuffer[BUFSIZE]; - snprintf(SectionBuffer, BUFSIZE, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, 0); - - // Try to get first driver from index 0 - string sDriverName = GfParmGetStrNC(pRobotSettings, - SectionBuffer, - ROB_ATTR_NAME, - const_cast(sUndefined)); - // Loop over all possible drivers, clear all buffers, // save defined driver names and descriptions. Drivers.clear(); @@ -147,9 +148,11 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* wel for (int i = 0; i < n; i++) { + char SectionBuffer[BUFSIZE]; + snprintf(SectionBuffer, BUFSIZE, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, i); - sDriverName = GfParmGetStr(pRobotSettings, SectionBuffer, + std::string sDriverName = GfParmGetStr(pRobotSettings, SectionBuffer, ROB_ATTR_NAME, sUndefined); // This driver is defined in robot's xml-file @@ -158,6 +161,12 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* wel Drivers.push_back(make_pair(sDriverName, sDriverDesc)); } // for i + if (GfParmWriteFile(nullptr, pRobotSettings, "shadow")) + { + PLogSHADOW->error("GfParmWriteFile failed\n"); + ret = -1; + } + GfParmReleaseHandle(pRobotSettings); } else @@ -169,7 +178,7 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* wel // Set max nb of interfaces to return. welcomeOut->maxNbItf = Drivers.size(); - return 0; + return ret; } // Module entry point (new fixed name scheme). @@ -210,12 +219,13 @@ extern "C" int shadow(tModInfo *modInfo) nameBuffer = "shadow"; // Filehandle for robot's xml-file - void *pRobotSettings = GfParmReadFileLocal(pathBuffer, GFPARM_RMODE_STD); + void *pRobotSettings = GfParmReadFileLocal(pathBuffer, + GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); if (pRobotSettings) { // Let's look what we have to provide here char SectionBuffer[BUFSIZE]; - int n = GfParmGetEltNb(pRobotSettings, ROB_SECT_ROBOTS); + int ret = 0, n = GfParmGetEltNb(pRobotSettings, ROB_SECT_ROBOTS); for (int i = 0; i < n; i++) { @@ -224,7 +234,14 @@ extern "C" int shadow(tModInfo *modInfo) std::string sDriverDesc = GfParmGetStr(pRobotSettings, SectionBuffer, ROB_ATTR_DESC, ""); Drivers.push_back(make_pair(sDriverName, sDriverDesc)); } + + if (GfParmWriteFile(nullptr, pRobotSettings, "shadow")) + ret = -1; + GfParmReleaseHandle(pRobotSettings); + + if (ret) + return ret; } return moduleInitialize(modInfo); diff --git a/src/drivers/simplix/src/unitmain.cpp b/src/drivers/simplix/src/unitmain.cpp index 6264df1e..0fb088c5 100644 --- a/src/drivers/simplix/src/unitmain.cpp +++ b/src/drivers/simplix/src/unitmain.cpp @@ -263,13 +263,19 @@ void* GetFileHandle(const char* RobotName) snprintf(BufPathXMLRel, BUFSIZE, // Robot's xml-filename "drivers/%s/%s.xml",RobotName,RobotName);// relative to installation + std::string dirstr = std::string(GfLocalDir()) + "drivers" + RobotName; + const char *dir = dirstr.c_str(); + + if (GfDirCreate(dir) != GF_DIR_CREATED) + return NULL; + // Test local installation path snprintf(BufPathXML, BUFSIZE, "%s%s", GetLocalDir(), RobPathXMLRel); snprintf(BufPathDir, BUFSIZE, "%s%s", GetLocalDir(), RobPathDirRel); RobotSettings = GfParmReadFile - (RobPathXML, GFPARM_RMODE_STD ); + (RobPathXML, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); if (!RobotSettings) { @@ -281,6 +287,13 @@ void* GetFileHandle(const char* RobotName) RobotSettings = GfParmReadFile (RobPathXML, GFPARM_RMODE_STD ); } + + if (GfParmWriteFile(nullptr, RobotSettings, "simplix")) + { + GfParmReleaseHandle(RobotSettings); + return NULL; + } + return RobotSettings; } //==========================================================================* diff --git a/src/drivers/usr/src/usr.cpp b/src/drivers/usr/src/usr.cpp index 955cda30..5af50ba0 100755 --- a/src/drivers/usr/src/usr.cpp +++ b/src/drivers/usr/src/usr.cpp @@ -93,22 +93,24 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, // Save module name and loadDir, and determine module XML file pathname. setRobotName(welcomeIn->name); - // Filehandle for robot's xml-file - void *pRobotSettings = GfParmReadFileLocal(pathBuffer, GFPARM_RMODE_STD); - PLogUSR = GfLogger::instance("USR"); + std::string dirstr = std::string(GfLocalDir()) + "drivers/usr"; + const char *dir = dirstr.c_str(); + + if (GfDirCreate(dir) != GF_DIR_CREATED) + { + PLogUSR->error("GfDirCreate %s failed\n", dir); + return -1; + } + + // Filehandle for robot's xml-file + int ret = 0; + void *pRobotSettings = GfParmReadFileLocal(pathBuffer, + GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); + if (pRobotSettings) // robot settings XML could be read { - char SectionBuffer[BUFSIZE]; - snprintf(SectionBuffer, BUFSIZE, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, 0); - - // Try to get first driver from index 0 - string sDriverName = GfParmGetStrNC(pRobotSettings, - SectionBuffer, - ROB_ATTR_NAME, - const_cast(sUndefined)); - // Loop over all possible drivers, clear all buffers, // save defined driver names and descriptions. Drivers.clear(); @@ -117,9 +119,11 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, for (int i = 0; i < n; i++) { + char SectionBuffer[BUFSIZE]; + snprintf(SectionBuffer, BUFSIZE, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, i); - sDriverName = GfParmGetStr(pRobotSettings, SectionBuffer, + std::string sDriverName = GfParmGetStr(pRobotSettings, SectionBuffer, ROB_ATTR_NAME, sUndefined); // This driver is defined in robot's xml-file @@ -128,6 +132,12 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, Drivers.push_back(make_pair(sDriverName, sDriverDesc)); } // for i + if (GfParmWriteFile(nullptr, pRobotSettings, "usr")) + { + PLogUSR->error("GfDirCreate %s failed\n", dir); + ret = -1; + } + GfParmReleaseHandle(pRobotSettings); } else // if robot settings XML could not be read @@ -139,7 +149,7 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, // Set max nb of interfaces to return. welcomeOut->maxNbItf = Drivers.size(); - return 0; + return ret; } // Module entry point (new fixed name scheme). @@ -175,17 +185,24 @@ extern "C" int moduleTerminate() // Module entry point extern "C" int usr(tModInfo *modInfo) { + std::string dirstr = std::string(GfLocalDir()) + "drivers/usr"; + const char *dir = dirstr.c_str(); + + if (GfDirCreate(dir) != GF_DIR_CREATED) + return -1; + Drivers.clear(); pathBuffer = "drivers/usr/usr.xml"; nameBuffer = "usr"; // Filehandle for robot's xml-file - void *pRobotSettings = GfParmReadFileLocal(pathBuffer, GFPARM_RMODE_STD); + void *pRobotSettings = GfParmReadFileLocal(pathBuffer, + GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); if (pRobotSettings) // Let's look what we have to provide here { char SectionBuffer[BUFSIZE]; - int n = GfParmGetEltNb(pRobotSettings, ROB_SECT_ROBOTS); + int ret = 0, n = GfParmGetEltNb(pRobotSettings, ROB_SECT_ROBOTS); for (int i = 0; i < n; i++) { @@ -195,7 +212,13 @@ extern "C" int usr(tModInfo *modInfo) Drivers.push_back(make_pair(sDriverName, sDriverDesc)); } + if (GfParmWriteFile(nullptr, pRobotSettings, "usr")) + ret = -1; + GfParmReleaseHandle(pRobotSettings); + + if (ret) + return ret; } return moduleInitialize(modInfo);