1 // ***************************************************************************
2 // BamHttp_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 7 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 bool ConnectSocket(void);
54 bool EnsureSocketConnection(void);
55 void ParseUrl(const std::string& url);
56 int64_t ReadFromSocket(char* data, const unsigned int numBytes);
57 bool ReceiveResponse(void);
58 bool SendRequest(const size_t numBytes = 0);
59 int64_t WriteToSocket(const char* data, const unsigned int numBytes);
67 // our connection data
68 std::string m_hostname;
70 std::string m_filename;
72 // our last (active) request & response info
73 HttpRequestHeader* m_request;
74 HttpResponseHeader* m_response;
76 // internal state flags
80 int64_t m_filePosition;
81 int64_t m_endRangeFilePosition;
84 } // namespace Internal
85 } // namespace BamTools