提交 64d5d10c 编写于 作者: M manjaro-xfce

准备实现以模块实例ID为标记的消息系统。消息系统可以用于全局配置的交互,比如模块之间的互相控制。

上级 e5554b65
......@@ -60,9 +60,9 @@ void DialogNetP2P::timerEvent(QTimerEvent * e)
{
fprintf(stderr,"Listening on port %d\n",m_n_port);
fflush(stderr);
TASKBUS::push_subject(0xffffffff,0,
TASKBUS::push_subject(TB_SUBJECT_CMD,0,
QString("source=%1;"
"destin=all;"
"destin=0;"
"function=listening;"
"hostaddr=%2;"
"port=%3;"
......@@ -82,9 +82,9 @@ void DialogNetP2P::timerEvent(QTimerEvent * e)
}
static int cc = 0;
if ((++cc)%10==0)
TASKBUS::push_subject(0xffffffff,0,
TASKBUS::push_subject(TB_SUBJECT_CMD,0,
QString("source=%1;"
"destin=all;"
"destin=0;"
"function=aloha;"
"class=network_p2p.taskbus;"
)
......
......@@ -200,9 +200,9 @@ int do_source(const cmdlineParser & args)
//保留最新的文件
const int keep_last = args.toInt("keep_last",1);
//Broadcast sample rates
TASKBUS::push_subject(0xffffffff,0,
TASKBUS::push_subject(TB_SUBJECT_CMD,0,
QString("source=%1;"
"destin=all;"
"destin=0;"
"function=sample_rate;"
"sample_rate=%2;"
"unit=1.0;"
......@@ -327,9 +327,9 @@ int do_source(const cmdlineParser & args)
start = clock();
finish = clock();
total_frames = 0;
TASKBUS::push_subject(0xffffffff,0,
TASKBUS::push_subject(TB_SUBJECT_CMD,0,
QString("source=%1;"
"destin=all;"
"destin=0;"
"function=aloha;"
"class=source_files.taskbus;"
)
......
......@@ -168,9 +168,9 @@ int do_iio(const cmdlineParser & args)
const double sample_rate = args.toDouble("sample_rate",2.5);
const double bw = args.toDouble("bw",2.5);
const double rf = args.toDouble("rf",1800);
TASKBUS::push_subject(0xffffffff,0,
TASKBUS::push_subject(TB_SUBJECT_CMD,0,
QString("source=%1;"
"destin=all;"
"destin=0;"
"function=sample_rate;"
"unit=1000000;"
"sample_rate=%2;"
......
......@@ -136,9 +136,9 @@ void DialogSoundCard::CreateAudioInput()
QAudioDevice inputDevice(infoIn);
mpAudioInputSound = new QAudioSource(inputDevice, mFormatSound, this);
//Broadcast sample rates
TASKBUS::push_subject(0xffffffff,0,
TASKBUS::push_subject(TB_SUBJECT_CMD,0,
QString("source=%1;"
"destin=all;"
"destin=0;"
"function=sample_rate;"
"sample_rate=%2;"
"unit=1;"
......
......@@ -88,7 +88,7 @@ bool taskNode::cmd_stop(QObject * node)
if (m_process->state()!=QProcess::Running)
return false;
//发送信令,终止
char cmd[] = "function=quit;ret=0;source=taskbus;destin=all;class=taskbus;";
char cmd[] = "function=quit;ret=0;source=0;destin=0;class=taskbus;";
subject_package_header header;
header.prefix[0] = 0x3C;
header.prefix[1] = 0x5A;
......@@ -203,7 +203,7 @@ void taskNode::slot_readyReadStandardOutput()
const TASKBUS::subject_package_header * header_package =
reinterpret_cast<const TASKBUS::subject_package_header *>(arr.constData());
//Command
if (header_package->subject_id == 0xffffffff)
if (header_package->subject_id == TB_SUBJECT_CMD)
{
//Command must endwith \0
const char * pCmd = arr.constData()+sizeof(TASKBUS::subject_package_header);
......@@ -398,7 +398,7 @@ bool taskNode::cmd_write(QObject * node,QByteArray arr)
bool taskNode::cmd_sendcmd(QMap<QString,QVariant> cmd, QSet<QString> destins)
{
if (destins.contains(m_uuid)==false
&&destins.contains("all")==false)
&&destins.contains("0")==false)
return false;
if (cmd.contains("source"))
if (cmd["source"]==m_uuid)
......
......@@ -559,7 +559,7 @@ void taskProject::slot_new_package(QByteArrayList pkgs)
if (srcfuns.size()==0)
throw "srcfuns.size() is 0";
//看看是否合法 See if it's legal.
if (header->subject_id!=0xffffffff)
if (header->subject_id!=TB_SUBJECT_CMD)
{
quint32 src_inst = mod->function_instance(srcfuns.first());
//专题是否被登记为内部专题
......@@ -661,7 +661,7 @@ void taskProject::slot_new_package(QByteArrayList pkgs)
* There are 3 reserved keywords:
* 1.source: ID of source module. ID is given by each module designer, UUID or
* full domain name is strongly recommanded.
* 2.destin: ID of destin modules. "all" means all modules. module names are seperated by ","
* 2.destin: ID of destin modules. "0" means all modules. module names are seperated by ","
* 3.function: function name.
*
* eg:
......@@ -904,7 +904,7 @@ void taskProject::slot_outside_recieved(QByteArray pkg)
if (header->data_length+sizeof( TASKBUS::subject_package_header)!=static_cast<size_t>(pkg.size()))
return;
try {
if (header->subject_id!=0xffffffff)
if (header->subject_id!=TB_SUBJECT_CMD)
{
//进行解析、转发 To parse, forward
if (m_iface_outside2inside_in.contains(header->subject_id)==false)
......
......@@ -18,6 +18,7 @@
//Comments:
//Next feature: Multithread-push protect.
namespace TASKBUS{
#define TB_SUBJECT_CMD 0xffffffffu
//数据专题包头结构体,1字节序对齐
//Datahead structure with pack = 1
#pragma pack(push,1)
......@@ -37,7 +38,7 @@ namespace TASKBUS{
//是否为控制指令 Whether to be a control instruction or a normal subject
inline bool is_control_subject(const subject_package_header & header);
inline bool is_valid_header(const subject_package_header & header);
//返回控制信令专题 0xffffffff
//返回控制信令专题 TB_SUBJECT_CMD
inline unsigned int control_subect_id();
//用于方便连线模式的函数, line connect mod(subject) functions
inline void push_subject(
......@@ -210,7 +211,7 @@ namespace TASKBUS{
inline bool is_control_subject(const subject_package_header & header)
{
if(header.prefix[0]==0x3C&&header.prefix[1]==0x5A&&header.prefix[2]==0x7E&&header.prefix[3]==0x69)
return (header.subject_id == 0xffffffff)?true:false;
return (header.subject_id == TB_SUBJECT_CMD)?true:false;
return false;
}
//提取控制命令
......@@ -239,7 +240,7 @@ namespace TASKBUS{
//返回控制信令专题
inline unsigned int control_subect_id()
{
return 0xffffffff;
return TB_SUBJECT_CMD;
}
/** Debug the modile.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册