Initial commit
This commit is contained in:
		
						commit
						d17500a3b0
					
				
					 18 changed files with 938 additions and 0 deletions
				
			
		
							
								
								
									
										36
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
# Prerequisites
 | 
			
		||||
*.d
 | 
			
		||||
 | 
			
		||||
# Compiled Object files
 | 
			
		||||
*.slo
 | 
			
		||||
*.lo
 | 
			
		||||
*.o
 | 
			
		||||
*.obj
 | 
			
		||||
 | 
			
		||||
# Precompiled Headers
 | 
			
		||||
*.gch
 | 
			
		||||
*.pch
 | 
			
		||||
 | 
			
		||||
# Compiled Dynamic libraries
 | 
			
		||||
*.so
 | 
			
		||||
*.dylib
 | 
			
		||||
*.dll
 | 
			
		||||
 | 
			
		||||
# Fortran module files
 | 
			
		||||
*.mod
 | 
			
		||||
*.smod
 | 
			
		||||
 | 
			
		||||
# Compiled Static libraries
 | 
			
		||||
*.lai
 | 
			
		||||
*.la
 | 
			
		||||
*.a
 | 
			
		||||
*.lib
 | 
			
		||||
 | 
			
		||||
# Executables
 | 
			
		||||
*.exe
 | 
			
		||||
*.out
 | 
			
		||||
*.app
 | 
			
		||||
 | 
			
		||||
build
 | 
			
		||||
cmake-build-debug
 | 
			
		||||
.idea
 | 
			
		||||
							
								
								
									
										106
									
								
								CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,106 @@
 | 
			
		|||
cmake_minimum_required (VERSION 3.2)
 | 
			
		||||
Project(emgauwa-core)
 | 
			
		||||
 | 
			
		||||
link_directories(/usr/local/lib)
 | 
			
		||||
link_libraries(drogon trantor pthread dl)
 | 
			
		||||
 | 
			
		||||
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
 | 
			
		||||
    EXEC_PROGRAM (gcc ARGS "--version | grep '^gcc'|awk '{print $3}' | sed s'/)//g' | sed s'/-.*//g'" OUTPUT_VARIABLE version)
 | 
			
		||||
    MESSAGE(STATUS "This is gcc version:: " ${version})
 | 
			
		||||
    if(version LESS 5.4.0)
 | 
			
		||||
        MESSAGE(STATUS "gcc is too old")
 | 
			
		||||
        stop()
 | 
			
		||||
    elseif(version LESS 7.1.0)
 | 
			
		||||
        set(CMAKE_CXX_STD_FLAGS c++14)
 | 
			
		||||
        MESSAGE(STATUS "c++14")
 | 
			
		||||
    else()
 | 
			
		||||
        set(CMAKE_CXX_STD_FLAGS c++17)
 | 
			
		||||
        MESSAGE(STATUS "c++17")
 | 
			
		||||
    endif()
 | 
			
		||||
else()
 | 
			
		||||
    set(CMAKE_CXX_STD_FLAGS c++17)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(CMAKE_BUILD_TYPE STREQUAL "")
 | 
			
		||||
    set(CMAKE_BUILD_TYPE Release)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -std=${CMAKE_CXX_STD_FLAGS}")
 | 
			
		||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -std=${CMAKE_CXX_STD_FLAGS}")
 | 
			
		||||
 | 
			
		||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
 | 
			
		||||
 | 
			
		||||
#jsoncpp
 | 
			
		||||
find_package (Jsoncpp REQUIRED)
 | 
			
		||||
include_directories(${JSONCPP_INCLUDE_DIRS})
 | 
			
		||||
link_libraries(${JSONCPP_LIBRARIES})
 | 
			
		||||
 | 
			
		||||
#uuid
 | 
			
		||||
find_package (UUID REQUIRED)
 | 
			
		||||
include_directories(${UUID_INCLUDE_DIR})
 | 
			
		||||
link_libraries(${UUID_LIBRARIES})
 | 
			
		||||
 | 
			
		||||
#OpenSSL
 | 
			
		||||
find_package (OpenSSL)
 | 
			
		||||
if(OpenSSL_FOUND)
 | 
			
		||||
    include_directories(${OPENSSL_INCLUDE_DIR})
 | 
			
		||||
    link_libraries(${OPENSSL_LIBRARIES})
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
#zlib
 | 
			
		||||
find_package(ZLIB REQUIRED)
 | 
			
		||||
include_directories(${ZLIB_INCLUDE_DIR})
 | 
			
		||||
link_libraries(${ZLIB_LIBRARIES})
 | 
			
		||||
 | 
			
		||||
#find postgres
 | 
			
		||||
find_package(PostgreSQL)
 | 
			
		||||
if(PostgreSQL_FOUND)
 | 
			
		||||
include_directories(${PostgreSQL_INCLUDE_DIR})
 | 
			
		||||
link_libraries(${PostgreSQL_LIBRARIES})
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
#Find mysql, only mariadb client liberary is supported
 | 
			
		||||
find_package(MySQL)
 | 
			
		||||
if(MYSQL_FOUND)
 | 
			
		||||
    message(STATUS "inc:" ${MYSQL_INCLUDE_DIR})
 | 
			
		||||
    message(STATUS "libs:" ${MYSQL_CLIENT_LIBS})
 | 
			
		||||
    message(STATUS "version:" ${MYSQL_VERSION_STRING})
 | 
			
		||||
    if(MYSQL_VERSION_STRING STREQUAL "")
 | 
			
		||||
        message(STATUS "The mysql in your system is not the mariadb, so we can't use it in drogon")
 | 
			
		||||
    else()
 | 
			
		||||
        message(STATUS "Ok! We find the mariadb!")
 | 
			
		||||
        include_directories(${MYSQL_INCLUDE_DIR})
 | 
			
		||||
        link_libraries(${MYSQL_CLIENT_LIBS})
 | 
			
		||||
    endif()
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
#Find sqlite3.
 | 
			
		||||
find_package (SQLite3)
 | 
			
		||||
if (SQLITE3_FOUND)
 | 
			
		||||
  include_directories(${SQLITE3_INCLUDE_DIRS})
 | 
			
		||||
  link_libraries(${SQLITE3_LIBRARIES})
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
AUX_SOURCE_DIRECTORY(./ SRC_DIR)
 | 
			
		||||
AUX_SOURCE_DIRECTORY(controllers CTL_SRC)
 | 
			
		||||
