📄 bse-agent.cc
字号:
/************************************************** * File: bse-agent.cc Author: Suman Banerjee <suman@cs.umd.edu> Date: July 31, 2001 Terms: GPL UNI implementation in myns This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * **************************************************/#include <stdio.h>#include <stdlib.h>#include <assert.h>#include "uninode.h"#include <scheduler.h>#include "app-packet.h"#include "bse-agent.h"#define LOG_BSE_SEND#define LOG_BSE_RECV#define LOG_BSE_JUNKbseAgent::bseAgent (void) : Agent () { rt.ba = this;}void bseAgent::init (int Id, int Index, Node *N) { Agent::init(Id,Index,N); t = AGENT_APPLICATION_BSE; return;}void bseAgent::start (void) { Agent::start();#ifdef LOG_BSE_JUNK printf ("[bse %d %d ] At %8.4f start\n", id, n->id, Scheduler::Clock());#endif // LOG_BSE_JUNK return;}void bseAgent::specific_rx_pkt_handler (Packet *p) { if (p->t != PACKET_APP) { printf ("[Err] BSE received unknown packet type\n"); return; } AppPacket *ap = (AppPacket *)p; switch (ap->st) { case JOIN : handle_join(ap); break; case SOURCE : handle_source(ap); break; default : printf ("[Err] BSE received unknown packet subtype\n"); } return;}void bseAgent::handle_join (AppPacket *p) { assert (p->st == JOIN); void * pos = m_member_list.Locate(p->src_agent); if (pos == NULL) { BseAgentInfo * new_ag = new BseAgentInfo (p->src_agent,p->src); m_member_list.Add(new_ag,p->src_agent); } else { BseAgentInfo * this_ag = m_member_list.GetAt(pos); this_ag->refresh = true; } return;}void bseAgent::handle_source (AppPacket *p) { assert (p->st == SOURCE); void * pos = m_source_list.Locate(p->src_agent); if (pos == NULL) { BseAgentInfo * new_ag = new BseAgentInfo (p->src_agent,p->src); m_source_list.Add(new_ag,p->src_agent); send_group_update_to_source(p->src_agent,p->src); } else { BseAgentInfo * this_ag = m_source_list.GetAt(pos); this_ag->refresh = true; } return;}void bseAgent::send_group_update_to_source (int aid, int nid) { AppPacket * resp = new AppPacket (SOURCE_UPDATE); resp->u.sourceupdate_p.count = m_member_list.GetSize(); int i = 0; for (void * pos = m_member_list.GetHeadPosition(); pos != NULL; m_member_list.GetNext(pos) ) { BseAgentInfo * this_ag = m_member_list.GetAt(pos); resp->u.sourceupdate_p.arr[i].agent_id = this_ag->ag.agent_id; resp->u.sourceupdate_p.arr[i].node_id = this_ag->ag.node_id; i++; } send_pkt(resp,aid,nid); return;}void bseAgent::handle_refresh_timeout (void) { for (void * pos = m_member_list.GetHeadPosition(); pos != NULL; ) { BseAgentInfo * this_ag = m_member_list.GetAt(pos); void * old_pos = pos; m_member_list.GetNext(pos); if (this_ag->refresh == false) { m_member_list.RemoveAt(old_pos); delete this_ag; } else this_ag->refresh = false; } for (void * pos = m_source_list.GetHeadPosition(); pos != NULL; ) { BseAgentInfo * this_ag = m_source_list.GetAt(pos); void * old_pos = pos; m_source_list.GetNext(pos); if (this_ag->refresh == false) { m_source_list.RemoveAt(old_pos); delete this_ag; } else this_ag->refresh = false; send_group_update_to_source(this_ag->ag.agent_id, this_ag->ag.node_id); } return;}void RefreshTimer::EventHandler (void) { ba->handle_refresh_timeout(); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -