Add google flags in preparation for deleting old logger.

Summary: Implement gflags and add optional port.

Reviewers: buda, teon.banek

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D391
This commit is contained in:
Dominik Gleich 2017-05-22 12:31:04 +02:00
parent 04670f7328
commit a2d3577f0f
4 changed files with 24 additions and 9 deletions

View File

@ -371,7 +371,7 @@ target_link_libraries(memgraph_lib stdc++fs)
add_dependencies(memgraph_lib generate_opencypher_parser
generate_plan_compiler_flags)
# executables that require memgraph_lib should link MEMGRAPH_ALL_LIBS to link all dependant libraries
set(MEMGRAPH_ALL_LIBS memgraph_lib stdc++fs Threads::Threads fmt yaml-cpp antlr_opencypher_parser_lib dl)
set(MEMGRAPH_ALL_LIBS gflags memgraph_lib stdc++fs Threads::Threads fmt yaml-cpp antlr_opencypher_parser_lib dl)
if (READLINE_FOUND)
list(APPEND MEMGRAPH_ALL_LIBS ${READLINE_LIBRARY})
endif()

View File

@ -16,6 +16,10 @@ add_subdirectory(fmt)
# setup google test
add_subdirectory(googletest)
# setup google flags
set(BUILD_gflags_LIB ON)
add_subdirectory(gflags)
# setup yaml cpp
# disable tests because yaml doesn't have MASTER_PROJECT flag like fmt has
# to override an option use option :)

View File

@ -53,3 +53,10 @@ lcov_to_xml_tag="59584761cb5da4687693faec05bf3e2b74e9dde9" # Dec 6, 2016
cd lcov-to-cobertura-xml
git checkout ${lcov_to_xml_tag}
cd ..
# google flags
git clone https://github.com/gflags/gflags.git
gflags_tag="652651b421ca5ac7b722a34a301fb656deca5198" # May 6, 2017
cd gflags
git checkout ${gflags_tag}
cd ..

View File

@ -1,6 +1,8 @@
#include <signal.h>
#include <iostream>
#include "gflags/gflags.h"
#include "dbms/dbms.hpp"
#include "query/engine.hpp"
@ -22,8 +24,9 @@
using endpoint_t = io::network::NetworkEndpoint;
using socket_t = io::network::Socket;
using session_t = communication::bolt::Session<socket_t>;
using result_stream_t = communication::bolt::ResultStream<
communication::bolt::Encoder<communication::bolt::ChunkedEncoderBuffer<socket_t>>>;
using result_stream_t =
communication::bolt::ResultStream<communication::bolt::Encoder<
communication::bolt::ChunkedEncoderBuffer<socket_t>>>;
using bolt_server_t =
communication::Server<session_t, result_stream_t, socket_t>;
@ -31,9 +34,8 @@ static bolt_server_t *serverptr;
Logger logger;
// TODO: load from config
static constexpr const char *interface = "0.0.0.0";
static constexpr const char *port = "7687";
DEFINE_string(interface, "0.0.0.0", "Default interface on which to listen.");
DEFINE_string(port, "7687", "Default port on which to listen.");
void throw_and_stacktace(std::string message) {
Stacktrace stacktrace;
@ -41,6 +43,7 @@ void throw_and_stacktace(std::string message) {
}
int main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
// logging init
#ifdef SYNC_LOGGER
logging::init_sync();
@ -76,7 +79,7 @@ int main(int argc, char **argv) {
// initialize endpoint
endpoint_t endpoint;
try {
endpoint = endpoint_t(interface, port);
endpoint = endpoint_t(FLAGS_interface, FLAGS_port);
} catch (io::network::NetworkEndpointException &e) {
logger.error("{}", e.what());
std::exit(EXIT_FAILURE);
@ -85,7 +88,8 @@ int main(int argc, char **argv) {
// initialize socket
socket_t socket;
if (!socket.Bind(endpoint)) {
logger.error("Cannot bind to socket on {} at {}", interface, port);
logger.error("Cannot bind to socket on {} at {}", FLAGS_interface,
FLAGS_port);
std::exit(EXIT_FAILURE);
}
if (!socket.SetNonBlocking()) {
@ -97,7 +101,7 @@ int main(int argc, char **argv) {
std::exit(EXIT_FAILURE);
}
logger.info("Listening on {} at {}", interface, port);
logger.info("Listening on {} at {}", FLAGS_interface, FLAGS_port);
Dbms dbms;
QueryEngine<result_stream_t> query_engine;