28 LOG(
DEBUG) <<
"WsMonitor::~WsMonitor() : Deleting this";
30 LOG(
ERROR) <<
"WsMonitor::~WsMonitor() : Error while stopping Fam monitor ";
32 LOG(
INFO) <<
"WsMonitor::~WsMonitor() : Fam stopped successfully";
34 LOG(
ERROR) <<
"WsMonitor::~WsMonitor() : Error while stopping Fam monitor ";
36 LOG(
INFO) <<
"WsMonitor::~WsMonitor() : Fam stopped successfully";
49 static const char* famevent[] = {
61 static char unknown_event[10];
63 if (code < FAMChanged || code > FAMEndExist) {
64 LOG(
ERROR) <<
"WsMonitor::WsMonitor() : Unknown event code returned by Gamin " << code << endl;
68 return famevent[code];
82 LOG(
INFO) <<
"WsMonitor::startChecker() : Will update FsTree every " <<
m_delay <<
"s if changes occurs";
84 LOG(
DEBUG) <<
"WsMonitor::startChecker() : Checking updated status : " <<
m_updated;
87 LOG(
INFO) <<
"WsMonitor::startChecker() : Updating FsTree";
97 int i, nmon, rc, fam_fd;
104 LOG(
ERROR) <<
"WsMonitor::startCallBack() : Malloc failed for Fam";
107 m_fc = (FAMConnection*)malloc(
sizeof(
m_fc));
109 if ((FAMOpen(
m_fc)) < 0) {
110 LOG(
ERROR) <<
"WsMonitor::startCallBack() : Fam open failed";
114 for (nmon = 0, i = 0; i <
m_paths.size(); i++) {
117 LOG(
ERROR) <<
"WsMonitor::startCallBack() : FAMMonitor failed" << endl;
124 LOG(
ERROR) <<
"WsMonitor::startCallBack() : Fam nothing to monitor." << endl;
128 fam_fd = FAMCONNECTION_GETFD(
m_fc);
130 FD_SET(fam_fd, &readfds);
133 if (select(fam_fd + 1, &readfds,
135 LOG(
ERROR) <<
"WsMonitor::startCallBack() : Select failed" << endl;
138 if (FD_ISSET(fam_fd, &readfds)) {
139 if (FAMNextEvent(
m_fc, &fe) < 0) {
140 LOG(
ERROR) <<
"WsMonitor::startCallBack() : FAMNextEvent Failed" << endl;
143 signal(fe.filename, fe.code);
150 int i, nmon, rc, fam_fd;
157 LOG(
ERROR) <<
"WsMonitor::startCallBackConfOnly() : Malloc failed for Fam";
160 m_fc2 = (FAMConnection*)malloc(
sizeof(
m_fc2));
162 if ((FAMOpen(
m_fc2)) < 0) {
163 LOG(
ERROR) <<
"WsMonitor::startCallBackConfOnly() Fam open failed";
167 for (nmon = 0, i = 0; i <
m_paths.size(); i++) {
169 ifstream fconf(config.c_str());
171 rc = FAMMonitorDirectory(
m_fc2, config.c_str(),
m_frp2 + i, 0);
173 LOG(
ERROR) <<
"WsMonitor::startCallBackConfOnly() : FAMMonitor failed" << endl;
181 LOG(
ERROR) <<
"WsMonitor::startCallBackConfOnly() : Fam nothing to monitor." << endl;
185 fam_fd = FAMCONNECTION_GETFD(
m_fc2);
187 FD_SET(fam_fd, &readfds);
190 if (select(fam_fd + 1, &readfds,
192 LOG(
ERROR) <<
"WsMonitor::startCallBackConfOnly() : Select failed" << endl;
195 if (FD_ISSET(fam_fd, &readfds)) {
196 if (FAMNextEvent(
m_fc2, &fe) < 0) {
197 LOG(
ERROR) <<
"WsMonitor::startCallBackConfOnly() : FAMNextEvent Failed" << endl;
209 temp = boost::filesystem::path(temp).string();
210 ifstream fconf(temp.c_str());
212 LOG(
DEBUG) <<
"WsMonitor::signal() : Lock File is present. Not updating";
217 LOG(
DEBUG) <<
"WsMonitor::signal() Change occured on " << filename <<
" - Code FamDeleted";
221 LOG(
DEBUG) <<
"WsMonitor::signal() : Change occured on " << filename <<
" - Code FamCreated";
232 temp = boost::filesystem::path(temp).string();
233 ifstream fconf(temp.c_str());
235 LOG(
DEBUG) <<
"WsMonitor::signalConf() : Lock File is present. Not updating";
240 LOG(
DEBUG) <<
"WsMonitor::signalConf() : Change occured on conf dir" << filename <<
" - Code FamDeleted";
244 LOG(
DEBUG) <<
"WsMonitor::signalConf() : Change occured on conf dir" << filename <<
" - Code FamCreated";
248 LOG(
DEBUG) <<
"WsMonitor::signalConf() : Change occured on conf dir " << filename <<
" - Code FamChanged";
int startCallBack()
Starts monitoring the Files of the filesystemtree Should be started in a separated thread...
int update()
update the fsTree
const char * eventName(const int &code)
Matches an event code with it's name.
handles the update of the FileSystemTree
const std::string PathToNodeProperties
std::vector< path > m_paths
WsFsTreeUpdater * m_updater
pointer to the WsFsTreeUpdater class
WsMonitor(WsFsTreeUpdater *u, std::vector< path > v, unsigned int delay)
Constructor.
bool m_updated
Changed occured ?
int signal(const std::string &filename, const int &code)
Called when a change occurs on a file monitored.
std::string get(const std::string §ion, const std::string &id, const std::string &def)
int signalConf(const std::string &filename, const int &code)
Called when a change occurs on a conf file monitored.
const std::string PathToLockFile
static WsGlobalProperties * instance()
int startCallBackConfOnly()
Starts monitoring the config Files of the filesystemtree Should be started in a separated thread...
Updates the tree and takes care of unconsistencies with the user.
Monitors the FileSystem for any modification.
int startChecker()
Starts loop that will monitor the m_updated variable every m_delay and update the tree if changed occ...
boost::thread * start()
Starts the monitoring process.