skeleton wip
This commit is contained in:
@@ -10,5 +10,6 @@ set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/lib")
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules/")
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../nats.c ${CMAKE_CURRENT_BINARY_DIR}/nats.c)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../json-c ${CMAKE_CURRENT_BINARY_DIR}/json-c)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../civetweb ${CMAKE_CURRENT_BINARY_DIR}/civetweb)
|
||||
add_subdirectory (src)
|
||||
|
||||
@@ -6,13 +6,17 @@ set (CMAKE_MODULE_PATH "${MODULE_PATH}")
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/../nats.c/src)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
#set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Werror=strict-aliasing")
|
||||
|
||||
file(
|
||||
GLOB_RECURSE
|
||||
source_files
|
||||
domo-iot.cpp
|
||||
main.cpp
|
||||
server/domo-server.cpp
|
||||
broker/nats-broker.cpp
|
||||
web/web-server.cpp
|
||||
)
|
||||
|
||||
add_executable (domo-iot ${source_files})
|
||||
@@ -24,6 +28,7 @@ target_link_libraries (domo-iot
|
||||
pthread
|
||||
event_pthreads
|
||||
civetweb-cpp
|
||||
json-c
|
||||
rt
|
||||
)
|
||||
|
||||
|
||||
70
src/broker/nats-broker.cpp
Normal file
70
src/broker/nats-broker.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*!
|
||||
* nats-broker.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
|
||||
*
|
||||
*/
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <adapters/libevent.h>
|
||||
|
||||
#include "nats-broker.h"
|
||||
|
||||
#include <nats.h>
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn NatsBroker
|
||||
*
|
||||
* @brief Constructor of the Nats Broker.
|
||||
*/
|
||||
NatsBroker::NatsBroker(void) : m_conn(NULL), m_opts(NULL), m_sub(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~NatsBroker
|
||||
*
|
||||
* @brief Destructor of the Nats.
|
||||
*/
|
||||
NatsBroker::~NatsBroker(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn setup
|
||||
*
|
||||
* @brief Setup the Broker.
|
||||
*/
|
||||
int NatsBroker::setup(void)
|
||||
{
|
||||
natsStatus the_status;
|
||||
|
||||
nats_Open(-1);
|
||||
|
||||
// One time initialization of things that we need.
|
||||
natsLibevent_Init();
|
||||
|
||||
if (natsOptions_Create(&m_opts) != NATS_OK)
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
51
src/broker/nats-broker.h
Normal file
51
src/broker/nats-broker.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*!
|
||||
* nats-broker.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 _NATS_BROKER_H
|
||||
#define _NATS_BROKER_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <nats.h>
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class NatsBroker
|
||||
{
|
||||
public:
|
||||
NatsBroker(void);
|
||||
~NatsBroker(void);
|
||||
|
||||
int setup(void);
|
||||
|
||||
private:
|
||||
natsConnection *m_conn;
|
||||
natsOptions *m_opts;
|
||||
natsSubscription *m_sub;
|
||||
};
|
||||
|
||||
#endif /* _NATS_BROKER_H */
|
||||
52
src/main.cpp
Normal file
52
src/main.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*!
|
||||
* main.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: 08/11/2019
|
||||
*
|
||||
*/
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "server/domo-server.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn main
|
||||
*
|
||||
* @brief Main function of domo-iot daemon.
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int the_return;
|
||||
|
||||
DomoServer the_server;
|
||||
|
||||
if (!the_server.setup())
|
||||
{
|
||||
fprintf(stderr, "Failed to setup the daemon.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
the_return = the_server.loop();
|
||||
|
||||
return the_return;
|
||||
}
|
||||
89
src/server/domo-server.cpp
Normal file
89
src/server/domo-server.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*!
|
||||
* domo-iot.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
|
||||
*
|
||||
*/
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <event.h>
|
||||
|
||||
#include "domo-server.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn DomoServer
|
||||
*
|
||||
* @brief Constructor of the Domo Server Object.
|
||||
*/
|
||||
DomoServer::DomoServer(void) : m_evt_loop(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~DomoServer
|
||||
*
|
||||
* @brief Destructor of the Domo Server Object.
|
||||
*/
|
||||
DomoServer::~DomoServer(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn setup
|
||||
*
|
||||
* @brief setup the Domo Server.
|
||||
*/
|
||||
bool DomoServer::setup(void)
|
||||
{
|
||||
|
||||
if (m_broker.setup())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_evt_loop = event_base_new();
|
||||
if (m_evt_loop == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn terminate
|
||||
*
|
||||
* @brief terminate the Domo Server.
|
||||
*/
|
||||
void DomoServer::terminate(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn loop
|
||||
*
|
||||
* @brief main loop function.
|
||||
*/
|
||||
int DomoServer::loop(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
57
src/server/domo-server.h
Normal file
57
src/server/domo-server.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*!
|
||||
* domo-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 _DOMO_SERVER_H
|
||||
#define _DOMO_SERVER_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include "broker/nats-broker.h"
|
||||
#include "web/web-server.h"
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
struct event_base;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class DomoServer
|
||||
{
|
||||
public:
|
||||
DomoServer(void);
|
||||
~DomoServer(void);
|
||||
|
||||
bool setup(void);
|
||||
void terminate(void);
|
||||
|
||||
int loop(void);
|
||||
|
||||
private:
|
||||
NatsBroker m_broker;
|
||||
WebServer m_server;
|
||||
struct event_base *m_evt_loop;
|
||||
};
|
||||
|
||||
#endif /* _DOMO_SERVER_H */
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <adapters/libevent.h>
|
||||
|
||||
#include <nats.h>
|
||||
|
||||
static void onMsg(natsConnection *nc, natsSubscription *sub, natsMsg *msg, void *closure)
|
||||
@@ -48,25 +49,25 @@ static void onMsg(natsConnection *nc, natsSubscription *sub, natsMsg *msg, void
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
natsConnection *conn = NULL;
|
||||
natsOptions *opts = NULL;
|
||||
natsSubscription *sub = NULL;
|
||||
natsStatus s;
|
||||
struct event_base *evLoop = NULL;
|
||||
nats_Open(-1);
|
||||
// natsConnection *conn = NULL;
|
||||
// natsOptions *opts = NULL;
|
||||
// natsSubscription *sub = NULL;
|
||||
// natsStatus s;
|
||||
// struct event_base *evLoop = NULL;
|
||||
// nats_Open(-1);
|
||||
|
||||
printf("Listening on subject 'foo'\n");
|
||||
|
||||
// One time initialization of things that we need.
|
||||
natsLibevent_Init();
|
||||
//natsLibevent_Init();
|
||||
|
||||
// Create a loop.
|
||||
evLoop = event_base_new();
|
||||
if (evLoop == NULL)
|
||||
s = NATS_ERR;
|
||||
// evLoop = event_base_new();
|
||||
// if (evLoop == NULL)
|
||||
// s = NATS_ERR;
|
||||
|
||||
if (natsOptions_Create(&opts) != NATS_OK)
|
||||
s = NATS_NO_MEMORY;
|
||||
// if (natsOptions_Create(&opts) != NATS_OK)
|
||||
// s = NATS_NO_MEMORY;
|
||||
|
||||
s = natsOptions_UseGlobalMessageDelivery(opts, true);
|
||||
|
||||
48
src/web/web-server.cpp
Normal file
48
src/web/web-server.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*!
|
||||
* web-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
|
||||
*
|
||||
*/
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include "web-server.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn WebServer
|
||||
*
|
||||
* @brief Constructor of the Web Server Object.
|
||||
*/
|
||||
|
||||
WebServer::WebServer(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~WebServer
|
||||
*
|
||||
* @brief Destructor of the Web Server Object.
|
||||
*/
|
||||
|
||||
WebServer::~WebServer(void)
|
||||
{
|
||||
}
|
||||
44
src/web/web-server.h
Normal file
44
src/web/web-server.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*!
|
||||
* web-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 _WEB_SERVER_H
|
||||
#define _WEB_SERVER_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class WebServer
|
||||
{
|
||||
public:
|
||||
WebServer(void);
|
||||
~WebServer(void);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* __WEB_SERVER_H */
|
||||
Reference in New Issue
Block a user