在复杂的工程中,整个系统被分为数个模块,每个模块提供有限的功能,由上层调用从而组成整个系统,为了保证每个模块的独立性,我们经常限制模块与模块之间直接联系,每个模块只提供有限的API或Com接口,内部完全封装起来。
有时候两个不同的逻辑层的模块需要通信,如果直接include头文件会使项目变的复杂,sigslot的出现为我们提供了一种解决问题的思想,它用“信号”的概念实现不同模块之间的传输问题,sigslot本身类似于一条通讯电缆,两端提供发送器和接收器,只要把两个模块用这条电缆连接起来就可以实现接口调用,而sigslot本身只是一个轻量级的作品,整个库只有一个.h文件,所以无论处于何种层次的库,都可以非常方便的包含它。
举个例子,我们设计一个发送消息的类,这个类负责在某种时刻向外界发出求救信号
#include "sigslot.h"
class Sender
{
public:
// 定义信号,该信号有两个参数
sigslot::signal2< std::string , int > SignalDanger;
// 该函数发送消息
void Panic()
{
SignalDanger("Help!", 0);
}
};
另外一个类则负责接收求助信号
class Receiver : public sigslot::has_slots<>
{
public:
// 接收SignalDanger 信号的函数,该函数参数必须和信号的参数一致
void OnDanger(std::string message, int time)
{
printf("I heard something like "%s" at %d!n", message.c_str(), time);
}
};
现在让我们在主逻辑中把这两个类连接起来
Sender sender;
Receiver receiver;
// 将发送者的信号连接到接收方的接收函数上;和断开连接
sender.SignalDanger.connect(&receiver, Receiver::OnDanger);
sender.SignalDanger.disconnect(&receiver);
只要在任何时候调用 sender.Panic()函数,就会把求救信号发送给接收者,而且这两个发送和接收端的模块都可以独立编译,不会出现版本问题。
libjingle命名规则:
信号命名:signal....
收到信号:on...
相关推荐
信号与系统 Signals and Systems Girod
Signals.and.SystemsOppenheim.EN.pdf Signals.and.SystemsOppenheim.EN.pdf
Radar Signals: An Introduction to Theory and Application introduces the reader to the basic theory and application of radar signals that are designated as large time-bandwidth or pulse-compression ...
经典书籍RADAR SIGNALS Matched Filter;Ambiguity Function;Basic Radar Signals;Frequency-Modulated Pulse。。。
一本很好的国外的信号谱分析教材.Spectral Analysis of Signals(Petre Stoica and Randolph Moses)
.B.P.Lathi,Linear.Systems.and.Signals 详细书签 英文原版
SPECTRAL ANALYSIS OF SIGNALS,Yanwei Wang,Jian Li, Petre Stoica著,信号谱分析,pdf格式电子书
Radar Signals by Nadav Levanon
In this letter, a new unambiguous tracking technique is proposed for binary offset carrier (BOC) modulated signals, which will be utilized in global navigation satellite systems (GNSS). The proposed ...
信号与系统试卷signals and systems
The CSignalCandles class provides trade signals, based on reversal candlestick patterns. The strategy called "Signals based on reversal candlestick patterns
Spectral Analysis of Signals 信号的光谱分析 作者 Petre &Randolph;
signals and systems with matlab code
前端项目-js-signals,自定义事件/消息系统
Signals and Systems with MATLAB Computing and Simulink Modeling 4th ed by Steven T Karris Amazon 5 star book!
奥本海默第二版,看上去像文字版实际上是影印版
To provide students with an understanding of random variables and random signals, and how these are modified by the action of a linear system.
Fundamentals Of Signals & Systems - Benoit Boulet 英文有书签 信号与系统基础
Signals and Systems\matlab基本信号处理函数及实例.rar