Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
ModWebSocket.cpp
00001 #include "ModWebSocket.h" 00002 #include "../net/httpd/mod/NyLPC_cModWebSocket_protected.h" 00003 #include "HttpdConnection.h" 00004 00005 namespace MiMic 00006 { 00007 ModWebSocket::ModWebSocket(const char* i_path):ModBaseClass(i_path) 00008 { 00009 this->_mod=NULL; 00010 } 00011 ModWebSocket::ModWebSocket() 00012 { 00013 this->_mod=NULL; 00014 } 00015 ModWebSocket::~ModWebSocket() 00016 { 00017 if(this->_mod!=NULL){ 00018 NyLPC_cModWebSocket_finalize(this->_mod); 00019 free(this->_mod); 00020 this->_mod=NULL; 00021 } 00022 } 00023 bool ModWebSocket::isStarted(){ 00024 return this->_mod!=NULL; 00025 } 00026 00027 void ModWebSocket::setParam(const char* i_path) 00028 { 00029 ModBaseClass::setParam(i_path); 00030 } 00031 00032 bool ModWebSocket::execute(HttpdConnection& i_connection) 00033 { 00034 i_connection.lockHttpd(); 00035 if(this->_mod!=NULL){ 00036 i_connection.unlockHttpd(); 00037 return false; 00038 } 00039 this->_mod=(NyLPC_TcModWebSocket_t*)malloc(sizeof(NyLPC_TcModWebSocket_t)); 00040 i_connection.unlockHttpd(); 00041 00042 if(this->_mod==NULL){ 00043 return false; 00044 } 00045 //initialize websocket 00046 NyLPC_cModWebSocket_initialize(this->_mod,this->_path); 00047 if(NyLPC_cModWebSocket_canHandle(this->_mod,i_connection._ref_inst)){ 00048 if(NyLPC_cModWebSocket_execute(this->_mod,i_connection._ref_inst)){ 00049 return true; 00050 } 00051 } 00052 NyLPC_cModWebSocket_finalize(this->_mod); 00053 free(this->_mod); 00054 i_connection.lockHttpd(); 00055 this->_mod=NULL; 00056 i_connection.unlockHttpd(); 00057 return false; 00058 } 00059 bool ModWebSocket::write(const void* i_tx_buf,int i_tx_size) 00060 { 00061 if(this->_mod==NULL){ 00062 return false; 00063 } 00064 return NyLPC_cModWebSocket_write(this->_mod,i_tx_buf,i_tx_size)?true:false; 00065 } 00066 00067 00068 00069 bool ModWebSocket::writeFormat(const char* i_fmt,...) 00070 { 00071 bool ret; 00072 va_list a; 00073 //ストリームの状態を更新する。 00074 va_start(a,i_fmt); 00075 ret=NyLPC_cModWebSocket_writeFormatV(this->_mod,i_fmt,a)?true:false; 00076 va_end(a); 00077 return ret; 00078 } 00079 00080 int ModWebSocket::read(void* i_rx_buf,int i_rx_size) 00081 { 00082 if(this->_mod==NULL){ 00083 return false; 00084 } 00085 //write here! 00086 return NyLPC_cModWebSocket_read(this->_mod,i_rx_buf,i_rx_size); 00087 } 00088 bool ModWebSocket::canRead() 00089 { 00090 if(this->_mod==NULL){ 00091 return false; 00092 } 00093 return NyLPC_cModWebSocket_canRead(this->_mod)?true:false; 00094 } 00095 00096 void ModWebSocket::close() 00097 { 00098 if(this->_mod==NULL){ 00099 return; 00100 } 00101 NyLPC_cModWebSocket_finalize(this->_mod); 00102 free(this->_mod); 00103 this->_mod=NULL; 00104 return; 00105 } 00106 }
Generated on Tue Jul 12 2022 16:22:56 by
