当前位置: 首页 > wzjs >正文

网站开发企业标准电子网站模板

网站开发企业标准,电子网站模板,社区做图网站,深圳做微网站1,引入 ubus提供了一种多进程通信的机制。存在一个守护进程ubusd,所以进程都注册到ubusd,ubusd进行消息的接收、分发管理。 ubus对多线程支持的不好,例如在多个线程中去请求同一个服务,就有可能出现不可预知的结果。 …

1,引入

        ubus提供了一种多进程通信的机制。存在一个守护进程ubusd,所以进程都注册到ubusd,ubusd进行消息的接收、分发管理。

ubus对多线程支持的不好,例如在多个线程中去请求同一个服务,就有可能出现不可预知的结果。

ubus通信一共有三种实现方式:①端对端通信  ②订阅/通知  ③事件(广播)

2,ubus命令的使用

ubus list :列出所有对象   
ubus -v list network.interface.lan : 查看指定对象的详细信息
ubus call network.interface.lan status :执行指定对象的方法并获取返回结果
ubus listen [事件类型]: 实时接收指定或所有 ubus 事件 
ubus send test.event '{"message":"Hello World"}'  : 发送自定义事件

  ubus subscribe mytest : 订阅mytest事件

3,向UBUS注册一个对象

主要步骤:uloop_init(); ubus_connect(NULL);ubus_add_uloop(ser_ctx);初始化object,ubus_add_object(ser_ctx, &sub_object);

代码实现:

int get_no_arg_info(struct ubus_context *ctx, struct ubus_object *obj,struct ubus_request_data *req, const char *method,struct blob_attr *msg)
{struct blob_buf b = {};blob_buf_init(&b, 0);blobmsg_add_string(&b, "obj_name", obj->name);blobmsg_add_u32(&b, "pid", (uint32_t)getpid());blobmsg_add_u32(&b, "uptime", (uint32_t)time(NULL));ubus_send_reply(ctx, req, b.head);blob_buf_free(&b);return 0;
}enum parm_num {T_ID = 0,T_NAME,T_AGE,T_MAX
};static const struct blobmsg_policy t_policy[] = {[T_ID]   = { .name = "id", .type = BLOBMSG_TYPE_INT32 },[T_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },[T_AGE]  = { .name = "age", .type = BLOBMSG_TYPE_INT32 },
};int get_arg_info(struct ubus_context *ctx, struct ubus_object *obj,struct ubus_request_data *req, const char *method,struct blob_attr *msg)
{int i = 0;struct blob_attr *tb[T_MAX];blobmsg_parse(t_policy, ARRAY_SIZE(t_policy), tb, blob_data(msg), blob_len(msg));for(i = 0; i < T_MAX; i++){if(!tb[i]){fprintf(stderr, "Failed to parse arg '%d'.\n", i);return -1;}}printf("-->id:   %d\n", blobmsg_get_u32(tb[T_ID]));printf("-->name: %s\n", blobmsg_get_string(tb[T_NAME]));printf("-->age:  %d\n", blobmsg_get_u32(tb[T_AGE]));return 0;
}static const struct ubus_method test_obj_methods[] = {UBUS_METHOD_NOARG("get_no_arg_info", get_no_arg_info),UBUS_METHOD( "get_arg_info", get_arg_info, t_policy),
};static struct ubus_object_type test_obj_type = UBUS_OBJECT_TYPE("test.service", test_obj_methods);static struct ubus_object test_object = {.name = "test.service",.type = &test_obj_type,.methods = test_obj_methods,.n_methods = ARRAY_SIZE(test_obj_methods),
};int main()
{int ret = 0;struct ubus_context *mytest_ctx = NULL;uloop_init();mytest_ctx = ubus_connect(NULL);if(!mytest_ctx) {fprintf(stderr, "Failed to connect ubus.\n");return ERROR;}ret = ubus_add_object(mytest_ctx, &test_object);if(ret) {fprintf(stderr, "Failed to add 'mytest' obj.\n");return ERROR;}ubus_add_uloop(mytest_ctx);uloop_run();ubus_free(mytest_ctx);uloop_done();
}

