Commit fb67f591 authored by Micha Mueller's avatar Micha Mueller
Browse files

Fixes not compiling Server mock-up

parent fc82d78b
......@@ -11,9 +11,9 @@ DISTFILES_HASHES = bacnet-stack-0.8.5.tgz|66b69111d91432fa67a7c6c1a653434d;freei
include $(DCDBCOREPATH)/common.mk
CXXFLAGS = -std=c++11 -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG -O2 -g -Wall -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-variable -DBOOST_LOG_DYN_LINK -I$(DCDBBASEPATH)/dcdb/include -I$(DCDBDEPLOYPATH)/include -I$(DCDBDEPSPATH)/cpp-netlib-0.12.0-final/deps/asio/asio/include -I$(DCDBDEPSPATH)/cpp-netlib-0.12.0-final -I$(DCDBDEPSPATH)/cpp-netlib-0.12.0-final/deps/cxxopts/src
CXXFLAGS = -std=c++11 -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG -O2 -g -Wall -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-variable -DBOOST_LOG_DYN_LINK -I$(DCDBBASEPATH)/dcdb/include -I$(DCDBDEPLOYPATH)/include -I$(DCDBDEPSPATH)/cpp-netlib-0.12.0-final/deps/asio/asio/include
LIBS = -L../deps/mosquitto_build/lib -L$(DCDBDEPLOYPATH)/lib/ -ldl -lmosquitto -lboost_system -lboost_thread -lboost_log_setup -lboost_log -lpthread -rdynamic
LIBS = -L../deps/mosquitto_build/lib -L$(DCDBDEPLOYPATH)/lib/ -ldl -lmosquitto -lboost_system -lboost_thread -lboost_log_setup -lboost_log -lpthread -lcppnetlib-server-parsers -rdynamic
OBJS = src/dcdbpusher.o src/Configuration.o src/Sensor.o src/MQTTPusher.o src/HttpsServer.o
PLUGINS_BASE = libdcdbplugin_pdu libdcdbplugin_sysfs libdcdbplugin_ipmi libdcdbplugin_bacnet
......
......@@ -8,25 +8,22 @@
#include "HttpsServer.h"
#include <iostream>
struct HttpsServer::requestHandler {
void operator()(server::request const &request, server::connection_ptr connection) {
server::string_type ip = source(request);
unsigned int port = request.source_port;
std::ostringstream data;
server::response_header headers[] = { {"Connection", "close"}, {"Content-Type", "text/plain"} };
data << "Hello, " << ip << ':' << port << '!';
connection->set_status(server::connection::ok);
connection->set_headers(boost::make_iterator_range(headers, headers + 2));
connection->write(data.str());
//response = server::response::stock_reply(server::response::ok, data.str());
}
void log(const server::string_type& message) {
LOG(error) << message;
}
};
void HttpsServer::requestHandler::operator()(server::request const &request, server::connection_ptr connection) {
server::string_type ip = source(request);
unsigned int port = request.source_port;
std::ostringstream data;
server::response_header headers[] = { {"Connection", "close"}, {"Content-Type", "text/plain"} };
data << "Hello, " << ip << ':' << port << '!' << std::endl;
connection->set_status(server::connection::ok);
connection->set_headers(boost::make_iterator_range(headers, headers + 2));
connection->write(data.str());
}
void HttpsServer::requestHandler::log(const server::string_type& message) {
LOG(error) << message;
}
HttpsServer::HttpsServer(const std::string& host, const std::string& port,
pluginVector_t& plugins) :
......
......@@ -8,19 +8,17 @@
#ifndef HTTPSSERVER_H_
#define HTTPSSERVER_H_
//Caution: include order matters! server.hpp needs to be included first
#include <boost/network/protocol/http/server.hpp>
#include "Configuration.h"
#include "Logging.h"
#include <boost/network/protocol/http/server.hpp>
/*
* Provides REST API services over configurable host and port.
*/
class HttpsServer {
struct requestHandler;
typedef boost::network::http::server<requestHandler> server;
public:
HttpsServer(const std::string& host, const std::string& port,
pluginVector_t& plugins);
......@@ -36,6 +34,17 @@ public:
private:
struct requestHandler;
typedef boost::network::http::server<requestHandler> server;
struct requestHandler {
void operator()(server::request const &request, server::connection_ptr connection);
void log(const server::string_type& message);
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
};
std::string _host;
std::string _port;
pluginVector_t& _plugins;
......
......@@ -28,10 +28,11 @@
#include <functional>
#include <string>
//Caution: include order matters! HttpsServer.h needs to be included first
#include "HttpsServer.h"
#include "Sensor.h"
#include "Configuration.h"
#include "MQTTPusher.h"
#include "HttpsServer.h"
#include <boost/foreach.hpp>
#include <boost/asio.hpp>
......@@ -48,7 +49,6 @@ using namespace std;
volatile int keepRunning;
pluginVector_t plugins;
HttpsServer httpsServer;
void sigintHandler(int sig) {
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
......@@ -64,8 +64,6 @@ void sigintHandler(int sig) {
LOG(info) << "Flushing MQTT queues...";
//Stop MQTTPusher
keepRunning = 0;
//Stop https server
httpsServer.stop();
}
void sigtermHandler(int sig) {
......@@ -326,7 +324,7 @@ int main(int argc, char** argv) {
//MQTTPusher and Https server get their own threads
MQTTPusher mqttPusher(globalSettings.brokerPort, globalSettings.brokerHost, globalSettings.mqttPrefix, plugins);
httpsServer(globalSettings.restHost, globalSettings.restPort, plugins);
HttpsServer httpsServer(globalSettings.restHost, globalSettings.restPort, plugins);
boost::thread mqttThread(bind(&MQTTPusher::push, &mqttPusher));
boost::thread restThread(bind(&HttpsServer::run, &httpsServer));
......@@ -338,8 +336,12 @@ int main(int argc, char** argv) {
//Run until Strg+C
mqttThread.join();
restThread.join();
threads.join_all();
//Stop https server
LOG(info) << "Stopping REST API Server...";
httpsServer.stop();
restThread.join();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment