Blame gio/kqueue/kqueue-sub.c

Packit ae235b
/*******************************************************************************
Packit ae235b
  Copyright (c) 2011, 2012 Dmitry Matveev <me@dmitrymatveev.co.uk>
Packit ae235b
Packit ae235b
  Permission is hereby granted, free of charge, to any person obtaining a copy
Packit ae235b
  of this software and associated documentation files (the "Software"), to deal
Packit ae235b
  in the Software without restriction, including without limitation the rights
Packit ae235b
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Packit ae235b
  copies of the Software, and to permit persons to whom the Software is
Packit ae235b
  furnished to do so, subject to the following conditions:
Packit ae235b
Packit ae235b
  The above copyright notice and this permission notice shall be included in
Packit ae235b
  all copies or substantial portions of the Software.
Packit ae235b
Packit ae235b
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit ae235b
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit ae235b
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit ae235b
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit ae235b
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit ae235b
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Packit ae235b
  THE SOFTWARE.
Packit ae235b
*******************************************************************************/
Packit ae235b
Packit ae235b
#include <glib.h>
Packit ae235b
Packit ae235b
#include "kqueue-sub.h"
Packit ae235b
Packit ae235b
static gboolean ks_debug_enabled = FALSE;
Packit ae235b
#define KS_W if (ks_debug_enabled) g_warning
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * _kh_sub_new:
Packit ae235b
 * @filename: a file path to monitor (will be copied)
Packit ae235b
 * @pair_moves: pair moves flag. Refer to #GFileMonitorFlags documentation.
Packit ae235b
 * @user_data: user-supplied poiner.
Packit ae235b
 *
Packit ae235b
 * Creates a new subscription object.
Packit ae235b
 *
Packit ae235b
 * Returns: a pointer to a created subscription object.
Packit ae235b
 **/
Packit ae235b
kqueue_sub*
Packit ae235b
_kh_sub_new (const gchar    *filename,
Packit ae235b
             gboolean        pair_moves,
Packit ae235b
             gpointer        user_data)
Packit ae235b
{
Packit ae235b
  kqueue_sub *sub = g_slice_new (kqueue_sub);
Packit ae235b
  g_assert (sub != NULL);
Packit ae235b
  
Packit ae235b
  sub->filename = g_strdup (filename);
Packit ae235b
  sub->pair_moves = pair_moves;
Packit ae235b
  sub->user_data = user_data;
Packit ae235b
  sub->fd = -1;
Packit ae235b
  sub->deps = NULL;
Packit ae235b
  /* I think that having such flag in the subscription is not good */
Packit ae235b
  sub->is_dir = 0;
Packit ae235b
Packit ae235b
  KS_W ("new subscription for %s being setup\n", sub->filename);
Packit ae235b
  
Packit ae235b
  return sub;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * _kh_sub_free:
Packit ae235b
 * @sub: a #kqueue_sub
Packit ae235b
 *
Packit ae235b
 * Frees a subscription object and all its associated memory.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
_kh_sub_free (kqueue_sub *sub)
Packit ae235b
{
Packit ae235b
  if (sub->deps)
Packit ae235b
    {
Packit ae235b
      dl_free (sub->deps);
Packit ae235b
      sub->deps = NULL;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_free (sub->filename);
Packit ae235b
  g_slice_free (kqueue_sub, sub);
Packit ae235b
}