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
mbed/mod/ModWebSocket.cpp
- Committer:
- nyatla
- Date:
- 2014-06-13
- Revision:
- 72:c118a7aa37a3
- Parent:
- 58:03b89038b21a
- Child:
- 73:8c7dd6fd462e
File content as of revision 72:c118a7aa37a3:
#include "ModWebSocket.h"
#include "../net/httpd/mod/NyLPC_cModWebSocket_protected.h"
#include "HttpdConnection.h"
namespace MiMic
{
ModWebSocket::ModWebSocket(const char* i_path):ModBaseClass(i_path)
{
this->_mod=NULL;
}
ModWebSocket::ModWebSocket()
{
this->_mod=NULL;
}
ModWebSocket::~ModWebSocket()
{
if(this->_mod!=NULL){
NyLPC_cModWebSocket_finalize(this->_mod);
this->_mod=NULL;
}
}
void ModWebSocket::setParam(const char* i_path)
{
ModBaseClass::setParam(i_path);
}
bool ModWebSocket::execute(HttpdConnection& i_connection)
{
if(this->_mod!=NULL){
return false;
}
this->_mod=(NyLPC_TcModWebSocket_t*)malloc(sizeof(NyLPC_TcModWebSocket_t));
if(this->_mod==NULL){
return false;
}
bool ret=false;
//initialize websocket
NyLPC_cModWebSocket_initialize(this->_mod,this->_path);
if(NyLPC_cModWebSocket_canHandle(this->_mod,i_connection._ref_inst)){
ret=NyLPC_cModWebSocket_execute(this->_mod,i_connection._ref_inst)?true:false;
}
NyLPC_cModWebSocket_finalize(this->_mod);
free(this->_mod);
this->_mod=NULL;
return ret;
}
bool ModWebSocket::write(const void* i_tx_buf,int i_tx_size)
{
if(this->_mod==NULL){
return false;
}
return NyLPC_cModWebSocket_write(this->_mod,i_tx_buf,i_tx_size)?true:false;
}
bool ModWebSocket::writeFormat(const char* i_fmt,...)
{
bool ret;
va_list a;
//ストリームの状態を更新する。
va_start(a,i_fmt);
ret=NyLPC_cModWebSocket_writeFormatV(this->_mod,i_fmt,a)?true:false;
va_end(a);
return ret;
}
int ModWebSocket::read(void* i_rx_buf,int i_rx_size)
{
if(this->_mod==NULL){
return false;
}
//write here!
return NyLPC_cModWebSocket_read(this->_mod,i_rx_buf,i_rx_size);
}
bool ModWebSocket::canRead()
{
return NyLPC_cModWebSocket_canRead(this->_mod)?true:false;
}
void ModWebSocket::close()
{
if(this->_mod==NULL){
return;
}
NyLPC_cModWebSocket_finalize(this->_mod);
this->_mod=NULL;
return;
}
}
