Oxygine  1
2g game engine
MyHttp.h
1 #pragma once
2 #include "core/oxygine.h"
3 #include "closure/closure.h"
4 #include "core/file.h"
5 
6 #include "IwHTTP.h"
7 
8 class MyHttp
9 {
10 public:
11  typedef Closure<void (MyHttp*)> DownloadDoneCallback;
12  typedef Closure<void (MyHttp*)> ErrorCallback;
13  typedef Closure<void (MyHttp*, int)> ProgressCallback;
14 
15  enum status
16  {
17  status_none,
18  status_inprogress,
19  status_done,
20  status_error
21  };
22 
23  MyHttp();
24  virtual ~MyHttp();
25 
26 
27  DownloadDoneCallback _cbDone;
28  ProgressCallback _cbProgress;
29  ErrorCallback _cbError;
30 
31  void getFile(const std::string& url, const std::string& name);
32  void get(const std::string& url);
33  void post(const std::string& url, const char* data, int size);
34 
35 
36  std::vector<unsigned char>& getBuffer() {return _data;}
37  status getStatus() const {return _status;}
38  unsigned int getTotalSize() const;
39  unsigned int getReceivedSize() const;
40  int getResponseCode() const;
41 
42 private:
43 
44  enum METHOD {GETFILE, GET, POST};
45  METHOD _method;
46  static int _gotHeaders(void* systemData, void* userData);
47  static int _gotData(void* systemData, void* userData);
48  static int _delayedError(void* systemData, void* userData);
49 
50 
51  void destroy();
52 
53  void gotHeaders();
54  void gotData(int size);
55  void progress(int size);
56 
57  void onError();
58 
59  std::string _url;
60  const char* _post;
61  int _postSize;
62 
63  std::vector<unsigned char> _tempBuffer;
64  std::vector<unsigned char> _data;
65  oxygine::file::handle _handle;
66  CIwHTTP* _http;
67 
68  status _status;
69 };
70 
71 
72 void makeSingleHttpAsyncGetRequest(const char* url);
73 void makeSingleHttpAsyncPostRequest(const char* url, const char* data, int size);
Definition: MyHttp.h:8
Definition: FileSystem.h:12