]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/io/BamFtp_p.h
cedf716a34efb357aa268b5fafca12dbc8bb2fb8
[bamtools.git] / src / api / internal / io / BamFtp_p.h
1 // ***************************************************************************
2 // BamFtp_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 October 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides reading/writing of BAM files on FTP server
8 // ***************************************************************************
9
10 #ifndef BAMFTP_P_H
11 #define BAMFTP_P_H
12
13 //  -------------
14 //  W A R N I N G
15 //  -------------
16 //
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.
20 //
21 // We mean it.
22
23 #include "api/IBamIODevice.h"
24 #include <string>
25
26 namespace BamTools {
27 namespace Internal {
28
29 class TcpSocket;
30
31 class BamFtp : public IBamIODevice {
32
33     // ctor & dtor
34     public:
35         BamFtp(const std::string& url);
36         ~BamFtp(void);
37
38     // IBamIODevice implementation
39     public:
40         void Close(void);
41         bool IsOpen(void) const;
42         bool IsRandomAccess(void) const;
43         bool Open(const IBamIODevice::OpenMode mode);
44         int64_t Read(char* data, const unsigned int numBytes);
45         bool Seek(const int64_t& position, const int origin = SEEK_SET);
46         int64_t Tell(void) const;
47         int64_t Write(const char* data, const unsigned int numBytes);
48
49     // internal methods
50     private:
51         bool ConnectCommandSocket(void);
52         bool ConnectDataSocket(void);        
53         bool ParsePassiveResponse(void);
54         void ParseUrl(const std::string& url);
55         int64_t ReadCommandSocket(char* data, const unsigned int numBytes);
56         int64_t ReadDataSocket(char* data, const unsigned int numBytes);
57         bool ReceiveReply(void);
58         bool SendCommand(const std::string& command, bool waitForReply);
59         int64_t WriteCommandSocket(const char* data, const unsigned int numBytes);
60         int64_t WriteDataSocket(const char* data, const unsigned int numBytes);
61
62     // data members
63     private:
64         // our main socket
65         TcpSocket* m_commandSocket;
66         TcpSocket* m_dataSocket;
67
68         // our connection data
69         std::string m_hostname;
70         uint16_t    m_port;
71         std::string m_dataHostname;
72         uint16_t    m_dataPort;
73         std::string m_filename;
74
75         std::string m_username;
76         std::string m_password;
77
78         std::string m_response;
79
80         // internal state flags
81         bool m_isUrlParsed;
82
83         // file position
84         int64_t m_filePosition;
85 };
86
87 } // namespace Internal
88 } // namespace BamTools
89
90 #endif // BAMFTP_P_H