2011-03-16 16:50:34 +03:00
|
|
|
/**
|
|
|
|
Based on example by:
|
|
|
|
Copyright (c) Ashish Shukla
|
|
|
|
|
|
|
|
This is licensed under GNU GPL v2 or later.
|
|
|
|
For license text, Refer to the the file COPYING or visit
|
|
|
|
http://www.gnu.org/licenses/gpl.txt .
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MIRALL_INOTIFY_H
|
|
|
|
#define MIRALL_INOTIFY_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2011-04-04 20:41:14 +04:00
|
|
|
#include <QMap>
|
2011-03-16 16:50:34 +03:00
|
|
|
#include <QString>
|
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
namespace Mirall
|
|
|
|
{
|
|
|
|
|
|
|
|
class INotify : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-03-17 09:13:30 +03:00
|
|
|
INotify(int mask);
|
2011-03-16 16:50:34 +03:00
|
|
|
~INotify();
|
|
|
|
|
|
|
|
static void initialize();
|
|
|
|
static void cleanup();
|
|
|
|
|
2011-03-17 09:13:30 +03:00
|
|
|
void addPath(const QString &name);
|
|
|
|
void removePath(const QString &name);
|
|
|
|
|
|
|
|
QStringList directories() const;
|
2011-03-16 16:50:34 +03:00
|
|
|
signals:
|
|
|
|
|
2011-03-19 23:18:43 +03:00
|
|
|
void notifyEvent(int mask, int cookie, const QString &name);
|
2011-03-16 16:50:34 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
class INotifyThread : public QThread
|
|
|
|
{
|
|
|
|
int _fd;
|
2011-04-05 20:31:19 +04:00
|
|
|
QMap<int, INotify*> _map;
|
2011-03-16 16:50:34 +03:00
|
|
|
public:
|
|
|
|
INotifyThread(int fd);
|
2011-03-21 00:13:40 +03:00
|
|
|
~INotifyThread();
|
2011-03-17 09:13:30 +03:00
|
|
|
void registerForNotification(INotify*, int);
|
2011-03-16 16:50:34 +03:00
|
|
|
void unregisterForNotification(INotify*);
|
2011-04-04 20:41:14 +04:00
|
|
|
// fireEvent happens from the inotify thread
|
|
|
|
// but addPath comes from the main thread
|
2011-03-16 16:50:34 +03:00
|
|
|
protected:
|
|
|
|
void run();
|
2011-03-21 00:13:40 +03:00
|
|
|
private:
|
|
|
|
size_t _buffer_size;
|
|
|
|
char *_buffer;
|
2011-03-16 16:50:34 +03:00
|
|
|
};
|
|
|
|
|
2011-03-17 09:13:30 +03:00
|
|
|
//INotify(int wd);
|
2011-03-19 23:18:43 +03:00
|
|
|
void fireEvent(int mask, int cookie, int wd, char *name);
|
2011-03-16 16:50:34 +03:00
|
|
|
static int s_fd;
|
|
|
|
static INotifyThread* s_thread;
|
2011-03-17 09:13:30 +03:00
|
|
|
|
|
|
|
// the mask is shared for all paths
|
|
|
|
int _mask;
|
2011-04-04 20:41:14 +04:00
|
|
|
QMap<QString, int> _wds;
|
2011-03-16 16:50:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|