1 // ***************************************************************************
2 // BamHttp_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 November 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides reading/writing of BAM files on HTTP server
8 // ***************************************************************************
17 // This file is not part of the BamTools API. It exists purely as an
18 // implementation detail. This header file may change from version to version
19 // without notice, or even be removed.
23 #include "api/IBamIODevice.h"
29 class HttpRequestHeader;
30 class HttpResponseHeader;
33 class BamHttp : public IBamIODevice {
37 BamHttp(const std::string& url);
40 // IBamIODevice implementation
43 bool IsOpen(void) const;
44 bool IsRandomAccess(void) const;
45 bool Open(const IBamIODevice::OpenMode mode);
46 int64_t Read(char* data, const unsigned int numBytes);
47 bool Seek(const int64_t& position, const int origin = SEEK_SET);
48 int64_t Tell(void) const;
49 int64_t Write(const char* data, const unsigned int numBytes);
53 void ClearResponse(void);
54 bool ConnectSocket(void);
55 void DisconnectSocket(void);
56 bool EnsureSocketConnection(void);
57 void ParseUrl(const std::string& url);
58 int64_t ReadFromSocket(char* data, const unsigned int numBytes);
59 bool ReceiveResponse(void);
60 bool SendGetRequest(const size_t numBytes = 0x10000);
61 bool SendHeadRequest(void);
62 int64_t WriteToSocket(const char* data, const unsigned int numBytes);
70 // our connection data
71 std::string m_hostname;
73 std::string m_filename;
75 // our last (active) request & response info
76 HttpRequestHeader* m_request;
77 HttpResponseHeader* m_response;
79 // internal state flags
83 int64_t m_filePosition;
84 int64_t m_fileEndPosition;
85 int64_t m_rangeEndPosition;
88 } // namespace Internal
89 } // namespace BamTools