Browse Source

init

master
Your Name 3 years ago
commit
23a11dd103
  1. 61
      .vscode/settings.json
  2. 88
      CMakeLists.txt
  3. 8
      README.md
  4. 120
      cmake/FindFFmpeg.cmake
  5. 96
      cmake/FindGFlags.cmake
  6. 94
      cmake/FindGlog.cmake
  7. 129
      cmake/FindMYSQL.cmake
  8. 0
      docker/Dockerfile
  9. 42
      framework/CMakeLists.txt
  10. BIN
      lib/libmodels.so
  11. 85
      modules/CMakeLists.txt
  12. 35
      modules/TcpServer/include/TcpServer.hpp
  13. 18
      modules/TcpServer/src/TcpServer.cpp
  14. 94
      modules/UserApp/include/UserApp.hpp
  15. 42
      modules/UserApp/src/UserApp.cpp
  16. 0
      source/config/config.ini
  17. 54
      source/src/main.cpp

61
.vscode/settings.json vendored

@ -0,0 +1,61 @@
{
"files.associations": {
"*.cpp": "cpp",
"iostream": "cpp",
"functional": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"ratio": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"numeric": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"regex": "cpp",
"utility": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp"
}
}

88
CMakeLists.txt

@ -0,0 +1,88 @@
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "Please create a separate directory for build files.")
endif()
cmake_minimum_required(VERSION 3.6)
project(ISNS C CXX)
set(CMAKE_VERBOSE_MAKEFILE OFF)
# ---[ Options
option(build_modules "build modules" ON)
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/source/bin/)
if(build_modules)
add_subdirectory(modules)
endif()
##OpenCV
if(WITH_OPENCV)
if(CMAKE_TOOLCHAIN_FILE)
if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv)
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_features2d opencv_flann)
if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv2/imgcodecs)
list(APPEND OpenCV_LIBS opencv_imgcodecs)
endif()
if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv2/videoio)
list(APPEND OpenCV_LIBS opencv_videoio)
endif()
message(STATUS "HAVE_OPENCV enabled")
message(STATUS "opencv libraries: ${OpenCV_LIBS}")
set(HAVE_OPENCV true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
else()
set (HAVE_OPENCV false)
endif()
else()
set(OpenCV_FIND_QUIETLY true)
#find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
find_package(OpenCV OPTIONAL_COMPONENTS imgcodecs)
find_package(OpenCV OPTIONAL_COMPONENTS videoio)
set(optional_opencv_libs ${OpenCV_LIBS})
find_package(OpenCV REQUIRED core imgproc highgui features2d)
if(OpenCV_FOUND)
if(imgcodecs_FOUND)
list(APPEND OpenCV_LIBS optional_opencv_libs)
endif()
message(STATUS "HAVE_OPENCV enabled")
message(STATUS "opencv libraries: ${OpenCV_LIBS}")
set(HAVE_OPENCV true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
else()
set (HAVE_OPENCV false)
endif()
endif()
else()
set (HAVE_OPENCV false)
endif()
#mysql
find_package(MYSQL QUIET)
if(MYSQL_FOUND AND ENABLE_MYSQL)
message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
include_directories(${MYSQL_INCLUDE_DIR})
include_directories(${MYSQL_INCLUDE_DIR}/mysql)
add_definitions(-DENABLE_MYSQL)
list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
endif()
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/rapidjson/include/)
include_directories(/usr/local/include/hv)
include_directories(${PROJECT_SOURCE_DIR}/modules/UserApp/include/)
#
aux_source_directory(./source/src DIR_SRCS)
add_compile_options(-Wall -std=c++11 -O2 -g)
link_directories(${PROJECT_SOURCE_DIR}/lib)
link_directories(/usr/local/lib)
list(APPEND ALL_LINKER_LIBS mk_api ZLToolKit dl ${3RDPARTY_LIBS} ${OpenCV_LIBS} pthread hv models)
#
add_executable(main ${DIR_SRCS})
#
target_link_libraries(main ${ALL_LINKER_LIBS})

8
README.md

@ -0,0 +1,8 @@
## Satellite
***
> Satellite

120
cmake/FindFFmpeg.cmake

@ -0,0 +1,120 @@
# ==============================================
# Try to find FFmpeg libraries:
# - avcodec
# - avformat
# - avdevice
# - avutil
# - swscale
# - avfilter
#
# FFMPEG_FOUND - system has FFmpeg
# FFMPEG_INCLUDE_DIR - the FFmpeg inc directory
# FFMPEG_LIBRARIES - Link these to use FFmpeg
# ==============================================
# Notice: this original script is from internet.
if (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
# in cache already
set(FFMPEG_FOUND TRUE)
else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
find_path(
FFMPEG_AVCODEC_INCLUDE_DIR
NAMES libavcodec/avcodec.h
PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS}
/usr/include/ffmpeg
/usr/local/include
/usr/local/ffmpeg/include
)
find_library(
FFMPEG_LIBAVCODEC
NAMES avcodec
PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS}
/usr/lib64
/usr/local/lib
/usr/local/ffmpeg/lib
/usr/lib/aarch64-linux-gnu/
)
find_library(
FFMPEG_LIBAVFORMAT
NAMES avformat
PATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS}
/usr/lib64
/usr/local/lib
/usr/local/ffmpeg/lib
/usr/lib/aarch64-linux-gnu
)
find_library(
FFMPEG_LIBSWRESAMPLE
NAMES swresample
PATHS ${_FFMPEG_SWRESAMPLE_LIBRARY_DIRS}
/usr/lib64
/usr/local/lib
/usr/local/ffmpeg/lib
/usr/lib/aarch64-linux-gnu/
)
find_library(
FFMPEG_LIBAVUTIL
NAMES avutil
PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}
/usr/lib64
/usr/local/lib
/usr/local/ffmpeg/lib
/usr/lib/aarch64-linux-gnu/
)
find_library(
FFMPEG_LIBSWSCALE
NAMES swscale
PATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS}
/usr/lib64
/usr/local/lib
/usr/local/ffmpeg/lib
/usr/lib/aarch64-linux-gnu/
)
find_library(
FFMPEG_LIBAVFILTER
NAMES avfilter
PATHS ${_FFMPEG_AVFILTER_LIBRARY_DIRS}
/usr/lib64
/usr/local/lib
/usr/local/ffmpeg/lib
/usr/lib/aarch64-linux-gnu/
)
find_library(
FFMPEG_LIBAVDEVICE
NAMES avdevice
PATHS ${_FFMPEG_AVDEVICE_LIBRARY_DIRS}
/usr/lib64
/usr/local/lib
/usr/local/ffmpeg/lib
/usr/lib/aarch64-linux-gnu/
)
if (WITH_FFMPEG_AVDEVICE AND NOT FFMPEG_LIBAVDEVICE)
message(FATAL_ERROR "Not find FFmpeg LIBAVDEVICE ")
endif ()
if (FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT AND FFMPEG_LIBAVUTIL AND FFMPEG_LIBSWSCALE AND FFMPEG_LIBSWRESAMPLE AND (FFMPEG_LIBAVDEVICE OR NOT WITH_FFMPEG_AVDEVICE))
set(FFMPEG_FOUND TRUE)
endif ()
if (FFMPEG_FOUND)
set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR})
set(FFMPEG_LIBRARIES
${FFMPEG_LIBAVCODEC}
${FFMPEG_LIBAVFORMAT}
${FFMPEG_LIBAVUTIL}
${FFMPEG_LIBSWSCALE}
${FFMPEG_LIBSWRESAMPLE})
if (WITH_FFMPEG_AVDEVICE)
list(APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBAVDEVICE})
endif (WITH_FFMPEG_AVDEVICE)
else (FFMPEG_FOUND)
message(FATAL_ERROR "Could not find FFmpeg libraries!")
endif (FFMPEG_FOUND)
endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)

