wfut 0.2.4
A client side C++ implementation of WFUT (WorldForge Update Tool).
IO.h
1// This file may be redistributed and modified only under the terms of
2// the GNU Lesser General Public License (See COPYING for details).
3// Copyright (C) 2005 - 2008 Simon Goodall
4
5#ifndef LIBWFUT_IO_H
6#define LIBWFUT_IO_H 1
7
8#include <cassert>
9#include <string>
10#include <map>
11#include <deque>
12#include <cstdio>
13
14#include <zlib.h>
15#include <curl/curl.h>
16#include <sigc++/signal.h>
17
18#include <libwfut/types.h>
19
20namespace WFUT {
21 // Internal data struct representing a single file being downloaded.
22 typedef struct {
23 std::string filename;
24 std::string path;
25 std::string url;
26 bool executable;
27 FILE *fp;
28 uLong actual_crc32;
29 uLong expected_crc32;
30 CURL *handle;
31 } DataStruct;
32
37class IO {
38public:
39 IO() :
40 m_initialised(false),
41 m_mhandle(NULL),
42 m_num_to_process(1)
43 {}
44
45 virtual ~IO() {
46 assert(m_initialised == false);
47 }
48
52 int init();
53
57 int shutdown();
58
62 int poll();
63
72 int downloadFile(const std::string &filename, const std::string &url, uLong expected_crc32);
73
82 int downloadFile(FILE *fp, const std::string &url, uLong expected_crc32);
83
93 int queueFile(const std::string &path, const std::string &filename, const std::string &url, uLong expected_crc32, bool executable);
94
98 sigc::signal<void, const std::string&, const std::string&> DownloadComplete;
103 sigc::signal<void, const std::string&, const std::string&, const std::string&> DownloadFailed;
104
108 int getMaxDownloads() const { return m_num_to_process; }
114 void setMaxDownloads(int i) { m_num_to_process = i; }
115
119 void abortAll();
120
124 void abortDownload(const std::string &);
125
126private:
127
128 void abortDownload(DataStruct *ds);
129
130 bool m_initialised;
131 CURLM *m_mhandle;
132 std::map<std::string, DataStruct*> m_files;
133 std::deque<CURL*> m_handles;
134 int m_num_to_process;
135};
136
137} /* namespace WFUT */
138
139#endif /* LIBEFUT_IO_H */
Definition: IO.h:37
sigc::signal< void, const std::string &, const std::string & > DownloadComplete
Definition: IO.h:98
int poll()
Definition: IO.cpp:251
int queueFile(const std::string &path, const std::string &filename, const std::string &url, uLong expected_crc32, bool executable)
Definition: IO.cpp:221
int shutdown()
Definition: IO.cpp:132
sigc::signal< void, const std::string &, const std::string &, const std::string & > DownloadFailed
Definition: IO.h:103
int init()
Definition: IO.cpp:117
void abortAll()
Definition: IO.cpp:351
int downloadFile(const std::string &filename, const std::string &url, uLong expected_crc32)
Definition: IO.cpp:160
int getMaxDownloads() const
Definition: IO.h:108
void setMaxDownloads(int i)
Definition: IO.h:114
void abortDownload(const std::string &)
Definition: IO.cpp:364