# lb_base **Repository Path**: litebmc/lb_base ## Basic Information - **Project Name**: lb_base - **Description**: litebmc的框架基础库(base library),是接口代码自动生成需要信赖的基础库,由上层应用注册属性变更、信号发送 、信号订阅、方法调用、读写属性方法以及向上层返回已注册的interface基本信息。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-05-23 - **Last Updated**: 2026-01-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## DBUS通信模型 DBUS是一种进程间通信机制,连接到总线的进程可通过总线接收或传递消息,总线收到消息时,根据不同的消息类型进行不同的处理,DBUS模型中存在服务端和客户端解决,服务端实现接口,客户端使用接口,D-Bus 规范参考:https://dbus.freedesktop.org/doc/dbus-specification.html#Introduction ## 接口编程模型 DBUS定义的基于接口的编程模型,参考[Introspection Data Format](https://dbus.freedesktop.org/doc/dbus-specification.html#Introspection%20Data%20Format)。 有很多基础库实现dbus交互,如DBusConnection(libdbus)、GDBusConnection(glib2.0)、sdbus(libsystemd)等,对于新手来说,熟练使用这些库还是存在不小的挑战。为此,litebmc.com设计了`litebmc/lbkit`代码自动生成工具,支持将[IDF文件: Interface description file](/docs/models/idf.md)转换成C代码,结合lb_base和lb_core简化dbus属性查询设置、对象注册、方法调用、信号收发逻辑。 实际上,dbus定义的接口、对象、属性、方法、信号模型足够通用,可以承载在其它总线上。为简化litebmc的依赖关系管理,减少依赖变更的影响,litebmc定义了[lb_base](https://gitee.com/litebmc/lb_base),该库仅实现基础模型,不承载具体总线实现,基于IDF生成的C代码只依赖lb_base,不依赖具体的接口实现[lb_core](https://gitee.com/litebmc/lb_core)。 lb_base定义了接口编程模型,为代码自动生成工具接口描述文件(与dbus的自举文件相同)生成C代码。 ```txt -------------- -------------- ----------------------------------------------------------------------------------- | server app | | client app | | LBImpl 通用dbus接口抽象(由lb_core具体实现dbus对象管理、方法路径、信号订阅、属性同步等功能) | -------------- -------------- ----------------------------------------------------------------------------------- | | | | # [服务端]发送属性变更事件 | | | | | property_changed(object, pop): void | V V V | # [服务端]信号发送函数 | ---------- -------------- -------------- | emit_signal(object, dest, signal, msg, error): bool | | plugin |-->| server lib | | client lib | | # [客户端]订阅intf接口的信号,用于监听服务端发送的信号 | ---------- -------------- -------------- | subscribe_signal(intf, bus, signal, object_path, arg0, handle, user_data): uint | | | | # [客户端]取消订阅,入参是订阅时返回的id | | | | unsubscribe_signal(id) | V V _______| # [客户端]调用服务端方法 | -------------- / | call_method(object, method, req, rsp, timeout_msec, error): gint | | public lib | / | # 属性读函数:服务端读内存,客户端属性有变更事件的读内存,无变更事件的调用dbus接口查询无端值 | -------------- / | read_property(object, prop, value, error): gint | | / | # 属性写函数: 服务端直接写内存并触发变更事件,客户端调用服务端属性设置接口 | V / | write_property(object, prop, value, error): gint | -------------- / ------------------------------------------------------------------------------------ | lb_base | ________/ -------------- ``` - lb_base: 定义了LBImpl接口模型,定义了dbus接口通信所需的回调函数,由lb_core模块负责实现,代码仓地址: https://gitee.com/litebmc/lb_base - lb_core: 对GDbusConnection(glib2.0)进行了二次封装,实现lb_base定义的名为`LBImpl `的接口函数,代码仓地址: https://gitee.com/litebmc/lb_core - idf文件: Interface description file,描述litebmc的(dbus)接口文件,支持描述dbus接口的properties、methods、signals以及配套的structures、enumerations、dictionaries、errors基本数据类型。特别的,支持描述接口需要实现的plugin事件等。IDF接口统一存储在interfaces代码仓: https://gitee.com/litebmc/interfaces/tree/master/dbus - server lib、client lib、和public lib: 由lbkit工具读取IDF文件自动生成的三个lib库,分别对应服务端实现、客户端实现以及公共库,这三个库最终会生成三个conan包,组件实现时只需要依赖conan包。conan仓地址: https://art.litebmc.com/artifactory/api/conan/center。 - server app和client app: 实现具体的服务端和客户端业务,服务端创建对象,提供方法实现,发送信号;客户端获取对象后调用方法或监听信号,APP示例: https://gitee.com/litebmc/lb_example_app - plugin lib: 以动态库形式实现idf定义的plugin插件功能,server_app启动时会尝试加载server lib定义的plugin信息加载插件,server_app实现dbus接口时需要在合适的时机调用插件方法,插件示例: https://gitee.com/litebmc/lb_example_plugin