96
cmake/FindGFlags.cmake

@ -0,0 +1,96 @@
#COPYRIGHT
#
#All contributions by the University of California:
#Copyright (c) 2014-2017 The Regents of the University of California (Regents)
#All rights reserved.
#
#All other contributions:
#Copyright (c) 2014-2017, the respective contributors
#All rights reserved.
#
#Caffe uses a shared copyright model: each contributor holds copyright over
#their contributions to Caffe. The project versioning records all such
#contribution and copyright details. If a contributor wants to further mark
#their specific copyright on a particular contribution, they should indicate
#their copyright solely in the commit message of the change when it is
#committed.
#
#LICENSE
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
#1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
#ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#CONTRIBUTION AGREEMENT
#
#By contributing to the BVLC/caffe repository through pull-request, comment,
#or otherwise, the contributor releases their content to the
#license and copyright terms herein.
#
# - Try to find GFLAGS
#
# The following variables are optionally searched for defaults
# GFLAGS_ROOT_DIR: Base directory where all GFLAGS components are found
#
# The following are set after configuration is done:
# GFLAGS_FOUND
# GFLAGS_INCLUDE_DIRS
# GFLAGS_LIBRARIES
# GFLAGS_LIBRARYRARY_DIRS
include(FindPackageHandleStandardArgs)
set(GFLAGS_ROOT_DIR "" CACHE PATH "Folder contains Gflags")
# We are testing only a couple of files in the include directories
if(WIN32)
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
PATHS ${GFLAGS_ROOT_DIR}/src/windows)
else()
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
PATHS ${GFLAGS_ROOT_DIR})
endif()
if(MSVC)
find_library(GFLAGS_LIBRARY_RELEASE
NAMES libgflags
PATHS ${GFLAGS_ROOT_DIR}
PATH_SUFFIXES Release)
find_library(GFLAGS_LIBRARY_DEBUG
NAMES libgflags-debug
PATHS ${GFLAGS_ROOT_DIR}
PATH_SUFFIXES Debug)
set(GFLAGS_LIBRARY optimized ${GFLAGS_LIBRARY_RELEASE} debug ${GFLAGS_LIBRARY_DEBUG})
else()
find_library(GFLAGS_LIBRARY gflags)
endif()
find_package_handle_standard_args(GFlags DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)
if(GFLAGS_FOUND)
set(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR})
set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY})
message(STATUS "Found gflags (include: ${GFLAGS_INCLUDE_DIR}, library: ${GFLAGS_LIBRARY})")
mark_as_advanced(GFLAGS_LIBRARY_DEBUG GFLAGS_LIBRARY_RELEASE
GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR GFLAGS_ROOT_DIR)
endif()