AUX_SOURCE_DIRECTORY(filters FILTER_SRC)
 | 
			
		||||
AUX_SOURCE_DIRECTORY(plugins PLUGIN_SRC)
 | 
			
		||||
AUX_SOURCE_DIRECTORY(models MODEL_SRC)
 | 
			
		||||
 | 
			
		||||
include_directories(/usr/local/include)
 | 
			
		||||
 | 
			
		||||
FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp)
 | 
			
		||||
foreach(cspFile ${SCP_LIST})
 | 
			
		||||
    message(STATUS "cspFile:" ${cspFile})
 | 
			
		||||
    EXEC_PROGRAM(basename ARGS "${cspFile} .csp" OUTPUT_VARIABLE classname)
 | 
			
		||||
    message(STATUS "view classname:" ${classname})
 | 
			
		||||
    add_custom_command(OUTPUT ${classname}.h ${classname}.cc
 | 
			
		||||
            COMMAND drogon_ctl
 | 
			
		||||
            ARGS create view ${cspFile}
 | 
			
		||||
            DEPENDS ${cspFile}
 | 
			
		||||
            VERBATIM )
 | 
			
		||||
    set(VIEWSRC ${VIEWSRC} ${classname}.cc)
 | 
			
		||||
endforeach()
 | 
			
		||||
 | 
			
		||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 | 
			
		||||
add_executable(emgauwa-core ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC} ${PLUGIN_SRC} ${MODEL_SRC})
 | 
			
		||||
							
								
								
									
										63
									
								
								cmake_modules/FindJsoncpp.cmake
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								cmake_modules/FindJsoncpp.cmake
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,63 @@
 | 
			
		|||
# Find jsoncpp
 | 
			
		||||
#
 | 
			
		||||
# Find the jsoncpp includes and library
 | 
			
		||||
# 
 | 
			
		||||
# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 
 | 
			
		||||
# 
 | 
			
		||||
# This module defines
 | 
			
		||||
#  JSONCPP_INCLUDE_DIRS, where to find header, etc.
 | 
			
		||||
#  JSONCPP_LIBRARIES, the libraries needed to use jsoncpp.
 | 
			
		||||
#  JSONCPP_FOUND, If false, do not try to use jsoncpp.
 | 
			
		||||
#  JSONCPP_INCLUDE_PREFIX, include prefix for jsoncpp
 | 
			
		||||
 | 
			
		||||
# only look in default directories
 | 
			
		||||
