[v3-update-sio] updates usage of log function to CCLOG macros, ensures correct data type is passed to log function

Signed-off-by: Chris Hannon <himynameschris@gmail.com>
This commit is contained in:
Chris Hannon 2015-04-24 00:16:24 -04:00
parent 162c28f3d0
commit da74d1be93
2 changed files with 63 additions and 63 deletions

View File

@ -230,7 +230,7 @@ std::string SocketIOPacket::stringify()
outS = s.GetString();
log("create args object: %s:", outS.c_str());
CCLOGINFO("create args object: %s:", outS.c_str());
}
return outS;
@ -298,7 +298,7 @@ std::string SocketIOPacketV10x::stringify()
outS = s.GetString();
log("create args object: %s:", outS.c_str());
CCLOGINFO("create args object: %s:", outS.c_str());
return outS;
@ -424,7 +424,7 @@ SIOClientImpl::~SIOClientImpl()
void SIOClientImpl::handshake()
{
log("SIOClientImpl::handshake() called");
CCLOGINFO("SIOClientImpl::handshake() called");
std::stringstream pre;
pre << "http://" << _uri << "/socket.io/1/?EIO=2&transport=polling&b64=true";
@ -436,7 +436,7 @@ void SIOClientImpl::handshake()
request->setResponseCallback(CC_CALLBACK_2(SIOClientImpl::handshakeResponse, this));
request->setTag("handshake");
log("SIOClientImpl::handshake() waiting");
CCLOGINFO("SIOClientImpl::handshake() waiting");
HttpClient::getInstance()->send(request);
@ -447,22 +447,22 @@ void SIOClientImpl::handshake()
void SIOClientImpl::handshakeResponse(HttpClient *sender, HttpResponse *response)
{
log("SIOClientImpl::handshakeResponse() called");
CCLOGINFO("SIOClientImpl::handshakeResponse() called");
if (0 != strlen(response->getHttpRequest()->getTag()))
{
log("%s completed", response->getHttpRequest()->getTag());
CCLOGINFO("%s completed", response->getHttpRequest()->getTag());
}
long statusCode = response->getResponseCode();
char statusString[64] = {};
sprintf(statusString, "HTTP Status Code: %ld, tag = %s", statusCode, response->getHttpRequest()->getTag());
log("response code: %ld", statusCode);
CCLOGINFO("response code: %ld", statusCode);
if (!response->isSucceed())
{
log("SIOClientImpl::handshake() failed");
log("error buffer: %s", response->getErrorBuffer());
CCLOGERROR("SIOClientImpl::handshake() failed");
CCLOGERROR("error buffer: %s", response->getErrorBuffer());
for (auto iter = _clients.begin(); iter != _clients.end(); ++iter)
{
@ -472,7 +472,7 @@ void SIOClientImpl::handshakeResponse(HttpClient *sender, HttpResponse *response
return;
}
log("SIOClientImpl::handshake() succeeded");
CCLOGINFO("SIOClientImpl::handshake() succeeded");
std::vector<char> *buffer = response->getResponseData();
std::stringstream s;
@ -483,7 +483,7 @@ void SIOClientImpl::handshakeResponse(HttpClient *sender, HttpResponse *response
s << (*buffer)[i];
}
log("SIOClientImpl::handshake() dump data: %s", s.str().c_str());
CCLOGINFO("SIOClientImpl::handshake() dump data: %s", s.str().c_str());
std::string res = s.str();
std::string sid = "";
@ -491,7 +491,7 @@ void SIOClientImpl::handshakeResponse(HttpClient *sender, HttpResponse *response
if (res.at(res.size() - 1) == '}') {
log("SIOClientImpl::handshake() Socket.IO 1.x detected");
CCLOGINFO("SIOClientImpl::handshake() Socket.IO 1.x detected");
_version = SocketIOPacket::V10x;
// sample: 97:0{"sid":"GMkL6lzCmgMvMs9bAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
@ -527,12 +527,12 @@ void SIOClientImpl::handshakeResponse(HttpClient *sender, HttpResponse *response
std::string timeout_str = temp.substr(a + 1, b - a);
timeout = atoi(timeout_str.c_str()) / 1000;
log("done parsing 1.x");
CCLOGINFO("done parsing 1.x");
}
else {
log("SIOClientImpl::handshake() Socket.IO 0.9.x detected");
CCLOGINFO("SIOClientImpl::handshake() Socket.IO 0.9.x detected");
_version = SocketIOPacket::V09x;
// sample: 3GYzE9md2Ig-lm3cf8Rv:60:60:websocket,htmlfile,xhr-polling,jsonp-polling
size_t pos = 0;
@ -570,7 +570,7 @@ void SIOClientImpl::handshakeResponse(HttpClient *sender, HttpResponse *response
void SIOClientImpl::openSocket()
{
log("SIOClientImpl::openSocket() called");
CCLOGINFO("SIOClientImpl::openSocket() called");
std::stringstream s;
@ -595,7 +595,7 @@ void SIOClientImpl::openSocket()
bool SIOClientImpl::init()
{
log("SIOClientImpl::init() successful");
CCLOGINFO("SIOClientImpl::init() successful");
return true;
}
@ -663,7 +663,7 @@ void SIOClientImpl::disconnectFromEndpoint(const std::string& endpoint)
if (_clients.empty() || endpoint == "/")
{
log("SIOClientImpl::disconnectFromEndpoint out of endpoints, checking for disconnect");
CCLOGINFO("SIOClientImpl::disconnectFromEndpoint out of endpoints, checking for disconnect");
if (_connected)
this->disconnect();
@ -684,7 +684,7 @@ void SIOClientImpl::heartbeat(float dt)
this->send(packet);
log("Heartbeat sent");
CCLOGINFO("Heartbeat sent");
}
@ -712,16 +712,16 @@ void SIOClientImpl::send(SocketIOPacket *packet)
std::string req = packet->toString();
if (_connected)
{
log("-->SEND:%s", req.data());
CCLOGINFO("-->SEND:%s", req.data());
_ws->send(req.data());
}
else
log("Cant send the message (%s) because disconnected", req);
CCLOGINFO("Cant send the message (%s) because disconnected", req.c_str());
}
void SIOClientImpl::emit(std::string endpoint, std::string eventname, std::string args)
{
log("Emitting event \"%s\"", eventname);
CCLOGINFO("Emitting event \"%s\"", eventname.c_str());
SocketIOPacket *packet = SocketIOPacket::createPacketWithType("event", _version);
packet->setEndpoint(endpoint == "/" ? "" : endpoint);
packet->setEvent(eventname);
@ -748,12 +748,12 @@ void SIOClientImpl::onOpen(WebSocket* ws)
iter->second->onOpen();
}
log("SIOClientImpl::onOpen socket connected!");
CCLOGINFO("SIOClientImpl::onOpen socket connected!");
}
void SIOClientImpl::onMessage(WebSocket* ws, const WebSocket::Data& data)
{
log("SIOClientImpl::onMessage received: %s", data.bytes);
CCLOGINFO("SIOClientImpl::onMessage received: %s", data.bytes);
std::string payload = data.bytes;
int control = atoi(payload.substr(0, 1).c_str());
@ -797,37 +797,37 @@ void SIOClientImpl::onMessage(WebSocket* ws, const WebSocket::Data& data)
s_data = payload;
if (c == nullptr) log("SIOClientImpl::onMessage client lookup returned nullptr");
if (c == nullptr) CCLOGINFO("SIOClientImpl::onMessage client lookup returned nullptr");
switch (control)
{
case 0:
log("Received Disconnect Signal for Endpoint: %s\n", endpoint.c_str());
CCLOGINFO("Received Disconnect Signal for Endpoint: %s\n", endpoint.c_str());
disconnectFromEndpoint(endpoint);
c->fireEvent("disconnect", payload);
break;
case 1:
log("Connected to endpoint: %s \n", endpoint.c_str());
CCLOGINFO("Connected to endpoint: %s \n", endpoint.c_str());
if (c) {
c->onConnect();
c->fireEvent("connect", payload);
}
break;
case 2:
log("Heartbeat received\n");
CCLOGINFO("Heartbeat received\n");
break;
case 3:
log("Message received: %s \n", s_data.c_str());
CCLOGINFO("Message received: %s \n", s_data.c_str());
if (c) c->getDelegate()->onMessage(c, s_data);
if (c) c->fireEvent("message", s_data);
break;
case 4:
log("JSON Message Received: %s \n", s_data.c_str());
CCLOGINFO("JSON Message Received: %s \n", s_data.c_str());
if (c) c->getDelegate()->onMessage(c, s_data);
if (c) c->fireEvent("json", s_data);
break;
case 5:
log("Event Received with data: %s \n", s_data.c_str());
CCLOGINFO("Event Received with data: %s \n", s_data.c_str());
if (c)
{
@ -845,15 +845,15 @@ void SIOClientImpl::onMessage(WebSocket* ws, const WebSocket::Data& data)
break;
case 6:
log("Message Ack\n");
CCLOGINFO("Message Ack\n");
break;
case 7:
log("Error\n");
CCLOGERROR("Error\n");
//if (c) c->getDelegate()->onError(c, s_data);
if (c) c->fireEvent("error", s_data);
break;
case 8:
log("Noop\n");
CCLOGINFO("Noop\n");
break;
}
}
@ -863,22 +863,22 @@ void SIOClientImpl::onMessage(WebSocket* ws, const WebSocket::Data& data)
switch (control)
{
case 0:
log("Not supposed to receive control 0 for websocket");
log("That's not good");
CCLOGINFO("Not supposed to receive control 0 for websocket");
CCLOGINFO("That's not good");
break;
case 1:
log("Not supposed to receive control 1 for websocket");
CCLOGINFO("Not supposed to receive control 1 for websocket");
break;
case 2:
log("Ping received, send pong");
CCLOGINFO("Ping received, send pong");
payload = "3" + payload;
_ws->send(payload.c_str());
break;
case 3:
log("Pong received");
CCLOGINFO("Pong received");
if (payload == "probe")
{
log("Request Update");
CCLOGINFO("Request Update");
_ws->send("5");
}
break;
@ -886,7 +886,7 @@ void SIOClientImpl::onMessage(WebSocket* ws, const WebSocket::Data& data)
const char second = payload.at(0);
int control2 = atoi(&second);
log("Message code: [%i]", control);
CCLOGINFO("Message code: [%i]", control);
SocketIOPacket *packetOut = SocketIOPacket::createPacketWithType("event", _version);
std::string endpoint = "";
@ -920,26 +920,26 @@ void SIOClientImpl::onMessage(WebSocket* ws, const WebSocket::Data& data)
switch (control2)
{
case 0:
log("Socket Connected");
CCLOGINFO("Socket Connected");
if (c) {
c->onConnect();
c->fireEvent("connect", payload);
}
break;
case 1:
log("Socket Disconnected");
CCLOGINFO("Socket Disconnected");
disconnectFromEndpoint(endpoint);
c->fireEvent("disconnect", payload);
break;
case 2:
{
log("Event Received (%s)", payload.c_str());
CCLOGINFO("Event Received (%s)", payload.c_str());
int a = payload.find("\"");
int b = payload.substr(a + 1).find("\"");
std::string eventname = payload.substr(a + 1, b - a + 1);
log("event name %s between %i and %i", eventname.c_str(), a, b);
CCLOGINFO("event name %s between %i and %i", eventname.c_str(), a, b);
payload = payload.substr(b + 4, payload.size() - (b + 5));
@ -949,26 +949,26 @@ void SIOClientImpl::onMessage(WebSocket* ws, const WebSocket::Data& data)
}
break;
case 3:
log("Message Ack");
CCLOGINFO("Message Ack");
break;
case 4:
log("Error");
CCLOGERROR("Error");
if (c) c->fireEvent("error", payload);
break;
case 5:
log("Binary Event");
CCLOGINFO("Binary Event");
break;
case 6:
log("Binary Ack");
CCLOGINFO("Binary Ack");
break;
}
}
break;
case 5:
log("Upgrade required");
CCLOGINFO("Upgrade required");
break;
case 6:
log("Noop\n");
CCLOGINFO("Noop\n");
break;
}
break;
@ -992,7 +992,7 @@ void SIOClientImpl::onClose(WebSocket* ws)
void SIOClientImpl::onError(WebSocket* ws, const WebSocket::ErrorCode& error)
{
log("Websocket error received: %s", error);
CCLOGERROR("Websocket error received: %d", error);
}
//begin SIOClient methods
@ -1079,7 +1079,7 @@ void SIOClient::on(const std::string& eventName, SIOEvent e)
void SIOClient::fireEvent(const std::string& eventName, const std::string& data)
{
log("SIOClient::fireEvent called with event name: %s and data: %s", eventName.c_str(), data.c_str());
CCLOGINFO("SIOClient::fireEvent called with event name: %s and data: %s", eventName.c_str(), data.c_str());
_delegate->fireEventToScript(this, eventName, data);
@ -1092,7 +1092,7 @@ void SIOClient::fireEvent(const std::string& eventName, const std::string& data)
return;
}
log("SIOClient::fireEvent no native event with name %s found", eventName.c_str());
CCLOGINFO("SIOClient::fireEvent no native event with name %s found", eventName.c_str());
}
//begin SocketIO methods

View File

@ -114,7 +114,7 @@ SocketIOTest::~SocketIOTest(void)
//test event callback handlers, these will be registered with socket.io
void SocketIOTest::testevent(SIOClient *client, const std::string& data) {
log("SocketIOTest::testevent called with data: %s", data.c_str());
CCLOGINFO("SocketIOTest::testevent called with data: %s", data.c_str());
std::stringstream s;
s << client->getTag() << " received event testevent with data: " << data.c_str();
@ -125,7 +125,7 @@ void SocketIOTest::testevent(SIOClient *client, const std::string& data) {
void SocketIOTest::echotest(SIOClient *client, const std::string& data) {
log("SocketIOTest::echotest called with data: %s", data.c_str());
CCLOGINFO("SocketIOTest::echotest called with data: %s", data.c_str());
std::stringstream s;
s << client->getTag() << " received event echotest with data: " << data.c_str();
@ -138,7 +138,7 @@ void SocketIOTest::echotest(SIOClient *client, const std::string& data) {
// 'message' events and handlers are now registered in the same way that other events are
void SocketIOTest::message(network::SIOClient* client, const std::string& data)
{
log("SocketIOTest::message received: %s", data.c_str());
CCLOGINFO("SocketIOTest::message received: %s", data.c_str());
std::stringstream s;
s << client->getTag() << " received message with content: " << data.c_str();
@ -148,7 +148,7 @@ void SocketIOTest::message(network::SIOClient* client, const std::string& data)
void SocketIOTest::json(network::SIOClient* client, const std::string& data)
{
log("SocketIOTest::json received: %s", data.c_str());
CCLOGINFO("SocketIOTest::json received: %s", data.c_str());
std::stringstream s;
s << client->getTag() << " received json message with content: " << data.c_str();
@ -158,7 +158,7 @@ void SocketIOTest::json(network::SIOClient* client, const std::string& data)
void SocketIOTest::connect(network::SIOClient* client, const std::string& data)
{
log("SocketIOTest::connect called");
CCLOGINFO("SocketIOTest::connect called");
std::stringstream s;
s << client->getTag() << " connected!";
@ -168,7 +168,7 @@ void SocketIOTest::connect(network::SIOClient* client, const std::string& data)
void SocketIOTest::disconnect(network::SIOClient* client, const std::string& data)
{
log("SocketIOTest::disconnect called");
CCLOGINFO("SocketIOTest::disconnect called");
std::stringstream s;
s << client->getTag() << " disconnected by server!";
@ -195,7 +195,7 @@ void SocketIOTest::closedSocketAction(network::SIOClient* client)
void SocketIOTest::onMenuSIOClientClicked(cocos2d::Ref *sender)
{
//create a client by using this static method, url does not need to contain the protocol
_sioClient = SocketIO::connect("ws://dev.channon.us:3009", *this);
_sioClient = SocketIO::connect("ws://dev.channon.us:3010", *this);
//you may set a tag for the client for reference in callbacks
_sioClient->setTag("Test Client");
@ -212,7 +212,7 @@ void SocketIOTest::onMenuSIOClientClicked(cocos2d::Ref *sender)
void SocketIOTest::onMenuSIOEndpointClicked(cocos2d::Ref *sender)
{
//repeat the same connection steps for the namespace "testpoint"
_sioEndpoint = SocketIO::connect("ws://dev.channon.us:3009/testpoint", *this);
_sioEndpoint = SocketIO::connect("ws://dev.channon.us:3010/testpoint", *this);
//a tag to differentiate in shared callbacks
_sioEndpoint->setTag("Test Endpoint");
@ -295,7 +295,7 @@ void SocketIOTest::onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender)
void SocketIOTest::onClose(network::SIOClient* client)
{
log("SocketIOTest::onClose called");
CCLOGINFO("SocketIOTest::onClose called");
std::stringstream s;
s << client->getTag() << " closed!";
@ -307,7 +307,7 @@ void SocketIOTest::onClose(network::SIOClient* client)
void SocketIOTest::onError(network::SIOClient* client, const std::string& data)
{
log("SocketIOTest::onError received: %s", data.c_str());
CCLOGERROR("SocketIOTest::onError received: %s", data.c_str());
std::stringstream s;
s << client->getTag() << " received error with content: " << data.c_str();