nlib
CurlInputStream.h
[詳解]
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
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
Definition: Config.h:223
入力ストリームの基底クラスを定義しています。
#define NLIB_CHECK_RESULT
関数の呼び出し元が戻り値をチェックする必要があることを示します。
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:86
基本的なAPIがCリンケージで宣言されています。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
入力ストリームの基底クラスです。このクラスを実体化することはできません。
Definition: InputStream.h:29
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:99
NLIB_CHECK_RESULT errno_t Init() noexcept
Init(BUFFER_SIZE_1X)を実行します。
libcurlを用いてダウンロードを行うためのストリームクラスです。
CurlInputStream() noexcept
デフォルトコンストラクタです。更にInit()でストリームを初期化する必要があります。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:224
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37