~ubuntu-branches/ubuntu/karmic/gtk-gnutella/karmic

« back to all changes in this revision

Viewing changes to src/if/core/fileinfo.h

  • Committer: Bazaar Package Importer
  • Author(s): Anand Kumria
  • Date: 2005-08-04 11:32:05 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050804113205-q746i4lgo3rtlegn
Tags: 0.95.4-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: fileinfo.h,v 1.12 2005/06/25 01:37:42 daichik Exp $
 
3
 *
 
4
 * Copyright (c) 2001-2003, Raphael Manfredi, Richard Eckart
 
5
 *
 
6
 *----------------------------------------------------------------------
 
7
 * This file is part of gtk-gnutella.
 
8
 *
 
9
 *  gtk-gnutella is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  gtk-gnutella is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with gtk-gnutella; if not, write to the Free Software
 
21
 *  Foundation, Inc.:
 
22
 *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 *----------------------------------------------------------------------
 
24
 */
 
25
 
 
26
#ifndef _if_core_fileinfo_h_
 
27
#define _if_core_fileinfo_h_
 
28
 
 
29
#include "common.h"
 
30
 
 
31
#include "if/core/downloads.h"  /* For gnet_srt_t */
 
32
 
 
33
struct shared_file;
 
34
struct download;
 
35
 
 
36
/**
 
37
 * These used to be in fileinfo.h, but we need them now at several places.
 
38
 */
 
39
enum dl_chunk_status {
 
40
    DL_CHUNK_EMPTY = 0,
 
41
    DL_CHUNK_BUSY  = 1,
 
42
    DL_CHUNK_DONE  = 2
 
43
};
 
44
 
 
45
typedef guint32 gnet_fi_t;
 
46
 
 
47
typedef struct gnet_fi_info {
 
48
        gnet_fi_t fi_handle;
 
49
        gchar *path;                            /**< Path of the directory of the file on disk */
 
50
        gchar *file_name;                       /**< Name of the file on disk */
 
51
        gchar *sha1;                            /**< SHA1 (binary) of the file or NULL */
 
52
        GSList *aliases;                        /**< List of aliases (NULL if none) */
 
53
} gnet_fi_info_t;
 
54
 
 
55
typedef struct gnet_fi_status {
 
56
        guint32         recvcount;
 
57
        guint32         refcount;
 
58
        guint32         lifecount;
 
59
        filesize_t  size;
 
60
        filesize_t  done;
 
61
        guint32         recv_last_rate;
 
62
        guint32         aqueued_count;
 
63
        guint32         pqueued_count;
 
64
} gnet_fi_status_t;
 
65
 
 
66
typedef struct gnet_fi_chunks {
 
67
    filesize_t  from;
 
68
    filesize_t  to;
 
69
    enum dl_chunk_status status;
 
70
    gboolean old;
 
71
} gnet_fi_chunks_t;
 
