wip in progress.

This commit is contained in:
NADAL Jean-Baptiste
2019-12-11 18:57:59 +01:00
parent 214b09e6d3
commit bde9ffd991
9 changed files with 309 additions and 35 deletions

View File

@@ -3,29 +3,41 @@ cmake_minimum_required(VERSION 3.0)
project(domo-iot)
set (CMAKE_MODULE_PATH "${MODULE_PATH}")
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD 14)
link_directories(${CMAKE_SOURCE_DIR}/build/lib)
include_directories(${CMAKE_SOURCE_DIR}/../nats.c/src)
include_directories(${CMAKE_SOURCE_DIR}/../libuv/include)
include_directories(${CMAKE_SOURCE_DIR}/build/libwebsockets/include)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/../libsourcey/src/base/include)
include_directories(${CMAKE_SOURCE_DIR}/../libsourcey/src/net/include)
include_directories(${CMAKE_SOURCE_DIR}/../libsourcey/vendor/libuv/include/)
include_directories(${CMAKE_SOURCE_DIR}/build)
#include_directories(${CMAKE_SOURCE_DIR}/libhttp/vendor/http-parser)
#set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Werror=strict-aliasing")
file(
GLOB_RECURSE
source_files
main.c
main.cpp
server/domo-server.cpp
broker/nats-broker.cpp
http/http-server.cpp
)
#http/http-server.cpp
add_executable (domo-iot ${source_files})
target_link_libraries (domo-iot
LINK_PUBLIC
nats_static
websockets
uv_a
rt
libuv
libscy_base.a
libscy_http.a
libscy_net.a
pthread
)
install (TARGETS domo-iot DESTINATION local/bin)

62
src/http/http-server.cpp Normal file
View File

@@ -0,0 +1,62 @@
/*!
* http-server.cpp
*
* Copyright (c) 2015-2019, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 13/11/2019
*
*/
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
/*------------------------------- INCLUDES ----------------------------------*/
#include <string.h>
#include "http-server.h"
/*! ----------------------------------------------------------------------------
* @fn HttpServer
*
* @brief Constructor of the HTTP Server Object.
*/
HttpServer::HttpServer(void)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~HttpServer
*
* @brief Destructor of the HTTP Server Object.
*/
HttpServer::~HttpServer(void)
{
}
/*! ----------------------------------------------------------------------------
* @fn setup
*
* @brief Setup the Http server
*/
int HttpServer::setup(char *a_document_root, int a_port, uv_loop_t *an_evt_loop)
{
return 0;
}

48
src/http/http-server.h Normal file
View File

@@ -0,0 +1,48 @@
/*!
* http-server.h
*
* Copyright (c) 2015-2019, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 13/11/2019
*
*/
#ifndef _HTTP_SERVER_H
#define _HTTP_SERVER_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <uv.h>
/*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class HttpServer
{
public:
HttpServer(void);
~HttpServer(void);
int setup(char *a_document_root, int a_port, uv_loop_t *an_evt_loop);
private:
};
#endif /* __HTTP_SERVER_H */

View File

@@ -28,11 +28,15 @@
/*-------------------------------- INCLUDES ---------------------------------*/
#include <scy/logger.h>
#include "domo-server.h"
#define kDocumentRoot "."
#define kPort 8081
using namespace std;
/*! ----------------------------------------------------------------------------
* @fn DomoServer
*
@@ -58,24 +62,27 @@ DomoServer::~DomoServer(void)
*/
bool DomoServer::setup(void)
{
LDebug("DomoServer::setup");
// Create the event loop.
m_evt_loop = uv_default_loop();
m_evt_loop = uv::defaultLoop();
if (m_evt_loop == NULL)
{
return false;
}
#if 0
if (m_broker.setup(m_evt_loop))
{
fprintf(stderr, "Failed to setup the Nats Broker.\n");
return false;
}
m_server.setup(kDocumentRoot, kPort, m_evt_loop);
m_http_server.setup(kDocumentRoot, kPort, m_evt_loop);
// TODO
m_broker.connect();
#endif
return true;
}
@@ -89,7 +96,7 @@ void DomoServer::terminate(void)
m_broker.terminate();
if (m_evt_loop != NULL)
uv_loop_close(m_evt_loop);
uv::closeLoop(m_evt_loop);
}
/*! ----------------------------------------------------------------------------
@@ -99,5 +106,6 @@ void DomoServer::terminate(void)
*/
int DomoServer::loop(void)
{
return uv_run(m_evt_loop, UV_RUN_DEFAULT);;
uv::runLoop(m_evt_loop, UV_RUN_DEFAULT);
return 0;
}

View File

@@ -28,13 +28,15 @@
/*------------------------------- INCLUDES ----------------------------------*/
#include <uv.h>
#include <scy/loop.h>
#include "broker/nats-broker.h"
#include "web/web-server.h"
#include "http/http-server.h"
/*---------------------------------- Deps -----------------------------------*/
using namespace scy;
/*--------------------------------- CLASS ----------------------------------*/
class DomoServer
@@ -50,8 +52,8 @@ public:
private:
NatsBroker m_broker;
WebServer m_server;
uv_loop_t *m_evt_loop;
HttpServer m_http_server;
uv::Loop *m_evt_loop;
};
#endif /* _DOMO_SERVER_H */