/* GLIB - Library of useful routines for C programming
 * glockedfile.h: Simplified wrapper for file locking
 *
 * Copyright 2005 Emmanuele Bassi
 *
 * This library 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 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __G_LOCKED_FILE_H__
#define __G_LOCKED_FILE_H__

#include <glib/gerror.h>

G_BEGIN_DECLS

typedef enum
{
  G_LOCKED_FILE_ERROR_LOCK,
  G_LOCKED_FILE_ERROR_UNLOCK,
  G_LOCKED_FILE_ERROR_ALREADY_LOCKED
} GLockedFileError;

#define G_LOCKED_FILE_ERROR g_locked_file_error_quark()

typedef enum
{
  G_LOCKED_FILE_READ = 1 << 0,
  G_LOCKED_FILE_WRITE = 1 << 1
} GLockedFileFlags;

typedef struct _GLockedFile GLockedFile;

GLockedFile *g_locked_file_new	     (const gchar       *filename,
				      GLockedFileFlags   lock_flags,
				      GError           **error);
gboolean     g_locked_file_lock      (GLockedFile       *file,
				      gint               tries,
				      gboolean           random_delta,
				      GError           **error);
gboolean     g_locked_file_try_lock  (GLockedFile       *file,
				      GError           **error);
gboolean     g_locked_file_is_locked (GLockedFile       *file);
gint         g_locked_file_get_fd    (GLockedFile       *file);
gboolean     g_locked_file_unlock    (GLockedFile       *file,
				      GError           **error);
void         g_locked_file_free      (GLockedFile       *file);

G_END_DECLS

#endif /* __G_LOCKED_FILE_H__ */