72
 
 
73
struct dl_file_info {
 
74
    gnet_fi_t fi_handle;    /**< Handle */
 
75
 
 
76
        guint32 flags;                  /**< Operating flags */
 
77
        gchar *file_name;               /**< Output file name (atom) */
 
78
        gchar *path;                    /**< Output file path (atom) */
 
79
        GSList *alias;                  /**< List of file name aliases (atoms) */
 
80
        filesize_t size;                /**< File size */
 
81
        guint64 *size_atom;             /**< File size (atom -- points to value in memory) */
 
82
        gchar *sha1;                    /**< server SHA1 (atom) if known, NULL if not. */
 
83
        gchar *cha1;                    /**< computed SHA1 (atom) if known, NULL if not. */
 
84
        gint32 refcount;                /**< Reference count of file (number of sources)*/
 
85
        GSList *sources;        /**< list of sources (struct download *) */
 
86
        gint32 lifecount;               /**< Amount of "alive" downloads referencing us */
 
87
        time_t stamp;                   /**< Time stamp */
 
88
        time_t ctime;                   /**< Creation time stamp */
 
89
        time_t ntime;                   /**< Last time a new source was added */
 
90
        time_t last_flush;              /**< When last flush to disk occurred */
 
91
        time_t last_dmesh;              /**< When last dmesh query was used */
 
92
        filesize_t done;                /**< Total number of bytes completed */
 
93
        GSList *chunklist;              /**< List of ranges within file */
 
94
        GSList *seen_on_network;  /**< List of ranges available on network */
 
95
        guint32 generation;             /**< Generation number, incremented on disk update */
 
96
        struct shared_file *sf; /**< When PFSP-server is enabled, share this file */
 
97
        gboolean file_size_known; /**< File size known? */
 
98
        gboolean use_swarming;  /**< Use swarming? */
 
99
        gboolean dirty;                 /**< Does it need saving? */
 
100
        gboolean dirty_status;  /**< Notify about status change on next interval */
 
101
        gboolean hashed;                /**< In hash tables? */
 
102
        guint32  aqueued_count; /**< Actively queued sources */
 
103
        guint32  pqueued_count; /**< Passively queued sources */
 
104
 
 
105
 
 
106
        /*
 
107
         * The following group is used to compute the aggregated reception rate.
 
108
         */
 
109
 
 
110
        gint32 recvcount;               /**< Amount of "receiving" downloads referencing us */
 
111
        guint32 recv_last_rate; /**< Last amount of bytes/sec received */
 
112
        guint32 recv_amount;    /**< Amount of bytes received this period */
 
113
        time_t recv_last_time;  /**< When did we last compute recv_last_rate? */
 
114
 
 
115
        /*
 
116
         * This group of fields is used by the background SHA1 and moving daemons.
 
117
         */
 
118
 
 
119
        guint cha1_elapsed;             /**< Time spent to compute the SHA1 */
 
120
        filesize_t cha1_hashed; /**< Amount of bytes hashed so far */
 
121
        guint copy_elapsed;             /**< Time spent to copy the file */
 
122
        filesize_t copied;              /**< Amount of bytes copied so far */
 
123
};
 
124
 
 
125
#define FILE_INFO_COMPLETE(x)   ((x)->done == (x)->size && (x)->file_size_known)
 
126
 
 
127
typedef void (*fi_listener_t) (gnet_fi_t);
 
128
typedef void (*fi_src_listener_t) (gnet_fi_t, gnet_src_t);
 
129
 
 
130
typedef enum {
 
131
        EV_FI_ADDED = 0,       /**< fi_listener */
 
132
        EV_FI_REMOVED,         /**< fi_listener */
 
133
        EV_FI_INFO_CHANGED,    /**< fi_listener */
 
134
        EV_FI_STATUS_CHANGED,  /**< fi_listener */
 
135
        EV_FI_STATUS_CHANGED_TRANSIENT, /**< fi_listener */
 
136
        EV_FI_SRC_ADDED,       /**< fi_src_listener */
 
137
        EV_FI_SRC_REMOVED,     /**< fi_src_listener */
 
138
        EV_FI_RANGES_CHANGED,  /**< fi_listener */
 
139
 
 
140
        EV_FI_EVENTS           /**< Number of events in this domain */
 
141
} gnet_fi_ev_t;
 
142
 
 
143
/*
 
144
 * Public interface, visible only from the bridge.
 
145
 */
 
146
 
 
147
#ifdef CORE_SOURCES
 
148
 
 
149
void fi_add_listener(fi_listener_t, gnet_fi_ev_t, frequency_t, guint32);
 
150
void fi_remove_listener(fi_listener_t, gnet_fi_ev_t);
 
151
 
 
152
gnet_fi_info_t *fi_get_info(gnet_fi_t);
 
153
void fi_free_info(gnet_fi_info_t *);
 
154
void fi_get_status(gnet_fi_t, gnet_fi_status_t *);
 
155
GSList *fi_get_chunks(gnet_fi_t);
 
156
void fi_free_chunks(GSList *chunks);
 
157
GSList *fi_get_ranges(gnet_fi_t);
 
158
void fi_free_ranges(GSList *ranges);
 
159
gchar **fi_get_aliases(gnet_fi_t fih);
 
160
 
 
161
void fi_purge_by_handle_list(GSList *list);
 
162
gboolean fi_purge(gnet_fi_t fih);
 
163
 
 
164
const gchar *file_info_readable_filename(const struct dl_file_info *fi);
 
165
 
 
166
#endif /* CORE_SOURCES */
 
167
#endif /* _if_core_fileinfo_h_ */
 
168
 
 
169
/* vi: set ts=4 sw=4 cindent: */