nlib
CurlInputStream.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
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  kBufferSize1x = 0,
35  kBufferSize2x,
36  kBufferSize3x,
37  kBufferSize4x,
38  BUFFER_SIZE_1X = kBufferSize1x,
39  BUFFER_SIZE_2X = kBufferSize2x,
40  BUFFER_SIZE_3X = kBufferSize3x,
41  BUFFER_SIZE_4X = kBufferSize4x
42  };
43 
44  public:
47  CURL* GetEasyHandle() const NLIB_NOEXCEPT;
48  CURLcode GetCurlError() const NLIB_NOEXCEPT;
49  CURLMcode GetCurlMultiError() const NLIB_NOEXCEPT;
50  NLIB_CHECK_RESULT errno_t Init(BufferSize buffer_size) NLIB_NOEXCEPT;
51  NLIB_CHECK_RESULT errno_t Init() NLIB_NOEXCEPT { return Init(kBufferSize1x); }
52  CURLcode SetUrl(const char* url) NLIB_NOEXCEPT;
53  bool StartDownload() NLIB_NOEXCEPT;
54 
55  private:
56  NLIB_VIS_HIDDEN static size_t ParseStreamCallback(char* contents, size_t length,
57  size_t nmemb, void *userp) NLIB_NOEXCEPT;
58  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
59  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
60  virtual void* GetWorkBuffer_(size_t* nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
61  struct CallbackInfo {
62  unsigned char* buf;
63  size_t pos;
64  size_t bufsize;
65  };
66 
67  private:
68  struct CurlInputStreamPrivate;
69  CurlInputStreamPrivate* prv_;
70 };
71 
72 NLIB_NAMESPACE_END
73 
74 #endif // NLIB_HAS_LIBCURL
75 #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:244
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:88
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:89
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:105
errno_t Init() noexcept
Executes Init(kBufferSize1x).
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:107
The stream class for downloading using libcurl.
constexpr 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:245
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37