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 
20 namespace 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 
37 class IO {
38 public:
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 
126 private:
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 */
WFUT::IO::downloadFile
int downloadFile(const std::string &filename, const std::string &url, uLong expected_crc32)
Definition: IO.cpp:160
WFUT::IO::getMaxDownloads
int getMaxDownloads() const
Definition: IO.h:108
WFUT::IO::DownloadComplete
sigc::signal< void, const std::string &, const std::string & > DownloadComplete
Definition: IO.h:98
WFUT::IO::abortAll
void abortAll()
Definition: IO.cpp:351
WFUT::IO::setMaxDownloads
void setMaxDownloads(int i)
Definition: IO.h:114
WFUT::DataStruct
Definition: IO.h:22
WFUT::IO::poll
int poll()
Definition: IO.cpp:251
WFUT::IO
Definition: IO.h:37
WFUT::IO::abortDownload
void abortDownload(const std::string &)
Definition: IO.cpp:364
WFUT::IO::init
int init()
Definition: IO.cpp:117
WFUT::IO::queueFile
int queueFile(const std::string &path, const std::string &filename, const std::string &url, uLong expected_crc32, bool executable)
Definition: IO.cpp:221
WFUT::IO::DownloadFailed
sigc::signal< void, const std::string &, const std::string &, const std::string & > DownloadFailed
Definition: IO.h:103
WFUT::IO::shutdown
int shutdown()
Definition: IO.cpp:132