消息分发有几种方式: 1、消息回调函数的使用 2、接口暴露,让每一个模块都继承这个模块 3、消息结构体统一或者约定格式,然后各个独立模块采用通信模块进行交互
以下是在一个分发的初步构想,未经验证
#pragma once
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <list>
#include <boost/thread.hpp>
/*
* ui界面层
* |
* |
* |
* service业务层(dispatcher分发模块)-----db数据库层
* |
* |
* |
* core通信层
*
*/
struct msg_param_t
{
std::string id;
std::string sender;
std::string receiver;
std::string body;
void* rsv;
};
typedef std::string msg_name_t;
typedef std::string msg_body_t;
//! 模板类,T为回调对象类型,每种msg 类型T中都需要定义相应的handle函数
// R代表请求的类型指针,这里使用泛型表示(暴露给上层)
template<typename T, typename R>
class msg_dispatcher_t
{
typedef R rcv_ptr_t; //! 消息的接收者