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

怎么做一个网站出来东方建设集团有限公司网站

怎么做一个网站出来,东方建设集团有限公司网站,兰州新区装修公司哪家好,公司网站建设需要什么一、binder驱动浅析 从上图看出,binder的通讯主要涉及三个步骤。 在 Binder Server 端定义好服务,然后向 ServiceManager 注册服务在 Binder Client 中向 ServiceManager 获取到服务发起远程调用,调用 Binder Server 中定义好的服务 整个流…

一、binder驱动浅析

从上图看出,binder的通讯主要涉及三个步骤。

  • 在 Binder Server 端定义好服务,然后向 ServiceManager 注册服务
  • 在 Binder Client 中向 ServiceManager 获取到服务
  • 发起远程调用,调用 Binder Server 中定义好的服务

整个流程都是建立在 Binder 驱动提供的跨进程调用能力之上,bingde驱动的实现比较复杂,现阶段我们先以黑盒的方式去了解它:

Binder 是一个 Linux 字符驱动,对外提供了以下函数供应用程序使用:

  • open(),用于打开 binder 驱动,返回 Binder 驱动的文件描述符
  • mmap(),用于在内核中申请一块内存,并完成应用层与内核层的虚拟地址映射
  • ioctl,在应用层调用 ioctl 向内核层发送数据或者读取内核层发送到应用层的数据:
ioctl(文件描述符,ioctl命令,数据)

文件描述符是在调用 open 时的返回值,ioctl 命令和第三个参数"数据"的类型是相关联的,具体如下:

ioctl命令数据类型函数动作
BINDER_WRITE_READstruct binder_write_read应用层向内核层收发数据
BINDER_SET_MAX_THREADSsize_t设置最大线程数
BINDER_SET_CONTEXT_MGRint or flat_binder_object设置当前进程为ServiceManager
BINDER_THREAD_EXITint删除 binder 线程
BINDER_VERSIONstruct binder_version获取 binder 协议版本

二、安卓提供的封装 

servicemanager - OpenGrok cross reference for /frameworks/native/cmds/servicemanager/

frameworks/native/cmds/servicemanager 目录下的 binder.cbctest.c 针对应用编写的需求,对open mmap ioctl 等基本操作做了封装,提供了以下几个函数:

  • binder_open:用于初始化 binder 驱动
  • binder_become_context_manager:设置当前进程为 ServiceManager
  • svcmgr_lookup:用于向 ServiceManager 查找服务
  • svcmgr_publish:用于向 ServiceManager 注册服务
  • binder_call:用于发起远程过程调用
  • binder_loop:进入循环,在循环中,获取和解析收到的 binder 数据

三、 ServiceManager 源码分析

  • 打开 Binder 驱动
  • 告知驱动自身为 service manager
  • 循环处理
    • 从驱动读取数据
    • 解析数据并调用
      • 处理service端的注册服务请求:其实就是在一个链表记录服务名
      • 处理client获取服务请求:
        • 在链表查询服务
        • 返回 server 进程的 handle
service_manager.cbinder_open //打开 Binder 驱动binder_become_context_manager //告知驱动自身为 service managerbinder_loopbinder_parse //从驱动读取数据并解析svcmgr_handler//根据不同的命令,进入不同的处理流程do_add_service //添加服务do_find_service//获取服务

四、编写自定义service代码

参考代码:bctest.c - OpenGrok cross reference for /frameworks/native/cmds/servicemanager/bctest.c

1、主流程:

  • 打开binder驱动
  • 注册服务
  • 进入loop,等待client请求服务

2、消息处理流程

当 client 发起远程调用时,server 端会收到数据,并将这些数据传递给服务回调函数,这个回调函数需要我们自己来定义:也就是binder_loop(bs, test_server_handler)传入的test_server_handler函数。

3、服务处理流程:hello_service_handler

