⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xrl_process_spy.cc

📁 RIP 协议实现
💻 CC
字号:
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-// Copyright (c) 2001-2008 XORP, Inc.//// Permission is hereby granted, free of charge, to any person obtaining a// copy of this software and associated documentation files (the "Software")// to deal in the Software without restriction, subject to the conditions// listed in the XORP LICENSE file. These conditions include: you must// preserve this copyright notice, and you cannot mention the copyright// holders in advertising related to the Software without their permission.// The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This// notice is a summary of the XORP LICENSE file; the license in that file is// legally binding.#ident "$XORP: xorp/rip/xrl_process_spy.cc,v 1.13 2008/07/23 05:11:38 pavlin Exp $"// #define DEBUG_LOGGING#include "rip_module.h"#include "libxorp/debug.h"#include "libxorp/xlog.h"#include "libxorp/xorp.h"#include "libxorp/eventloop.hh"#include "libxipc/xrl_router.hh"#include "xrl/interfaces/finder_event_notifier_xif.hh"#include "xrl_config.hh"#include "xrl_process_spy.hh"XrlProcessSpy::XrlProcessSpy(XrlRouter& rtr)    : ServiceBase("FEA/RIB Process Watcher"), _rtr(rtr){    _cname[FEA_IDX] = xrl_fea_name();    _cname[RIB_IDX] = xrl_rib_name();}XrlProcessSpy::~XrlProcessSpy(){}boolXrlProcessSpy::fea_present() const{    if (status() == SERVICE_RUNNING)	return _iname[FEA_IDX].empty() == false;    debug_msg("XrlProcessSpy::fea_present() called when not "	      "SERVICE_RUNNING.\n");    return false;}boolXrlProcessSpy::rib_present() const{    if (status() == SERVICE_RUNNING)	return _iname[RIB_IDX].empty() == false;    debug_msg("XrlProcessSpy::rib_present() called when not "	      "SERVICE_RUNNING.\n");    return false;}voidXrlProcessSpy::birth_event(const string& class_name,			   const string& instance_name){    debug_msg("Birth event: class %s instance %s\n",	      class_name.c_str(), instance_name.c_str());    for (uint32_t i = 0; i < END_IDX; i++) {	if (class_name != _cname[i]) {	    continue;	}	if (_iname[i].empty() == false) {	    XLOG_WARNING("Got ");	}	_iname[i] = instance_name;    }}voidXrlProcessSpy::death_event(const string& class_name,			   const string& instance_name){    debug_msg("Death event: class %s instance %s\n",	      class_name.c_str(), instance_name.c_str());    for (uint32_t i = 0; i < END_IDX; i++) {	if (class_name != _cname[i]) {	    continue;	}	if (_iname[i] == instance_name) {	    _iname[i].erase();	    return;	}    }}intXrlProcessSpy::startup(){    if (status() == SERVICE_READY || status() == SERVICE_SHUTDOWN) {	send_register(0);	set_status(SERVICE_STARTING);    }    return (XORP_OK);}voidXrlProcessSpy::schedule_register_retry(uint32_t idx){    EventLoop& e = _rtr.eventloop();    _retry = e.new_oneoff_after_ms(100,				   callback(this,					    &XrlProcessSpy::send_register,					    idx));}voidXrlProcessSpy::send_register(uint32_t idx){    XrlFinderEventNotifierV0p1Client x(&_rtr);    if (x.send_register_class_event_interest("finder", _rtr.instance_name(),		_cname[idx], callback(this, &XrlProcessSpy::register_cb, idx))	== false) {	XLOG_ERROR("Failed to send interest registration for \"%s\"\n",		   _cname[idx].c_str());	schedule_register_retry(idx);    }}voidXrlProcessSpy::register_cb(const XrlError& xe, uint32_t idx){    if (XrlError::OKAY() != xe) {	XLOG_ERROR("Failed to register interest in \"%s\": %s\n",		   _cname[idx].c_str(), xe.str().c_str());	schedule_register_retry(idx);	return;    }    debug_msg("Registered interest in %s\n", _cname[idx].c_str());    idx++;    if (idx < END_IDX) {	send_register(idx);    } else {	set_status(SERVICE_RUNNING);    }}intXrlProcessSpy::shutdown(){    if (status() == SERVICE_RUNNING) {	send_deregister(0);	set_status(SERVICE_SHUTTING_DOWN);    }    return (XORP_OK);}voidXrlProcessSpy::schedule_deregister_retry(uint32_t idx){    EventLoop& e = _rtr.eventloop();    _retry = e.new_oneoff_after_ms(100,				   callback(this,					    &XrlProcessSpy::send_deregister,					    idx));}voidXrlProcessSpy::send_deregister(uint32_t idx){    XrlFinderEventNotifierV0p1Client x(&_rtr);    if (x.send_deregister_class_event_interest(		"finder", _rtr.instance_name(), _cname[idx],		callback(this, &XrlProcessSpy::deregister_cb, idx))	== false) {	XLOG_ERROR("Failed to send interest registration for \"%s\"\n",		   _cname[idx].c_str());	schedule_deregister_retry(idx);    }}voidXrlProcessSpy::deregister_cb(const XrlError& xe, uint32_t idx){    if (XrlError::OKAY() != xe) {	XLOG_ERROR("Failed to deregister interest in \"%s\": %s\n",		   _cname[idx].c_str(), xe.str().c_str());	schedule_deregister_retry(idx);	return;    }    debug_msg("Deregistered interest in %s\n", _cname[idx].c_str());    idx++;    if (idx < END_IDX) {	send_deregister(idx);    } else {	set_status(SERVICE_SHUTDOWN);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -