OpenTTD
network_content.h
Go to the documentation of this file.
1 /* $Id: network_content.h 27468 2015-12-10 18:28:01Z zuu $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #ifndef NETWORK_CONTENT_H
13 #define NETWORK_CONTENT_H
14 
15 #include "core/tcp_content.h"
16 #include "core/tcp_http.h"
17 
18 #if defined(ENABLE_NETWORK)
19 
24 
28 typedef const ContentInfo * const * ConstContentIterator;
29 
36  virtual void OnConnect(bool success) {}
37 
41  virtual void OnDisconnect() {}
42 
47  virtual void OnReceiveContentInfo(const ContentInfo *ci) {}
48 
54  virtual void OnDownloadProgress(const ContentInfo *ci, int bytes) {}
55 
60  virtual void OnDownloadComplete(ContentID cid) {}
61 
63  virtual ~ContentCallback() {}
64 };
65 
70 protected:
77 
78  FILE *curFile;
80  bool isConnecting;
81  uint32 lastActivity;
82 
83  friend class NetworkContentConnecter;
84 
85  virtual bool Receive_SERVER_INFO(Packet *p);
86  virtual bool Receive_SERVER_CONTENT(Packet *p);
87 
90 
91  void OnConnect(bool success);
92  void OnDisconnect();
93  void OnReceiveContentInfo(const ContentInfo *ci);
94  void OnDownloadProgress(const ContentInfo *ci, int bytes);
95  void OnDownloadComplete(ContentID cid);
96 
97  void OnFailure();
98  void OnReceiveData(const char *data, size_t length);
99 
100  bool BeforeDownload();
101  void AfterDownload();
102 
103  void DownloadSelectedContentHTTP(const ContentIDList &content);
104  void DownloadSelectedContentFallback(const ContentIDList &content);
105 public:
107  static const int IDLE_TIMEOUT = 60 * 1000;
108 
111 
112  void Connect();
113  void SendReceive();
114  void Close();
115 
116  void RequestContentList(ContentType type);
117  void RequestContentList(uint count, const ContentID *content_ids);
118  void RequestContentList(ContentVector *cv, bool send_md5sum = true);
119 
120  void DownloadSelectedContent(uint &files, uint &bytes, bool fallback = false);
121 
122  void Select(ContentID cid);
123  void Unselect(ContentID cid);
124  void SelectAll();
125  void SelectUpgrade();
126  void UnselectAll();
127  void ToggleSelectedState(const ContentInfo *ci);
128 
129  void ReverseLookupDependency(ConstContentVector &parents, const ContentInfo *child) const;
130  void ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const;
132 
134  uint Length() const { return this->infos.Length(); }
136  ConstContentIterator Begin() const { return this->infos.Begin(); }
138  ConstContentIterator Get(uint32 index) const { return this->infos.Get(index); }
140  ConstContentIterator End() const { return this->infos.End(); }
141 
142  void Clear();
143 
145  void AddCallback(ContentCallback *cb) { this->callbacks.Include(cb); }
147  void RemoveCallback(ContentCallback *cb) { this->callbacks.Erase(this->callbacks.Find(cb)); }
148 };
149 
151 
153 
154 void ShowMissingContentWindow(const struct GRFConfig *list);
155 
156 #else
157 static inline void ShowNetworkContentListWindow() {}
158 #endif /* ENABLE_NETWORK */
159 
160 #endif /* NETWORK_CONTENT_H */