C++消息分发模块框架的构想

本文探讨了C++中实现消息分发的三种方式:消息回调函数、继承接口和统一消息结构体进行模块间通信。提出了一个初步的消息分发框架构想,尚未经过实践验证。
摘要由CSDN通过智能技术生成

消息分发有几种方式: 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                         
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值