コード例 #1
0
void NoteDirectoryWatcherApplicationAddin::handle_file_system_change_event(
  const Glib::RefPtr<Gio::File> & file, const Glib::RefPtr<Gio::File> &, Gio::FileMonitorEvent event_type)
{
  switch(event_type) {
  case Gio::FILE_MONITOR_EVENT_CHANGED:
  case Gio::FILE_MONITOR_EVENT_DELETED:
  case Gio::FILE_MONITOR_EVENT_CREATED:
  case Gio::FILE_MONITOR_EVENT_MOVED:
    break;
  default:
    return;
  }

  Glib::ustring note_id = get_id(file->get_path());

  DBG_OUT("NoteDirectoryWatcher: %s has %d (note_id=%s)", file->get_path().c_str(), int(event_type), note_id.c_str());

  // Record that the file has been added/changed/deleted.  Adds/changes trump
  // deletes.  Record the date.
  m_lock.lock();
  try {
    auto record = m_file_change_records.find(note_id);
    if(record == m_file_change_records.end()) {
      m_file_change_records[note_id] = NoteFileChangeRecord();
      record = m_file_change_records.find(note_id);
    }

    if(event_type == Gio::FILE_MONITOR_EVENT_CHANGED) {
      record->second.changed = true;
      record->second.deleted = false;
    }
    else if(event_type == Gio::FILE_MONITOR_EVENT_CREATED) {
      record->second.changed = true;
      record->second.deleted = false;
    }
    else if(event_type == Gio::FILE_MONITOR_EVENT_MOVED) {
      record->second.changed = true;
      record->second.deleted = false;
    }
    else if(event_type == Gio::FILE_MONITOR_EVENT_DELETED) {
      if(!record->second.changed) {
	record->second.deleted = true;
      }
    }

    record->second.last_change = sharp::DateTime::now();
  }
  catch(...)
  {}
  m_lock.unlock();

  Glib::RefPtr<Glib::TimeoutSource> timeout = Glib::TimeoutSource::create(m_check_interval * 1000);
  timeout->connect(sigc::mem_fun(*this, &NoteDirectoryWatcherApplicationAddin::handle_timeout));
  timeout->attach();
}
コード例 #2
0
ファイル: main.cpp プロジェクト: mmicael1/Nagios-check
int main(int argc, char * argv[])
{
	std::stringstream ss;
	std::string filename = "/tmp/status.dat";
	std::string alert = "";

	std::string defaultConfig = "config.cfg";

	if(argc>1)
		defaultConfig = std::string(argv[1]);
	std::vector <ConfigParser::Host> config = readConfig(defaultConfig);
	unsigned int i = 0;
	while(i < config.size())
	{
		ss.str("");

		ss << "scp -q "
			<< config[i].userName
			<< "@"
			<< config[i].hostName
			<< ":"
			<<  config[i].fileName
			<< " " << filename;

		//std::cout << ss.str() << std::endl;
		system(ss.str().c_str());

		alert += read(filename);

		i++;
	}

	if(!alert.empty())
	{

		Gtk::Main app(argc, argv);
		Gtk::MessageDialog dial(alert);

		// je cre un timer qui, aprs 10000ms,
		// lance la fonction timeout()
		Glib::RefPtr<Glib::TimeoutSource> ts;
		ts = Glib::TimeoutSource::create(10000);
		ts->connect(sigc::ptr_fun(&timeout));
		ts->attach();

		// je connecte le click du bouton valider  la fonction quit();
		dial.signal_response().connect(sigc::ptr_fun(&quit));

		// je balance la sauce
		app.run(dial);

	}

	return 0;
}