void NotifyWorker::startWatching()
{
    QLOG_TRACE() << "inotify starting";
    try
    {
        Inotify notify;

        int32_t watch_mask = (IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO);
        QByteArray dir_str = watch_dir.toLocal8Bit();
        InotifyWatch iw(dir_str.data(), watch_mask);

        notify.Add(iw);


        for(;;)
        {
            notify.WaitForEvents();
            QLOG_TRACE() << "iNotify event received";

            size_t count = notify.GetEventCount();

            while(count > 0)
            {
                InotifyEvent event;
                bool got_event = notify.GetEvent(&event);

                if(got_event)
                {
                    FileEvent e;
                    std::string s;
                    event.DumpTypes(s);

                    e.type = QString::fromUtf8(s.c_str());
                    e.cookie = event.GetCookie();
                    e.name = QString(event.GetName().c_str());

                    if(!e.type.contains("IN_ISDIR"))
                    {
                        emit fEvent(e);
                    }
                }

                count--;
            }
        }
    }
    catch(InotifyException e)
    {
        QLOG_WARN() << "Inotify failed to start: " + QString::fromStdString(e.GetMessage());
    }
}
Exemple #2
0
// Set some watchers so we can monitorize dirs, files etc.
void On::setWatchers() {

    // Set JSON watcher
    Inotify notify;
    InotifyWatch watch("/var/local/asturix/launcherjsonview.json", IN_CLOSE_WRITE);
    notify.Add(watch);
    for (;;) {
        notify.WaitForEvents();
        size_t count = notify.GetEventCount();
        while (count > 0) {
            InotifyEvent event;
            bool got_event = notify.GetEvent(&event);
            if (got_event) {
                QMetaObject::invokeMethod(this,"appsChanged",Qt::QueuedConnection);
            }
            count--;
        }
    }

    DConfClient *dConfWallpaper = dconf_client_new(NULL, iconThemeChanged, NULL, NULL);
    dconf_client_watch(dConfWallpaper, "/org/gnome/desktop/interface/icon-theme", NULL, NULL);
}
Exemple #3
0
/**
 * Tell the observer to watch the given folder. 
 * Then, the observer will process all the rules
 *
 * @param string path the path to be watched
 * @param vector<Rule> the list of rules to be checked
 */
void Observer::observe(string path, vector<Rule*> rules){
    this->_observing[path] = true;
    try {
        Inotify notify;
 
        InotifyWatch watch(path, IN_CREATE);
        notify.Add(watch);
		cout << "Start observing for changes in " << path << endl;
 
        while (this->_observing[path]) {
            notify.WaitForEvents();
 
            size_t count = notify.GetEventCount();
            while (count > 0) {
                InotifyEvent event;
                bool got_event = notify.GetEvent(&event);
 
                if (got_event) {
                    string mask_str;
                    event.DumpTypes(mask_str);
 
                    string filename = event.GetName();
                    this->run_rules(rules, path + '/' + filename, mask_str); 
                }
 
                count--;
            }
        }
     } catch (InotifyException &e) {
         cerr << "Inotify exception occured: " << e.GetMessage() << endl;
     } catch (exception &e) {
         cerr << "STL exception occured: " << e.what() << endl;
     } catch (...) {
         cerr << "unknown exception occured" << endl;
     }
}