OSDN Git Service

update libMiMic
[mimic/MiMicSDK.git] / lib / src / NyLPC_cPtrStream.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_TCPTRSTREAM_H_\r
27 #define NYLPC_TCPTRSTREAM_H_\r
28 \r
29 /**********************************************************************\r
30  *\r
31  * NyLPC_TcPtrStream 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  * ブロッキングストリームのベース型です。\r
42  */\r
43 typedef struct NyLPC_TcPtrStream NyLPC_TcPtrStream_t;\r
44 \r
45 \r
46 typedef NyLPC_TInt32 (*NyLPC_TcPtrStream_pread)(NyLPC_TcPtrStream_t* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_wait_msec);\r
47 typedef NyLPC_TBool (*NyLPC_TcPtrStream_write)(NyLPC_TcPtrStream_t* i_inst,const void* i_data,NyLPC_TInt16 i_length,NyLPC_TUInt32 i_wait_msec);\r
48 typedef void (*NyLPC_TcPtrStream_rseek)(NyLPC_TcPtrStream_t* i_inst,NyLPC_TUInt16 i_seek);\r
49 typedef void (*NyLPC_TcPtrStream_close)(NyLPC_TcPtrStream_t* i_inst);\r
50 \r
51 struct NyLPC_TcPtrStream_TInterface\r
52 {\r
53     NyLPC_TcPtrStream_pread pread;\r
54     NyLPC_TcPtrStream_write write;\r
55     NyLPC_TcPtrStream_rseek readSeek;\r
56     NyLPC_TcPtrStream_close close;\r
57 };\r
58 \r
59 \r
60 struct NyLPC_TcPtrStream\r
61 {\r
62     const struct NyLPC_TcPtrStream_TInterface* _interface;\r
63 };\r
64 \r
65 /**\r
66  * ストリームからデータを読み出して、そのポインタを返します。\r
67  * @return\r
68  * ストリームから読み込んだデータサイズを返します。\r
69  * 0の場合はタイムアウトです。\r
70  * 0未満の場合はエラーです。\r
71  */\r
72 #define NyLPC_cPtrStream_read(i_inst,o_buf_ptr,i_wait_msec) (i_inst)->_interface->read((i_inst),o_buf_ptr,i_wait_msec)\r
73 /**\r
74  * ストリームへデータを書き込みます。\r
75  * @param i_length\r
76  * i_dataのデータ長を指定します。-1の場合、strlenを実行します。\r
77  * @return\r
78  * 規定時間内にストリームへの書き込みが完了すると、TRUEを返します。\r
79  */\r
80 #define NyLPC_cPtrStream_write(i_inst,i_data,i_length,i_wait_msec) (i_inst)->_interface->write((i_inst),i_data,i_length,i_wait_msec)\r
81 \r
82 /**\r
83  * 改行付でストリームへ書き込みます。\r
84  */\r
85 NyLPC_TBool NyLPC_cPtrStream_writeln(NyLPC_TcPtrStream_t* i_inst,const void* i_data,NyLPC_TInt16 i_length,NyLPC_TUInt32 i_wait_msec);\r
86 /**\r
87  * 数値をストリームへ書き込みます。\r
88  * @param i_base\r
89  * 10以上を指定してください。\r
90  */\r
91 NyLPC_TBool NyLPC_cPtrStream_writeInt(NyLPC_TcPtrStream_t* i_inst,NyLPC_TInt32 i_val,NyLPC_TUInt32 i_wait_msec,NyLPC_TUInt32 i_base);\r
92 \r
93 /**\r
94  * 書き込みメモリを要求します。\r
95  * @return\r
96  * 書き込みメモリの先頭ポインタを返します。この値は次回のpwriteに入力してください。\r
97  */\r
98 #define NyLPC_cPtrStream_wreserv(i_inst,i_hint,o_len)\r
99 \r
100 \r
101 #define NyLPC_cPtrStream_rseek(i_inst,i_seek) (i_inst)->_interface->preadSeek((i_inst),i_seek)\r
102 /**\r
103 ストリームに対する操作を閉じます。\r
104 readの場合は占有している共有メモリの解放、ブロックしているタスクの解放をします。\r
105 writeの場合はバッファに残っているデータの書き込みを保証します。\r
106 */\r
107 #define NyLPC_cPtrStream_close(i_inst) i_inst->_interface->close(i_inst)\r
108 \r
109 #ifdef __cplusplus\r
110 }\r
111 #endif /* __cplusplus */\r
112 \r
113 #endif /* NYLPC_TCPTRSTREAM_H_ */\r