wfut  0.2.4
A client side C++ implementation of WFUT (WorldForge Update Tool).
WFUT.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 - 2007 Simon Goodall
4 
5 #ifndef LIBWFUT_WFUT_H
6 #define LIBWFUT_WFUT_H 1
7 
8 #include <string>
9 #include <cassert>
10 
11 #include <sigc++/signal.h>
12 
13 #include <libwfut/types.h>
14 #include <libwfut/ChannelFileList.h>
15 
16 namespace WFUT {
17 
18 class IO;
19 
22 typedef enum {
23  WFUT_NO_ERROR = 0, // No error occured. Success
24  WFUT_GENERAL_ERROR, // A general error happened. Nothing specific case.
25  WFUT_DOWNLOAD_ERROR, // An error happened during download.
26  WFUT_PARSE_ERROR, // An error happened during the parsing of a file
27  WFUT_WRITE_ERROR // An error happened trying to write a file.
28 } WFUTError;
29 
30 typedef enum {
31  WFUT_UPDATE_NONE = 0, // No update required
32  WFUT_UPDATE_NO_LOCAL, // No local version of the file
33  WFUT_UPDATE_SERVER_SYSTEM, // Server copy is newer than system version
34  WFUT_UPDATE_SERVER_LOCAL, // Server copy is newer than local version
35  WFUT_UPDATE_MISSING, // Local copy is missing
36  WFUT_UPDATE_MODIFIED, // Local copy is modified
37  WFUT_UPDATE_DELETED // Server copy has been deleted
38 } WFUTUpdateReason;
39 
54 class WFUTClient {
55 public:
56  WFUTClient():
57  m_initialised(false),
58  m_io(NULL)
59  {}
60  virtual ~WFUTClient() {
61  if (m_initialised) shutdown();
62  }
63 
67  WFUTError init();
68 
72  WFUTError shutdown();
73 
82  void updateChannel(const ChannelFileList &updates,
83  const std::string &urlPrefix,
84  const std::string &pathPrefix);
85 
89  void updateFile(const FileObject &file,
90  const std::string &urlPrefix,
91  const std::string &pathPrefix);
92 
96  WFUTError getMirrorList(const std::string &url, MirrorList &mirrors);
97 
102  WFUTError getChannelList(const std::string &url, ChannelList &channels);
103 
107  WFUTError getFileList(const std::string &url, ChannelFileList &files);
108 
111  WFUTError getLocalList(const std::string &filename, ChannelFileList &files);
112 
117  WFUTError saveLocalList(const ChannelFileList &files,
118  const std::string &filename);
119 
131  WFUTError calculateUpdates(const ChannelFileList &server,
132  const ChannelFileList &system,
133  const ChannelFileList &local,
134  ChannelFileList &updates,
135  const std::string &prefix);
136 
137 
143  int poll();
144 
149  sigc::signal<void, const std::string&, const std::string&> DownloadComplete;
150 
158  sigc::signal<void, const std::string&, const std::string&, const std::string&> DownloadFailed;
159 
166  sigc::signal<void, const std::string&, const WFUTUpdateReason> UpdateReason;
167 
171  void abortAll();
172 
176  void abortDownload(const std::string &filename);
177 
178 private:
179  void onDownloadComplete(const std::string &url, const std::string &filename);
180  void onDownloadFailed(const std::string &url, const std::string &filename, const std::string &reason);
181 
182  bool m_initialised;
183  IO *m_io;
184 };
185 
186 } /* namespace WFUT */
187 
188 #endif /* LIBWFUT_WFUT_H */
void abortAll()
Definition: WFUT.cpp:278
Definition: IO.h:37
sigc::signal< void, const std::string &, const std::string & > DownloadComplete
Definition: WFUT.h:149
sigc::signal< void, const std::string &, const std::string &, const std::string & > DownloadFailed
Definition: WFUT.h:158
WFUTError shutdown()
Definition: WFUT.cpp:41
WFUTError getChannelList(const std::string &url, ChannelList &channels)
Definition: WFUT.cpp:118
WFUTError getLocalList(const std::string &filename, ChannelFileList &files)
Definition: WFUT.cpp:192
void updateFile(const FileObject &file, const std::string &urlPrefix, const std::string &pathPrefix)
Definition: WFUT.cpp:71
WFUTError getMirrorList(const std::string &url, MirrorList &mirrors)
Definition: WFUT.cpp:81
void abortDownload(const std::string &filename)
Definition: WFUT.cpp:274
sigc::signal< void, const std::string &, const WFUTUpdateReason > UpdateReason
Definition: WFUT.h:166
WFUTError getFileList(const std::string &url, ChannelFileList &files)
Definition: WFUT.cpp:154
WFUTError calculateUpdates(const ChannelFileList &server, const ChannelFileList &system, const ChannelFileList &local, ChannelFileList &updates, const std::string &prefix)
Definition: WFUT.cpp:215
WFUTError saveLocalList(const ChannelFileList &files, const std::string &filename)
Definition: WFUT.cpp:201
void updateChannel(const ChannelFileList &updates, const std::string &urlPrefix, const std::string &pathPrefix)
Definition: WFUT.cpp:53
WFUTError init()
Definition: WFUT.cpp:23