Skip to content

Commit

Permalink
remove ch_protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
tadasv committed Dec 7, 2013
1 parent c32d0a6 commit ad9ad46
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 213 deletions.
6 changes: 3 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ chimp_CXXFLAGS = -I$(top_srcdir)/src

bin_PROGRAMS = chimp

chimp_SOURCES = ch_protocol.cc \
ch_protocol.h \
ch_log.cc \
chimp_SOURCES = ch_log.cc \
ch_log.h \
ch_row.cc \
ch_row.h \
Expand All @@ -21,6 +19,8 @@ chimp_SOURCES = ch_protocol.cc \
transport/command/abstract_command.cc \
transport/command/ping.h \
transport/command/ping.cc \
transport/command/dsnew.h \
transport/command/dsnew.cc \
transport/server.h \
transport/server.cc \
transport/client.h \
Expand Down
120 changes: 0 additions & 120 deletions src/ch_protocol.cc

This file was deleted.

73 changes: 0 additions & 73 deletions src/ch_protocol.h

This file was deleted.

3 changes: 0 additions & 3 deletions src/transport/command/ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
#ifndef CH_INCLUDE_GUARD_B3F7ACA4_559D_45B4_9E0F_B1248AF16E1D
#define CH_INCLUDE_GUARD_B3F7ACA4_559D_45B4_9E0F_B1248AF16E1D

#include <memory>

#include "transport/client.h"
#include "transport/abstract_response.h"
#include "transport/command/abstract_command.h"

namespace chimp {

namespace transport {
namespace command {

Expand Down
18 changes: 13 additions & 5 deletions src/transport/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "transport/client.h"
#include "transport/error_response.h"
#include "transport/command/ping.h"
#include "transport/command/dsnew.h"


namespace chimp {
Expand Down Expand Up @@ -78,20 +79,23 @@ static void _read_cb(uv_stream_t *client_handle, ssize_t nread, uv_buf_t buf)
} else {
std::string command_name(msg.data.via.array.ptr[0].via.raw.ptr,
msg.data.via.array.ptr[0].via.raw.size);
std::map<std::string, ch_command_t>::iterator iter = client->server->commands.find(command_name);
std::map<std::string, chimp::transport::Server::Command>::iterator iter = client->server->commands.find(command_name);
if (iter == client->server->commands.end()) {
std::shared_ptr<AbstractResponse> response(new ErrorResponse(
chimp::transport::RESPONSE_CODE_SERVER_ERROR,
"unsupported command"));
client->Write(response);
} else {
ch_command_t command = iter->second;
chimp::transport::Server::Command command = iter->second;
chimp::transport::command::AbstractCommand *cmd = NULL;

switch (command) {
case CH_COMMAND_PING:
case chimp::transport::Server::PING:
cmd = new chimp::transport::command::Ping(client);
break;
case chimp::transport::Server::DSNEW:
cmd = new chimp::transport::command::DatasetNew(client);
break;
default:
{
std::shared_ptr<AbstractResponse> response(new ErrorResponse(
Expand All @@ -107,6 +111,10 @@ static void _read_cb(uv_stream_t *client_handle, ssize_t nread, uv_buf_t buf)
cmd->Execute();
} else {
CH_LOG_ERROR("failed to unpack message");
std::shared_ptr<AbstractResponse> response(new ErrorResponse(
chimp::transport::RESPONSE_CODE_USER_ERROR,
"failed to unpack message"));
client->Write(response);
}
delete cmd;
}
Expand Down Expand Up @@ -144,8 +152,8 @@ Server::Server(ServerSettings settings, uv_loop_t *loop)
{
this->loop = loop;
this->settings_ = settings;
this->commands["PING"] = CH_COMMAND_PING;
this->commands["DSNEW"] = CH_COMMAND_DSNEW;
this->commands["PING"] = chimp::transport::Server::PING;
this->commands["DSNEW"] = chimp::transport::Server::DSNEW;
uv_tcp_init(this->loop, &this->handle);
this->handle.data = this;
}
Expand Down
8 changes: 6 additions & 2 deletions src/transport/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <uv.h>
#include <map>
#include <ch_protocol.h>


namespace chimp {
Expand All @@ -41,13 +40,18 @@ class Server {
int socket_backlog;
};

enum Command {
PING,
DSNEW
};

Server(ServerSettings settings, uv_loop_t *loop);
int Start();
public:
uv_loop_t *loop;
uv_tcp_t handle;
ServerSettings settings_;
std::map<std::string, ch_command_t> commands;
std::map<std::string, Command> commands;
};

}
Expand Down
9 changes: 2 additions & 7 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_core_CXXFLAGS = -I$(top_srcdir)/src
test_protocol_CXXFLAGS = -I$(top_srcdir)/src

noinst_PROGRAMS = test_core test_protocol
noinst_PROGRAMS = test_core

test_core_SOURCES = ../src/ch_row.cc \
../src/ch_row.h \
Expand All @@ -10,9 +10,4 @@ test_core_SOURCES = ../src/ch_row.cc \
test_core.cc
test_core_LDADD = -lgtest -lpthread

test_protocol_SOURCES = ../src/ch_protocol.h \
../src/ch_protocol.cc \
test_protocol.cc
test_protocol_LDADD = -lgtest -lpthread -lmsgpack

TESTS = test_core test_protocol
TESTS = test_core

0 comments on commit ad9ad46

Please sign in to comment.