2006-05-21 18:11:05 -05:00
|
|
|
/*
|
2005-08-25 09:29:01 +00:00
|
|
|
* moofilewatch.h
|
|
|
|
*
|
2010-12-21 20:15:45 -08:00
|
|
|
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
2005-08-25 09:29:01 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* This file is part of medit. medit is free software; you can
|
|
|
|
* redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License,
|
|
|
|
* or (at your option) any later version.
|
2005-08-25 09:29:01 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
2005-08-25 09:29:01 +00:00
|
|
|
*/
|
|
|
|
|
2009-07-04 00:32:57 -07:00
|
|
|
/* Files and directory monitor. Uses stat().
|
2005-08-25 09:29:01 +00:00
|
|
|
On win32 does FindFirstChangeNotification and ReadDirectoryChangesW. */
|
|
|
|
|
2016-01-01 22:25:53 -08:00
|
|
|
#pragma once
|
2005-08-25 09:29:01 +00:00
|
|
|
|
|
|
|
#include <glib-object.h>
|
2016-01-02 07:09:54 -08:00
|
|
|
#include <moocpp/grefptr.h>
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
enum MooFileEventCode {
|
2006-12-08 14:55:46 -06:00
|
|
|
MOO_FILE_EVENT_CHANGED,
|
2006-12-15 21:12:31 -06:00
|
|
|
MOO_FILE_EVENT_CREATED,
|
2006-12-08 14:55:46 -06:00
|
|
|
MOO_FILE_EVENT_DELETED,
|
|
|
|
MOO_FILE_EVENT_ERROR
|
2016-01-02 07:09:54 -08:00
|
|
|
};
|
2006-12-08 14:55:46 -06:00
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
struct MooFileEvent {
|
2006-12-08 14:55:46 -06:00
|
|
|
MooFileEventCode code;
|
|
|
|
guint monitor_id;
|
|
|
|
char *filename;
|
|
|
|
GError *error;
|
2005-08-25 09:29:01 +00:00
|
|
|
};
|
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
class MooFileWatch;
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
typedef void (*MooFileWatchCallback) (MooFileWatch& watch,
|
|
|
|
MooFileEvent* event,
|
2006-12-08 14:55:46 -06:00
|
|
|
gpointer user_data);
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 13:51:52 -08:00
|
|
|
namespace moo
|
|
|
|
{
|
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
template<>
|
2016-01-02 13:51:52 -08:00
|
|
|
class obj_ref_unref<MooFileWatch> : public obj_class_ref_unref<MooFileWatch>
|
2016-01-02 07:09:54 -08:00
|
|
|
{
|
|
|
|
};
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 13:51:52 -08:00
|
|
|
using MooFileWatchPtr = grefptr<MooFileWatch>;
|
|
|
|
|
|
|
|
} // namespace moo
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
class MooFileWatch
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MooFileWatch();
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 13:51:52 -08:00
|
|
|
static moo::MooFileWatchPtr create (GError **error);
|
2006-12-08 14:55:46 -06:00
|
|
|
|
2016-01-02 13:51:52 -08:00
|
|
|
bool close (GError **error);
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 13:51:52 -08:00
|
|
|
guint create_monitor (const char *filename,
|
|
|
|
MooFileWatchCallback callback,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify,
|
|
|
|
GError **error);
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 13:51:52 -08:00
|
|
|
void cancel_monitor (guint monitor_id);
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
struct Impl;
|
2016-01-02 13:51:52 -08:00
|
|
|
Impl& impl () { return *m_impl; }
|
2005-08-25 09:29:01 +00:00
|
|
|
|
2016-01-02 13:51:52 -08:00
|
|
|
void ref ();
|
|
|
|
void unref ();
|
2015-12-30 00:12:49 -08:00
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
MooFileWatch(const MooFileWatch&) = delete;
|
|
|
|
MooFileWatch& operator=(const MooFileWatch&) = delete;
|
2016-01-01 22:25:53 -08:00
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
private:
|
|
|
|
~MooFileWatch();
|
2015-12-30 00:12:49 -08:00
|
|
|
|
2016-01-02 07:09:54 -08:00
|
|
|
int m_ref;
|
|
|
|
std::unique_ptr<Impl> m_impl;
|
2015-12-30 00:12:49 -08:00
|
|
|
};
|