1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set expandtab ts=4 shiftwidth=4: */
4 * Copyright (C) 2008 Sun Microsystems, Inc. All rights reserved.
5 * Use is subject to license terms.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Authors: Lin Ma <lin.ma@sun.com>
28 #include "fen-missing.h"
30 G_LOCK_EXTERN (fen_lock);
31 #define SCAN_MISSING_INTERVAL 4000 /* in milliseconds */
33 #ifdef GIO_COMPILATION
34 #define FM_W if (fm_debug_enabled) g_warning
35 gboolean fm_debug_enabled = FALSE;
37 #include "gam_error.h"
38 #define FM_W(...) GAM_DEBUG(DEBUG_INFO, __VA_ARGS__)
41 /* global data structure for scan missing files */
42 static GList *missing_list = NULL;
43 static guint scan_missing_source_id = 0;
45 static gboolean scan_missing_list (gpointer data);
48 scan_missing_list (gpointer data)
50 GList *existing_list = NULL;
57 for (idx = missing_list; idx; idx = idx->next) {
58 f = (fdata*)idx->data;
60 if (_port_add (&f->fobj, &f->len, f)) {
61 /* TODO - emit CREATE event */
62 _fdata_emit_events (f, FN_EVENT_CREATED);
63 existing_list = g_list_prepend (existing_list, idx);
67 for (idx = existing_list; idx; idx = idx->next) {
68 missing_list = g_list_remove_link (missing_list, (GList *)idx->data);
69 g_list_free_1 ((GList *)idx->data);
71 g_list_free (existing_list);
73 if (missing_list == NULL) {
74 scan_missing_source_id = 0;
85 * Unsafe, need lock fen_lock.
88 _missing_add (fdata *f)
92 g_assert (!_is_ported (f));
94 if (g_list_find (missing_list, f) != NULL) {
95 FM_W ("%s is ALREADY added %s\n", __func__, FN_NAME(f));
98 FM_W ("%s is added %s\n", __func__, FN_NAME(f));
100 missing_list = g_list_prepend (missing_list, f);
102 /* if doesn't scan, then start */
103 if (scan_missing_source_id == 0) {
104 scan_missing_source_id = g_timeout_add (SCAN_MISSING_INTERVAL,
107 g_assert (scan_missing_source_id > 0);
114 * Unsafe, need lock fen_lock.
117 _missing_remove (fdata *f)
119 FM_W ("%s %s\n", __func__, FN_NAME(f));
120 missing_list = g_list_remove (missing_list, f);