gpreader.h 1.6 KB
Newer Older
1 2 3 4 5
#ifndef __GP_READER__
#define __GP_READER__

#include <string>

P
Peifeng Qiu 已提交
6
#include "s3bucket_reader.h"
7
#include "s3common_reader.h"
A
Adam Lee 已提交
8 9
#include "s3interface.h"
#include "s3key_reader.h"
10

11 12
extern string gpReaderErrorMessage;

P
Peifeng Qiu 已提交
13
class GPReader : public Reader {
14
   public:
P
Peifeng Qiu 已提交
15 16 17 18 19 20 21 22 23 24
    GPReader(const string &url);
    virtual ~GPReader() {
    }

    virtual void open(const ReaderParams &params);

    // read() attempts to read up to count bytes into the buffer starting at
    // buffer.
    // Return 0 if EOF. Throw exception if encounters errors.
    virtual uint64_t read(char *buf, uint64_t count);
25

P
Peifeng Qiu 已提交
26 27 28
    // This should be reentrant, has no side effects when called multiple times.
    virtual void close();

K
Kuien Liu 已提交
29 30 31 32
    ListBucketResult *getKeyList() {
        return bucketReader.getKeyList();
    }

P
Peifeng Qiu 已提交
33 34
   private:
    void constructReaderParam(const string &url);
35 36

   protected:
P
Peifeng Qiu 已提交
37
    S3BucketReader bucketReader;
38 39
    S3CommonReader commonReader;
    DecompressReader uncomressReader;
P
Peifeng Qiu 已提交
40 41 42 43 44 45 46 47 48
    S3RESTfulService restfulService;

    S3Service s3service;
    ReaderParams params;
    S3Credential cred;

    // it links to itself by default
    // but the pointer here leaves a chance to mock it in unit test
    S3RESTfulService *restfulServicePtr;
49 50 51
};

// Following 3 functions are invoked by s3_import(), need to be exception safe
P
Peifeng Qiu 已提交
52 53 54
GPReader *reader_init(const char *url_with_options);
bool reader_transfer_data(GPReader *reader, char *data_buf, int &data_len);
bool reader_cleanup(GPReader **reader);
55

56 57 58 59
// Two thread related functions, called only by gpreader and gpcheckcloud
int thread_setup(void);
int thread_cleanup(void);

60
#endif