我们在注册服务的时候,传入了一个func handle, hello_service_handler。当收到client请求服务的时候,会进入这个函数进行处理。

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/types.h>
#include<stdbool.h>
#include <string.h>#include "binder.h"#define LOG_TAG "BinderServer"
#include <log/log.h>#define HELLO_SVR_CMD_SAYHELLO     1
#define HELLO_SVR_CMD_SAYHELLO_TO  2void sayhello(void)
{static int cnt = 0;//fprintf(stderr, "say hello : %d\n", ++cnt);ALOGW("say hello : %d\n", ++cnt);
}int sayhello_to(char *name)
{static int cnt = 0;//fprintf(stderr, "say hello to %s : %d\n", name, ++cnt);ALOGW("say hello to %s : %d\n", name, ++cnt);return cnt;
}int hello_service_handler(struct binder_state *bs,struct binder_transaction_data_secctx *txn_secctx,struct binder_io *msg,struct binder_io *reply)
{struct binder_transaction_data *txn = &txn_secctx->transaction_data;/* 根据txn->code知道要调用哪一个函数* 如果需要参数, 可以从msg取出* 如果要返回结果, 可以把结果放入reply*//* sayhello* sayhello_to*/uint16_t *s;char name[512];size_t len;//uint32_t handle;uint32_t strict_policy;int i;// Equivalent to Parcel::enforceInterface(), reading the RPC// header with the strict mode policy mask and the interface name.// Note that we ignore the strict_policy and don't propagate it// further (since we do no outbound RPCs anyway).strict_policy = bio_get_uint32(msg);switch(txn->code) {case HELLO_SVR_CMD_SAYHELLO:sayhello();bio_put_uint32(reply, 0); /* no exception */return 0;case HELLO_SVR_CMD_SAYHELLO_TO:/* 从msg里取出字符串 */s = bio_get_string16(msg, &len);  //"IHelloService"s = bio_get_string16(msg, &len);  // nameif (s == NULL) {return -1;}for (i = 0; i < len; i++)name[i] = s[i];name[i] = '\0';/* 处理 */i = sayhello_to(name);/* 把结果放入reply */bio_put_uint32(reply, 0); /* no exception */bio_put_uint32(reply, i);break;default:fprintf(stderr, "unknown code %d\n", txn->code);return -1;}return 0;
}int test_server_handler(struct binder_state *bs,struct binder_transaction_data_secctx *txn_secctx,struct binder_io *msg,struct binder_io *reply)
{struct binder_transaction_data *txn = &txn_secctx->transaction_data;int (*handler)(struct binder_state *bs,struct binder_transaction_data *txn,struct binder_io *msg,struct binder_io *reply);handler = (int (*)(struct binder_state *bs,struct binder_transaction_data *txn,struct binder_io *msg,struct binder_io *reply))txn->target.ptr;return handler(bs, txn, msg, reply);
}int main(int argc, char **argv)
{struct binder_state *bs;uint32_t svcmgr = BINDER_SERVICE_MANAGER;uint32_t handle;int ret;//打开驱动bs = binder_open("/dev/binder", 128*1024);if (!bs) {fprintf(stderr, "failed to open binder driver\n");return -1;}//添加服务ret = svcmgr_publish(bs, svcmgr, "hello", hello_service_handler);if (ret) {fprintf(stderr, "failed to publish hello service\n");return -1;}binder_loop(bs, test_server_handler);return 0;
}

五、编写自定义client 代码

