This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088
Dependents: MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more
ModJsonRpc.h
00001 #include "NyLPC_net.h" 00002 #include "ModBaseClass.h" 00003 #include "HttpdConnection.h" 00004 #include "Httpd.h" 00005 #include "Net.h" 00006 00007 00008 namespace MiMic 00009 { 00010 class HttpdConnection; 00011 00012 /** 00013 * This class is Websocket module. 00014 * The class provides 3 services. 00015 * <ul> 00016 * <li>d.xml - a device description.</li> 00017 * <li>control/xx - soap handler</li> 00018 * <li>event/xx -event handler.</li> 00019 * </ul> 00020 */ 00021 class ModJsonRpc:ModBaseClass 00022 { 00023 public: 00024 typedef struct TcJsonRpcEx{ 00025 NyLPC_TcModJsonRpc_t super; 00026 ModJsonRpc* cppmod_ptr; 00027 }TcJsonRpcEx_t; 00028 public: 00029 class BasicRpcObject 00030 { 00031 public: 00032 void* obj; 00033 BasicRpcObject(void* i_ptr) : obj(i_ptr){}; 00034 virtual ~BasicRpcObject(){} 00035 }; 00036 template< class T > class RpcObject : public BasicRpcObject{ 00037 public: 00038 RpcObject(T* i_ptr) : BasicRpcObject(i_ptr){}; 00039 virtual ~RpcObject(){delete (static_cast<T*>(this->obj));} 00040 }; 00041 template< class T > class RpcArray : public BasicRpcObject{ 00042 public: 00043 RpcArray(T* i_ptr) : BasicRpcObject(i_ptr){}; 00044 virtual ~RpcArray(){delete[] (static_cast<T*>(this->obj));} 00045 }; 00046 private: 00047 public: 00048 const static int PARSE_ERROR=NyLPC_TJsonRpcErrorCode_PARSE_ERROR; 00049 const static int INVALID_REQUEST=NyLPC_TJsonRpcErrorCode_INVALID_REQUEST; 00050 const static int METHOD_NOT_FOUND=NyLPC_TJsonRpcErrorCode_METHOD_NOT_FOUND; 00051 const static int INVALID_PARAMS=NyLPC_TJsonRpcErrorCode_INVALID_PARAMS; 00052 const static int INTERNAL_ERROR=NyLPC_TJsonRpcErrorCode_INTERNAL_ERROR; 00053 const static int SERVER_ERROR_BASE=NyLPC_TJsonRpcErrorCode_SERVER_ERROR_BASE; 00054 private: 00055 BasicRpcObject** _objects; 00056 const struct NyLPC_TJsonRpcClassDef** _rpc_table; 00057 protected: 00058 TcJsonRpcEx_t* _mod; 00059 public: 00060 ModJsonRpc(); 00061 /** 00062 * @param i_rpc_table 00063 * An address of Json RPC functions table. 00064 */ 00065 ModJsonRpc(const char* i_path,const struct NyLPC_TJsonRpcClassDef** i_rpc_table); 00066 virtual ~ModJsonRpc(); 00067 bool isStarted(); 00068 void setParam(const char* i_path,const struct NyLPC_TJsonRpcClassDef** i_rpc_table); 00069 /** 00070 * This function prepares Json rpc loop with websocket negotiation. 00071 * @return 00072 * true if successful;otherwishe false. 00073 */ 00074 bool execute(HttpdConnection& i_connection); 00075 void dispatchRpc(); 00076 00077 public: 00078 //for development 00079 int addObject(BasicRpcObject* i_object); 00080 bool removeObject(int i_id); 00081 00082 void* getObject(int i_oid); 00083 bool putResult(unsigned int i_id); 00084 bool putResult(unsigned int i_id,const char* i_params_fmt,...); 00085 bool putError(unsigned int i_id,int i_code); 00086 }; 00087 }
Generated on Tue Jul 12 2022 15:46:14 by 1.7.2