find_path(
 | 
			
		||||
	JSONCPP_INCLUDE_DIR 
 | 
			
		||||
	NAMES jsoncpp/json/json.h json/json.h
 | 
			
		||||
	DOC "jsoncpp include dir"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
find_library(
 | 
			
		||||
	JSONCPP_LIBRARY
 | 
			
		||||
	NAMES jsoncpp
 | 
			
		||||
	DOC "jsoncpp library"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
set(JSONCPP_INCLUDE_DIRS ${JSONCPP_INCLUDE_DIR})
 | 
			
		||||
set(JSONCPP_LIBRARIES ${JSONCPP_LIBRARY})
 | 
			
		||||
 | 
			
		||||
# debug library on windows
 | 
			
		||||
# same naming convention as in qt (appending debug library with d)
 | 
			
		||||
# boost is using the same "hack" as us with "optimized" and "debug"
 | 
			
		||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
 | 
			
		||||
	find_library(
 | 
			
		||||
		JSONCPP_LIBRARY_DEBUG
 | 
			
		||||
		NAMES jsoncppd
 | 
			
		||||
		DOC "jsoncpp debug library"
 | 
			
		||||
	)
 | 
			
		||||
	
 | 
			
		||||
	set(JSONCPP_LIBRARIES optimized ${JSONCPP_LIBRARIES} debug ${JSONCPP_LIBRARY_DEBUG})
 | 
			
		||||
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# find JSONCPP_INCLUDE_PREFIX
 | 
			
		||||
find_path(
 | 
			
		||||
	JSONCPP_INCLUDE_PREFIX
 | 
			
		||||
	NAMES json.h
 | 
			
		||||
	PATH_SUFFIXES jsoncpp/json json
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
if (${JSONCPP_INCLUDE_PREFIX} MATCHES "jsoncpp")
 | 
			
		||||
	set(JSONCPP_INCLUDE_PREFIX "jsoncpp")
 | 
			
		||||
	set(JSONCPP_INCLUDE_DIRS "${JSONCPP_INCLUDE_DIRS}/jsoncpp")
 | 
			
		||||
else()
 | 
			
		||||
	set(JSONCPP_INCLUDE_PREFIX "")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE
 | 
			
		||||
# if all listed variables are TRUE, hide their existence from configuration view
 | 
			
		||||
include(FindPackageHandleStandardArgs)
 | 
			
		||||
find_package_handle_standard_args(jsoncpp DEFAULT_MSG
 | 
			
		||||
	JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY)
 | 
			
		||||
mark_as_advanced (JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY)
 | 
			
		||||
							
								
								
									
										114
									
								
								cmake_modules/FindMySQL.cmake
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								cmake_modules/FindMySQL.cmake
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,114 @@
 | 
			
		|||
#--------------------------------------------------------
 | 
			
		||||
# Copyright (C) 1995-2007 MySQL AB
 | 
			
		||||
#
 | 
			
		||||
# This program is free software; you can redistribute it and/or modify
 | 
			
		||||
# it under the terms of version 2 of the GNU General Public License as
 | 
			
		||||
# published by the Free Software Foundation.
 | 
			
		||||
#
 | 
			
		||||
# There are special exceptions to the terms and conditions of the GPL
 | 
			
		||||
# as it is applied to this software. View the full text of the exception
 | 
			
		||||
# in file LICENSE.exceptions in the top-level directory of this software
 | 
			
		||||
# distribution.
 | 
			
		||||
#
 | 
			
		||||
# This program 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 General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License
 | 
			
		||||
# along with this program; if not, write to the Free Software
 | 
			
		||||
# Foundation, Inc.,
 | 
			
		||||
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 | 
			
		||||
#
 | 
			
		||||
# The MySQL Connector/ODBC is licensed under the terms of the
 | 
			
		||||
# GPL, like most MySQL Connectors. There are special exceptions
 | 
			
		||||
# to the terms and conditions of the GPL as it is applied to
 | 
			
		||||
# this software, see the FLOSS License Exception available on
 | 
			
		||||
# mysql.com.
 | 
			
		||||
 | 
			
		||||
##########################################################################
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#-------------- FIND MYSQL_INCLUDE_DIR ------------------
 | 
			
		||||
FIND_PATH(MYSQL_INCLUDE_DIR mysql.h
 | 
			
		||||
  /usr/include/mysql
 | 
			
		||||
  /usr/local/include/mysql
 | 
			
		||||
  /opt/mysql/mysql/include
 | 
			
		||||
  /opt/mysql/mysql/include/mysql
 | 
			
		||||
  /opt/mysql/include
 | 
			
		||||
  /opt/local/include/mysql5
 | 
			
		||||
  /usr/local/mysql/include
 | 
			
		||||
  /usr/local/mysql/include/mysql
 | 
			
		||||
  $ENV{ProgramFiles}/MySQL/*/include
 | 
			
		||||
  $ENV{SystemDrive}/MySQL/*/include)
 | 
			
		||||
 | 
			
		||||
#----------------- FIND MYSQL_LIB_DIR -------------------
 | 
			
		||||
IF (WIN32)
 | 
			
		||||
  # Set lib path suffixes
 | 
			
		||||
  # dist = for mysql binary distributions
 | 
			
		||||
  # build = for custom built tree
 | 
			
		||||
  IF (CMAKE_BUILD_TYPE STREQUAL Debug)
 | 
			
		||||
    SET(libsuffixDist debug)
 | 
			
		||||
    SET(libsuffixBuild Debug)
 | 
			
		||||
  ELSE (CMAKE_BUILD_TYPE STREQUAL Debug)
 | 
			
		||||
    SET(libsuffixDist opt)
 | 
			
		||||
    SET(libsuffixBuild Release)
 | 
			
		||||
    ADD_DEFINITIONS(-DDBUG_OFF)
 | 
			
		||||
  ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug)
 | 
			
		||||
 | 
			
		||||
  FIND_LIBRARY(MYSQL_LIB NAMES mysqlclient
 | 
			
		||||
    PATHS
 | 
			
		||||
    $ENV{MYSQL_DIR}/lib/${libsuffixDist}
 | 
			
		||||
    $ENV{MYSQL_DIR}/libmysql
 | 
			
		||||
    $ENV{MYSQL_DIR}/libmysql/${libsuffixBuild}
 | 
			
		||||
    $ENV{MYSQL_DIR}/client/${libsuffixBuild}
 | 
			
		||||
    $ENV{MYSQL_DIR}/libmysql/${libsuffixBuild}
 | 
			
		||||
    $ENV{ProgramFiles}/MySQL/*/lib/${libsuffixDist}
 | 
			
		||||
    $ENV{SystemDrive}/MySQL/*/lib/${libsuffixDist})
 | 
			
		||||
ELSE (WIN32)
 | 
			
		||||
  FIND_LIBRARY(MYSQL_LIB NAMES mysqlclient_r mariadbclient
 | 
			
		||||
    PATHS
 | 
			
		||||
    /usr/lib/mysql
 | 
			
		||||
    /usr/local/lib/mysql
 | 
			
		||||
    /usr/local/mysql/lib
 | 
			
		||||
    /usr/local/mysql/lib/mysql
 | 
			
		||||
    /opt/local/mysql5/lib
 | 
			
		||||
    /opt/local/lib/mysql5/mysql
 | 
			
		||||
    /opt/mysql/mysql/lib/mysql
 | 
			
		||||
    /opt/mysql/lib/mysql)
 | 
			
		||||
ENDIF (WIN32)
 | 
			
		||||
 | 
			
		||||
IF(MYSQL_LIB)
 | 
			
		||||
  GET_FILENAME_COMPONENT(MYSQL_LIB_DIR ${MYSQL_LIB} PATH)
 | 
			
		||||
ENDIF(MYSQL_LIB)
 | 
			
		||||
 | 
			
		||||
set(MYSQL_VERSION_STRING "")
 | 
			
		||||
 | 
			
		||||
EXEC_PROGRAM (grep ARGS "MARIADB_BASE_VERSION ${MYSQL_INCLUDE_DIR}/*.h|awk '{print $3}'" OUTPUT_VARIABLE MYSQL_VERSION_STRING)
 | 
			
		||||
 | 
			
		||||
IF (MYSQL_INCLUDE_DIR AND MYSQL_LIB_DIR)
 | 
			
		||||
  SET(MYSQL_FOUND TRUE)
 | 
			
		||||
 | 
			
		||||
  FIND_LIBRARY(MYSQL_ZLIB zlib PATHS ${MYSQL_LIB_DIR})
 | 
			
		||||
  FIND_LIBRARY(MYSQL_TAOCRYPT taocrypt PATHS ${MYSQL_LIB_DIR})
 | 
			
		||||
  IF (MYSQL_LIB)
 | 
			
		||||
    SET(MYSQL_CLIENT_LIBS ${MYSQL_LIB})
 | 
			
		||||
  ELSE()
 | 
			
		||||
    SET(MYSQL_CLIENT_LIBS mysqlclient_r)
 | 
			
		||||
  ENDIF()
 | 
			
		||||
  IF (MYSQL_ZLIB)
 | 
			
		||||
    SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} zlib)
 | 
			
		||||
  ENDIF (MYSQL_ZLIB)
 | 
			
		||||
  IF (MYSQL_TAOCRYPT)
 | 
			
		||||
    SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} taocrypt)
 | 
			
		||||
  ENDIF (MYSQL_TAOCRYPT)
 | 
			
		||||
  # Added needed mysqlclient dependencies on Windows
 | 
			
		||||
  IF (WIN32)
 | 
			
		||||
    SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} ws2_32)
 | 
			
		||||
  ENDIF (WIN32)
 | 
			
		||||
 | 
			
		||||
  MESSAGE(STATUS "MySQL Include dir: ${MYSQL_INCLUDE_DIR}  library dir: ${MYSQL_LIB_DIR}")
 | 
			
		||||
  MESSAGE(STATUS "MySQL client libraries: ${MYSQL_CLIENT_LIBS}")
 | 
			
		||||
ELSEIF (MySQL_FIND_REQUIRED)
 | 
			
		||||
  MESSAGE(FATAL_ERROR "Cannot find MySQL. Include dir: ${MYSQL_INCLUDE_DIR}  library dir: ${MYSQL_LIB_DIR}")
 | 
			
		||||
ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIB_DIR)
 | 
			
		||||
							
								
								
									
										37
									
								
								cmake_modules/FindSQLite3.cmake
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								cmake_modules/FindSQLite3.cmake
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
# Copyright (C) 2007-2009 LuaDist.
 | 
			
		||||