编写 Client 程序的主要流程如下:

  • open  binder 驱动
  • 向service manager查询服务,获取到服务的句柄 handle
  • 通过 handle 调用远程调用函数
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/types.h>
#include <stdbool.h>
#include <string.h>
#include "binder.h"#define HELLO_SVR_CMD_SAYHELLO     1
#define HELLO_SVR_CMD_SAYHELLO_TO  2int g_handle = 0;
struct binder_state *g_bs;void sayhello(void)
{unsigned iodata[512/4];struct binder_io msg, reply;/* 构造binder_io */bio_init(&msg, iodata, sizeof(iodata), 4);/* 放入参数 */bio_put_uint32(&msg, 0);  // strict mode headerbio_put_string16_x(&msg, "IHelloService");/* 调用binder_call */if (binder_call(g_bs, &msg, &reply, g_handle, HELLO_SVR_CMD_SAYHELLO))return ;/* 从reply中解析出返回值 */binder_done(g_bs, &msg, &reply);}int main(int argc, char **argv)
{int fd;struct binder_state *bs;uint32_t svcmgr = BINDER_SERVICE_MANAGER;int ret;bs = binder_open("/dev/binder", 128*1024);if (!bs) {fprintf(stderr, "failed to open binder driver\n");return -1;}g_bs = bs;/* get service */g_handle = svcmgr_lookup(bs, svcmgr, "hello");if (!g_handle) {return -1;} //调用服务sayhello();}

六、梳理(待整理)

ref:

https://juejin.cn/post/7214342319347712057

Android系统--Binder系统具体框架分析(一) - lkq1220 - 博客园

https://juejin.cn/post/7210245482861264955

第5课第1节_Binder系统_C程序示例_框架分析_哔哩哔哩_bilibili

XRefAndroid - Support AOSP 15.0 AndroidXRef & OpenHarmony 5.0

【Android ServiceManager】从源码入手,剖析ServiceManager是如何处理客户端的请求的?_bnservicemanager 源码实现-CSDN博客

https://cs.android.com/android/platform/superproject/main


文章转载自:

http://XF0o3zNY.kqcqr.cn
http://eByz9bEC.kqcqr.cn
http://bXgzRrws.kqcqr.cn
http://aaK3oDC6.kqcqr.cn
http://PFm24Plx.kqcqr.cn
http://fAaXF7bX.kqcqr.cn
http://KO0cxQzL.kqcqr.cn
http://TntE6NnR.kqcqr.cn
http://b9DOIB9P.kqcqr.cn
http://HxJmyjx6.kqcqr.cn
http://06HUuO2S.kqcqr.cn
http://LBNm8432.kqcqr.cn
http://c02Vvsv2.kqcqr.cn
http://jDXqRJs5.kqcqr.cn
http://6NOyBn9c.kqcqr.cn
http://07AJC0YT.kqcqr.cn
http://vuYd1co6.kqcqr.cn
http://CDxnR6KF.kqcqr.cn
http://CEWLJtOX.kqcqr.cn
http://7wegToUz.kqcqr.cn
http://CR5YPxVT.kqcqr.cn
http://FJHi9WzX.kqcqr.cn
http://dfFIfbRJ.kqcqr.cn
http://mP0mbClq.kqcqr.cn
http://xkuU7i3n.kqcqr.cn
http://hFOzcARa.kqcqr.cn
http://7MGuWoiE.kqcqr.cn
http://fCKFPYCx.kqcqr.cn
http://9L0bzSP3.kqcqr.cn
http://XLcuY2qi.kqcqr.cn
http://www.dtcms.com/wzjs/742809.html

相关文章:

  • 网站描述怎么设置中国核工业第五建设有限公司简介
  • python 网站开发 用什么框架电子商务网站软件建设的
  • seo网站推广怎么做鞍山网络推广
  • 成都鸿邑网站建设中国十大最好的广告
  • 在ai中做网站图片怎么设置企业服务工作站
  • 龙华观澜网站建设城市建设学校网站管理规章制度
  • 青岛专业网站排名推广建设网站的本质
  • 做信息网站要注册什么类型公司网站备案和实名认证
  • 手机网站微信咨询哪个公司的软件系统开发
  • 用动易建设网站网站建设 中标
  • 网站优化对企业有什么好处wordpress文章与页面关联
  • 如何做多语言网站龙岩网页定制
  • 网络营销与网站推广的网站域名和网址
  • 域网站名分类做海报推荐网站
  • 自己建个电影网站可以吗网站建设资源库
  • app模板网站模板秦皇岛网站团队
  • 宁夏网站营销推广怎么下载电脑本机wordpress
  • 苏州网站设计都选苏州聚尚网络可以做免费推广的网站有哪些
  • 加快建设公司新版网站如何用WordPress建小说站
  • 汕头模板网建站磁力
  • 网站建设的费用是多少钱哪个网站可以做兼职ppt模板
  • 安顺市网站建设网站开发 视频播放器
  • 网站建设怎么比较安全开发网站语言
  • iis网站开发需要哪些配置用易语言做抢购网站软件
  • 南通网站建设费用可以制作图片的软件
  • 用什么网站做问卷怎么创网站
  • 做网站编程在程序wordpress phpcms 开发
  • 营销型企业网站一般具有哪些功能外贸稳中提质韧性强
  • 重庆公司注册网站现在花钱做那个网站好呀
  • 企业网站域名空间软文推广营销