测试:

总结:

        1,实现了向UBUS添加一个object的代码,需要依赖Ubus头文件:#include <libubox/blobmsg_json.h>  #include <libubus.h>

        2,比较繁琐的点是在test_object这个结构体的初始化,无参数调用使用UBUS_METHOD_NOARG, 有参数调用使用:UBUS_METHOD,此时UBUS_METHOD的后两个参数不能填NULL,否则段错误。

        3,使用UBUS 命令call,其内部ubus_invoke,实现UBUS端到端通信。


文章转载自:

http://jygW988S.jLxLd.cn
http://6uSGIwa7.jLxLd.cn
http://fwsWKOdt.jLxLd.cn
http://LNjPCaTw.jLxLd.cn
http://QRZX89Gs.jLxLd.cn
http://0Fg9FiTF.jLxLd.cn
http://71X24dNL.jLxLd.cn
http://wLdluG2r.jLxLd.cn
http://fHHFY5AX.jLxLd.cn
http://GWz5qbl1.jLxLd.cn
http://Q180GuN0.jLxLd.cn
http://Mp7oqpbD.jLxLd.cn
http://JT7s1RIV.jLxLd.cn
http://jxY3Nf3l.jLxLd.cn
http://SDQ2rYP4.jLxLd.cn
http://lvINB4co.jLxLd.cn
http://I9Rn3vmK.jLxLd.cn
http://j8O2WltX.jLxLd.cn
http://31j4jrb0.jLxLd.cn
http://otW8EzQg.jLxLd.cn
http://hIsIlw81.jLxLd.cn
http://8NsW78JE.jLxLd.cn
http://4dAZGfo1.jLxLd.cn
http://FQSGirPi.jLxLd.cn
http://11ebLZod.jLxLd.cn
http://ajkZ2aTM.jLxLd.cn
http://RGzOYK3p.jLxLd.cn
http://pyHhtwda.jLxLd.cn
http://FKLZmuUQ.jLxLd.cn
http://Y1wK8Msf.jLxLd.cn
http://www.dtcms.com/wzjs/722301.html

相关文章:

  • 企业网站建设公司注意哪些问题综合搜索引擎
  • 二级学院网站建设自评报告网站怎么做关键词研究
  • 英文建站网站手机非法网站怎么解决方案
  • 沧州网站的公众号织梦怎么关闭网站
  • 阅读网站模板做网站要用那些软件
  • .net 接单网站世界政务网站绩效评估指标体系建设
  • 东莞有什么比较好的网站公司天长企业网站制作
  • 网站猜你喜欢代码请人用wordpress建站假期
  • 网站建设 部署与发布视频教程电子商务网站建设课
  • 网站seo设置wordpress添加标签
  • 渭南建站设计上海2023展会时间
  • 网站建设大神级公司免费下载ppt模板网站推荐
  • 食品行业网站建设方案怎么在网站上做360全景图片
  • 官网站内推广内容室内设计公司和装修公司的区别
  • 无锡 网站 seo 优化哈尔滨巨耀网站建设
  • 网站做seo有什么作用怎么建网站
  • 自己网站建设的流程是什么建立企业营销网站主要包括哪些内容
  • 网站下载免费新版长沙竹叶网络科技有限公司
  • 网站建设是那个行业wordpress文章形式
  • 网站推广120祝明电子商务网站建设实验报告
  • 个人网站 云服务器广州番禺网站公司哪家好
  • 免费购物网站建设深圳企业招聘信息最新招聘信息
  • 网站开发 一般用什么语言平面设计培训班学费
  • 怎样自己做公司网站做网盟行业网站的图片广告的销售
  • 青浦苏州网站建设精美大气的餐饮类企业网站
  • 网站外包公司2345浏览器免费版
  • 什么网站可以做试题html 音乐网站
  • 网站菜单导航怎么做的wordpress的seo如何写关键词
  • 网站开发项目安全加固的要求免费的商城网站
  • 云主机建多个网站厚街网站建设价格