# Created by Peter Kapec <kapecp@gmail.com>
 | 
			
		||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
 | 
			
		||||
# For details see the COPYRIGHT file distributed with LuaDist.
 | 
			
		||||
#	Note:
 | 
			
		||||
#		Searching headers and libraries is very simple and is NOT as powerful as scripts
 | 
			
		||||
#		distributed with CMake, because LuaDist defines directories to search for.
 | 
			
		||||
#		Everyone is encouraged to contact the author with improvements. Maybe this file
 | 
			
		||||
#		becomes part of CMake distribution sometimes.
 | 
			
		||||
 | 
			
		||||
# - Find sqlite3
 | 
			
		||||
# Find the native SQLITE3 headers and libraries.
 | 
			
		||||
#
 | 
			
		||||
# SQLITE3_INCLUDE_DIRS	- where to find sqlite3.h, etc.
 | 
			
		||||
# SQLITE3_LIBRARIES	- List of libraries when using sqlite.
 | 
			
		||||
# SQLITE3_FOUND	- True if sqlite found.
 | 
			
		||||
 | 
			
		||||
# Look for the header file.
 | 
			
		||||
FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
 | 
			
		||||
 | 
			
		||||
# Look for the library.
 | 
			
		||||
FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3)
 | 
			
		||||
 | 
			
		||||
# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE.
 | 
			
		||||
INCLUDE(FindPackageHandleStandardArgs)
 | 
			
		||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)
 | 
			
		||||
 | 
			
		||||
# Copy the results to the output variables.
 | 
			
		||||
IF(SQLITE3_FOUND)
 | 
			
		||||
	SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
 | 
			
		||||
	SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
 | 
			
		||||
ELSE(SQLITE3_FOUND)
 | 
			
		||||
	SET(SQLITE3_LIBRARIES)
 | 
			
		||||
	SET(SQLITE3_INCLUDE_DIRS)
 | 
			
		||||
ENDIF(SQLITE3_FOUND)
 | 
			
		||||
 | 
			
		||||
MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
 | 
			
		||||
							
								
								
									
										119
									
								
								cmake_modules/FindUUID.cmake
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								cmake_modules/FindUUID.cmake
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,119 @@
 | 
			
		|||
# - Try to find UUID
 | 
			
		||||
# Once done this will define
 | 
			
		||||
#
 | 
			
		||||
# UUID_FOUND - system has UUID
 | 
			
		||||
# UUID_INCLUDE_DIRS - the UUID include directory
 | 
			
		||||
# UUID_LIBRARIES - Link these to use UUID
 | 
			
		||||
# UUID_DEFINITIONS - Compiler switches required for using UUID
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
 | 
			
		||||
#
 | 
			
		||||
# Redistribution and use is allowed according to the terms of the New
 | 
			
		||||
