nlib
CurlInputStream.h
Go to the documentation of this file.
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12 
13  *---------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_CURLINPUTSTREAM_H_
17 #define INCLUDE_NN_NLIB_CURLINPUTSTREAM_H_
18 
19 #include "nn/nlib/Platform.h"
20 #ifdef NLIB_HAS_LIBCURL
21 
22 #ifndef CAFE
23 #include <curl/curl.h> // NOLINT
24 #else
25 #include <cafe/curl/curl.h> // NOLINT
26 #endif
27 #include "nn/nlib/InputStream.h"
28 
29 NLIB_NAMESPACE_BEGIN
30 
32  public:
33  enum BufferSize {
34  BUFFER_SIZE_1X = 0,
35  BUFFER_SIZE_2X,
36  BUFFER_SIZE_3X,
37  BUFFER_SIZE_4X
38  };
39 
40  public:
41  CurlInputStream() NLIB_NOEXCEPT : prv_(NULL) {}
43  CURL* GetEasyHandle() const NLIB_NOEXCEPT;
44  CURLcode GetCurlError() const NLIB_NOEXCEPT;
45  CURLMcode GetCurlMultiError() const NLIB_NOEXCEPT;
46  NLIB_CHECK_RESULT errno_t Init(BufferSize buffer_size) NLIB_NOEXCEPT;
47  NLIB_CHECK_RESULT errno_t Init() NLIB_NOEXCEPT { return Init(BUFFER_SIZE_1X); }
48  CURLcode SetUrl(const char* url) NLIB_NOEXCEPT;
49  bool StartDownload() NLIB_NOEXCEPT;
50 
51  private:
52  NLIB_VIS_HIDDEN static size_t ParseStreamCallback(char* contents, size_t length,
53  size_t nmemb, void *userp) NLIB_NOEXCEPT;
54  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
55  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
56  virtual void* GetWorkBuffer_(size_t* nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
57  struct CallbackInfo {
58  unsigned char* buf;
59  size_t pos;
60  size_t bufsize;
61  };
62 
63  private:
64  struct CurlInputStreamPrivate;
65  CurlInputStreamPrivate* prv_;
66 };
67 
68 NLIB_NAMESPACE_END
69 
70 #endif // NLIB_HAS_LIBCURL
71 #endif // INCLUDE_NN_NLIB_CURLINPUTSTREAM_H_
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:223
Defines the base class for input streams.
#define NLIB_CHECK_RESULT
Indicates that the caller of the function must check the returned value.
#define NLIB_VIS_HIDDEN
Symbols for functions and classes are not made available outside of the library.
Definition: Platform_unix.h:86
Basic APIs are declared with a C linkage.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:29
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
NLIB_CHECK_RESULT errno_t Init() noexcept
Executes Init(BUFFER_SIZE_1X).
The stream class for downloading using libcurl.
CurlInputStream() noexcept
Instantiates the object with default parameters (default constructor). The stream must be initialized...
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:224
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37