This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Fork of libMiMic by Ryo Iizuka

Committer:
nyatla
Date:
Fri Jun 13 11:06:33 2014 +0000
Revision:
72:c118a7aa37a3
Parent:
71:855020258513
Child:
77:8651d3c19a55
mbedAPI???????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 71:855020258513 1 #ifndef NYLPC_CJSONRPCPARSER_H_
nyatla 71:855020258513 2 #define NYLPC_CJSONRPCPARSER_H_
nyatla 71:855020258513 3 #ifdef __cplusplus
nyatla 71:855020258513 4 extern "C" {
nyatla 71:855020258513 5 #endif
nyatla 71:855020258513 6
nyatla 71:855020258513 7 #include "NyLPC_stdlib.h"
nyatla 71:855020258513 8
nyatla 72:c118a7aa37a3 9
nyatla 72:c118a7aa37a3 10 #define NyLPC_TJsonRpcErrorCode_PARSE_ERROR (-32700)
nyatla 72:c118a7aa37a3 11 #define NyLPC_TJsonRpcErrorCode_INVALID_REQUEST (-32600)
nyatla 72:c118a7aa37a3 12 #define NyLPC_TJsonRpcErrorCode_METHOD_NOT_FOUND (-32601)
nyatla 72:c118a7aa37a3 13 #define NyLPC_TJsonRpcErrorCode_INVALID_PARAMS (-32602)
nyatla 72:c118a7aa37a3 14 #define NyLPC_TJsonRpcErrorCode_INTERNAL_ERROR (-32603)
nyatla 72:c118a7aa37a3 15 #define NyLPC_TJsonRpcErrorCode_SERVER_ERROR_BASE (-32000)
nyatla 72:c118a7aa37a3 16
nyatla 72:c118a7aa37a3 17
nyatla 71:855020258513 18 /** 型定義*/
nyatla 71:855020258513 19 union NyLPC_TJsonRpcParserResult;
nyatla 71:855020258513 20
nyatla 71:855020258513 21 /**
nyatla 71:855020258513 22 * RPC関数ハンドラ型です。
nyatla 71:855020258513 23 * @param
nyatla 71:855020258513 24 */
nyatla 71:855020258513 25 typedef NyLPC_TBool (*NyLPC_TJsonRpcHandler)(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param);
nyatla 71:855020258513 26
nyatla 71:855020258513 27 /**
nyatla 71:855020258513 28 * JSON RPC定義テーブルの一要素。
nyatla 71:855020258513 29 * メソッド名とパラメータパターンのセットを定義します。
nyatla 71:855020258513 30 * この構造体は配列としてNyLPC_TJsonRpcFunctionTableから参照されます。
nyatla 71:855020258513 31 */
nyatla 71:855020258513 32 struct NyLPC_TJsonRpcMethodDef
nyatla 71:855020258513 33 {
nyatla 71:855020258513 34 /**
nyatla 71:855020258513 35 * 関数名
nyatla 71:855020258513 36 */
nyatla 71:855020258513 37 const char* name;
nyatla 71:855020258513 38 /**
nyatla 71:855020258513 39 * パラメータパターン
nyatla 71:855020258513 40 * <ul>
nyatla 71:855020258513 41 * <li>s - 文字列</li>
nyatla 71:855020258513 42 * <li>i - signed int32</li>
nyatla 71:855020258513 43 * <li>s - unsigned int32</li>
nyatla 71:855020258513 44 * </ul>
nyatla 71:855020258513 45 */
nyatla 71:855020258513 46 const char* param_patt;
nyatla 71:855020258513 47 /**
nyatla 71:855020258513 48 * 外部のDispatch関数で使われるRPC関数ハンドラ。
nyatla 71:855020258513 49 */
nyatla 71:855020258513 50 NyLPC_TJsonRpcHandler handler;
nyatla 71:855020258513 51 };
nyatla 71:855020258513 52
nyatla 71:855020258513 53
nyatla 71:855020258513 54 /**
nyatla 71:855020258513 55 * JsonRPCクラスの定義テーブル。
nyatla 71:855020258513 56 * JsonRPCは、 [namespace]::[]
nyatla 71:855020258513 57 */
nyatla 71:855020258513 58 struct NyLPC_TJsonRpcClassDef
nyatla 71:855020258513 59 {
nyatla 71:855020258513 60 const char* names_pace;
nyatla 71:855020258513 61 const char* class_name;
nyatla 71:855020258513 62 const struct NyLPC_TJsonRpcMethodDef* functions;
nyatla 71:855020258513 63 };
nyatla 71:855020258513 64
nyatla 71:855020258513 65
nyatla 71:855020258513 66
nyatla 71:855020258513 67
nyatla 71:855020258513 68
nyatla 71:855020258513 69 #define NyLPC_TJsonRpcParserResult_TYPE_UNKNOWN 0
nyatla 71:855020258513 70 #define NyLPC_TJsonRpcParserResult_TYPE_RESULT 1
nyatla 71:855020258513 71 #define NyLPC_TJsonRpcParserResult_TYPE_METHOD 2
nyatla 71:855020258513 72
nyatla 71:855020258513 73 /** NyLPC_TJsonRpcParserResultが格納できる引数の最大数。パラメータの最大数に等しくなります。*/
nyatla 71:855020258513 74 #define NyLPC_TJsonRpcParserResult_NUMBER_OF_PARAM_INDEX 16
nyatla 71:855020258513 75 /**
nyatla 71:855020258513 76 * NyLPC_TJsonRpcParserResultが格納できるパラメータの総バイト数。
nyatla 71:855020258513 77 * (文字数+1)+(uint32|int32)*4+uint8の合計値です。
nyatla 71:855020258513 78 */
nyatla 71:855020258513 79 #define NyLPC_TJsonRpcParserResult_PARAM_BUF 128
nyatla 71:855020258513 80
nyatla 71:855020258513 81 /**
nyatla 71:855020258513 82 * JSONRPC構文のパース結果を格納します。
nyatla 71:855020258513 83 * 開発メモ
nyatla 71:855020258513 84 * 更新する場合は、param_indexまでの構造体のレイアウトを破壊しないようにしてください。
nyatla 71:855020258513 85 */
nyatla 71:855020258513 86 union NyLPC_TJsonRpcParserResult
nyatla 71:855020258513 87 {
nyatla 71:855020258513 88 NyLPC_TUInt8 type; //タイプ
nyatla 71:855020258513 89 /** この構造体は type==NyLPC_TJsonRpcParserResult_TYPE_METHODのときに有効です。*/
nyatla 71:855020258513 90 struct{
nyatla 71:855020258513 91 NyLPC_TUInt8 _type; //タイプ
nyatla 71:855020258513 92 NyLPC_TUInt8 func_number; //確定した関数番号。
nyatla 71:855020258513 93 NyLPC_TUInt8 _padding[2]; //パディング
nyatla 71:855020258513 94 NyLPC_TInt32 id; //idパラメータの値
nyatla 71:855020258513 95 NyLPC_TChar param_buf[NyLPC_TJsonRpcParserResult_PARAM_BUF];
nyatla 71:855020258513 96 NyLPC_TUInt8 param_index[NyLPC_TJsonRpcParserResult_NUMBER_OF_PARAM_INDEX];
nyatla 71:855020258513 97 /** 関数の含まれるクラスへのポインタ。*/
nyatla 71:855020258513 98 const struct NyLPC_TJsonRpcClassDef* class_def;
nyatla 71:855020258513 99 }method;
nyatla 71:855020258513 100 struct{
nyatla 71:855020258513 101 NyLPC_TUInt8 _type; //タイプ
nyatla 71:855020258513 102 NyLPC_TUInt8 _padding[3]; //パディング
nyatla 71:855020258513 103 NyLPC_TInt32 id; //idパラメータの値
nyatla 71:855020258513 104 NyLPC_TChar param_buf[NyLPC_TJsonRpcParserResult_PARAM_BUF];
nyatla 71:855020258513 105 NyLPC_TUInt8 param_index[NyLPC_TJsonRpcParserResult_NUMBER_OF_PARAM_INDEX];
nyatla 71:855020258513 106 }result;
nyatla 71:855020258513 107 struct{
nyatla 71:855020258513 108 NyLPC_TUInt8 _type; //タイプ
nyatla 71:855020258513 109 NyLPC_TInt8 _padding[3];//
nyatla 71:855020258513 110 NyLPC_TInt32 _id; //idパラメータの値
nyatla 71:855020258513 111 NyLPC_TChar param_buf[NyLPC_TJsonRpcParserResult_PARAM_BUF];
nyatla 71:855020258513 112 NyLPC_TUInt8 param_index[NyLPC_TJsonRpcParserResult_NUMBER_OF_PARAM_INDEX];
nyatla 71:855020258513 113 }raw;
nyatla 71:855020258513 114 };
nyatla 71:855020258513 115 /**
nyatla 71:855020258513 116 * Resultに格納される結果がハンドラを持っているかを返します。
nyatla 71:855020258513 117 */
nyatla 71:855020258513 118 #define NyLPC_TJsonRpcParserResult_hasMethodHandler(i_struct) ((i_struct)->method.class_def->functions[(i_struct)->method.func_number].handler!=NULL)
nyatla 71:855020258513 119 /**
nyatla 71:855020258513 120 * Resultに含まれるハンドラを呼び出します。
nyatla 71:855020258513 121 * @param i_struct
nyatla 71:855020258513 122 * Result構造体
nyatla 71:855020258513 123 * @param i_param
nyatla 71:855020258513 124 * ハンドラに引き渡すパラメータ
nyatla 71:855020258513 125 * @return
nyatla 71:855020258513 126 * FALSEの場合、ループを終了してください。
nyatla 71:855020258513 127 */
nyatla 71:855020258513 128 #define NyLPC_TJsonRpcParserResult_callMethodHandler(i_struct,i_param) (i_struct)->method.class_def->functions[(i_struct)->method.func_number].handler((i_struct),(i_param))
nyatla 71:855020258513 129
nyatla 71:855020258513 130 /**
nyatla 71:855020258513 131 * i_idx番目のパラメータをuint32としてo_valへ取り出します。
nyatla 71:855020258513 132 */
nyatla 71:855020258513 133 NyLPC_TBool NyLPC_TJsonRpcParserResult_getUInt32(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, NyLPC_TUInt32* o_val);
nyatla 71:855020258513 134 /**
nyatla 71:855020258513 135 * i_idx番目のパラメータをint32としてo_valへ取り出します。
nyatla 71:855020258513 136 */
nyatla 71:855020258513 137 NyLPC_TBool NyLPC_TJsonRpcParserResult_getInt32(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, NyLPC_TInt32* o_val);
nyatla 71:855020258513 138 /**
nyatla 71:855020258513 139 * i_idx番目のパラメータをchar[]としてo_valへ取り出します。
nyatla 71:855020258513 140 */
nyatla 71:855020258513 141 NyLPC_TBool NyLPC_TJsonRpcParserResult_getStr(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, const NyLPC_TChar** o_val);
nyatla 71:855020258513 142 /**
nyatla 71:855020258513 143 * i_idx番目のパラメータをuint8としてo_valへ取り出します。
nyatla 71:855020258513 144 */
nyatla 71:855020258513 145 NyLPC_TBool NyLPC_TJsonRpcParserResult_getByte(const union NyLPC_TJsonRpcParserResult* i_struct, NyLPC_TInt16 i_idx, NyLPC_TUInt8* o_val);
nyatla 71:855020258513 146
nyatla 71:855020258513 147 /********************************************************************************
nyatla 71:855020258513 148 *
nyatla 71:855020258513 149 * NyLPC_TcJsonRpcParser
nyatla 71:855020258513 150 *
nyatla 71:855020258513 151 ********************************************************************************/
nyatla 71:855020258513 152 /**
nyatla 71:855020258513 153 * JSONRPCの型定義定数です。
nyatla 71:855020258513 154 */
nyatla 71:855020258513 155 #define NyLPC_cJsonRpcParser_TYPE_INT32 'd'
nyatla 71:855020258513 156 #define NyLPC_cJsonRpcParser_TYPE_UINT32 'u'
nyatla 71:855020258513 157 #define NyLPC_cJsonRpcParser_TYPE_STRING 's'
nyatla 71:855020258513 158 #define NyLPC_cJsonRpcParser_TYPE_BYTE 'b'
nyatla 71:855020258513 159
nyatla 71:855020258513 160 /**
nyatla 71:855020258513 161 * JsonRPCメッセージをパースします。パース出来るメッセージは以下の通りです。
nyatla 71:855020258513 162 * クラスは、RPC関数定義テーブルに従ってメッセージを分析し、テーブルに存在する関数のみを返却することができます。
nyatla 71:855020258513 163 * <p>
nyatla 71:855020258513 164 * メッセージ形式
nyatla 71:855020258513 165 * <pre>
nyatla 71:855020258513 166 * METHOD:
nyatla 71:855020258513 167 * {"method":METHOD,"version":VERSION,"params":PARAMS,"id":ID}
nyatla 71:855020258513 168 * METHOD VERSION as string
nyatla 71:855020258513 169 * ID as uint32
nyatla 71:855020258513 170 * PARAMS as Array of (string|uint32|int32)
nyatla 71:855020258513 171 * </pre>
nyatla 71:855020258513 172 * </p>
nyatla 71:855020258513 173 */
nyatla 71:855020258513 174 typedef struct NyLPC_TcJsonRpcParser NyLPC_TcJsonRpcParser_t;
nyatla 71:855020258513 175
nyatla 71:855020258513 176
nyatla 71:855020258513 177
nyatla 71:855020258513 178
nyatla 71:855020258513 179 /** パーサの状態値*/
nyatla 71:855020258513 180 typedef NyLPC_TUInt8 NyLPC_TcJsonRpcParser_TStatus;
nyatla 71:855020258513 181
nyatla 71:855020258513 182 #define NyLPC_TcJsonRpcParser_ST_START 0x01 //開始ブランケット受信待ち
nyatla 71:855020258513 183 #define NyLPC_TcJsonRpcParser_ST_END 0x02 //終了受信済
nyatla 71:855020258513 184 #define NyLPC_TcJsonRpcParser_ST_ERROR 0x03 //エラー発生
nyatla 71:855020258513 185 #define NyLPC_TcJsonRpcParser_ST_NAME_Q 0x04 //名前クオート受信待ち
nyatla 71:855020258513 186 #define NyLPC_TcJsonRpcParser_ST_NAME_STR 0x05 //名前受信中
nyatla 71:855020258513 187 #define NyLPC_TcJsonRpcParser_ST_NV_SEP 0x06 //名前と値のセパレータ待ち
nyatla 71:855020258513 188 #define NyLPC_TcJsonRpcParser_ST_VAL 0x07 //値開始待ち
nyatla 71:855020258513 189 #define NyLPC_TcJsonRpcParser_ST_VAL_STR 0x08 //文字列受信
nyatla 71:855020258513 190 #define NyLPC_TcJsonRpcParser_ST_VAL_UINT 0x09 //UINT受信中
nyatla 71:855020258513 191 #define NyLPC_TcJsonRpcParser_ST_VAL_INT 0x10 //INT受信中
nyatla 71:855020258513 192 #define NyLPC_TcJsonRpcParser_ST_NEXT 0x11 //次のNAMEもしくは終了ブランケット
nyatla 71:855020258513 193 #define NyLPC_TcJsonRpcParser_ST_PARAMS 0x12 //PARAM要素パース中
nyatla 71:855020258513 194
nyatla 71:855020258513 195
nyatla 71:855020258513 196
nyatla 71:855020258513 197 /** NyLPC_TcJsonRpcParserの定数値です。 字句解析ワークメモリの長さ。256未満8*n-1の数を指定してください。 */
nyatla 71:855020258513 198 #define NyLPC_TcJsonRpcParser_WORK_MAX 47
nyatla 71:855020258513 199
nyatla 71:855020258513 200 /**
nyatla 71:855020258513 201 * クラス構造体です。
nyatla 71:855020258513 202 */
nyatla 71:855020258513 203 struct NyLPC_TcJsonRpcParser
nyatla 71:855020258513 204 {
nyatla 71:855020258513 205 const struct NyLPC_TJsonRpcClassDef** _class_def;
nyatla 71:855020258513 206 union{
nyatla 71:855020258513 207 struct{
nyatla 71:855020258513 208 NyLPC_TChar buf[NyLPC_TcJsonRpcParser_WORK_MAX]; //文字解析メモリ
nyatla 71:855020258513 209 NyLPC_TUInt8 n; //字句解析の文字数
nyatla 71:855020258513 210 }str;
nyatla 71:855020258513 211 struct{
nyatla 71:855020258513 212 NyLPC_TInt32 v;
nyatla 71:855020258513 213 NyLPC_TInt8 s;
nyatla 71:855020258513 214 }int32;
nyatla 71:855020258513 215 NyLPC_TUInt32 uint32;
nyatla 71:855020258513 216 }_work;
nyatla 71:855020258513 217 NyLPC_TcJsonRpcParser_TStatus _st; //パーサステータス
nyatla 71:855020258513 218 NyLPC_TUInt8 _pst; //PARAMS解析ステータス
nyatla 71:855020258513 219 NyLPC_TUInt8 _name_id; //解析中のNAME_ID
nyatla 71:855020258513 220 NyLPC_TUInt8 _pcounter; //パラメタ解析に使うワークカウンタ
nyatla 71:855020258513 221 union NyLPC_TJsonRpcParserResult* _result;//出力格納先
nyatla 71:855020258513 222 };
nyatla 71:855020258513 223
nyatla 71:855020258513 224
nyatla 71:855020258513 225
nyatla 71:855020258513 226
nyatla 71:855020258513 227
nyatla 71:855020258513 228
nyatla 71:855020258513 229 /**
nyatla 71:855020258513 230 * インスタンスを初期化します。
nyatla 71:855020258513 231 * @param i_class_def
nyatla 71:855020258513 232 * クラステーブルの配列です。NULLで終端します。
nyatla 71:855020258513 233 */
nyatla 71:855020258513 234 void NyLPC_cJsonRpcParser_initialize(
nyatla 71:855020258513 235 NyLPC_TcJsonRpcParser_t* i_inst,
nyatla 71:855020258513 236 const struct NyLPC_TJsonRpcClassDef** i_class_def);
nyatla 71:855020258513 237
nyatla 71:855020258513 238 #define NyLPC_cJsonRpcParser_finalize(i)
nyatla 71:855020258513 239 /**
nyatla 71:855020258513 240 * パーサの状態を初期化します。
nyatla 71:855020258513 241 * @param i_result
nyatla 71:855020258513 242 * パース結果の出力先構造体のアドレスです。
nyatla 71:855020258513 243 */
nyatla 71:855020258513 244 void NyLPC_cJsonRpcParser_initParser(NyLPC_TcJsonRpcParser_t* i_inst, union NyLPC_TJsonRpcParserResult* i_result);
nyatla 71:855020258513 245 /**
nyatla 71:855020258513 246 * パーサに文字列を入力します。入力後は、NyLPC_cJsonRpcParser_getStatusでパーサの状態をチェックしてください。
nyatla 71:855020258513 247  */
nyatla 71:855020258513 248 void NyLPC_cJsonRpcParser_putChar(NyLPC_TcJsonRpcParser_t* i_inst, char i_c);
nyatla 71:855020258513 249
nyatla 71:855020258513 250 #define NyLPC_cJsonRpcParser_getStatus(i) ((i)->_st)
nyatla 71:855020258513 251 /** クラス定義テーブルを返します。*/
nyatla 71:855020258513 252 #define NyLPC_cJsonRpcParser_getClassDef(i) ((i)->_class_def)
nyatla 71:855020258513 253
nyatla 71:855020258513 254
nyatla 71:855020258513 255 #ifdef __cplusplus
nyatla 71:855020258513 256 }
nyatla 71:855020258513 257 #endif /* __cplusplus */
nyatla 71:855020258513 258
nyatla 71:855020258513 259 #endif /* NYLPC_CJSONRPCPARSER4_H_ */