# BSD license.
 | 
			
		||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if (UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
 | 
			
		||||
	# in cache already
 | 
			
		||||
	set(UUID_FOUND TRUE)
 | 
			
		||||
else (UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
 | 
			
		||||
	find_path(UUID_INCLUDE_DIR
 | 
			
		||||
		NAMES
 | 
			
		||||
			uuid.h
 | 
			
		||||
		PATH_SUFFIXES
 | 
			
		||||
			uuid
 | 
			
		||||
		HINTS
 | 
			
		||||
			${UUID_DIR}/include
 | 
			
		||||
			$ENV{UUID_DIR}/include
 | 
			
		||||
			$ENV{UUID_DIR}
 | 
			
		||||
			${DELTA3D_EXT_DIR}/inc
 | 
			
		||||
			$ENV{DELTA_ROOT}/ext/inc
 | 
			
		||||
			$ENV{DELTA_ROOT}
 | 
			
		||||
		PATHS
 | 
			
		||||
			~/Library/Frameworks
 | 
			
		||||
			/Library/Frameworks
 | 
			
		||||
			/usr/local/include
 | 
			
		||||
			/usr/include
 | 
			
		||||
			/usr/include/gdal
 | 
			
		||||
			/sw/include # Fink
 | 
			
		||||
			/opt/local/include # DarwinPorts
 | 
			
		||||
			/opt/csw/include # Blastwave
 | 
			
		||||
			/opt/include
 | 
			
		||||
			[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include
 | 
			
		||||
			/usr/freeware/include
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	find_library(UUID_LIBRARY
 | 
			
		||||
		NAMES
 | 
			
		||||
			uuid ossp-uuid
 | 
			
		||||
		HINTS
 | 
			
		||||
			${UUID_DIR}/lib
 | 
			
		||||
			$ENV{UUID_DIR}/lib
 | 
			
		||||
			$ENV{UUID_DIR}
 | 
			
		||||
			${DELTA3D_EXT_DIR}/lib
 | 
			
		||||
			$ENV{DELTA_ROOT}/ext/lib
 | 
			
		||||
			$ENV{DELTA_ROOT}
 | 
			
		||||
			$ENV{OSG_ROOT}/lib
 | 
			
		||||
		PATHS
 | 
			
		||||
			~/Library/Frameworks
 | 
			
		||||
			/Library/Frameworks
 | 
			
		||||
			/usr/local/lib
 | 
			
		||||
			/usr/lib
 | 
			
		||||
			/sw/lib
 | 
			
		||||
			/opt/local/lib
 | 
			
		||||
			/opt/csw/lib
 | 
			
		||||
			/opt/lib
 | 
			
		||||
			/usr/freeware/lib64
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	find_library(UUID_LIBRARY_DEBUG
 | 
			
		||||
		NAMES
 | 
			
		||||
			uuidd 
 | 
			
		||||
		HINTS
 | 
			
		||||
			${UUID_DIR}/lib
 | 
			
		||||
			$ENV{UUID_DIR}/lib
 | 
			
		||||
			$ENV{UUID_DIR}
 | 
			
		||||
			${DELTA3D_EXT_DIR}/lib
 | 
			
		||||
			$ENV{DELTA_ROOT}/ext/lib
 | 
			
		||||
			$ENV{DELTA_ROOT}
 | 
			
		||||
			$ENV{OSG_ROOT}/lib
 | 
			
		||||
		PATHS
 | 
			
		||||
			~/Library/Frameworks
 | 
			
		||||
			/Library/Frameworks
 | 
			
		||||
			/usr/local/lib
 | 
			
		||||
			/usr/lib
 | 
			
		||||
			/sw/lib
 | 
			
		||||
			/opt/local/lib
 | 
			
		||||
			/opt/csw/lib
 | 
			
		||||
			/opt/lib
 | 
			
		||||
			/usr/freeware/lib64
 | 
			
		||||
	)
 | 
			
		||||
	
 | 
			
		||||
	if (NOT UUID_LIBRARY AND BSD)
 | 
			
		||||
		set(UUID_LIBRARY "")
 | 
			
		||||
	endif(NOT UUID_LIBRARY AND BSD)
 | 
			
		||||
 | 
			
		||||
	set(UUID_INCLUDE_DIRS ${UUID_INCLUDE_DIR})
 | 
			
		||||
	set(UUID_LIBRARIES ${UUID_LIBRARY})
 | 
			
		||||
 | 
			
		||||
	if (UUID_INCLUDE_DIRS)
 | 
			
		||||
		if (BSD OR UUID_LIBRARIES)
 | 
			
		||||
			set(UUID_FOUND TRUE)
 | 
			
		||||
		endif (BSD OR UUID_LIBRARIES)
 | 
			
		||||
	endif (UUID_INCLUDE_DIRS)
 | 
			
		||||
 | 
			
		||||
	if (UUID_FOUND)
 | 
			
		||||
		if (NOT UUID_FIND_QUIETLY)
 | 
			
		||||
			message(STATUS "Found UUID: ${UUID_LIBRARIES}")
 | 
			
		||||
		endif (NOT UUID_FIND_QUIETLY)
 | 
			
		||||
	else (UUID_FOUND)
 | 
			
		||||
		if (UUID_FIND_REQUIRED)
 | 
			
		||||
			message(FATAL_ERROR "Could not find UUID")
 | 
			
		||||
		endif (UUID_FIND_REQUIRED)
 | 
			
		||||
	endif (UUID_FOUND)
 | 
			
		||||
 | 
			
		||||
	# show the UUID_INCLUDE_DIRS and UUID_LIBRARIES variables only in the advanced view
 | 
			
		||||
	mark_as_advanced(UUID_INCLUDE_DIRS UUID_LIBRARIES)
 | 
			
		||||
 | 
			
		||||
endif (UUID_LIBRARIES AND UUID_INCLUDE_DIRS)
 | 
			
		||||
							
								
								
									
										63
									
								
								config.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								config.json
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,63 @@
 | 
			
		|||
{
 | 
			
		||||
    "listeners": [
 | 
			
		||||
        {
 | 
			
		||||
            "address": "0.0.0.0",
 | 
			
		||||
            "port": 5000,
 | 
			
		||||
            "https": false
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "app": {
 | 
			
		||||
        "threads_num": 1,
 | 
			
		||||
        "enable_session": false,
 | 
			
		||||
        "session_timeout": 0,
 | 
			
		||||
        "document_root": "./static/",
 | 
			
		||||
        "home_page": "index.html",
 | 
			
		||||
        "upload_path": "uploads",
 | 
			
		||||
        "file_types": [
 | 
			
		||||
            "gif",
 | 
			
		||||
            "png",
 | 
			
		||||
            "jpg",
 | 
			
		||||
            "js",
 | 
			
		||||
            "css",
 | 
			
		||||
            "html",
 | 
			
		||||
            "ico",
 | 
			
		||||
            "swf",
 | 
			
		||||
            "xap",
 | 
			
		||||
            "apk",
 | 
			
		||||
            "cur",
 | 
			
		||||
            "xml"
 | 
			
		||||
        ],
 | 
			
		||||
        "max_connections": 100000,
 | 
			
		||||
        "max_connections_per_ip": 0,
 | 
			
		||||
        "load_dynamic_views": false,
 | 
			
		||||
        "dynamic_views_path": [
 | 
			
		||||
            "./views"
 | 
			
		||||
        ],
 | 
			
		||||
        "log": {
 | 
			
		||||
            "logfile_base_name": "",
 | 
			
		||||
            "log_size_limit": 100000000,
 | 
			
		||||
            "log_level": "DEBUG"
 | 
			
		||||
        },
 | 
			
		||||
        "run_as_daemon": false,
 | 
			
		||||
        "relaunch_on_error": false,
 | 
			
		||||
        "use_sendfile": true,
 | 
			
		||||
        "use_gzip": true,
 | 
			
		||||
        "static_files_cache_time": 5,
 | 
			
		||||
        "idle_connection_timeout": 60,
 | 
			
		||||
        "server_header_field": "",
 | 
			
		||||
        "keepalive_requests": 0,
 | 
			
		||||
        "pipelining_requests": 0,
 | 
			
		||||
        "gzip_static": true,
 | 
			
		||||
        "client_max_body_size": "1M",
 | 
			
		||||
        "client_max_memory_body_size": "64K",
 | 
			
		||||
        "client_max_websocket_message_size": "128K"
 | 
			
		||||
    },
 | 
			
		||||
    "plugins": [{
 | 
			
		||||
        "dependencies": [],
 | 
			
		||||
        "config": {
 | 
			
		||||
            "heartbeat_interval": 2
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
    }],
 | 
			
		||||
    "custom_config": {}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										185
									
								
								config.template.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										185
									
								
								config.template.json
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,185 @@
 | 
			
		|||
/* This is a JSON format configuration file
 | 
			
		||||
 */
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
    //ssl:The global ssl files setting
 | 
			
		||||
    "ssl": {
 | 
			
		||||
        "cert": "../../trantor/trantor/tests/server.pem",
 | 
			
		||||
        "key": "../../trantor/trantor/tests/server.pem"
 | 
			
		||||
    },
 | 
			
		||||
    "listeners": [
 | 
			
		||||
        {
 | 
			
		||||
            //address: Ip address,0.0.0.0 by default
 | 
			
		||||
            "address": "0.0.0.0",
 | 
			
		||||
            //port: Port number
 | 
			
		||||
            "port": 80,
 | 
			
		||||
            //https: If true, use https for security,false by default
 | 
			
		||||
            "https": false
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "address": "0.0.0.0",
 | 
			
		||||
            "port": 443,
 | 
			
		||||
            "https": true,
 | 
			
		||||
            //cert,key: Cert file path and key file path, empty by default,
 | 
			
		||||
            //if empty, use the global setting
 | 
			
		||||
            "cert": "",
 | 
			
		||||
            "key": ""
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "db_clients": [
 | 
			
		||||
        {
 | 
			
		||||
            //name: Name of the client,'default' by default
 | 
			
		||||
            //"name":"",
 | 
			
		||||
            //rdbms: Server type, postgresql,mysql or sqlite3, "postgresql" by default
 | 
			
		||||
            "rdbms": "postgresql",
 | 
			
		||||
            //filename: Sqlite3 db file name
 | 
			
		||||
            //"filename":"",
 | 
			
		||||
            //host: Server address,localhost by default
 | 
			
		||||
            "host": "127.0.0.1",
 | 
			
		||||
            //port: Server port, 5432 by default
 | 
			
		||||
            "port": 5432,
 | 
			
		||||
            //dbname: Database name
 | 
			
		||||
            "dbname": "test",
 | 
			
		||||
            //user: 'postgres' by default
 | 
			
		||||
            "user": "",
 | 
			
		||||
            //passwd: '' by default
 | 
			
		||||
            "passwd": "",
 | 
			
		||||
            //is_fast: false by default, if it is true, the client is faster but user can't call
 | 
			
		||||
            //any synchronous interface of it.
 | 
			
		||||
            "is_fast": false,
 | 
			
		||||
            //connection_number: 1 by default, valid only if is_fast is false.
 | 
			
		||||
            "connection_number": 1
 | 
			
		||||
        }
 | 
			
		||||
    ],*/
 | 
			
		||||
    "app": {
 | 
			
		||||
        //threads_num: The number of IO threads, 1 by default, if the value is set to 0, the number of threads
 | 
			
		||||
        //is the number of CPU cores
 | 
			
		||||
        "threads_num": 1,
 | 
			
		||||
        //enable_session: False by default
 | 
			
		||||
        "enable_session": false,
 | 
			
		||||
        "session_timeout": 0,
 | 
			
		||||
        //document_root: Root path of HTTP document, defaut path is ./
 | 
			
		||||
        "document_root": "./",
 | 
			
		||||
        //home_page: Set the HTML file of the home page, the default value is "index.html"
 | 
			
		||||
        //If there isn't any handler registered to the path "/", the home page file in the "document_root" is send to clients as a response
 | 
			
		||||
        //to the request for "/".
 | 
			
		||||
        "home_page": "index.html",
 | 
			
		||||
        //upload_path: The path to save the uploaded file. "uploads" by default. 
 | 
			
		||||
        //If the path isn't prefixed with /, ./ or ../,
 | 
			
		||||
        //it is relative path of document_root path
 | 
			
		||||
        "upload_path": "uploads",
 | 
			
		||||
        /* file_types:
 | 
			
		||||
         * HTTP download file types,The file types supported by drogon
 | 
			
		||||
         * by default are "html", "js", "css", "xml", "xsl", "txt", "svg",
 | 
			
		||||
         * "ttf", "otf", "woff2", "woff" , "eot", "png", "jpg", "jpeg",
 | 
			
		||||
         * "gif", "bmp", "ico", "icns", etc. */
 | 
			
		||||
        "file_types": [
 | 
			
		||||
            "gif",
 | 
			
		||||
            "png",
 | 
			
		||||
            "jpg",
 | 
			
		||||
            "js",
 | 
			
		||||
            "css",
 | 
			
		||||
            "html",
 | 
			
		||||
            "ico",
 | 
			
		||||
            "swf",
 | 
			
		||||
            "xap",
 | 
			
		||||
            "apk",
 | 
			
		||||
            "cur",
 | 
			
		||||
            "xml"
 | 
			
		||||
        ],
 | 
			
		||||
        //max_connections: maximum connections number,100000 by default
 | 
			
		||||
        "max_connections": 100000,
 | 
			
		||||
        //max_connections_per_ip: maximum connections number per clinet,0 by default which means no limit
 | 
			
		||||
        "max_connections_per_ip": 0,
 | 
			
		||||
        //Load_dynamic_views: False by default, when set to true, drogon
 | 
			
		||||
        //compiles and loads dynamically "CSP View Files" in directories defined
 | 
			
		||||
        //by "dynamic_views_path"
 | 
			
		||||
        "load_dynamic_views": false,
 | 
			
		||||
        //dynamic_views_path: If the path isn't prefixed with /, ./ or ../,
 | 
			
		||||
        //it is relative path of document_root path
 | 
			
		||||
        "dynamic_views_path": [
 | 
			
		||||
            "./views"
 | 
			
		||||
        ],
 | 
			
		||||
        //log: Set log output, drogon output logs to stdout by default
 | 
			
		||||
        "log": {
 | 
			
		||||
            //log_path: Log file path,empty by default,in which case,logs are output to the stdout
 | 
			
		||||
            //"log_path": "./",
 | 
			
		||||
            //logfile_base_name: Log file base name,empty by default which means drogon names logfile as
 | 
			
		||||
            //drogon.log ...
 | 
			
		||||
            "logfile_base_name": "",
 | 
			
		||||
            //log_size_limit: 100000000 bytes by default,
 | 
			
		||||
            //When the log file size reaches "log_size_limit", the log file is switched.
 | 
			
		||||
            "log_size_limit": 100000000,
 | 
			
		||||
            //log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
 | 
			
		||||
            //The TRACE level is only valid when built in DEBUG mode.
 | 
			
		||||
            "log_level": "DEBUG"
 | 
			
		||||
        },
 | 
			
		||||
        //run_as_daemon: False by default
 | 
			
		||||
        "run_as_daemon": false,
 | 
			
		||||
        //relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
 | 
			
		||||
        "relaunch_on_error": false,
 | 
			
		||||
        //use_sendfile: True by default, if ture, the program 
 | 
			
		||||
        //uses sendfile() system-call to send static files to clients;
 | 
			
		||||
        "use_sendfile": true,
 | 
			
		||||
        //use_gzip: True by default, use gzip to compress the response body's content;
 | 
			
		||||
        "use_gzip": true,
 | 
			
		||||
        //static_files_cache_time: 5 (seconds) by default, the time in which the static file response is cached,
 | 
			
		||||
        //0 means cache forever, the negative value means no cache
 | 
			
		||||
        "static_files_cache_time": 5,
 | 
			
		||||
        //simple_controllers_map: Used to configure mapping from path to simple controller
 | 
			
		||||
        "simple_controllers_map": [{
 | 
			
		||||
            "path": "/path/name",
 | 
			
		||||
            "controller": "controllerClassName",
 | 
			
		||||
            "http_methods": [
 | 
			
		||||
                "get",
 | 
			
		||||
                "post"
 | 
			
		||||
            ],
 | 
			
		||||
            "filters": [
 | 
			
		||||
                "FilterClassName"
 | 
			
		||||
            ]
 | 
			
		||||
        }],
 | 
			
		||||
        //idle_connection_timeout: Defaults to 60 seconds, the lifetime 
 | 
			
		||||
        //of the connection without read or write
 | 
			
		||||
        "idle_connection_timeout": 60,
 | 
			
		||||
        //server_header_field: Set the 'server' header field in each response sent by drogon,
 | 
			
		||||
        //empty string by default with which the 'server' header field is set to "Server: drogon/version string\r\n"
 | 
			
		||||
        "server_header_field": "",
 | 
			
		||||
        //keepalive_requests: Set the maximum number of requests that can be served through one keep-alive connection. 
 | 
			
		||||
        //After the maximum number of requests are made, the connection is closed.
 | 
			
		||||
        //The default value of 0 means no limit.
 | 
			
		||||
        "keepalive_requests": 0,
 | 
			
		||||
        //pipelining_requests: Set the maximum number of unhandled requests that can be cached in pipelining buffer. 
 | 
			
		||||
        //After the maximum number of requests are made, the connection is closed.
 | 
			
		||||
        //The default value of 0 means no limit.
 | 
			
		||||
        "pipelining_requests": 0,
 | 
			
		||||
        //gzip_static: If it is set to true, when the client requests a static file, drogon first finds the compressed 
 | 
			
		||||
        //file with the extension ".gz" in the same path and send the compressed file to the client.
 | 
			
		||||
        //The default value of gzip_static is true.
 | 
			
		||||
        "gzip_static": true,
 | 
			
		||||
        //client_max_body_size: Set the maximum body size of HTTP requests received by drogon. The default value is "1M".
 | 
			
		||||
        //One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
 | 
			
		||||
        "client_max_body_size": "1M",
 | 
			
		||||
        //max_memory_body_size: Set the maximum body size in memory of HTTP requests received by drogon. The default value is "64K" bytes.
 | 
			
		||||
        //If the body size of a HTTP request exceeds this limit, the body is stored to a temporary file for processing.
 | 
			
		||||
        //Setting it to "" means no limit.
 | 
			
		||||
        "client_max_memory_body_size": "64K",
 | 
			
		||||
        //client_max_websocket_message_size: Set the maximum size of messages sent by WebSocket client. The default value is "128K".
 | 
			
		||||
        //One can set it to "1024", "1k", "10M", "1G", etc. Setting it to "" means no limit.
 | 
			
		||||
        "client_max_websocket_message_size": "128K"
 | 
			
		||||
    },
 | 
			
		||||
    //plugins: Define all plugins running in the application
 | 
			
		||||
    "plugins": [{
 | 
			
		||||
        //name: The class name of the plugin
 | 
			
		||||
        //"name": "TestPlugin",
 | 
			
		||||
        //dependencies: Plugins that the plugin depends on. It can be commented out
 | 
			
		||||
        "dependencies": [],
 | 
			
		||||
        //config: The configuration of the plugin. This json object is the parameter to initialize the plugin.
 | 
			
		||||
        //It can be commented out
 | 
			
		||||
        "config": {
 | 
			
		||||
            "heartbeat_interval": 2
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
    }],
 | 
			
		||||
    //custom_config: custom configuration for users. This object can be get by the app().getCustomConfig() method. 
 | 
			
		||||
    "custom_config": {}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										43
									
								
								controllers/api_v1_Devices.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								controllers/api_v1_Devices.cc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,43 @@
 | 
			
		|||
#include "api_v1_Devices.h"
 | 
			
		||||
using namespace api::v1;
 | 
			
		||||
//add definition of your processing function here
 | 
			
		||||
 | 
			
		||||
void Devices::get_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    std::cout << "Get All\n";
 | 
			
		||||
 | 
			
		||||
    auto resp=HttpResponse::newHttpResponse();
 | 
			
		||||
    callback(resp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Devices::get_one(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
 | 
			
		||||
                      std::string device_id)
 | 
			
		||||
{
 | 
			
		||||
    std::cout << "Get One: " << device_id << "\n";
 | 
			
		||||
 | 
			
		||||
    auto resp=HttpResponse::newHttpResponse();
 | 
			
		||||
    callback(resp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Devices::get_relays_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
 | 
			
		||||
                             std::string device_id)
 | 
			
		||||
{
 | 
			
		||||
    std::cout << "Get Relays All: " << device_id << "\n";
 | 
			
		||||
 | 
			
		||||
    auto resp=HttpResponse::newHttpResponse();
 | 
			
		||||
    callback(resp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Devices::get_relays_one(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
 | 
			
		||||
                             std::string device_id, std::string relay_id)
 | 
			
		||||
{
 | 
			
		||||
    std::cout << "Get Relays One: " << device_id << "; " << relay_id << "\n";
 | 
			
		||||
 | 
			
		||||
    Json::Value ret;
 | 
			
		||||
    ret["result"] = "ok";
 | 
			
		||||
    ret["device_id"] = device_id;
 | 
			
		||||
    ret["relay_id"] = relay_id;
 | 
			
		||||
    auto resp = HttpResponse::newHttpJsonResponse(ret);
 | 
			
		||||
    callback(resp);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								controllers/api_v1_Devices.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								controllers/api_v1_Devices.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
#pragma once
 | 
			
		||||
#include <drogon/HttpController.h>
 | 
			
		||||
using namespace drogon;
 | 
			
		||||
namespace api
 | 
			
		||||
{
 | 
			
		||||
    namespace v1
 | 
			
		||||
    {
 | 
			
		||||
        class Devices:public drogon::HttpController<Devices>
 | 
			
		||||
        {
 | 
			
		||||
        public:
 | 
			
		||||
            METHOD_LIST_BEGIN
 | 
			
		||||
            METHOD_ADD(Devices::get_all,"/",Get);
 | 
			
		||||
            METHOD_ADD(Devices::get_one,"/{1}",Get);
 | 
			
		||||
            METHOD_ADD(Devices::get_relays_all,"/{1}/relays",Get);
 | 
			
		||||
            METHOD_ADD(Devices::get_relays_one,"/{1}/relays/{2}",Get);
 | 
			
		||||
            METHOD_LIST_END
 | 
			
		||||
 | 
			
		||||
            void get_all(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback);
 | 
			
		||||
            void get_one(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string device_id);
 | 
			
		||||
            void get_relays_all(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string device_id);
 | 
			
		||||
            void get_relays_one(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string device_id,std::string relay_id);
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								globals.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								globals.cc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
//
 | 
			
		||||
// Created by tobias on 11/07/19.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <sqlite3.h>
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
 | 
			
		||||
namespace globals
 | 
			
		||||
{
 | 
			
		||||
    sqlite3 *db;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								globals.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								globals.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
//
 | 
			
		||||
// Created by tobias on 11/07/19.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef EMGAUWA_CORE_GLOBALS_H
 | 
			
		||||
#define EMGAUWA_CORE_GLOBALS_H
 | 
			
		||||
 | 
			
		||||
namespace globals
 | 
			
		||||
{
 | 
			
		||||
    extern sqlite3 *db;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif //EMGAUWA_CORE_GLOBALS_H
 | 
			
		||||
							
								
								
									
										36
									
								
								main.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								main.cc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
#include <drogon/drogon.h>
 | 
			
		||||
#include <sqlite3.h>
 | 
			
		||||
 | 
			
		||||
#include <models/device_dbo.h>
 | 
			
		||||
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
 | 
			
		||||
    int rc;
 | 
			
		||||
 | 
			
		||||
    /* Open database */
 | 
			
		||||
    rc = sqlite3_open("test.db", &globals::db);
 | 
			
		||||
 | 
			
		||||
    if( rc ) {
 | 
			
		||||
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(globals::db));
 | 
			
		||||
        return 1;
 | 
			
		||||
    } else {
 | 
			
		||||
        fprintf(stderr, "Opened database successfully\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    device_dbo test;
 | 
			
		||||
    strcpy(test.id, "meine-tolle_id-123");
 | 
			
		||||
    strcpy(test.name, "test_device latest name");
 | 
			
		||||
    strcpy(test.ip, "192.168.1.68");
 | 
			
		||||
    test.active = true;
 | 
			
		||||
 | 
			
		||||
    test.save();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //Load config file
 | 
			
		||||
    drogon::app().loadConfigFile("../config.json");
 | 
			
		||||
    //Run HTTP framework,the method will block in the internal event loop
 | 
			
		||||
    drogon::app().run();
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								models/device_dbo.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								models/device_dbo.cc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,32 @@
 | 
			
		|||
//
 | 
			
		||||
// Created by tobias on 08/07/19.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <cstdio>
 | 
			
		||||
#include "device_dbo.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
 | 
			
		||||
bool device_dbo::save()
 | 
			
		||||
{
 | 
			
		||||
    int rc;
 | 
			
		||||
    sqlite3_stmt *stmt;
 | 
			
		||||
 | 
			
		||||
    //sqlite3_prepare_v2(db, "INSERT INTO devices(id, name, ip, active) values (?1, ?2, ?3, ?4);", -1, &stmt, nullptr);
 | 
			
		||||
    sqlite3_prepare_v2(globals::db, "UPDATE devices set name = ?2, ip = ?3, active = ?4 WHERE id = ?1;", -1, &stmt, nullptr);
 | 
			
		||||
 | 
			
		||||
    sqlite3_bind_text(stmt, 1, this->id, -1, SQLITE_STATIC);
 | 
			
		||||
    sqlite3_bind_text(stmt, 2, this->name, -1, SQLITE_STATIC);
 | 
			
		||||
    sqlite3_bind_text(stmt, 3, this->ip, -1, SQLITE_STATIC);
 | 
			
		||||
    sqlite3_bind_int(stmt, 4, this->active);
 | 
			
		||||
    //sqlite3_bind_int(stmt, 2, 21);
 | 
			
		||||
 | 
			
		||||
    rc = sqlite3_step(stmt);
 | 
			
		||||
    if (rc != SQLITE_DONE) {
 | 
			
		||||
        printf("ERROR inserting data: %s\n", sqlite3_errmsg(globals::db));
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sqlite3_finalize(stmt);
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								models/device_dbo.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								models/device_dbo.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
#ifndef EMGAUWA_CORE_DEVICE_DBO_H
 | 
			
		||||
#define EMGAUWA_CORE_DEVICE_DBO_H
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <sqlite3.h>
 | 
			
		||||
 | 
			
		||||
class device_dbo
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    char id[23];
 | 
			
		||||
    char name[128];
 | 
			
		||||
    char ip[17];
 | 
			
		||||
    bool active;
 | 
			
		||||
    int port;
 | 
			
		||||
    int relay_count;
 | 
			
		||||
 | 
			
		||||
    bool save();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif //EMGAUWA_CORE_DEVICE_DBO_H
 | 
			
		||||
							
								
								
									
										15
									
								
								models/model.template.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								models/model.template.json
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
{
 | 
			
		||||
    //rdbms:server type, postgresql,mysql or sqlite3
 | 
			
		||||
    "rdbms":"postgresql",
 | 
			
		||||
    //filename:sqlite3 db file name
 | 
			
		||||
    //"filename":"",
 | 
			
		||||
    //host:server address,localhost by default;
 | 
			
		||||
    "host":"127.0.0.1",
 | 
			
		||||
    //port:server port, 5432 by default;
 | 
			
		||||
    "port":5432,
 | 
			
		||||
    //dbname:Database name;
 | 
			
		||||
    "dbname":"",
 | 
			
		||||
    "user":"",
 | 
			
		||||
    "passwd":"",
 | 
			
		||||
    "tables":[]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								models/schedule_dbo.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								models/schedule_dbo.cc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
//
 | 
			
		||||
// Created by tobias on 09/07/19.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include "schedule_dbo.h"
 | 
			
		||||
							
								
								
									
										15
									
								
								models/schedule_dbo.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								models/schedule_dbo.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
//
 | 
			
		||||
// Created by tobias on 09/07/19.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef EMGAUWA_CORE_SCHEDULE_DBO_H
 | 
			
		||||
#define EMGAUWA_CORE_SCHEDULE_DBO_H
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class schedule_dbo
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif //EMGAUWA_CORE_SCHEDULE_DBO_H
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue