Home | History | Annotate | Download | only in fen
      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 Sun Microsystems, Inc. All rights reserved.
      5  * Use is subject to license terms.
      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 (at) sun.com>
     23  */
     24 
     25 #include <fcntl.h>
     26 #include <sys/types.h>
     27 #include <sys/stat.h>
     28 #include "fen-node.h"
     29 #include "fen-kernel.h"
     30 
     31 #ifndef _FEN_DATA_H_
     32 #define _FEN_DATA_H_
     33 
     34 #define FN_EVENT_CREATED	0
     35 #define FN_NAME(fp)	(((fdata*)(fp))->fobj.fo_name)
     36 #define FN_NODE(fp)	(((fdata*)(fp))->node)
     37 #define	FN_IS_DIR(fp)	(((fdata*)(fp))->is_dir)
     38 #define	FN_IS_PASSIVE(fp)	(((fdata*)(fp))->subs == NULL)
     39 #define	FN_IS_MONDIR(fp)	(((fdata*)(fp))->mon_dir_num > 0)
     40 #define	FN_IS_LIVING(fp)	(!((fdata*)(fp))->is_cancelled)
     41 
     42 typedef struct
     43 {
     44 	file_obj_t fobj;
     45     off_t len;
     46     gboolean is_cancelled;
     47 
     48     node_t* node;
     49 	/* to identify if the path is dir */
     50 	gboolean is_dir;
     51     guint mon_dir_num;
     52 
     53 	/* List of subscriptions monitoring this fdata/path */
     54 	GList *subs;
     55 
     56     /* prcessed changed events num */
     57     guint changed_event_num;
     58 
     59     /* process events source id */
     60     GQueue* eventq;
     61     guint eventq_id;
     62     guint change_update_id;
     63 } fdata;
     64 
     65 /* fdata functions */
     66 fdata* fdata_new (node_t* node, gboolean is_mondir);
     67 void fdata_reset (fdata* data);
     68 void fdata_emit_events_once (fdata *f, int event, gpointer sub);
     69 void fdata_emit_events (fdata *f, int event);
     70 void fdata_add_event (fdata *f, fnode_event_t *ev);
     71 void fdata_adjust_deleted (fdata *f);
     72 fdata* get_parent_data (fdata* data);
     73 node_t* get_parent_node (fdata* data);
     74 gboolean is_monitoring (fdata* data);
     75 
     76 /* sub */
     77 void fdata_sub_add (fdata *f, gpointer sub);
     78 void fdata_sub_remove (fdata *f, gpointer sub);
     79 
     80 /* misc */
     81 node_t* add_missing_cb (node_t* parent, gpointer user_data);
     82 gboolean pre_del_cb (node_t* node, gpointer user_data);
     83 
     84 /* init */
     85 gboolean fdata_class_init (void (*user_emit_cb) (fdata*, int),
     86   void (*user_emit_once_cb) (fdata*, int,  gpointer),
     87   int (*user_event_converter) (int event));
     88 
     89 #endif /* _FEN_DATA_H_ */
     90