OSDN Git Service

iHttpPtrStream.pread関数にタイムアウト引数を追加
[mimic/MiMicSDK.git] / lib / src / http / NyLPC_iHttpPtrStream.h
1 /*********************************************************************************\r
2  * PROJECT: MiMic\r
3  * --------------------------------------------------------------------------------\r
4  *\r
5  * This file is part of MiMic\r
6  * Copyright (C)2011 Ryo Iizuka\r
7  *\r
8  * MiMic is free software: you can redistribute it and/or modify\r
9  * it under the terms of the GNU Lesser General Public License as published\r
10  * by the Free Software Foundation, either version 3 of the License, or\r
11  * (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU Lesser General Public License\r
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
20  *\r
21  * For further information please contact.\r
22  *      http://nyatla.jp/\r
23  *      <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
24  *\r
25  *********************************************************************************/\r
26 #ifndef NyLPC_TiHttpPtrStream_H_\r
27 #define NyLPC_TiHttpPtrStream_H_\r
28 \r
29 /**********************************************************************\r
30  *\r
31  * NyLPC_TiHttpPtrStream class\r
32  *\r
33  **********************************************************************/\r
34 #include "NyLPC_stdlib.h"\r
35 \r
36 #ifdef __cplusplus\r
37 extern "C" {\r
38 #endif /* __cplusplus */\r
39 \r
40 /**\r
41  * Httpストリームのインタフェイス。\r
42  */\r
43 typedef struct NyLPC_TiHttpPtrStream NyLPC_TiHttpPtrStream_t;\r
44 \r
45 /**\r
46  * ストリームのエンコーディングモード\r
47  */\r
48 typedef NyLPC_TUInt8 NyLPC_TiHttpPtrStream_ET;\r
49 #define NyLPC_TiHttpPtrStream_ET_NONE 0x00\r
50 #define NyLPC_TiHttpPtrStream_ET_CHUNKED 0x01\r
51 \r
52 /**\r
53  * HTTP通信タイムアウトのデフォルト値\r
54  */\r
55 #define NyLPC_TiHttpPtrStream_DEFAULT_HTTP_TIMEOUT (5*1000)\r
56 \r
57 \r
58 typedef NyLPC_TInt32 (*NyLPC_TiHttpPtrStream_pread)(void* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_timeout);\r
59 typedef NyLPC_TBool (*NyLPC_TiHttpPtrStream_write)(void* i_inst,const void* i_data,NyLPC_TInt32 i_length);\r
60 typedef void (*NyLPC_TiHttpPtrStream_rseek)(void* i_inst,NyLPC_TUInt16 i_seek);\r
61 typedef NyLPC_TBool (*NyLPC_TiHttpPtrStream_flush)(void* i_inst);\r
62 typedef void (*NyLPC_TiHttpPtrStream_setReadEncoding)(void* i_inst,NyLPC_TiHttpPtrStream_ET i_et);\r
63 typedef void (*NyLPC_TiHttpPtrStream_setWriteEncoding)(void* i_inst,NyLPC_TiHttpPtrStream_ET i_et);\r
64 \r
65 /**\r
66  * _interface_httpptrstreamで宣言してください。\r
67  */\r
68 struct NyLPC_TiHttpPtrStream_TInterface\r
69 {\r
70         NyLPC_TiHttpPtrStream_pread pread;\r
71         NyLPC_TiHttpPtrStream_write write;\r
72         NyLPC_TiHttpPtrStream_rseek readSeek;\r
73         NyLPC_TiHttpPtrStream_flush flush;\r
74         NyLPC_TiHttpPtrStream_setReadEncoding setreadencoding;\r
75         NyLPC_TiHttpPtrStream_setWriteEncoding setwriteencoding;\r
76 };\r
77 struct NyLPC_TiHttpPtrStream\r
78 {\r
79         /**\r
80          * 継承クラスで実装すべきハンドラ\r
81          */\r
82         const struct NyLPC_TiHttpPtrStream_TInterface* absfunc;\r
83 };\r
84 \r
85 /**\r
86  * ストリームからデータを読み出して、そのポインタを返します。\r
87  * @return\r
88  * ストリームから読み込んだデータサイズを返します。\r
89  * 0の場合はタイムアウトです。\r
90  * 0未満の場合はエラーです。\r
91  */\r
92 #define NyLPC_iHttpPtrStream_pread(i_inst,o_buf_ptr,i_timeout) (i_inst)->absfunc->pread((i_inst),(o_buf_ptr),i_timeout)\r
93 /**\r
94  * ストリームへデータを書き込みます。\r
95  * @param i_length\r
96  * i_dataのデータ長を指定します。-1の場合、strlenを実行します。\r
97  * @return\r
98  * 規定時間内にストリームへの書き込みが完了すると、TRUEを返します。\r
99  */\r
100 #define NyLPC_iHttpPtrStream_write(i_inst,i_data,i_length) (i_inst)->absfunc->write((i_inst),i_data,i_length)\r
101 #define NyLPC_iHttpPtrStream_rseek(i_inst,i_seek) (i_inst)->absfunc->readSeek((i_inst),(i_seek))\r
102 /**\r
103  * バッファに残っているデータを送信し、空にします。\r
104  */\r
105 #define NyLPC_iHttpPtrStream_flush(i_inst) (i_inst)->absfunc->flush(i_inst)\r
106 \r
107 /**\r
108  * 読み出しエンコーディングの設定。\r
109  * この関数は削除するかもしれない。使用しないこと。\r
110  * @bug 関数が非対称。cHttpBasicBodyParserがチャンク読み出し処理を肩代わりしている?\r
111  */\r
112 #define NyLPC_iHttpPtrStream_setReadEncoding(i_inst,i_et) (i_inst)->absfunc->setreadencoding((i_inst),i_et)\r
113 /**\r
114  * 書込みエンコーディングの設定。\r
115  */\r
116 #define NyLPC_iHttpPtrStream_setWriteEncoding(i_inst,i_et) (i_inst)->absfunc->setwriteencoding((i_inst),i_et)\r
117 \r
118 #ifdef __cplusplus\r
119 }\r
120 #endif /* __cplusplus */\r
121 \r
122 #endif /* NyLPC_TiHttpPtrStream_H_ */\r