(二)SDN 控制器 NOX 源码分析之—— Component

Component_context
1.构造函数:Component_context(const Component_name& name, const std::string& config_path);
Component_context对象保存着组件的注册信息,通过“组件名和组件的配置文件”这两个参数来初始化对象
注册信息保存在Component_context :: properties变量中
2.保存的信息:在这个对象中保存着一个组件完整的信息,由Kernel来执行;其中Component_context保存的信息有:组件名【name】、组件当前状态【current_state】、组件需求的状态【required_state】、组件注册信息【properties】、组件对应实例【Componet】、组件对其它组件的依赖【Dependency_list】、组件注册的事件响应函数【install_actions】、NOX内核实例【kernel】
3.接口
/* State transition management methods */
virtual void install(const Component_state to_state);
virtual void uninstall(const Component_state to_state);

/* Attempts to resolve the dependencies for the given state. Returns true if all the dependencies are met. */ 
bool resolve_dependencies(const Component_state);

/* Accessors for member variables */ 
    Interface_description get_interface() const;
    Component* get_instance() const;
    Component_state get_state() const;
    Component_state get_required_state() const;
    void set_required_state(const Component_state);

/* Return a human-readable status report. */
    std::string get_status() const;
    std::string get_error_message(hash_set<Component_context*>) const;

/* Public Component_context methods to be provided for components. */
    Component_name get_name() const;
    Component* resolve_by_name(const Component_name&) const;
     //通过kernel->get(name, INSTALLED);查询已经安装到核心的的组件名对应的Component_context对象,进而得到相应的Component实例句柄
    Component* get_by_name(const Component_name&) const;
    Component* get_by_interface(const Interface_description&) const;
    Kernel* get_kernel() const;

CONFIGURATION
/* Return the value of a configuration key. */
    template<class Type> Type get_config(const std::string& key) const
    {
        return properties.get<Type>(key);
    }

/* Return the value of a configuration key. */
    template<class Type> Type
    get_config(const std::string& key, const Type& default_value) const
    {
        return properties.get(key, default_value);
    }
    const boost::property_tree::ptree& get_config_child(const std::string& key) const;

/* Return the value of a configuration key. */
    std::list<std::string> get_config_list(const std::string& key) const;

/* Return the ptree under a configuration key. */
    const boost::property_tree::ptree&
    get_property_tree(const std::string& key) const;

/* Return true if the key exists. */
    const bool has(const std::string&) const;

Component
组件类是所有组件的基类,它规范了组件需要实现的几个功能;其中包含了它自己的Component_context实例句柄和event_dispatcher实例句柄;
通过event_dispatcher 句柄可以将其它组件联系起来,将事件以及事件处理方法共享到整个NOX中;
构造函数:Component(const Component_context* ctxt);
因为event_dispatcher是它的子类,所以在对event_dispatcher实例句柄赋值时需要分开讨论,具体看componet.cc代码实现

接口:(以下接口都是通过event_dispatcher 句柄来执行相应操作的)
/** 
* Configure the component
* The method should block until the configuration completes.
*/
    virtual void configure() {}
/**
* Start the component.
* The method should block until the component runs. Container(即Kernel实例) will not pass any method invocations before starting completes. 
 */
    virtual void install() {}
/* Event management methods */
/* Register an event */
    template <typename T>
    inline
    void register_event() const
    {
        register_event(T::static_get_name());
    }

/* Register an event handler */
    template <typename T>
    inline
    void register_handler(const Event_handler& h) const
    {
        register_handler(T::static_get_name(), h);
    }

/* Dispatch an event directly */
    void dispatch(const Event&) const;

/* Post an event */
    void post(const Event&) const;

Name_dependency
这个类根据组件名构造对象,通过这个对象的resolve方法来安装组件,是resolve方法的参数是无效的;

Simple_component_factory
设计意图是通过接口描述来生成组件实例,但是instance()成员方法还是依赖于Component_context实例,所以感觉用处不大

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值