Added README and simpleeventcatcher, which i forgot to add to last commit
diff --git a/filesystemwatcher/README.md b/filesystemwatcher/README.md
new file mode 100644
index 0000000..da229ca
--- /dev/null
+++ b/filesystemwatcher/README.md
@@ -0,0 +1,65 @@
+Overview:
+
+FileSystemWatcher reports changes that are made to a monitored directory by signaling a registered callback function and passing that function a list of changes that have occurred. Each element of the list represents a file and the action that was performed on that file.
+
+Example:
+
+ ADDED: /Users/jared/Desktop/test.txt
+
+The list is held in a vector of type sEventInfo, where sEventInfo is a struct defined as follows:
+
+ enum eEvent {
+ ADDED = 0,
+ MODIFIED,
+ DELETED
+ };
+
+ struct sEventInfo {
+ eEvent event;
+ std::string absFilePath;
+ };
+
+The eEvent enumerator specifies the action taken on the file and the string absFilePath is the absolute file path of the file.
+
+Usage:
+
+SimpleEventCatcher is a dummy class that serves as an example of how to register for signals from FileSystemWatcher. These are the basic steps:
+
+ // invoke file system watcher on specified path
+ FileSystemWatcher watcher("/Users/jared/Desktop");
+
+ // pass the instance of FileSystemWatcher to the class
+ // that will register for event notifications
+ SimpleEventCatcher dirEventCatcher(&watcher);
+
+ // register for directory event signal (callback function)
+ QObject::connect(watcher, SIGNAL(dirEventSignal(std::vector<sEventInfo>)), this,
+ SLOT(handleDirEvent(std::vector<sEventInfo>)));
+
+ // implement handleDirEvent
+ void SimpleEventCatcher::handleDirEvent(std::vector<sEventInfo>)
+ {
+ /* implementation here */
+ }
+
+Debug:
+
+The debug flag can be set in filesystemwatcher.h. It is set to 1 by default and outputs the following information to the console:
+
+[BOOTSTRAP]
+
+[TIMER] Triggered Path: "/Users/jared/Desktop"
+ "ADDED: /Users/jared/Desktop/test2.txt"
+ "ADDED: /Users/jared/Desktop/test.txt"
+
+[SIGNAL] From SimpleEventCatcher Slot:
+ "ADDED: /Users/jared/Desktop/test2.txt"
+ "ADDED: /Users/jared/Desktop/test.txt"
+
+[\BOOTSTRAP]
+
+[WATCHER] Triggered Path: "/Users/jared/Desktop"
+ "DELETED: /Users/jared/Desktop/test2.txt"
+
+[SIGNAL] From SimpleEventCatcher Slot:
+ "DELETED: /Users/jared/Desktop/test2.txt"
diff --git a/filesystemwatcher/filesystemwatcher.cpp b/filesystemwatcher/filesystemwatcher.cpp
index 79363e8..b887292 100644
--- a/filesystemwatcher/filesystemwatcher.cpp
+++ b/filesystemwatcher/filesystemwatcher.cpp
@@ -50,7 +50,13 @@
void FileSystemWatcher::bootstrap()
{
// bootstrap specific steps
+#if DEBUG
+ qDebug() << endl << "[BOOTSTRAP]";
+#endif
timerCallbackSlot();
+#if DEBUG
+ qDebug() << endl << "[\\BOOTSTRAP]";
+#endif
}
void FileSystemWatcher::watcherCallbackSlot(QString dirPath)
@@ -82,8 +88,9 @@
// DEBUG: Print Changes
printChanges(dirChanges);
#endif
- // emit the signal
- emit dirEventSignal(dirChanges);
+ // emit the signal if not empty
+ if(!dirChanges.empty())
+ emit dirEventSignal(dirChanges);
}
QHash<QString, qint64> FileSystemWatcher::scanDirectory(QString dirPath)
diff --git a/filesystemwatcher/simpleeventcatcher.cpp b/filesystemwatcher/simpleeventcatcher.cpp
new file mode 100644
index 0000000..f1061fb
--- /dev/null
+++ b/filesystemwatcher/simpleeventcatcher.cpp
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Jared Lindblom <lindblom@cs.ucla.edu>
+ */
+
+#include "simpleeventcatcher.h"
+
+SimpleEventCatcher::SimpleEventCatcher(FileSystemWatcher* watcher, QObject *parent) :
+ QObject(parent)
+{
+ // register for directory event signal (callback function)
+ QObject::connect(watcher, SIGNAL(dirEventSignal(std::vector<sEventInfo>)), this, SLOT(handleDirEvent(std::vector<sEventInfo>)));
+}
+
+void SimpleEventCatcher::handleDirEvent(std::vector<sEventInfo> dirChanges)
+{
+ qDebug() << endl << "[SIGNAL] From SimpleEventCatcher Slot:";
+
+ if(!dirChanges.empty())
+ {
+ for(size_t i = 0; i < dirChanges.size(); i++)
+ {
+ QString tempString;
+
+ eEvent event = dirChanges[i].event;
+ QString absFilePath = QString::fromStdString(dirChanges[i].absFilePath);
+
+ switch(event)
+ {
+ case ADDED:
+ tempString.append("ADDED: ");
+ break;
+ case MODIFIED:
+ tempString.append("MODIFIED: ");
+ break;
+ case DELETED:
+ tempString.append("DELETED: ");
+ break;
+ }
+
+ tempString.append(absFilePath);
+
+ qDebug() << "\t" << tempString;
+ }
+ }
+ else
+ {
+ qDebug() << "\t[EMPTY]";
+ }
+}
+
+#if WAF
+#include "simpleeventcatcher.moc"
+#include "simpleeventcatcher.cpp.moc"
+#endif
diff --git a/filesystemwatcher/simpleeventcatcher.h b/filesystemwatcher/simpleeventcatcher.h
new file mode 100644
index 0000000..2a858fd
--- /dev/null
+++ b/filesystemwatcher/simpleeventcatcher.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Jared Lindblom <lindblom@cs.ucla.edu>
+ */
+
+#ifndef SIMPLEEVENTCATCHER_H
+#define SIMPLEEVENTCATCHER_H
+
+#include "filesystemwatcher.h"
+#include <QObject>
+#include <QDebug>
+#include <vector>
+#include <structs.h>
+
+class SimpleEventCatcher : public QObject
+{
+ Q_OBJECT
+public:
+ explicit SimpleEventCatcher(FileSystemWatcher* watcher, QObject *parent = 0);
+
+public slots:
+ // handle signal
+ void handleDirEvent(std::vector<sEventInfo> dirChanges);
+};
+
+#endif // SIMPLEEVENTCATCHER_H
diff --git a/filesystemwatcher/structs.h b/filesystemwatcher/structs.h
new file mode 100644
index 0000000..93008b1
--- /dev/null
+++ b/filesystemwatcher/structs.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Jared Lindblom <lindblom@cs.ucla.edu>
+ */
+
+#ifndef STRUCTS_H
+#define STRUCTS_H
+
+enum eEvent {
+ ADDED = 0,
+ MODIFIED,
+ DELETED
+};
+
+struct sEventInfo {
+ eEvent event;
+ std::string absFilePath;
+};
+
+#endif // STRUCTS_H