Skip to content

Commit

Permalink
Merge pull request #22 from hamidr/libevpp
Browse files Browse the repository at this point in the history
Use Libevpp from a separate project
  • Loading branch information
hamidr authored Jan 11, 2017
2 parents 8dd752d + 96ea9f8 commit 3e6b3f1
Show file tree
Hide file tree
Showing 35 changed files with 131 additions and 700 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/libevpp"]
path = libs/libevpp
url = https://github.com/hamidr/libevpp
41 changes: 12 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,21 @@ endif()

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
set(PROJECT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/includes)

set(PROJECT_SOURCE_DIR src)
set(PROJECT_INCLUDE_DIR includes)

include_directories(${PROJECT_INCLUDE_DIR})
include_directories("/usr/include/")
include_directories("/usr/local/include")
include_directories(/usr/include/)
include_directories(/usr/local/include)

link_directories("/usr/lib")
link_directories("/usr/local/lib")
link_directories(/usr/lib)
link_directories(/usr/local/lib)

add_subdirectory(libs/libevpp/)

add_library(event_loop
${PROJECT_SOURCE_DIR}/event_loop/socket_watcher.cpp
${PROJECT_SOURCE_DIR}/event_loop/event_loop_ev.cpp)
include_directories(libs/libevpp/includes)

add_library(network
${PROJECT_SOURCE_DIR}/network/async_socket.cpp
${PROJECT_SOURCE_DIR}/network/unix_socket.cpp
${PROJECT_SOURCE_DIR}/network/tcp_socket.cpp)

add_library(parser
${PROJECT_SOURCE_DIR}/parser/base_resp_parser.cpp
Expand All @@ -59,19 +54,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_EXE_LINKER_FLAGS "-s") ## Strip binary
endif()

target_link_libraries(event_loop ev)
target_link_libraries(async_redis event_loop parser network)

install(TARGETS event_loop
LIBRARY DESTINATION /usr/local/lib/
ARCHIVE DESTINATION /usr/local/lib/)

install(TARGETS parser
LIBRARY DESTINATION /usr/local/lib/
ARCHIVE DESTINATION /usr/local/lib/
)

install(DIRECTORY ${PROJECT_INCLUDE_DIR}/ DESTINATION /usr/local/include)
target_link_libraries(async_redis network parser)

add_executable (a1.out ${CMAKE_SOURCE_DIR}/test/main.cpp)
target_link_libraries(a1.out async_redis)
add_executable (a2.out test/main.cpp)
target_link_libraries(a2.out async_redis)
6 changes: 3 additions & 3 deletions examples/tcp_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include <unordered_map>

namespace async_redis {
namespace tcp_server {
namespace examples {

class tcp_server
{
public:
using tcp_socket = async_redis::network::tcp_socket;
using async_socket = async_redis::network::async_socket;
using tcp_socket = libevpp::network::tcp_socket;
using async_socket = libevpp::network::async_socket;

tcp_server(event_loop::event_loop_ev &event_loop)
: loop_(event_loop), listener_(event_loop) {
Expand Down
11 changes: 7 additions & 4 deletions includes/connection.hpp → includes/async_redis/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
#include <memory>
#include <tuple>

#include <parser/base_resp_parser.h>
#include <network/async_socket.hpp>
#include <async_redis/parser/base_resp_parser.h>
#include <libevpp/event_loop/event_loop_ev.h>
#include <libevpp/network/async_socket.hpp>

using namespace libevpp;

namespace async_redis
{
class connection
{
using async_socket = network::async_socket;
using async_socket = libevpp::network::async_socket;

public:
using parser_t = parser::base_resp_parser::parser;
using reply_cb_t = std::function<void (parser_t)>;
using reply_cb_t = std::function<void (parser_t&)>;

connection(event_loop::event_loop_ev& event_loop);

Expand Down
7 changes: 4 additions & 3 deletions includes/monitor.hpp → includes/async_redis/monitor.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once

#include <network/async_socket.hpp>
#include <parser/base_resp_parser.h>
#include <libevpp/network/async_socket.hpp>
#include <async_redis/parser/base_resp_parser.h>

#include <unordered_map>
#include <list>
#include <string>

using std::string;
using namespace libevpp;

namespace async_redis
{
Expand All @@ -24,7 +25,7 @@ namespace async_redis
};

using parser_t = parser::base_resp_parser::parser;
using watcher_cb_t = std::function<void (const string&, parser_t, EventState)>;
using watcher_cb_t = std::function<void (const string&, parser_t&, EventState)>;

monitor(event_loop::event_loop_ev &event_loop);

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ namespace async_redis {
virtual int parse_append(const char*, ssize_t, bool&) = 0;
virtual std::string to_string() const = 0;
virtual void map(const caller_t &fn);
bool is_array() const;
bool is_number() const;
bool is_string() const;
bool is_enum() const;
bool is_error() const;

void print();
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include <memory>

#include "connection.hpp"
#include <async_redis/connection.hpp>

namespace async_redis
{
Expand Down Expand Up @@ -38,6 +38,7 @@ namespace async_redis
void decr(const string& field, reply_cb_t reply);
void ping(reply_cb_t reply);
void publish(const string& channel, const string& msg, reply_cb_t&& reply);
void sort(const string& hash_name, std::vector<string>&& fields, reply_cb_t&& reply);

//TODO: wtf?! doesnt make sense with multiple connections!
// void select(uint catalog, reply_cb_t&& reply) {
Expand Down
17 changes: 9 additions & 8 deletions includes/sentinel.hpp → includes/async_redis/sentinel.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#pragma once
#include <network/async_socket.hpp>
#include <parser/base_resp_parser.h>
#include <libevpp/network/async_socket.hpp>
#include <async_redis/parser/base_resp_parser.h>

#include <monitor.hpp>
#include <async_redis/monitor.hpp>
#include <functional>
#include <connection.hpp>
// #include <memory>
#include <async_redis/connection.hpp>

using namespace libevpp;

namespace async_redis {
class sentinel
{
using socket_t = ::async_redis::network::async_socket;
using socket_t = libevpp::network::async_socket;
using connect_cb_t = socket_t::connect_handler_t;

public:
Expand Down Expand Up @@ -54,7 +55,7 @@ namespace async_redis {

private:
int connected_ = 0;
std::unique_ptr<monitor> stream_;
std::unique_ptr<connection> conn_;
monitor stream_;
connection conn_;
};
}
48 changes: 0 additions & 48 deletions includes/event_loop/event_loop_ev.h

This file was deleted.

47 changes: 0 additions & 47 deletions includes/event_loop/socket_watcher.h

This file was deleted.

75 changes: 0 additions & 75 deletions includes/network/async_socket.hpp

This file was deleted.

18 changes: 0 additions & 18 deletions includes/network/tcp_socket.hpp

This file was deleted.

Loading

0 comments on commit 3e6b3f1

Please sign in to comment.