1 /***************************************************************************
3 * Copyright (C) 2006 David Brodsky *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation and appearing *
8 * in the file LICENSE.GPL included in the packaging of this file. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * General Public License for more details. *
15 ***************************************************************************/
17 #ifndef _main_torrentmanager_h
18 #define _main_torrentmanager_h
22 #include <tairon/core/string.h>
24 using Tairon::Core::String
;
44 /** \brief Holds informations about managed torrents.
46 * This class is a singleton.
50 /** Client for this torrent. If there is no such client then it is zero.
52 TorrentClient
*client
;
54 /** This client's storage. It is used for fast-resuming.
58 /** Meta info of the torrent. If the metainfo has not been loaded yet then
61 Tairent::Core::BEncode
*metaInfo
;
63 /** Whether this torrent is completely downloaded.
67 /** Filename of torrent.
72 /** \brief TorrentManager keeps informations about managed torrents.
77 /** Constructs a TorrentManager object; calls loadTorrent().
81 /** Destroys the object.
85 /** Converts data in bin to its hexadecimal variant.
87 static String
binToHex(const String
&data
);
89 /** Deletes all active clients.
93 /** Returns a TorrentClient object associated with given info hash. The
94 * method returns 0 if there is no such client.
96 TorrentClient
*getClient(const String
&infoHash
);
98 /** Returns client ID.
100 const String
&getClientID();
102 /** Converts data in hex to its binary original.
104 static String
hexToBin(const String
&data
);
106 /** Saves informations about managed torrents to torrents.xml file in
107 * torrents-directory configuration option.
111 /** Returns pointer to the instance of this class.
113 static TorrentManager
*self() {
114 return torrentManager
;
117 /** Starts downloading unfinished torrents.
119 void startTorrents();
121 /** Stops downloading torrents.
126 /** Helper method for converting hex char to an integer.
128 static char hexToBin(char c
);
130 /** Loads metainfo from a file with given filename. A new
131 * Tairent::Core::BEncode object is created and filled with
132 * informations from the file. Zero is returned if any error occurs
135 Tairent::Core::BEncode
*loadMetaInfo(const String
&filename
);
137 /** Loads informations about one torrent from a node.
139 * \param t Element with informations about torrent.
141 void loadTorrent(TiXmlNode
*t
);
143 /** Loads informations about torrents from file torrents.xml stored in
144 * a directory whose name is stored in Tairon::Core::Config as
145 * "torrents-directory".
149 /** Creates client ID.
158 /** Pointer to the instance of this class.
160 static TorrentManager
*torrentManager
;
162 /** Mapping hash (raw, not human-readable) -> info about torrent.
164 std::map
<String
, TorrentStruct
*> torrents
;
169 }; // namespace Tairent
173 // vim: ai sw=4 ts=4 noet fdm=marker