Moving files to packaging and extracing new tarball.
[profile/ivi/glib2.git] / gio / fen / fen-node.h
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set expandtab ts=4 shiftwidth=4: */
3 /* 
4  * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
5  * reserved.
6  *
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.
11  *
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.
16  *
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.
21  *
22  * Authors: Lin Ma <lin.ma@sun.com>
23  */
24
25 #include <port.h>
26 #include <gio/gio.h>
27
28 #ifndef _FEN_NODE_H_
29 #define _FEN_NODE_H_
30
31 #ifdef GIO_COMPILATION
32 #define FN_EVENT_CREATED G_FILE_MONITOR_EVENT_CREATED
33 #else
34 #define FN_EVENT_CREATED GAMIN_EVENT_CREATED
35 #endif
36
37 #define NODE_STATE_NONE       0x00000000
38 #define NODE_STATE_ASSOCIATED 0x00000001 /* This is a confilct to NODE_FLAG_STAT_DONE */
39 #define NODE_STATE_HAS_EVENTS 0x00000002
40
41 #define NODE_FLAG_NONE             0x00000000
42 #define NODE_FLAG_SNAPSHOT_UPDATED 0x00000001
43 #define NODE_FLAG_DIR              0x00000002
44 #define NODE_FLAG_STAT_UPDATED     0x00000004
45
46 #define NODE_CLE_STATE(f, st)  (f->state &= ~(st))
47 #define NODE_SET_STATE(f, st)  (f->state = ((f->state & ~(st)) | (st)))
48 #define NODE_HAS_STATE(f, st)  (f->state & (st))
49
50 #define NODE_CLE_FLAG(f, fl)  (f->flag &= ~(fl))
51 #define NODE_SET_FLAG(f, fl)  (f->flag = ((f->flag & ~(fl)) | (fl)))
52 #define NODE_HAS_FLAG(f, fl)  (f->flag & (fl))
53
54 typedef struct node node_t;
55 struct node
56 {
57     file_obj_t  fobj;           /* Inherit from file_obj_t, must be the first. */
58     GSource    *source;
59     gchar      *basename;
60     guint32     state;
61         guint32     flag;
62     GTimeVal    atv;            /* Timestamp for the first added sub. */
63
64         /* the parent and children of node */
65     node_t *parent;
66     GHashTable *children; /* children in basename */
67
68         /* List of subscriptions monitoring this fdata/path */
69         GList *subs;
70         GList *dir_subs;
71
72 #ifdef GIO_COMPILATION
73     GFile* gfile;
74 #endif
75 };
76
77 #define FILE_OBJECT(f)                ((file_obj_t *)(f))
78 #define NODE_NAME(f)                  (FILE_OBJECT(f)->fo_name)
79 #define NODE_PARENT(f)                (((node_t *)f)->parent)
80 #define NODE_IS_ACTIVE(f)             (f->dir_subs || f->subs)
81 #define NODE_IS_REQUIRED_BY_PARENT(f) (NODE_PARENT(f) && NODE_PARENT(f)->dir_subs)
82
83 gboolean node_timeval_lt(const GTimeVal *val1, const GTimeVal *val2);
84 gboolean node_try_delete(node_t* node);
85 void     node_traverse(node_t* node, void(*traverse_cb)(node_t*, gpointer), gpointer user_data);
86 node_t*  node_find(node_t* node, const gchar* filename, gboolean create_on_missing);
87 gint     node_lstat(node_t *f);
88 void     node_create_children_snapshot(node_t *f, gint created_event, gboolean emit);
89 void     node_adjust_deleted(node_t *f);
90 gboolean node_class_init();
91
92 typedef struct node_event
93 {
94     int e;
95     gpointer user_data;
96     gpointer pair_data;
97     GTimeVal ctv;               /* Created timestamp */
98     GTimeVal rename_tv;         /* Possible rename timestamp */
99 } node_event_t;
100
101 node_event_t* node_event_new (int event, gpointer user_data);
102 void node_event_delete (node_event_t* ev);
103
104 #endif /* _FEN_NODE_H_ */