Commit 5b549dc6 authored by Locatelli's avatar Locatelli

Add a servant manager message:

Get last time of a ressource file
parent 815bb123
......@@ -165,4 +165,12 @@ std::string FileUtilities::getDirectoryName(fs::path& path1, const std::string&
return path3.string();
}
time_t FileUtilities::getFileLastTime(const std::string& name) throw (NotRegularFile) {
fs::path file(name);
if (fs::is_regular_file(file) == false) {
throw NotRegularFile("cannot read " + file.string());
}
return fs::last_write_time(file);
}
}
......@@ -23,6 +23,7 @@
#include <common/base/Exception.h>
#include <string>
#include <vector>
#include <utility>
namespace common {
......@@ -87,6 +88,10 @@ public:
*/
static std::string getDirectoryName(boost::filesystem::path& path1, const std::string& name) throw (NoSuchDirectoryException);
/*!
* \brief get file size
*/
static time_t getFileLastTime(const std::string& name) throw (NotRegularFile);
};
}
......
......@@ -49,18 +49,19 @@ message Message {
ReadBinaryResourceFile = 18;
ReadResourceFile = 19;
WriteResourceFile = 20;
GetResourceFileLastTime = 21;
GetServantPropertiesValue = 21;
GetServantCommandsState = 22;
GetServantPropertiesValue = 22;
GetServantCommandsState = 23;
GetFamilyImageKeys = 23;
GetControllerIconKeys = 24;
GetFamilyImageKeys = 24;
GetControllerIconKeys = 25;
UserLog = 25;
UserLog = 26;
GetControllerTypesInheritingType = 26;
GetControllerTypesInheritingType = 27;
HasRunningCommands = 27;
HasRunningCommands = 28;
}
required Type type = 1;
......
......@@ -105,6 +105,7 @@ void ServantManagerResponder::initProcessFunctions() {
m_processFunctions[servantmanager::Message::ReadBinaryResourceFile] = ProcessFunction(&ServantManagerResponder::processReadBinaryResourceFile, true);
m_processFunctions[servantmanager::Message::ReadResourceFile] = ProcessFunction(&ServantManagerResponder::processReadResourceFile, true);
m_processFunctions[servantmanager::Message::WriteResourceFile] = ProcessFunction(&ServantManagerResponder::processWriteResourceFile, true);
m_processFunctions[servantmanager::Message::GetResourceFileLastTime] = ProcessFunction(&ServantManagerResponder::processGetResourceFileLastTime, true);
m_processFunctions[servantmanager::Message::GetServantPropertiesValue] = ProcessFunction(&ServantManagerResponder::processGetServantPropertiesValue, true);
m_processFunctions[servantmanager::Message::GetServantCommandsState] = ProcessFunction(&ServantManagerResponder::processGetServantCommandsState, true);
m_processFunctions[servantmanager::Message::GetFamilyImageKeys] = ProcessFunction(&ServantManagerResponder::processGetFamilyImageKeys, true);
......@@ -451,6 +452,24 @@ void ServantManagerResponder::processWriteResourceFile(const std::string & messa
responseMessage.SerializeToString(&response);
}
void ServantManagerResponder::processGetResourceFileLastTime(const std::string & message, std::string & response) {
servantmanager::ReadResourceRequest messageRequest;
messageRequest.ParseFromString(message);
common::Int32Response responseMessage;
try {
time_t date = ModuleManager::getInstance()->getResourceFileLastTime(messageRequest.type(), messageRequest.filename());
responseMessage.set_value((int32) date);
} catch (const NoSuchFile& e) {
responseMessage.set_error(common::Error::NO_SUCH_RESOURCE);
}
// Serialize the response.
responseMessage.SerializeToString(&response);
}
void ServantManagerResponder::processGetServantPropertiesValue(const std::string & message, std::string & response) {
servantmanager::ServantRequest messageRequest;
......
......@@ -86,6 +86,7 @@ private:
void processReadBinaryResourceFile(const std::string & message, std::string & response);
void processReadResourceFile(const std::string & message, std::string & response);
void processWriteResourceFile(const std::string & message, std::string & response);
void processGetResourceFileLastTime(const std::string & message, std::string & response);
void processGetServantPropertiesValue(const std::string & message, std::string & response);
void processGetServantCommandsState(const std::string & message, std::string & response);
......
......@@ -20,6 +20,7 @@
#include "LoadSequenceParser.h"
#include "DataProvider/Property/XMLFileCollector.h"
#include "DataProvider/Property/PropertyInfos.h"
#include <common/base/Date.h>
#include <common/base/FileUtilities.h>
#include <common/base/ServerProperties.h>
#include <boost/filesystem/operations.hpp>
......@@ -891,3 +892,21 @@ std::string ModuleManager::getResourceFilePath(const std::string& fileName) {
return fullPath;
}
time_t ModuleManager::getResourceFileLastTime(const std::string& type, const std::string& fileName) {
// find the file
map<string, string>::iterator r = m_moduleResources.find(fileName);
if (r == m_moduleResources.end()) {
throw NoSuchFile(fileName);
}
time_t date;
try {
date = FileUtilities::getFileLastTime(r->second);
}
catch (const FileUtilities::NotRegularFile& e) {
throw NoSuchFile(fileName);
}
return date;
}
......@@ -244,6 +244,12 @@ public:
*/
std::string getResourceFilePath(const std::string& fileName);
/**
* Reads the resource file last time.
* throws: NoSuchFile
*/
time_t getResourceFileLastTime(const std::string& type, const std::string& fileName);
private:
ModuleManager();
~ModuleManager();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment