demo
This commit is contained in:
+10
-2
@@ -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})
|
||||
add_executable(dcapp main.cpp
|
||||
./datacenter/src/datacenter.cpp
|
||||
./datacenter/src/userinterface.cpp
|
||||
./datacenter/src/queue.cpp
|
||||
${DC_SRC} ${DS_SRC} ${DQ_SRC})
|
||||
@@ -1,5 +1,5 @@
|
||||
##数据中心APP
|
||||
|
||||
###1、多进程工作模式
|
||||
由主进程master + workNw +workPw 三个进程组成
|
||||
##数据中心APP
|
||||
|
||||
###1、多进程工作模式
|
||||
由主进程master + workNw +workPw 三个进程组成
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#include "dataservice.h"
|
||||
|
||||
#include "dataservice.h"
|
||||
|
||||
REGISTER_SERVICE(DataService);
|
||||
+39
-39
@@ -1,40 +1,40 @@
|
||||
#ifndef _DCAPP_DATASERVICE_DATASERVICE_H_
|
||||
#define _DCAPP_DATASERVICE_DATASERVICE_H_
|
||||
|
||||
#include <unistd.h>
|
||||
#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 <unistd.h>
|
||||
#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_
|
||||
@@ -1,42 +1,42 @@
|
||||
#ifndef _DCAPP_SERVICE_H_
|
||||
#define _DCAPP_SERVICE_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
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<std::string, IService*>& getServiceMap(){
|
||||
static std::map<std::string, IService*> 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 <map>
|
||||
#include <string>
|
||||
|
||||
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<std::string, IService*>& getServiceMap(){
|
||||
static std::map<std::string, IService*> serviceMap;
|
||||
return serviceMap;
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_SERVICE(className) \
|
||||
struct className##Register { \
|
||||
className##Register() { \
|
||||
ServiceFactovy::getServiceMap()[#className] = new className(); \
|
||||
} \
|
||||
} className##RegisterInstance;
|
||||
|
||||
#endif // _DCAPP_SERVICE_H_
|
||||
Reference in New Issue
Block a user