klayout 源码分析系列续 plugin

本文详细介绍了插件系统的工作原理,以ant::Service为例,分为三个步骤:声明、注册和生成。首先,声明了一个继承自多个基类的Service类,包含鼠标事件处理函数。接着,通过tl::RegisteredClass模板将插件类注册到系统中。最后,在LayoutView类中遍历并创建所有注册的插件,根据选项决定是否创建特定插件。这个过程揭示了插件系统如何动态加载和管理组件。
摘要由CSDN通过智能技术生成

plugin 的使用分三步,下面以ant::Service举例。

第一步. 声明

class ANT_PUBLIC Service
  : public lay::ViewService,
    public lay::Editable,
    public lay::Plugin,
    public lay::Drawing,
    public db::Object
{
    Service (db::Manager *manager, lay::LayoutView *view);

    virtual bool mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio);

    virtual bool mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio);

    virtual bool mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio);

}

第二步. 注册

通过模板把plugin类注册到系统中

antPlugin.cc

static tl::RegisteredClass<lay::PluginDeclaration> config_decl (new ant::PluginDeclaration (), 3000, "ant::Plugin");

}

第三步.生成

void LayoutView::create_plugins (lay::PluginRoot *root, const lay::PluginDeclaration *except_this)
{
  for (std::vector<lay::Plugin *>::iterator p = mp_plugins.begin (); p != mp_plugins.end (); ++p) {
    delete *p;
  }
  mp_plugins.clear ();

  //  create the plugins
  for (tl::Registrar<lay::PluginDeclaration>::iterator cls = tl::Registrar<lay::PluginDeclaration>::begin (); cls != tl::Registrar<lay::PluginDeclaration>::end (); ++cls) {

    if (&*cls != except_this) {

      //  TODO: clean solution. The following is a HACK:
      if (cls.current_name () == "ant::Plugin" || cls.current_name () == "img::Plugin") {
        //  ant and img are created always
        create_plugin (root, &*cls);
      } else if ((m_options & LV_NoPlugins) == 0) {
        //  others: only create unless LV_NoPlugins is set
        create_plugin (root, &*cls);
      } else if ((m_options & LV_NoGrid) == 0 && cls.current_name () == "GridNetPlugin") {
        //  except grid net plugin which is created on request
        create_plugin (root, &*cls);
      }

    }

  }

  mode (default_mode ());
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
neutron 的插件部分负责实现具体的网络功能,如虚拟网络、路由、安全组等。在 neutron 中,插件是通过扩展 neutron 的核心服务来实现的。因此,插件的代码位于 `neutron/services` 目录下。 插件的实现一般需要继承 neutron 的核心服务类,例如 L3 插件需要继承 `neutron.services.l3_router.l3_router_plugin.L3RouterPlugin` 类。插件需要实现一些特定的方法来提供网络功能,例如 L3 插件需要实现 `create_router`、`update_router`、`delete_router` 等方法来管理 L3 路由器。 在插件的实现中,还需要与 neutron 的其他服务进行协同工作,如与网络代理服务通信来实现 DHCP、L3 路由等功能。为了实现这些功能,插件需要通过调用 neutron 的 API 接口、代理接口等来完成。 除了实现特定的网络功能外,插件还需要处理一些通用的网络操作,如网络异常处理、配置文件解析等。这些通用的操作一般放在插件的 `neutron/services/common` 目录下。 在插件的实现过程中,需要注意以下几个方面: 1. 实现特定的网络功能:插件需要实现特定的方法来提供网络功能,例如虚拟网络、路由、安全组等。 2. 与其他服务的协同工作:插件需要与 neutron 的其他服务进行协同工作,如与网络代理服务通信来实现 DHCP、L3 路由等功能。 3. 处理通用的网络操作:插件还需要处理一些通用的网络操作,如网络异常处理、配置文件解析等。 4. 调试和测试:在插件的实现过程中,需要进行调试和测试,以确保插件能够正确地提供网络功能。 总之,neutron 插件源码分析需要深入了解网络技术和 OpenStack 的架构设计,同时需要具备良好的编程能力和调试能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天天进步2015

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值