Add main page for Doxygen generated documentation.
[tairent.git] / src / main / torrentmanager.h
blob6a5786644a10ab5044165a223b106c2d275c16dd
1 /***************************************************************************
2 * *
3 * Copyright (C) 2006 David Brodsky *
4 * *
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. *
9 * *
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. *
14 * *
15 ***************************************************************************/
17 #ifndef _main_torrentmanager_h
18 #define _main_torrentmanager_h
20 #include <map>
22 #include <tairon/core/string.h>
24 using Tairon::Core::String;
26 class TiXmlNode;
28 namespace Tairon
31 namespace Net
34 class Timer;
36 }; // namespace Net
38 }; // namespace Tairon
40 namespace Tairent
43 namespace Core
46 class BEncode;
48 }; // namespace Core
50 namespace Main
53 class Storage;
54 class TorrentClient;
56 /** \brief Holds informations about managed torrents.
58 * This class is a singleton.
60 struct TorrentStruct
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.
68 Storage *storage;
70 /** Meta info of the torrent. If the metainfo has not been loaded yet then
71 * it is zero.
73 Tairent::Core::BEncode *metaInfo;
75 /** Whether this torrent is completely downloaded.
77 bool complete;
79 /** Filename of torrent.
81 String torrentFile;
84 /** \brief TorrentManager keeps informations about managed torrents.
86 class TorrentManager
88 public:
89 /** Constructs a TorrentManager object; calls loadTorrent().
91 TorrentManager();
93 /** Destroys the object.
95 ~TorrentManager();
97 /** Converts data in bin to its hexadecimal variant.
99 static String binToHex(const String &data);
101 /** Deletes all active clients.
103 void destroy();
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.
121 void save();
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.
135 void stopTorrents();
137 private:
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
145 * while loading.
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".
159 void loadTorrents();
161 /** Creates client ID.
163 void makeClientID();
165 private:
166 /** Client ID.
168 String clientID;
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;
183 }; // namespace Main
185 }; // namespace Tairent
187 #endif
189 // vim: ai sw=4 ts=4 noet fdm=marker