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
;
38 }; // namespace Tairon
56 /** \brief Holds informations about managed torrents.
58 * This class is a singleton.
62 /** Client for this torrent. If there is no such client then it is zero.
64 TorrentClient
*client
;
66 /** This client's storage. It is used for fast-resuming.
70 /** Meta info of the torrent. If the metainfo has not been loaded yet then
73 Tairent::Core::BEncode
*metaInfo
;
75 /** Whether this torrent is completely downloaded.
79 /** Filename of torrent.
84 /** \brief TorrentManager keeps informations about managed torrents.
89 /** Constructs a TorrentManager object; calls loadTorrent().
93 /** Destroys the object.
97 /** Converts data in bin to its hexadecimal variant.
99 static String
binToHex(const String
&data
);
101 /** Deletes all active clients.
105 /** Returns a TorrentClient object associated with given info hash. The
106 * method returns 0 if there is no such client.
108 TorrentClient
*getClient(const String
&infoHash
);
110 /** Returns client ID.
112 const String
&getClientID();
114 /** Converts data in hex to its binary original.
116 static String
hexToBin(const String
&data
);
118 /** Saves informations about managed torrents to torrents.xml file in
119 * torrents-directory configuration option.
123 /** Returns pointer to the instance of this class.
125 static TorrentManager
*self() {
126 return torrentManager
;
129 /** Starts downloading unfinished torrents.
131 void startTorrents();
133 /** Stops downloading torrents.
138 /** Helper method for converting hex char to an integer.
140 static char hexToBin(char c
);
142 /** Loads metainfo from a file with given filename. A new
143 * Tairent::Core::BEncode object is created and filled with
144 * informations from the file. Zero is returned if any error occurs
147 Tairent::Core::BEncode
*loadMetaInfo(const String
&filename
);
149 /** Loads informations about one torrent from a node.
151 * \param t Element with informations about torrent.
153 void loadTorrent(TiXmlNode
*t
);
155 /** Loads informations about torrents from file torrents.xml stored in
156 * a directory whose name is stored in Tairon::Core::Config as
157 * "torrents-directory".
161 /** Creates client ID.
170 /** Timer for calling save() method.
172 Tairon::Net::Timer
*saveTimer
;
174 /** Pointer to the instance of this class.
176 static TorrentManager
*torrentManager
;
178 /** Mapping hash (raw, not human-readable) -> info about torrent.
180 std::map
<String
, TorrentStruct
*> torrents
;
185 }; // namespace Tairent
189 // vim: ai sw=4 ts=4 noet fdm=marker