zoukankan      html  css  js  c++  java
  • Ubus简单理解

    这篇文章介绍了关于blobmsg的内容,属于libubox库,是libubus的依赖库,在关于消息的传递中会使用到相关内容
    https://www.cnblogs.com/embedded-linux/p/6792359.html)
    这篇文章讲了三种ubus使用的实例,内含代码
    https://blog.csdn.net/jasonchen_gbd/article/details/46055885)

    首先明确一下,文章中提到的“Object”是一个“ubus_object”结构体,这个结构体有很多成员,但是目前我在例子中只看到以下几个成员的使用。

    ubus_object.name :obj的名字,字符串
    ubus_object.type :另外一个结构体指针,是和methods有关的结构体
    ubus_object.methods :obj的一些方法,结构体数组
    ubus_object. n_methods: obj方法数量
    ubus_object. subscribe_cb :obj的methods被订阅时的回调函数

    【第一种使用场景】subscriber和notifier


    Notifier:发送消息的一方,使用以下函数
    ubus_add_object()
    ubus_notify():通知消息
    Subscriber: 订阅(接收)消息的一方,使用以下函数
    ubus_register_subscriber()
    ubus_lookup_id()
    ubus_subscribe():订阅消息
    *函数使用方法自行调查

    【第二种使用场景】invoke(远程调用)

    Pro1作为被调用者,需要有一个obj
    Pro2作为调用者可以使用ubus_invoke()函数进行调用pro1的某个method。
    /*
    主要使用函数ubus_invoke()的声明如下:
    int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method, struct blob_attr *msg, ubus_data_handler_t cb, void priv, int timeout);
    其中cb参数是消息回调函数,其函数类型定义为:
    typedef void (
    ubus_data_handler_t)(struct ubus_request *req, int type, struct blob_attr *msg);
    参数type是请求消息的类型,如UBUS_MSG_INVOKE,UBUS_MSG_DATA等。
    参数msg存放从服务端得到的回复消息,struct blob_attr类型,同样用blobmsg_parse()来解析。
    参数req保存了请求方的消息属性,其中req->priv即ubus_invoke()中的priv参数,
    用这个参数可以零活的传递一些额外的数据。
    */

    【第三种使用场景】event方式广播通知

    在event方式广播通知下,pro1向pro2,pro3和pro4广播名为"add_device"的事件,但是在三个其他进程中只有pro2对这个event注册了监听,所以也只有pro2会对这个事件进行处理。
    Pro1广播event函数:ubus _send_event()
    pro2对这个event注册监听:ubus_register_event_handler()

    以上

  • 相关阅读:
    socket.io
    CUDA升级后
    QT安装
    windows时钟服务设置
    QT的DPI支持
    cudaDeviceProp结构体
    C#调用C++的dll各种传参
    「LibreOJ#516」DP 一般看规律
    「LibreOJ#515」贪心只能过样例 (暴力+bitset)
    [Codeforces888E]Maximum Subsequence(暴力+meet-in-the-middle)
  • 原文地址:https://www.cnblogs.com/y-c-y/p/12187422.html
Copyright © 2011-2022 走看看