94
cmake/FindGlog.cmake

@ -0,0 +1,94 @@
#COPYRIGHT
#
#All contributions by the University of California:
#Copyright (c) 2014-2017 The Regents of the University of California (Regents)
#All rights reserved.
#
#All other contributions:
#Copyright (c) 2014-2017, the respective contributors
#All rights reserved.
#
#Caffe uses a shared copyright model: each contributor holds copyright over
#their contributions to Caffe. The project versioning records all such
#contribution and copyright details. If a contributor wants to further mark
#their specific copyright on a particular contribution, they should indicate
#their copyright solely in the commit message of the change when it is
#committed.
#
#LICENSE
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
#1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
#ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#CONTRIBUTION AGREEMENT
#
#By contributing to the BVLC/caffe repository through pull-request, comment,
#or otherwise, the contributor releases their content to the
#license and copyright terms herein.
#
# - Try to find Glog
#
# The following variables are optionally searched for defaults
# GLOG_ROOT_DIR: Base directory where all GLOG components are found
#
# The following are set after configuration is done:
# GLOG_FOUND
# GLOG_INCLUDE_DIRS
# GLOG_LIBRARIES
# GLOG_LIBRARYRARY_DIRS
include(FindPackageHandleStandardArgs)
set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog")
if(WIN32)
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS ${GLOG_ROOT_DIR}/src/windows)
else()
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS ${GLOG_ROOT_DIR})
endif()
if(MSVC)
find_library(GLOG_LIBRARY_RELEASE libglog_static
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES Release)
find_library(GLOG_LIBRARY_DEBUG libglog_static
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES Debug)
set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG})
else()
find_library(GLOG_LIBRARY glog
PATHS ${GLOG_ROOT_DIR}
PATH_SUFFIXES lib lib64)
endif()
find_package_handle_standard_args(Glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY)
if(GLOG_FOUND)
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})
set(GLOG_LIBRARIES ${GLOG_LIBRARY})
message(STATUS "Found glog (include: ${GLOG_INCLUDE_DIR}, library: ${GLOG_LIBRARY})")
mark_as_advanced(GLOG_ROOT_DIR GLOG_LIBRARY_RELEASE GLOG_LIBRARY_DEBUG
GLOG_LIBRARY GLOG_INCLUDE_DIR)
endif()

