moved all stuff to github
This commit is contained in:
parent
095fbeeb67
commit
296ae46ed8
|
@ -0,0 +1,2 @@
|
|||
.git* export-ignore
|
||||
/CMakeLists.txt export-subst
|
|
@ -0,0 +1,2 @@
|
|||
/build
|
||||
/tags
|
|
@ -0,0 +1,115 @@
|
|||
cmake_minimum_required(VERSION 2.8.6)
|
||||
|
||||
set(VERSION "0.1")
|
||||
# $Format:Packaged from commit %H%nset(COMMIT %h)%nset(REFS "%d")$
|
||||
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
|
||||
enable_testing()
|
||||
|
||||
include_directories(src contrib/epee/include "${CMAKE_BINARY_DIR}/version")
|
||||
|
||||
set(STATIC ${MSVC} CACHE BOOL "Link libraries statically")
|
||||
|
||||
if(MSVC)
|
||||
add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /FIinline_c.h /D__SSE4_1__")
|
||||
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10485760")
|
||||
if(STATIC)
|
||||
foreach(VAR CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE)
|
||||
string(REPLACE "/MD" "/MT" ${VAR} "${${VAR}}")
|
||||
endforeach()
|
||||
endif()
|
||||
include_directories(SYSTEM src/platform/msc)
|
||||
else()
|
||||
set(ARCH native CACHE STRING "CPU to build for: -march value or default")
|
||||
if("${ARCH}" STREQUAL "default")
|
||||
set(ARCH_FLAG "")
|
||||
else()
|
||||
set(ARCH_FLAG "-march=${ARCH}")
|
||||
endif()
|
||||
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Werror -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
set(WARNINGS "${WARNINGS} -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unused-private-field -Wno-error=unneeded-internal-declaration")
|
||||
else()
|
||||
set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized")
|
||||
endif()
|
||||
if(MINGW)
|
||||
set(WARNINGS "${WARNINGS} -Wno-error=unused-value")
|
||||
set(MINGW_FLAG "-DWIN32_LEAN_AND_MEAN")
|
||||
include_directories(SYSTEM src/platform/mingw)
|
||||
else()
|
||||
set(MINGW_FLAG "")
|
||||
endif()
|
||||
set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes")
|
||||
set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
|
||||
try_compile(STATIC_ASSERT_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/utils/test-static-assert.c" COMPILE_DEFINITIONS "-std=c11")
|
||||
if(STATIC_ASSERT_RES)
|
||||
set(STATIC_ASSERT_FLAG "")
|
||||
else()
|
||||
set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG}")
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8))
|
||||
set(DEBUG_FLAGS "-g3 -Og")
|
||||
else()
|
||||
set(DEBUG_FLAGS "-g3 -O0")
|
||||
endif()
|
||||
set(RELEASE_FLAGS "-Ofast -DNDEBUG -Wno-unused-variable -flto")
|
||||
#if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT MINGW)
|
||||
# set(RELEASE_FLAGS "${RELEASE_FLAGS} -fno-fat-lto-objects")
|
||||
#endif()
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}")
|
||||
if(STATIC)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
||||
function(add_executable name)
|
||||
_add_executable("${name}" ${ARGN})
|
||||
set_target_properties("${name}" PROPERTIES LINK_SEARCH_START_STATIC ON LINK_SEARCH_END_STATIC ON)
|
||||
endfunction()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(STATIC)
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
set(Boost_USE_STATIC_RUNTIME ON)
|
||||
endif()
|
||||
find_package(Boost 1.53 REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization atomic program_options)
|
||||
if((${Boost_MAJOR_VERSION} EQUAL 1) AND (${Boost_MINOR_VERSION} EQUAL 54))
|
||||
message(SEND_ERROR "Boost version 1.54 is unsupported, more details are available here http://goo.gl/RrCFmA")
|
||||
endif()
|
||||
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
|
||||
if(MINGW)
|
||||
set(Boost_LIBRARIES "${Boost_LIBRARIES};ws2_32;mswsock")
|
||||
endif()
|
||||
|
||||
set(COMMIT_ID_IN_VERSION ON CACHE BOOL "Include commit ID in version")
|
||||
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version")
|
||||
if (NOT COMMIT_ID_IN_VERSION)
|
||||
set(VERSION "${VERSION}-unknown")
|
||||
configure_file("src/version.h.in" "version/version.h")
|
||||
add_custom_target(version ALL)
|
||||
elseif(DEFINED COMMIT)
|
||||
string(REPLACE "." "\\." VERSION_RE "${VERSION}")
|
||||
if(NOT REFS MATCHES "(\\(|, )tag: v${VERSION_RE}(\\)|, )")
|
||||
set(VERSION "${VERSION}-g${COMMIT}")
|
||||
endif()
|
||||
configure_file("src/version.h.in" "version/version.h")
|
||||
add_custom_target(version ALL)
|
||||
else()
|
||||
find_package(Git QUIET)
|
||||
if(Git_FOUND)
|
||||
add_custom_target(version ALL "${CMAKE_COMMAND}" "-D" "VERSION=${VERSION}" "-D" "GIT=${GIT_EXECUTABLE}" "-D" "TO=${CMAKE_BINARY_DIR}/version/version.h" "-P" "src/version.cmake" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
|
||||
else()
|
||||
set(VERSION "${VERSION}-unknown")
|
||||
configure_file("src/version.h.in" "version/version.h")
|
||||
add_custom_target(version ALL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(tests)
|
20
LICENSE
20
LICENSE
|
@ -1,20 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Antonio Juarez
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,33 @@
|
|||
all: all-release
|
||||
|
||||
cmake-debug:
|
||||
mkdir -p build/debug
|
||||
cd build/debug && cmake -D CMAKE_BUILD_TYPE=Debug ../..
|
||||
|
||||
build-debug: cmake-debug
|
||||
cd build/debug && $(MAKE)
|
||||
|
||||
test-debug: build-debug
|
||||
cd build/debug && $(MAKE) test
|
||||
|
||||
all-debug: build-debug
|
||||
|
||||
cmake-release:
|
||||
mkdir -p build/release
|
||||
cd build/release && cmake -D CMAKE_BUILD_TYPE=Release ../..
|
||||
|
||||
build-release: cmake-release
|
||||
cd build/release && $(MAKE)
|
||||
|
||||
test-release: build-release
|
||||
cd build/release && $(MAKE) test
|
||||
|
||||
all-release: build-release
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
||||
tags:
|
||||
ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ src contrib tests/gtest
|
||||
|
||||
.PHONY: all cmake-debug build-debug test-debug all-debug cmake-release build-release test-release all-release clean tags
|
|
@ -0,0 +1,32 @@
|
|||
-= Building Cybernote =-
|
||||
|
||||
On *nix:
|
||||
|
||||
Dependencies: GCC 4.7 or later, CMake 2.8.6 or later, and Boost 1.53 or later (except 1.54, more details here: http://goo.gl/RrCFmA).
|
||||
You may download them from:
|
||||
http://gcc.gnu.org/
|
||||
http://www.cmake.org/
|
||||
http://www.boost.org/
|
||||
Alternatively, it may be possible to install them using a package manager.
|
||||
|
||||
To build, change to a directory where this file is located, and run `make'. The resulting executables can be found in build/release/src.
|
||||
|
||||
Advanced options:
|
||||
Parallel build: run `make -j<number of threads>' instead of `make'.
|
||||
Debug build: run `make build-debug'.
|
||||
Test suite: run `make test-release' to run tests in addition to building. Running `make test-debug' will do the same to the debug version.
|
||||
Building with Clang: it may be possible to use Clang instead of GCC, but this may not work everywhere. To build, run `export CC=clang CXX=clang++' before running `make'.
|
||||
|
||||
On Windows:
|
||||
Dependencies: MSVC 2012 or later, CMake 2.8.6 or later, and Boost 1.53 or later. You may download them from:
|
||||
http://www.microsoft.com/
|
||||
http://www.cmake.org/
|
||||
http://www.boost.org/
|
||||
|
||||
To build, change to a directory where this file is located, and run this commands:
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "Visual Studio 11 Win64" ..
|
||||
|
||||
And then do Build.
|
||||
Good luck!
|
|
@ -0,0 +1,25 @@
|
|||
Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Andrey N. Sabelnikov nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL Andrey N. Sabelnikov BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1 @@
|
|||
epee - is a small library of helpers, wrappers, tools and and so on, used to make my life easier.
|
|
@ -0,0 +1 @@
|
|||
/build/*
|
|
@ -0,0 +1,49 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
set(Boost_USE_MULTITHREADED ON)
|
||||
#set(Boost_DEBUG 1)
|
||||
find_package(Boost COMPONENTS system filesystem thread date_time chrono regex )
|
||||
|
||||
include_directories( ${Boost_INCLUDE_DIRS} )
|
||||
|
||||
|
||||
IF (MSVC)
|
||||
add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /nologo /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /bigobj" )
|
||||
ELSE()
|
||||
# set stuff for other systems
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-reorder -D_GNU_SOURCE")
|
||||
ENDIF()
|
||||
|
||||
|
||||
include_directories(.)
|
||||
include_directories(../include)
|
||||
include_directories(iface)
|
||||
|
||||
|
||||
# Add folders to filters
|
||||
file(GLOB_RECURSE LEVIN_GENERAL_SECTION RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/demo_levin_server/*.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/demo_levin_server/*.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/demo_levin_server/*.cpp)
|
||||
|
||||
file(GLOB_RECURSE HTTP_GENERAL_SECTION RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/demo_http_server/*.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/demo_http_server/*.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/demo_http_server/*.cpp)
|
||||
|
||||
|
||||
|
||||
source_group(general FILES ${LEVIN_GENERAL_SECTION} FILES ${HTTP_GENERAL_SECTION})
|
||||
#source_group(general FILES ${HTTP_GENERAL_SECTION})
|
||||
|
||||
add_executable(demo_http_server ${HTTP_GENERAL_SECTION} )
|
||||
add_executable(demo_levin_server ${LEVIN_GENERAL_SECTION} )
|
||||
|
||||
target_link_libraries( demo_http_server ${Boost_LIBRARIES} )
|
||||
target_link_libraries( demo_levin_server ${Boost_LIBRARIES} )
|
||||
|
||||
IF (NOT WIN32)
|
||||
target_link_libraries (demo_http_server rt)
|
||||
target_link_libraries (demo_levin_server rt)
|
||||
ENDIF()
|
||||
|
||||
|
|
@ -0,0 +1,217 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "console_handler.h"
|
||||
#include "demo_http_server.h"
|
||||
#include "net/http_client.h"
|
||||
#include "storages/http_abstract_invoke.h"
|
||||
|
||||
|
||||
template<class t_request, class t_response>
|
||||
bool communicate(const std::string url, t_request& req, t_response& rsp, const std::string& ip, const std::string& port, bool use_json, bool use_jrpc = false)
|
||||
{
|
||||
epee::net_utils::http::http_simple_client http_client;
|
||||
bool r = http_client.connect(ip, port, 1000);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to connect");
|
||||
if(use_json)
|
||||
{
|
||||
if(use_jrpc)
|
||||
{
|
||||
epee::json_rpc::request<t_request> req_t = AUTO_VAL_INIT(req_t);
|
||||
req_t.params = req;
|
||||
req_t.id = "10";
|
||||
req_t.method = "command_example_1";
|
||||
req_t.version = "1.1";
|
||||
epee::json_rpc::response<t_response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
|
||||
if(!epee::net_utils::invoke_http_json_remote_command2("/request_json_rpc", req_t, resp_t, http_client))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
rsp = resp_t.result;
|
||||
return true;
|
||||
}else
|
||||
return epee::net_utils::invoke_http_json_remote_command2(url, req, rsp, http_client);
|
||||
}
|
||||
else
|
||||
return epee::net_utils::invoke_http_bin_remote_command2(url, req, rsp, http_client);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
TRY_ENTRY();
|
||||
string_tools::set_module_name_and_folder(argv[0]);
|
||||
|
||||
//set up logging options
|
||||
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2);
|
||||
log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
|
||||
log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
log_space::log_singletone::get_default_log_file().c_str(),
|
||||
log_space::log_singletone::get_default_log_folder().c_str());
|
||||
|
||||
|
||||
|
||||
LOG_PRINT("Demo server starting ...", LOG_LEVEL_0);
|
||||
|
||||
|
||||
demo::demo_http_server srv;
|
||||
|
||||
start_default_console(&srv);
|
||||
|
||||
std::string bind_param = "0.0.0.0";
|
||||
std::string port = "83";
|
||||
|
||||
if(!srv.init(port, bind_param))
|
||||
{
|
||||
LOG_ERROR("Failed to initialize srv!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
//log loop
|
||||
srv.run();
|
||||
size_t count = 0;
|
||||
while (!srv.is_stop())
|
||||
{
|
||||
|
||||
demo::COMMAND_EXAMPLE_1::request req;
|
||||
req.sub = demo::get_test_data();
|
||||
demo::COMMAND_EXAMPLE_1::response rsp;
|
||||
bool r = false;
|
||||
if(count%2)
|
||||
{//invoke json
|
||||
r = communicate("/request_api_json_1", req, rsp, "127.0.0.1", port, true, true);
|
||||
}else{
|
||||
r = communicate("/request_api_bin_1", req, rsp, "127.0.0.1", port, false);
|
||||
}
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to invoke http request");
|
||||
CHECK_AND_ASSERT_MES(rsp.m_success, false, "wrong response");
|
||||
CHECK_AND_ASSERT_MES(rsp.subs.size()==1, false, "wrong response");
|
||||
CHECK_AND_ASSERT_MES(rsp.subs.front() == demo::get_test_data(), false, "wrong response");
|
||||
//misc_utils::sleep_no_w(1000);
|
||||
++count;
|
||||
}
|
||||
bool r = srv.wait_stop();
|
||||
CHECK_AND_ASSERT_MES(r, 1, "failed to wait server stop");
|
||||
srv.deinit();
|
||||
|
||||
LOG_PRINT("Demo server stoped.", LOG_LEVEL_0);
|
||||
return 1;
|
||||
|
||||
CATCH_ENTRY_L0("main", 1);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
namespace demo
|
||||
{
|
||||
bool demo_http_server::init(const std::string& bind_port, const std::string& bind_ip)
|
||||
{
|
||||
|
||||
|
||||
//set self as callback handler
|
||||
m_net_server.get_config_object().m_phandler = this;
|
||||
|
||||
//here set folder for hosting reqests
|
||||
m_net_server.get_config_object().m_folder = "";
|
||||
|
||||
LOG_PRINT_L0("Binding on " << bind_ip << ":" << bind_port);
|
||||
return m_net_server.init_server(bind_port, bind_ip);
|
||||
}
|
||||
|
||||
bool demo_http_server::run()
|
||||
{
|
||||
m_stop = false;
|
||||
//here you can set worker threads count
|
||||
int thrds_count = 4;
|
||||
|
||||
//go to loop
|
||||
LOG_PRINT("Run net_service loop( " << thrds_count << " threads)...", LOG_LEVEL_0);
|
||||
if(!m_net_server.run_server(thrds_count, false))
|
||||
{
|
||||
LOG_ERROR("Failed to run net tcp server!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool demo_http_server::deinit()
|
||||
{
|
||||
return m_net_server.deinit_server();
|
||||
}
|
||||
|
||||
bool demo_http_server::send_stop_signal()
|
||||
{
|
||||
m_stop = true;
|
||||
m_net_server.send_stop_signal();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool demo_http_server::on_requestr_uri_1(const net_utils::http::http_request_info& query_info,
|
||||
net_utils::http::http_response_info& response,
|
||||
const net_utils::connection_context_base& m_conn_context)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool demo_http_server::on_requestr_uri_2(const net_utils::http::http_request_info& query_info,
|
||||
net_utils::http::http_response_info& response,
|
||||
const net_utils::connection_context_base& m_conn_context)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool demo_http_server::on_hosting_request( const net_utils::http::http_request_info& query_info,
|
||||
net_utils::http::http_response_info& response,
|
||||
const net_utils::connection_context_base& m_conn_context)
|
||||
{
|
||||
//read file from filesystem here
|
||||
return true;
|
||||
}
|
||||
|
||||
bool demo_http_server::on_request_api_1(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(req.sub == demo::get_test_data(), false, "wrong request");
|
||||
res.m_success = true;
|
||||
res.subs.push_back(req.sub);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool demo_http_server::on_request_api_1_with_error(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res, epee::json_rpc::error& error_resp)
|
||||
{
|
||||
error_resp.code = 232432;
|
||||
error_resp.message = "bla bla bla";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool demo_http_server::on_request_api_2(const COMMAND_EXAMPLE_2::request& req, COMMAND_EXAMPLE_2::response& res)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "net/http_server_cp2.h"
|
||||
#include "transport_defs.h"
|
||||
#include "net/http_server_handlers_map2.h"
|
||||
|
||||
using namespace epee;
|
||||
|
||||
namespace demo
|
||||
{
|
||||
|
||||
class demo_http_server: public net_utils::http::i_http_server_handler
|
||||
{
|
||||
public:
|
||||
demo_http_server():m_stop(false){}
|
||||
bool run();
|
||||
bool init(const std::string& bind_port = "11112", const std::string& bind_ip = "0.0.0.0");
|
||||
bool deinit();
|
||||
bool send_stop_signal();
|
||||
bool is_stop(){return m_stop;}
|
||||
bool wait_stop(){return m_net_server.timed_wait_server_stop(100000);}
|
||||
private:
|
||||
|
||||
|
||||
CHAIN_HTTP_TO_MAP2(); //forward http requests to uri map
|
||||
|
||||
BEGIN_URI_MAP2()
|
||||
MAP_URI2("/requestr_uri_1", on_requestr_uri_1)
|
||||
MAP_URI2("/requestr_uri_2", on_requestr_uri_1)
|
||||
//MAP_URI_AUTO_XML2("/request_api_xml_1", on_request_api_1, COMMAND_EXAMPLE_1)
|
||||
//MAP_URI_AUTO_XML2("/request_api_xml_2", on_request_api_2, COMMAND_EXAMPLE_2)
|
||||
MAP_URI_AUTO_JON2("/request_api_json_1", on_request_api_1, COMMAND_EXAMPLE_1)
|
||||
MAP_URI_AUTO_JON2("/request_api_json_2", on_request_api_2, COMMAND_EXAMPLE_2)
|
||||
MAP_URI_AUTO_BIN2("/request_api_bin_1", on_request_api_1, COMMAND_EXAMPLE_1)
|
||||
MAP_URI_AUTO_BIN2("/request_api_bin_2", on_request_api_2, COMMAND_EXAMPLE_2)
|
||||
BEGIN_JSON_RPC_MAP("/request_json_rpc")
|
||||
MAP_JON_RPC("command_example_1", on_request_api_1, COMMAND_EXAMPLE_1)
|
||||
MAP_JON_RPC("command_example_2", on_request_api_2, COMMAND_EXAMPLE_2)
|
||||
MAP_JON_RPC_WE("command_example_1_we", on_request_api_1_with_error, COMMAND_EXAMPLE_1)
|
||||
END_JSON_RPC_MAP()
|
||||
CHAIN_URI_MAP2(on_hosting_request)
|
||||
END_URI_MAP2()
|
||||
|
||||
|
||||
|
||||
bool on_requestr_uri_1(const net_utils::http::http_request_info& query_info,
|
||||
net_utils::http::http_response_info& response,
|
||||
const net_utils::connection_context_base& m_conn_context);
|
||||
|
||||
|
||||
bool on_requestr_uri_2(const net_utils::http::http_request_info& query_info,
|
||||
net_utils::http::http_response_info& response,
|
||||
const net_utils::connection_context_base& m_conn_context);
|
||||
|
||||
|
||||
|
||||
|
||||
bool on_hosting_request( const net_utils::http::http_request_info& query_info,
|
||||
net_utils::http::http_response_info& response,
|
||||
const net_utils::connection_context_base& m_conn_context);
|
||||
|
||||
bool on_request_api_1(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res);
|
||||
bool on_request_api_2(const COMMAND_EXAMPLE_2::request& req, COMMAND_EXAMPLE_2::response& res);
|
||||
|
||||
bool on_request_api_1_with_error(const COMMAND_EXAMPLE_1::request& req, COMMAND_EXAMPLE_1::response& res, epee::json_rpc::error& error_resp);
|
||||
|
||||
net_utils::boosted_http_server_custum_handling m_net_server;
|
||||
std::atomic<bool> m_stop;
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// demo_http_server.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define BOOST_FILESYSTEM_VERSION 3
|
||||
#define ENABLE_RELEASE_LOGGING
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
// The following macros define the minimum required platform. The minimum required platform
|
||||
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
|
||||
// your application. The macros work by enabling all features available on platform versions up to and
|
||||
// including the version specified.
|
||||
|
||||
// Modify the following defines if you have to target a platform prior to the ones specified below.
|
||||
// Refer to MSDN for the latest info on corresponding values for different platforms.
|
||||
#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
|
||||
#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "demo_levin_server.h"
|
||||
#include "console_handler.h"
|
||||
|
||||
|
||||
template<class t_request>
|
||||
bool communicate(net_utils::boosted_levin_async_server& transport, int id, t_request& req, const std::string& ip, const std::string& port, bool use_async)
|
||||
{
|
||||
if(use_async)
|
||||
{
|
||||
//IMPORTANT: do not pass local parameters from stack by reference! connect_async returns immediately, and callback will call in any thread later
|
||||
transport.connect_async(ip, port, 10000, [&transport, id, req, ip, port](net_utils::connection_context_base& ctx, const boost::system::error_code& ec_)
|
||||
{
|
||||
if(!!ec_)
|
||||
{
|
||||
LOG_ERROR("Failed to connect to " << ip << ":" << port);
|
||||
}else
|
||||
{//connected ok!
|
||||
|
||||
epee::net_utils::async_invoke_remote_command2<demo::COMMAND_EXAMPLE_1::response>(ctx.m_connection_id, id, req, transport.get_config_object(), [&transport, ip, port](int res_code, demo::COMMAND_EXAMPLE_1::response& rsp, net_utils::connection_context_base& ctx)
|
||||
{
|
||||
if(res_code < 0)
|
||||
{
|
||||
LOG_ERROR("Failed to invoke to " << ip << ":" << port);
|
||||
}else
|
||||
{//invoked ok
|
||||
CHECK_AND_ASSERT_MES(rsp.m_success, false, "wrong response");
|
||||
CHECK_AND_ASSERT_MES(rsp.subs.size()==1, false, "wrong response");
|
||||
CHECK_AND_ASSERT_MES(rsp.subs.front() == demo::get_test_data(), false, "wrong response");
|
||||
LOG_PRINT_GREEN("Client COMMAND_EXAMPLE_1 async invoked ok", LOG_LEVEL_0);
|
||||
}
|
||||
transport.get_config_object().close(ctx.m_connection_id);
|
||||
return true;
|
||||
});
|
||||
LOG_PRINT_GREEN("Client COMMAND_EXAMPLE_1 async invoke requested", LOG_LEVEL_0);
|
||||
}
|
||||
});
|
||||
}else
|
||||
{
|
||||
net_utils::connection_context_base ctx = AUTO_VAL_INIT(ctx);
|
||||
bool r = transport.connect(ip, port, 10000, ctx);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to connect to " << ip << ":" << port);
|
||||
demo::COMMAND_EXAMPLE_1::response rsp = AUTO_VAL_INIT(rsp);
|
||||
LOG_PRINT_GREEN("Client COMMAND_EXAMPLE_1 sync invoke requested", LOG_LEVEL_0);
|
||||
r = epee::net_utils::invoke_remote_command2(ctx.m_connection_id, id, req, rsp, transport.get_config_object());
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to invoke levin request");
|
||||
CHECK_AND_ASSERT_MES(rsp.m_success, false, "wrong response");
|
||||
CHECK_AND_ASSERT_MES(rsp.subs.size()==1, false, "wrong response");
|
||||
CHECK_AND_ASSERT_MES(rsp.subs.front() == demo::get_test_data(), false, "wrong response");
|
||||
transport.get_config_object().close(ctx.m_connection_id);
|
||||
LOG_PRINT_GREEN("Client COMMAND_EXAMPLE_1 sync invoked ok", LOG_LEVEL_0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
TRY_ENTRY();
|
||||
string_tools::set_module_name_and_folder(argv[0]);
|
||||
|
||||
//set up logging options
|
||||
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2);
|
||||
log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
|
||||
log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
log_space::log_singletone::get_default_log_file().c_str(),
|
||||
log_space::log_singletone::get_default_log_folder().c_str());
|
||||
|
||||
|
||||
|
||||
LOG_PRINT("Demo server starting ...", LOG_LEVEL_0);
|
||||
|
||||
|
||||
demo::demo_levin_server srv;
|
||||
|
||||
start_default_console(&srv);
|
||||
|
||||
std::string bind_param = "0.0.0.0";
|
||||
std::string port = "12345";
|
||||
|
||||
if(!srv.init(port, bind_param))
|
||||
{
|
||||
LOG_ERROR("Failed to initialize srv!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
srv.run();
|
||||
|
||||
size_t c = 1;
|
||||
while (!srv.is_stop())
|
||||
{
|
||||
|
||||
demo::COMMAND_EXAMPLE_1::request req;
|
||||
req.sub = demo::get_test_data();
|
||||
bool r = communicate(srv.get_server(), demo::COMMAND_EXAMPLE_1::ID, req, "127.0.0.1", port, (c%2 == 0));
|
||||
misc_utils::sleep_no_w(1000);
|
||||
++c;
|
||||
}
|
||||
bool r = srv.wait_stop();
|
||||
CHECK_AND_ASSERT_MES(r, 1, "failed to wait server stop");
|
||||
|
||||
|
||||
srv.deinit();
|
||||
|
||||
LOG_PRINT("Demo server stoped.", LOG_LEVEL_0);
|
||||
return 1;
|
||||
|
||||
CATCH_ENTRY_L0("main", 1);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
namespace demo
|
||||
{
|
||||
bool demo_levin_server::init(const std::string& bind_port, const std::string& bind_ip)
|
||||
{
|
||||
m_net_server.get_config_object().m_pcommands_handler = this;
|
||||
LOG_PRINT_L0("Binding on " << bind_ip << ":" << bind_port);
|
||||
return m_net_server.init_server(bind_port, bind_ip);
|
||||
}
|
||||
|
||||
bool demo_levin_server::run()
|
||||
{
|
||||
m_stop = false;
|
||||
//here you can set worker threads count
|
||||
int thrds_count = 4;
|
||||
m_net_server.get_config_object().m_invoke_timeout = 10000;
|
||||
m_net_server.get_config_object().m_pcommands_handler = this;
|
||||
|
||||
//go to loop
|
||||
LOG_PRINT("Run net_service loop( " << thrds_count << " threads)...", LOG_LEVEL_0);
|
||||
if(!m_net_server.run_server(thrds_count, false))
|
||||
{
|
||||
LOG_ERROR("Failed to run net tcp server!");
|
||||
}
|
||||
|
||||
LOG_PRINT("net_service loop stopped.", LOG_LEVEL_0);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool demo_levin_server::deinit()
|
||||
{
|
||||
return m_net_server.deinit_server();
|
||||
}
|
||||
|
||||
bool demo_levin_server::send_stop_signal()
|
||||
{
|
||||
m_net_server.send_stop_signal();
|
||||
return true;
|
||||
}
|
||||
int demo_levin_server::handle_command_1(int command, COMMAND_EXAMPLE_1::request& arg, COMMAND_EXAMPLE_1::response& rsp, const net_utils::connection_context_base& context)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(arg.sub == demo::get_test_data(), false, "wrong request");
|
||||
rsp.m_success = true;
|
||||
rsp.subs.push_back(arg.sub);
|
||||
LOG_PRINT_GREEN("Server COMMAND_EXAMPLE_1 ok", LOG_LEVEL_0);
|
||||
return 1;
|
||||
}
|
||||
int demo_levin_server::handle_command_2(int command, COMMAND_EXAMPLE_2::request& arg, COMMAND_EXAMPLE_2::response& rsp, const net_utils::connection_context_base& context)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int demo_levin_server::handle_notify_1(int command, COMMAND_EXAMPLE_1::request& arg, const net_utils::connection_context_base& context)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int demo_levin_server::handle_notify_2(int command, COMMAND_EXAMPLE_2::request& arg, const net_utils::connection_context_base& context)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "net/levin_server_cp2.h"
|
||||
#include "transport_defs.h"
|
||||
#include "storages/levin_abstract_invoke2.h"
|
||||
|
||||
using namespace epee;
|
||||
|
||||
namespace demo
|
||||
{
|
||||
|
||||
class demo_levin_server: public levin::levin_commands_handler<>
|
||||
{
|
||||
public:
|
||||
bool run();
|
||||
bool init(const std::string& bind_port = "11112", const std::string& bind_ip = "0.0.0.0");
|
||||
bool deinit();
|
||||
bool send_stop_signal();
|
||||
bool is_stop(){return m_stop;}
|
||||
bool wait_stop(){return m_net_server.timed_wait_server_stop(100000);}
|
||||
net_utils::boosted_levin_async_server& get_server(){return m_net_server;}
|
||||
private:
|
||||
|
||||
|
||||
CHAIN_LEVIN_INVOKE_MAP(); //move levin_commands_handler interface invoke(...) callbacks into invoke map
|
||||
CHAIN_LEVIN_NOTIFY_STUB(); //move levin_commands_handler interface notify(...) callbacks into nothing
|
||||
|
||||
BEGIN_INVOKE_MAP2(demo_levin_server)
|
||||
HANDLE_INVOKE_T2(COMMAND_EXAMPLE_1, &demo_levin_server::handle_command_1)
|
||||
HANDLE_INVOKE_T2(COMMAND_EXAMPLE_2, &demo_levin_server::handle_command_2)
|
||||
HANDLE_NOTIFY_T2(COMMAND_EXAMPLE_1, &demo_levin_server::handle_notify_1)
|
||||
HANDLE_NOTIFY_T2(COMMAND_EXAMPLE_2, &demo_levin_server::handle_notify_2)
|
||||
END_INVOKE_MAP2()
|
||||
|
||||
//----------------- commands handlers ----------------------------------------------
|
||||
int handle_command_1(int command, COMMAND_EXAMPLE_1::request& arg, COMMAND_EXAMPLE_1::response& rsp, const net_utils::connection_context_base& context);
|
||||
int handle_command_2(int command, COMMAND_EXAMPLE_2::request& arg, COMMAND_EXAMPLE_2::response& rsp, const net_utils::connection_context_base& context);
|
||||
int handle_notify_1(int command, COMMAND_EXAMPLE_1::request& arg, const net_utils::connection_context_base& context);
|
||||
int handle_notify_2(int command, COMMAND_EXAMPLE_2::request& arg, const net_utils::connection_context_base& context);
|
||||
//----------------------------------------------------------------------------------
|
||||
net_utils::boosted_levin_async_server m_net_server;
|
||||
std::atomic<bool> m_stop;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define BOOST_FILESYSTEM_VERSION 3
|
||||
#define ENABLE_RELEASE_LOGGING
|
||||
#include "log_opt_defs.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
// The following macros define the minimum required platform. The minimum required platform
|
||||
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
|
||||
// your application. The macros work by enabling all features available on platform versions up to and
|
||||
// including the version specified.
|
||||
|
||||
// Modify the following defines if you have to target a platform prior to the ones specified below.
|
||||
// Refer to MSDN for the latest info on corresponding values for different platforms.
|
||||
#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
|
||||
#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
#cmake -DBOOST_ROOT=/usr/local/proj/boost_1_49_0 -DBOOST_LIBRARYDIR=/usr/local/proj/boost_1_49_0/stage/lib ..
|
|
@ -0,0 +1,7 @@
|
|||
mkdir build
|
||||
|
||||
cd build
|
||||
|
||||
cmake "-DBoost_USE_STATIC_LIBS=TRUE" -G "Visual Studio 11 Win64" ..
|
||||
cd ..
|
||||
pause
|
|
@ -0,0 +1,213 @@
|
|||
#pragma once
|
||||
|
||||
#include "serialization/keyvalue_serialization.h"
|
||||
|
||||
|
||||
namespace demo
|
||||
{
|
||||
|
||||
struct some_test_subdata
|
||||
{
|
||||
std::string m_str;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(m_str)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct some_test_data
|
||||
{
|
||||
std::string m_str;
|
||||
uint64_t m_uint64;
|
||||
uint32_t m_uint32;
|
||||
uint16_t m_uint16;
|
||||
uint8_t m_uint8;
|
||||
int64_t m_int64;
|
||||
int32_t m_int32;
|
||||
int16_t m_int16;
|
||||
int8_t m_int8;
|
||||
double m_double;
|
||||
bool m_bool;
|
||||
std::list<std::string> m_list_of_str;
|
||||
std::list<uint64_t> m_list_of_uint64_t;
|
||||
std::list<uint32_t> m_list_of_uint32_t;
|
||||
std::list<uint16_t> m_list_of_uint16_t;
|
||||
std::list<uint8_t> m_list_of_uint8_t;
|
||||
std::list<int64_t> m_list_of_int64_t;
|
||||
std::list<int32_t> m_list_of_int32_t;
|
||||
std::list<int16_t> m_list_of_int16_t;
|
||||
std::list<int8_t> m_list_of_int8_t;
|
||||
std::list<double> m_list_of_double;
|
||||
std::list<bool> m_list_of_bool;
|
||||
some_test_subdata m_subobj;
|
||||
std::list<some_test_data> m_list_of_self;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(m_str)
|
||||
KV_SERIALIZE(m_uint64)
|
||||
KV_SERIALIZE(m_uint32)
|
||||
KV_SERIALIZE(m_uint16)
|
||||
KV_SERIALIZE(m_uint8)
|
||||
KV_SERIALIZE(m_int64)
|
||||
KV_SERIALIZE(m_int32)
|
||||
KV_SERIALIZE(m_int16)
|
||||
KV_SERIALIZE(m_int8)
|
||||
KV_SERIALIZE(m_double)
|
||||
KV_SERIALIZE(m_bool)
|
||||
KV_SERIALIZE(m_subobj)
|
||||
KV_SERIALIZE(m_list_of_str)
|
||||
KV_SERIALIZE(m_list_of_uint64_t)
|
||||
KV_SERIALIZE(m_list_of_uint32_t)
|
||||
KV_SERIALIZE(m_list_of_uint16_t)
|
||||
KV_SERIALIZE(m_list_of_uint8_t)
|
||||
KV_SERIALIZE(m_list_of_int64_t)
|
||||
KV_SERIALIZE(m_list_of_int32_t)
|
||||
KV_SERIALIZE(m_list_of_int16_t)
|
||||
KV_SERIALIZE(m_list_of_int8_t)
|
||||
KV_SERIALIZE(m_list_of_double)
|
||||
KV_SERIALIZE(m_list_of_bool)
|
||||
KV_SERIALIZE(m_list_of_self)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
struct COMMAND_EXAMPLE_1
|
||||
{
|
||||
const static int ID = 1000;
|
||||
|
||||
struct request
|
||||
{
|
||||
std::string example_string_data;
|
||||
some_test_data sub;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(example_string_data)
|
||||
KV_SERIALIZE(sub)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
struct response
|
||||
{
|
||||
bool m_success;
|
||||
std::list<some_test_data> subs;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(m_success)
|
||||
KV_SERIALIZE(subs)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct COMMAND_EXAMPLE_2
|
||||
{
|
||||
const static int ID = 1001;
|
||||
|
||||
struct request
|
||||
{
|
||||
std::string example_string_data2;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(example_string_data2)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
bool m_success;
|
||||
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(m_success)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------------------
|
||||
//in debug purpose
|
||||
bool operator != (const some_test_subdata& a, const some_test_subdata& b)
|
||||
{
|
||||
return b.m_str != a.m_str;
|
||||
}
|
||||
|
||||
bool operator == (const some_test_data& a, const some_test_data& b)
|
||||
{
|
||||
if( b.m_str != a.m_str
|
||||
|| b.m_uint64 != a.m_uint64
|
||||
|| b.m_uint32 != a.m_uint32
|
||||
|| b.m_uint16 != a.m_uint16
|
||||
|| b.m_uint8 != a.m_uint8
|
||||
|| b.m_int64 != a.m_int64
|
||||
|| b.m_int32 != a.m_int32
|
||||
|| b.m_int16 != a.m_int16
|
||||
|| b.m_int8 != a.m_int8
|
||||
|| b.m_double != a.m_double
|
||||
|| b.m_bool != a.m_bool
|
||||
|| b.m_list_of_str != a.m_list_of_str
|
||||
|| b.m_list_of_uint64_t != a.m_list_of_uint64_t
|
||||
|| b.m_list_of_uint32_t != a.m_list_of_uint32_t
|
||||
|| b.m_list_of_uint16_t != a.m_list_of_uint16_t
|
||||
|| b.m_list_of_uint8_t != a.m_list_of_uint8_t
|
||||
|| b.m_list_of_int64_t != a.m_list_of_int64_t
|
||||
|| b.m_list_of_int32_t != a.m_list_of_int32_t
|
||||
|| b.m_list_of_int16_t != a.m_list_of_int16_t
|
||||
|| b.m_list_of_int8_t != a.m_list_of_int8_t
|
||||
|| b.m_list_of_double != a.m_list_of_double
|
||||
|| b.m_list_of_bool != a.m_list_of_bool
|
||||
|| b.m_subobj != a.m_subobj
|
||||
|| b.m_list_of_self != a.m_list_of_self
|
||||
)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline some_test_data get_test_data()
|
||||
{
|
||||
some_test_data s;
|
||||
s.m_str = "zuzuzuzuzuz";
|
||||
s.m_uint64 = 111111111111111;
|
||||
s.m_uint32 = 2222222;
|
||||
s.m_uint16 = 2222;
|
||||
s.m_uint8 = 22;
|
||||
s.m_int64 = -111111111111111;
|
||||
s.m_int32 = -2222222;
|
||||
s.m_int16 = -2222;
|
||||
s.m_int8 = -24;
|
||||
s.m_double = 0.11111;
|
||||
s.m_bool = true;
|
||||
s.m_list_of_str.push_back("1112121");
|
||||
s.m_list_of_uint64_t.push_back(1111111111);
|
||||
s.m_list_of_uint64_t.push_back(2222222222);
|
||||
s.m_list_of_uint32_t.push_back(1111111);
|
||||
s.m_list_of_uint32_t.push_back(2222222);
|
||||
s.m_list_of_uint16_t.push_back(1111);
|
||||
s.m_list_of_uint16_t.push_back(2222);
|
||||
s.m_list_of_uint8_t.push_back(11);
|
||||
s.m_list_of_uint8_t.push_back(22);
|
||||
|
||||
|
||||
s.m_list_of_int64_t.push_back(-1111111111);
|
||||
s.m_list_of_int64_t.push_back(-222222222);
|
||||
s.m_list_of_int32_t.push_back(-1111111);
|
||||
s.m_list_of_int32_t.push_back(-2222222);
|
||||
s.m_list_of_int16_t.push_back(-1111);
|
||||
s.m_list_of_int16_t.push_back(-2222);
|
||||
s.m_list_of_int8_t.push_back(-11);
|
||||
s.m_list_of_int8_t.push_back(-22);
|
||||
|
||||
s.m_list_of_double.push_back(0.11111);
|
||||
s.m_list_of_double.push_back(0.22222);
|
||||
s.m_list_of_bool.push_back(true);
|
||||
s.m_list_of_bool.push_back(false);
|
||||
|
||||
s.m_subobj.m_str = "subszzzzzzzz";
|
||||
s.m_list_of_self.push_back(s);
|
||||
return s;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,310 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace epee
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
template<class t_server>
|
||||
bool empty_commands_handler(t_server* psrv, const std::string& command)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class t_server, class chain_handler>
|
||||
bool default_console_handler(t_server* psrv, chain_handler ch_handler, const std::string usage = "")
|
||||
{
|
||||
TRY_ENTRY();
|
||||
bool continue_handle = true;
|
||||
while(continue_handle)
|
||||
{
|
||||
char command_buff[400] = {0};
|
||||
std::string command;
|
||||
std::cin.getline(command_buff, 399);
|
||||
if(std::cin.eof() || std::cin.fail())
|
||||
{
|
||||
LOG_PRINT("std::cin.eof() or std::cin.fail(), stopping...", LOG_LEVEL_0);
|
||||
continue_handle = false;
|
||||
break;
|
||||
}
|
||||
command = command_buff;
|
||||
|
||||
if(!command.compare("exit") || !command.compare("q") )
|
||||
{
|
||||
psrv->send_stop_signal();
|
||||
continue_handle = false;
|
||||
}else if ( !command.compare(0, 7, "set_log"))
|
||||
{
|
||||
//parse set_log command
|
||||
if(command.size() != 9)
|
||||
{
|
||||
std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
|
||||
continue;
|
||||
}
|
||||
int n = 0;
|
||||
if(!string_tools::get_xtype_from_string(n, command.substr(8, 1)))
|
||||
{
|
||||
std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
|
||||
continue;
|
||||
}
|
||||
log_space::get_set_log_detalisation_level(true, n);
|
||||
LOG_PRINT_L0("New log level set " << n);
|
||||
}
|
||||
else if(ch_handler(psrv, command))
|
||||
continue;
|
||||
else
|
||||
{
|
||||
std::cout << "unknown command: " << command << std::endl;
|
||||
std::cout << usage;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
CATCH_ENTRY_L0("console_handler", false);
|
||||
}
|
||||
|
||||
template<class chain_handler>
|
||||
bool default_console_handler2(chain_handler ch_handler, const std::string usage)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
bool continue_handle = true;
|
||||
while(continue_handle)
|
||||
{
|
||||
char command_buff[400] = {0};
|
||||
std::string command;
|
||||
std::cin.getline(command_buff, 399);
|
||||
if(std::cin.eof() || std::cin.fail())
|
||||
{
|
||||
|
||||
LOG_PRINT("std::cin.eof() or std::cin.fail(), stopping...", LOG_LEVEL_0);
|
||||
continue_handle = false;
|
||||
break;
|
||||
}
|
||||
command = command_buff;
|
||||
|
||||
if(!command.compare("exit") || !command.compare("q") )
|
||||
{
|
||||
continue_handle = false;
|
||||
}else if ( !command.compare(0, 7, "set_log"))
|
||||
{
|
||||
//parse set_log command
|
||||
if(command.size() != 9)
|
||||
{
|
||||
std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
|
||||
continue;
|
||||
}
|
||||
int n = 0;
|
||||
if(!string_tools::get_xtype_from_string(n, command.substr(8, 1)))
|
||||
{
|
||||
std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
|
||||
continue;
|
||||
}
|
||||
log_space::get_set_log_detalisation_level(true, n);
|
||||
LOG_PRINT_L0("New log level set " << n);
|
||||
}
|
||||
else if(ch_handler(command))
|
||||
continue;
|
||||
else
|
||||
{
|
||||
std::cout << "unknown command: " << command << std::endl;
|
||||
std::cout << usage;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
CATCH_ENTRY_L0("console_handler", false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class t_server, class t_handler>
|
||||
bool start_default_console(t_server* ptsrv, t_handler handlr, const std::string& usage = "")
|
||||
{
|
||||
boost::thread( boost::bind(default_console_handler<t_server, t_handler>, ptsrv, handlr, usage) );
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class t_server>
|
||||
bool start_default_console(t_server* ptsrv, const std::string& usage = "")
|
||||