Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
244 chris 1
#ifndef __HTTPTRANSFER_H__
2
#define __HTTPTRANSFER_H__
3
 
4
#include "Common.h"
5
 
6
namespace Sexy
7
{
8
 
9
class HTTPTransfer
10
{
11
public:
12
        enum
13
        {
14
                RESULT_DONE,
15
                RESULT_NOT_STARTED,
16
                RESULT_NOT_COMPLETED,
17
                RESULT_NOT_FOUND,
18
                RESULT_HTTP_ERROR,
19
                RESULT_ABORTED,
20
                RESULT_SOCKET_ERROR,
21
                RESULT_INVALID_ADDR,
22
                RESULT_CONNECT_FAIL,
23
                RESULT_DISCONNECTED
24
        };
25
 
26
        int                                             mTransferId;
27
        int                                             mSocket;
28
        std::string                             mSendStr;
29
        std::string                             mSpecifiedBaseURL;
30
        std::string                             mSpecifiedRelURL;
31
        std::string                             mURL;
32
        std::string                             mProto;
33
        std::string                             mHost; 
34
        int                                             mPort;
35
        std::string                             mPath;
36
 
37
        int                                             mContentLength;
38
        std::string                             mContent;
39
 
40
        bool                                    mTransferPending;
41
        bool                                    mThreadRunning;
42
        bool                                    mExiting;
43
        bool                                    mAborted;
44
        int                                             mResult;
45
 
46
        int                                             mDemoLastKnownResult;
47
 
48
protected:
49
        void                                    PrepareTransfer(const std::string& theURL);
50
        void                                    StartTransfer();
51
        void                                    GetHelper(const std::string& theURL);
52
 
53
        void                                    PostHelper(const std::string& theURL, const std::string& theParams);
54
 
55
        void                                    Fail(int theResult);
56
        void                                    GetThreadProc();
57
        static void                             GetThreadProcStub(void *theArg);
58
        static std::string              GetAbsURL(const std::string& theBaseURL, const std::string& theRelURL);
59
 
60
        void                                    UpdateStatus();
61
        bool                                    SocketWait(bool checkRead, bool checkWrite);
62
 
63
public:
64
        HTTPTransfer();
65
        virtual ~HTTPTransfer();
66
 
67
        void                                    Get(const std::string& theURL);
68
        void                                    Get(const std::string& theBaseURL, const std::string& theRelURL);
69
 
70
        void                                    Post(const std::string& theURL, const std::string& theParams);
71
        void                                    Post(const std::string& theBaseURL, const std::string& theRelURL, const std::string& theParams);
72
 
73
        void                                    SendRequestString(const std::string& theHost, const std::string& theSendString);
74
 
75
        void                                    Reset();
76
        void                                    Abort();
77
        void                                    WaitFor();
78
        int                                             GetResultCode();
79
        std::string                             GetContent();  
80
};
81
 
82
};
83
 
84
#endif //__HTTPTRANSFER_H__