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
;
43 /** \brief Holds informations about managed torrents.
45 * This class is a singleton.
49 /** Client for this torrent. If there is no such client then it is zero.
51 TorrentClient
*client
;
53 /** Meta info of the torrent. If the metainfo has not been loaded yet then
56 Tairent::Core::BEncode
*metaInfo
;
58 /** Whether this torrent is completely downloaded.
62 /** Filename of torrent.
67 /** \brief TorrentManager keeps informations about managed torrents.
72 /** Constructs a TorrentManager object; calls loadTorrent().
76 /** Destroys the object.
80 /** Deletes all active clients.
84 TorrentClient
*getClient(const String
&infoHash
);
86 /** Returns client ID.
88 const String
&getClientID();
90 /** Converts data in hex to its binary original.
92 static String
hexToBin(const String
&data
);
94 /** Returns pointer to the instance of this class.
96 static TorrentManager
*self() {
97 return torrentManager
;
100 /** Starts downloading unfinished torrents.
102 void startTorrents();
104 /** Stops downloading torrents.
109 /** Helper method for converting hex char to an integer.
111 static char hexToBin(char c
);
113 /** Loads metainfo from a file with given filename. A new
114 * Tairent::Core::BEncode object is created and filled with
115 * informations from the file. Zero is returned if any error occurs
118 Tairent::Core::BEncode
*loadMetaInfo(const String
&filename
);
120 /** Loads informations about one torrent from a node.
122 * \param t Element with informations about torrent.
124 void loadTorrent(TiXmlNode
*t
);
126 /** Loads informations about torrents from file torrents.xml stored in
127 * a directory whose name is stored in Tairon::Core::Config as
128 * "torrents-directory".
132 /** Creates client ID.
141 /** Pointer to the instance of this class.
143 static TorrentManager
*torrentManager
;
145 /** Mapping hash (raw, not human-readable) -> info about torrent.
147 std::map
<String
, TorrentStruct
*> torrents
;
152 }; // namespace Tairent
156 // vim: ai sw=4 ts=4 noet fdm=marker