129
cmake/FindMYSQL.cmake

@ -0,0 +1,129 @@
# - Try to find MySQL / MySQL Embedded library
# Find the MySQL includes and client library
# This module defines
# MYSQL_INCLUDE_DIR, where to find mysql.h
# MYSQL_LIBRARIES, the libraries needed to use MySQL.
# MYSQL_LIB_DIR, path to the MYSQL_LIBRARIES
# MYSQL_EMBEDDED_LIBRARIES, the libraries needed to use MySQL Embedded.
# MYSQL_EMBEDDED_LIB_DIR, path to the MYSQL_EMBEDDED_LIBRARIES
# MYSQL_FOUND, If false, do not try to use MySQL.
# MYSQL_EMBEDDED_FOUND, If false, do not try to use MySQL Embedded.
# Copyright (c) 2006-2008, Jarosław Staniek <staniek@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
include(CheckCXXSourceCompiles)
if(WIN32)
find_path(MYSQL_INCLUDE_DIR mysql.h
PATHS
$ENV{MYSQL_INCLUDE_DIR}
$ENV{MYSQL_DIR}/include
$ENV{ProgramFiles}/MySQL/*/include
$ENV{SystemDrive}/MySQL/*/include
$ENV{ProgramW6432}/MySQL/*/include
)
else(WIN32)
find_path(MYSQL_INCLUDE_DIR mysql/mysql.h
PATHS
$ENV{MYSQL_INCLUDE_DIR}
$ENV{MYSQL_DIR}/include
/usr/local/mysql/include
PATH_SUFFIXES
mysql
)
endif(WIN32)
if(WIN32)
if (${CMAKE_BUILD_TYPE})
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER)
endif()
# path suffix for debug/release mode
# binary_dist: mysql binary distribution
# build_dist: custom build
if(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
set(binary_dist debug)
set(build_dist Debug)
else(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
ADD_DEFINITIONS(-DDBUG_OFF)
set(binary_dist opt)
set(build_dist Release)
endif(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
# find_library(MYSQL_LIBRARIES NAMES mysqlclient
set(MYSQL_LIB_PATHS
$ENV{MYSQL_DIR}/lib/${binary_dist}
$ENV{MYSQL_DIR}/libmysql/${build_dist}
$ENV{MYSQL_DIR}/client/${build_dist}
$ENV{ProgramFiles}/MySQL/*/lib/${binary_dist}
$ENV{SystemDrive}/MySQL/*/lib/${binary_dist}
$ENV{MYSQL_DIR}/lib/opt
$ENV{MYSQL_DIR}/client/release
$ENV{ProgramFiles}/MySQL/*/lib/opt
$ENV{ProgramFiles}/MySQL/*/lib/
$ENV{SystemDrive}/MySQL/*/lib/opt
$ENV{ProgramW6432}/MySQL/*/lib
)
find_library(MYSQL_LIBRARIES NAMES libmysql
PATHS
${MYSQL_LIB_PATHS}
)
else(WIN32)
# find_library(MYSQL_LIBRARIES NAMES mysqlclient
set(MYSQL_LIB_PATHS
$ENV{MYSQL_DIR}/libmysql_r/.libs
$ENV{MYSQL_DIR}/lib
$ENV{MYSQL_DIR}/lib/mysql
/usr/local/mysql/lib
/opt/mysql/mysql/lib
$ENV{MYSQL_DIR}/libmysql_r/.libs
$ENV{MYSQL_DIR}/lib
$ENV{MYSQL_DIR}/lib/mysql
/usr/local/mysql/lib
/opt/mysql/mysql/lib
PATH_SUFFIXES
mysql
)
find_library(MYSQL_LIBRARIES NAMES mysqlclient
PATHS
${MYSQL_LIB_PATHS}
)
endif(WIN32)
find_library(MYSQL_EMBEDDED_LIBRARIES NAMES mysqld
PATHS
${MYSQL_LIB_PATHS}
)
if(MYSQL_LIBRARIES)
get_filename_component(MYSQL_LIB_DIR ${MYSQL_LIBRARIES} PATH)
endif(MYSQL_LIBRARIES)
if(MYSQL_EMBEDDED_LIBRARIES)
get_filename_component(MYSQL_EMBEDDED_LIB_DIR ${MYSQL_EMBEDDED_LIBRARIES} PATH)
endif(MYSQL_EMBEDDED_LIBRARIES)
set( CMAKE_REQUIRED_INCLUDES ${MYSQL_INCLUDE_DIR} )
set( CMAKE_REQUIRED_LIBRARIES ${MYSQL_EMBEDDED_LIBRARIES} )
check_cxx_source_compiles( "#include <mysql.h>\nint main() { int i = MYSQL_OPT_USE_EMBEDDED_CONNECTION; }" HAVE_MYSQL_OPT_EMBEDDED_CONNECTION )
if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
set(MYSQL_FOUND TRUE)
message(STATUS "Found MySQL: ${MYSQL_INCLUDE_DIR}, ${MYSQL_LIBRARIES}")
else(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
set(MYSQL_FOUND FALSE)
message(STATUS "MySQL not found.")
endif(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
if(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
set(MYSQL_EMBEDDED_FOUND TRUE)
message(STATUS "Found MySQL Embedded: ${MYSQL_INCLUDE_DIR}, ${MYSQL_EMBEDDED_LIBRARIES}")
else(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
set(MYSQL_EMBEDDED_FOUND FALSE)
message(STATUS "MySQL Embedded not found.")
endif(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES MYSQL_EMBEDDED_LIBRARIES)

0
docker/Dockerfile

42
framework/CMakeLists.txt

@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.6)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib/)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/)
set(INS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
add_compile_options(-std=c++11)
# compile flags
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
set(CNSTREAM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(LIBRARY_OUTPUT_PATH ${CNSTREAM_ROOT_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/)
set(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake)
set(VERSION_HEAD_FILE ${INS_ROOT_DIR}/framework/core/include/ins_version.hpp)
execute_process(COMMAND awk /INS_MAJOR_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
string(REGEX MATCH "[0-9]+" MAJOR_VERSION ${VERSION_STR})
execute_process(COMMAND awk /INS_MINOR_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
string(REGEX MATCH "[0-9]+" MINOR_VERSION ${VERSION_STR})
execute_process(COMMAND awk /INS_PATCH_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
string(REGEX MATCH "[0-9]+" PATCH_VERSION ${VERSION_STR})
set(ISNS_TARGET_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
include_directories(${3RDPARTY_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/rapidjson/include/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dataType/include/)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/core/src core_srcs)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/dataType/src core_srcs)
add_library(ins_core SHARED ${core_srcs} )
target_link_libraries(ins_core protobuf ${SOURCE_LINKER_LIBS})
target_link_libraries(ins_core dl pthread ${CNRT_LIBS} ${GFLAGS_LIBRARIES})
set_target_properties(ins_core PROPERTIES LINK_FLAGS_RELEASE -s)
set_target_properties(ins_core PROPERTIES VERSION ${ISNS_TARGET_VERSION})

BIN
lib/libmodels.so

Binary file not shown.

85
modules/CMakeLists.txt

@ -0,0 +1,85 @@
cmake_minimum_required(VERSION 3.6)
set(INS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib/)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(NOT COMPILER_SUPPORTS_CXX11)
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
if(USE_libstdcpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
endif()
# compile flags
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
# ---[ Options
option(build_UserApp "build module UserApp " ON)
option(build_TcpServer "build module TcpServer" ON)
# ---[ 3rdparty
set(3RDPARTY_LIBS "")
set(DEPENDENCIES "")
set(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake)
# ---[ opencv
set(OpenCV_FIND_QUIETLY true)
#find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
find_package(OpenCV OPTIONAL_COMPONENTS imgcodecs)
find_package(OpenCV OPTIONAL_COMPONENTS videoio)
set(optional_opencv_libs ${OpenCV_LIBS})
find_package(OpenCV REQUIRED core imgproc highgui features2d)
if(OpenCV_FOUND)
if(imgcodecs_FOUND)
list(APPEND OpenCV_LIBS optional_opencv_libs)
endif()
include_directories(${OpenCV_INCLUDE_DIRS})
list(APPEND 3RDPARTY_LIBS ${OpenCV_LIBS})
message(STATUS "opencv include: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "opencv libraries: ${OpenCV_LIBS}")
else()
message(FATAL_ERROR "opencv not found!")
endif()
find_package(MYSQL QUIET)
if(MYSQL_FOUND AND ENABLE_MYSQL)
message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
include_directories(${MYSQL_INCLUDE_DIR})
include_directories(${MYSQL_INCLUDE_DIR}/mysql)
add_definitions(-DENABLE_MYSQL)
list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
endif()
set(module_list "")
if(build_UserApp)
list(APPEND module_list UserApp)
include_directories(${PROJECT_SOURCE_DIR}/modules/UserApp/src)
install(DIRECTORY UserApp/include/ DESTINATION include)
endif()
if(build_TcpServer)
list(APPEND module_list TcpServer)
include_directories(${PROJECT_SOURCE_DIR}/modules/TcpServer/src)
install(DIRECTORY TcpServer/include/ DESTINATION include)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(/usr/local/include/hv)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/rapidjson/include/)
foreach(module ${module_list})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
list(APPEND srcs ${module_src})
endforeach()
add_library(models SHARED ${srcs})
install(TARGETS models LIBRARY DESTINATION lib)
target_link_libraries(models ${3RDPARTY_LIBS} rt dl pthread ZLToolKit hv )

35
modules/TcpServer/include/TcpServer.hpp

@ -0,0 +1,35 @@
/*
* @Description:
* @Version: 1.0
* @Autor: lishengyin
* @Date: 2022-04-11 17:30:58
* @LastEditors: lishengyin
* @LastEditTime: 2022-04-11 17:43:09
*/
#ifndef __TCPSERVER_HPP_
#define __TCPSERVER_HPP_
#include "UserApp.hpp"
#include "TcpServer.hpp"
class TcpServer:private NonCopyable
{
private:
TcpServer(int port):port_(port){}
public:
using Ptr = std::shared_ptr<TcpServer>;
~TcpServer();
/**
* @description:
* @param {int} port
* @return {*}
*/
static std::shared_ptr<TcpServer> CreateNew(int port);
private:
int port_;
};
#endif

18
modules/TcpServer/src/TcpServer.cpp

@ -0,0 +1,18 @@
/*
* @Description:
* @Version: 1.0
* @Autor: lishengyin
* @Date: 2022-04-11 17:31:02
* @LastEditors: lishengyin
* @LastEditTime: 2022-04-11 17:43:05
*/
#include "TcpServer.hpp"
/**
* @description:
* @param {int} port
* @return {*}
*/
std::shared_ptr<TcpServer> TcpServer::CreateNew(int port){
return std::shared_ptr<TcpServer>(new TcpServer(port));
}

94
modules/UserApp/include/UserApp.hpp

@ -0,0 +1,94 @@
/*
* @Description:
* @Version: 1.0
* @Autor: lishengyin
* @Date: 2022-04-11 17:12:05
* @LastEditors: lishengyin
* @LastEditTime: 2022-04-11 17:31:20
*/
#ifndef __USERAPP_HPP_
#define __USERAPP_HPP_
#include <iostream>
#include <string.h>
#include <unistd.h>
#include <string>
#include <vector>
#include <atomic>
#include <bitset>
#include <functional>
#include <list>
#include <memory>
#include <string>
#include <thread>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define OK 0
#define ERR -1
// NonCopyAble
class NonCopyable {
protected:
NonCopyable() {};
~NonCopyable() {};
public:
NonCopyable(const NonCopyable&) = delete;
NonCopyable(NonCopyable&&) = delete;
NonCopyable& operator=(const NonCopyable&) = delete;
NonCopyable& operator=(NonCopyable&&) = delete;
static std::string getDataTime(){
char ctime[80];
time_t rawtime;
struct tm *info;
time(&rawtime);
info = localtime(&rawtime);
strftime(ctime, 80, "%Y-%m-%d %H:%M:%S", info);
std::string DataTime = ctime;
return DataTime;
}
};
class UserApp:private NonCopyable
{
private:
UserApp(std::string appName):appName_(appName){}
public:
using Ptr = std::shared_ptr<UserApp>;
~UserApp(){}
/**
* @description:
* @param {string} appName
* @return {*}
*/
static std::shared_ptr<UserApp> CreateNew(std::string appName);
/**
* @description:
* @param {*}
* @return {*}
*/
int8_t Init();
/**
* @description:
* @param {*}
* @return {*}
*/
int8_t StartTask();
private:
std::string appName_;
};
#endif

42
modules/UserApp/src/UserApp.cpp

@ -0,0 +1,42 @@
/*
* @Description:
* @Version: 1.0
* @Autor: lishengyin
* @Date: 2022-04-11 17:12:10
* @LastEditors: lishengyin
* @LastEditTime: 2022-04-11 17:41:49
*/
#include "UserApp.hpp"
/**
* @description:
* @param {string} appName
* @return {*}
*/
std::shared_ptr<UserApp> UserApp::CreateNew(std::string appName){
return std::shared_ptr<UserApp>(new UserApp(appName));
}
/**
* @description:
* @param {*}
* @return {*}
*/
int8_t UserApp::Init(){
return OK;
}
/**
* @description:
* @param {*}
* @return {*}
*/
int8_t StartTask(){
return OK;
}

0
source/config/config.ini

54
source/src/main.cpp

@ -0,0 +1,54 @@
#include <iostream>
#include <signal.h>
#include "Util/logger.h"
#include "Util/NoticeCenter.h"
#include "UserApp.hpp"
#include "Network/TcpServer.h"
using namespace std;
using namespace toolkit;
class EchoSession: public TcpSession {
public:
EchoSession(const Socket::Ptr &sock) :
TcpSession(sock) {
DebugL;
}
~EchoSession() {
DebugL;
}
virtual void onRecv(const Buffer::Ptr &buf) override{
//处理客户端发送过来的数据
TraceL << buf->data() << " from port:" << get_local_port();
send(buf);
}
virtual void onError(const SockException &err) override{
//客户端断开连接或其他原因导致该对象脱离TCPServer管理
WarnL << err.what();
}
virtual void onManager() override{
//定时管理该对象,譬如会话超时检查
DebugL;
}
private:
Ticker _ticker;
};
int main(int argc, char *argv[])
{
//设置退出信号处理函数
static semaphore sem;
signal(SIGINT, [](int) { sem.post(); });// 设置退出信号
// 设置日志
Logger::Instance().add(std::make_shared<ConsoleChannel>());
Logger::Instance().add(std::make_shared<FileChannel>());
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
TcpServer::Ptr server(new TcpServer());
server->start<EchoSession>(7400);//监听9000端口
sem.wait();
return 0;
}
Loading…
Cancel
Save