From 7cbae4eb4860088242193a753ec1457563dd0021 Mon Sep 17 00:00:00 2001 From: zjp <57092954@qq.com> Date: Mon, 24 Feb 2025 08:57:55 +0800 Subject: [PATCH] demo --- CMakeLists.txt | 12 +++++- Readme.md | 8 ++-- dataservice/dataservice.cpp | 4 +- dataservice/dataservice.h | 78 +++++++++++++++++------------------ service.h | 82 ++++++++++++++++++------------------- 5 files changed, 96 insertions(+), 88 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 291940a..6be929e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,19 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.13) project(dcapp) set(CMAKE_CXX_STANDARD 14) include_directories(./) +include_directories(./datacenter/inc) + + +LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/lib/arm) aux_source_directory(./datacenter DC_SRC) aux_source_directory(./dataservice DS_SRC) -add_executable(dcapp main.cpp ${DC_SRC} ${DS_SRC}) \ No newline at end of file +add_executable(dcapp main.cpp +./datacenter/src/datacenter.cpp +./datacenter/src/userinterface.cpp +./datacenter/src/queue.cpp +${DC_SRC} ${DS_SRC} ${DQ_SRC}) \ No newline at end of file diff --git a/Readme.md b/Readme.md index 5342e36..d2ab4d3 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,5 @@ -##数据中心APP - -###1、多进程工作模式 - 由主进程master + workNw +workPw 三个进程组成 +##数据中心APP + +###1、多进程工作模式 + 由主进程master + workNw +workPw 三个进程组成 \ No newline at end of file diff --git a/dataservice/dataservice.cpp b/dataservice/dataservice.cpp index 6f663d8..ec5947f 100644 --- a/dataservice/dataservice.cpp +++ b/dataservice/dataservice.cpp @@ -1,3 +1,3 @@ -#include "dataservice.h" - +#include "dataservice.h" + REGISTER_SERVICE(DataService); \ No newline at end of file diff --git a/dataservice/dataservice.h b/dataservice/dataservice.h index 1588031..859d42d 100644 --- a/dataservice/dataservice.h +++ b/dataservice/dataservice.h @@ -1,40 +1,40 @@ -#ifndef _DCAPP_DATASERVICE_DATASERVICE_H_ -#define _DCAPP_DATASERVICE_DATASERVICE_H_ - -#include -#include "service.h" - -class DataService :public IService { -public: - DataService() { - printf(".1.\n"); - } - ~DataService(){ - printf(".2.\n"); - } - - /** - * 服务初始化 - */ - virtual int Init(void *pData) { - printf("--- DataService Init.....\n"); - return 0; - } - - /** - * 执行业务(业务循环) while(1){doSomeThings...} - */ - virtual void Exec() { - while(1){ - printf("-- DataService doThins...\n"); - sleep(2); - } - } - - virtual const char* getServiceName(){ - return "DataService"; - } - -}; - +#ifndef _DCAPP_DATASERVICE_DATASERVICE_H_ +#define _DCAPP_DATASERVICE_DATASERVICE_H_ + +#include +#include "service.h" + +class DataService :public IService { +public: + DataService() { + printf(".11.\n"); + } + ~DataService(){ + printf(".22.\n"); + } + + /** + * 服务初始化 + */ + virtual int Init(void *pData) { + printf("--- DataService Init.....\n"); + return 0; + } + + /** + * 执行业务(业务循环) while(1){doSomeThings...} + */ + virtual void Exec() { + while(1){ + //printf("-- DataService doThins...\n"); + sleep(2); + } + } + + virtual const char* getServiceName(){ + return "DataService"; + } + +}; + #endif // _DCAPP_DATASERVICE_DATASERVICE_H_ \ No newline at end of file diff --git a/service.h b/service.h index 846b933..e84860c 100644 --- a/service.h +++ b/service.h @@ -1,42 +1,42 @@ -#ifndef _DCAPP_SERVICE_H_ -#define _DCAPP_SERVICE_H_ - -#include -#include - -class IService{ -public: - /** - * 服务初始化 - */ - virtual int Init(void *pData) = 0; - - /** - * 执行业务(业务循环) while(1){doSomeThings...} - */ - virtual void Exec() = 0; - - /** - * 获取服务名称 - * @return - */ - virtual const char* getServiceName() = 0; -}; - - -class ServiceFactovy{ -public: - static std::map& getServiceMap(){ - static std::map serviceMap; - return serviceMap; - } -}; - -#define REGISTER_SERVICE(className) \ - struct className##Register { \ - className##Register() { \ - ServiceFactovy::getServiceMap()[#className] = new className(); \ - } \ - } className##RegisterInstance; - +#ifndef _DCAPP_SERVICE_H_ +#define _DCAPP_SERVICE_H_ + +#include +#include + +class IService{ +public: + /** + * 服务初始化 + */ + virtual int Init(void *pData) = 0; + + /** + * 执行业务(业务循环) while(1){doSomeThings...} + */ + virtual void Exec() = 0; + + /** + * 获取服务名称 + * @return + */ + virtual const char* getServiceName() = 0; +}; + + +class ServiceFactovy{ +public: + static std::map& getServiceMap(){ + static std::map serviceMap; + return serviceMap; + } +}; + +#define REGISTER_SERVICE(className) \ + struct className##Register { \ + className##Register() { \ + ServiceFactovy::getServiceMap()[#className] = new className(); \ + } \ + } className##RegisterInstance; + #endif // _DCAPP_SERVICE_H_ \ No newline at end of file