Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

fileinfo.h

Go to the documentation of this file.
00001 /*
00002  * $Id: fileinfo.h,v 1.19 2005/11/21 21:13:47 rmanfredi Exp $
00003  *
00004  * Copyright (c) 2001-2003, Raphael Manfredi, Richard Eckart
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *----------------------------------------------------------------------
00024  */
00025 
00026 #ifndef _if_core_fileinfo_h_
00027 #define _if_core_fileinfo_h_
00028 
00029 #include "common.h"
00030 
00031 #include "if/core/downloads.h"  /* For gnet_srt_t */
00032 
00033 struct shared_file;
00034 struct download;
00035 
00039 enum dl_chunk_status {
00040     DL_CHUNK_EMPTY = 0,         
00041     DL_CHUNK_BUSY  = 1,         
00042     DL_CHUNK_DONE  = 2,         
00043 };
00044 
00045 typedef guint32 gnet_fi_t;
00046 
00047 typedef struct gnet_fi_info {
00048     gnet_fi_t fi_handle;
00049     gchar *path;                
00050     gchar *file_name;           
00051     gchar *sha1;                
00052     GSList *aliases;            
00053 } gnet_fi_info_t;
00054 
00055 typedef struct gnet_fi_status {
00056     guint32     recvcount;
00057     guint32     refcount;
00058     guint32     lifecount;
00059     filesize_t  size;
00060     filesize_t  done;
00061     guint32     recv_last_rate;
00062     guint32     aqueued_count;
00063     guint32     pqueued_count;
00064 
00065     /*
00066      * The following are set only when file has been completely downloaded.
00067      */
00068 
00069     gboolean    has_sha1;
00070     gboolean    sha1_matched;
00071     filesize_t  sha1_hashed;
00072     filesize_t  copied;
00073 } gnet_fi_status_t;
00074 
00075 typedef struct gnet_fi_chunks {
00076     filesize_t  from;
00077     filesize_t  to;
00078     enum dl_chunk_status status;
00079     gboolean old;
00080 } gnet_fi_chunks_t;
00081 
00082 typedef struct dl_file_info {
00083     gnet_fi_t fi_handle;    
00084     gchar *guid;            
00085     guint32 flags;          
00086     gchar *file_name;       
00087     gchar *path;            
00088     GSList *alias;          
00089     filesize_t size;        
00090     guint64 *size_atom;     
00091     gchar *sha1;            
00092     gchar *cha1;            
00093     gint32 refcount;        
00094     GSList *sources;        
00095     gint32 lifecount;       
00096     time_t stamp;           
00097     time_t ctime;           
00098     time_t ntime;           
00099     time_t last_flush;      
00100     time_t last_dmesh;      
00101     filesize_t done;        
00102     GSList *chunklist;      
00103     GSList *seen_on_network;  
00104     guint32 generation;     
00105     struct shared_file *sf; 
00106     gboolean file_size_known; 
00107     gboolean use_swarming;  
00108     gboolean dirty;         
00109     gboolean dirty_status;  
00110     gboolean hashed;        
00111     guint32  aqueued_count; 
00112     guint32  pqueued_count; 
00114     /*
00115      * The following group is used to compute the aggregated reception rate.
00116      */
00117 
00118     gint32 recvcount;       
00119     guint32 recv_last_rate; 
00120     guint32 recv_amount;    
00121     time_t recv_last_time;  
00123     /*
00124      * This group of fields is used by the background SHA1 and moving daemons.
00125      */
00126 
00127     guint cha1_elapsed;     
00128     filesize_t cha1_hashed; 
00129     guint copy_elapsed;     
00130     filesize_t copied;      
00131 } fileinfo_t;
00132 
00133 #define FILE_INFO_COMPLETE(x)   ((x)->done == (x)->size && (x)->file_size_known)
00134 
00135 #define FILE_INFO_COMPLETE_AFTER(x,z)   \
00136     ((x)->done + (z) >= (x)->size && (x)->file_size_known)
00137 
00138 typedef void (*fi_listener_t) (gnet_fi_t);
00139 typedef void (*fi_src_listener_t) (gnet_fi_t, gnet_src_t);
00140 
00141 typedef enum {
00142     EV_FI_ADDED = 0,       
00143     EV_FI_REMOVED,         
00144     EV_FI_INFO_CHANGED,    
00145     EV_FI_STATUS_CHANGED,  
00146     EV_FI_STATUS_CHANGED_TRANSIENT, 
00147     EV_FI_SRC_ADDED,       
00148     EV_FI_SRC_REMOVED,     
00149     EV_FI_RANGES_CHANGED,  
00151     EV_FI_EVENTS           
00152 } gnet_fi_ev_t;
00153 
00154 /*
00155  * Public interface, visible only from the bridge.
00156  */
00157 
00158 #ifdef CORE_SOURCES
00159 
00160 void fi_add_listener(fi_listener_t, gnet_fi_ev_t, frequency_t, guint32);
00161 void fi_remove_listener(fi_listener_t, gnet_fi_ev_t);
00162 
00163 gnet_fi_info_t *fi_get_info(gnet_fi_t);
00164 void fi_free_info(gnet_fi_info_t *);
00165 void fi_get_status(gnet_fi_t, gnet_fi_status_t *);
00166 GSList *fi_get_chunks(gnet_fi_t);
00167 void fi_free_chunks(GSList *chunks);
00168 GSList *fi_get_ranges(gnet_fi_t);
00169 void fi_free_ranges(GSList *ranges);
00170 gchar **fi_get_aliases(gnet_fi_t fih);
00171 
00172 void fi_purge_by_handle_list(const GSList *list);
00173 
00174 const gchar *file_info_readable_filename(const struct dl_file_info *fi);
00175 
00176 #endif /* CORE_SOURCES */
00177 #endif /* _if_core_fileinfo_h_ */
00178 
00179 /* vi: set ts=4 sw=4 cindent: */

Generated on Sun Feb 12 10:49:56 2006 for Gtk-Gnutella by doxygen 1.3.6