IPC 的 Proxy-Stub 设计模式 ( c)

Similar documents
IPC 的 Proxy-Stub 设计模式 (b)

F03_c. 观摩 : SurfaceView 小框架 基於軟硬整合觀點. 的特殊性设计 ( c) By 高煥堂

Understanding IO patterns of SSDs

<properties> <jdk.version>1.8</jdk.version> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties>

Chapter 1 (Part 2) Introduction to Operating System

三 依赖注入 (dependency injection) 的学习

ICP Enablon User Manual Factory ICP Enablon 用户手册 工厂 Version th Jul 2012 版本 年 7 月 16 日. Content 内容

Logitech G302 Daedalus Prime Setup Guide 设置指南

Triangle - Delaunay Triangulator

Ganglia 是 UC Berkeley 发起的一个开源集群监视项目, 主要是用来监控系统性能, 如 :cpu mem 硬盘利用率, I/O 负载 网络流量情况等, 通过曲线很容易见到每个节点的工作状态, 对合理调整 分配系统资源, 提高系统整体性能起到重要作用

PCU50 的整盘备份. 本文只针对操作系统为 Windows XP 版本的 PCU50 PCU50 启动硬件自检完后, 出现下面文字时, 按向下光标键 光标条停在 SINUMERIK 下方的空白处, 如下图, 按回车键 PCU50 会进入到服务画面, 如下图

NyearBluetoothPrint SDK. Development Document--Android

Previous on Computer Networks Class 18. ICMP: Internet Control Message Protocol IP Protocol Actually a IP packet

如何查看 Cache Engine 缓存中有哪些网站 /URL

Packaging 10Apr2012 Rev V Specification MBXL HSG 1. PURPOSE 目的 2. APPLICABLE PRODUCT 适用范围

Multiprotocol Label Switching The future of IP Backbone Technology

组播路由 - MSDP 和 PIM 通过走

#MDCC Swift 链式语法应 用 陈乘

Command Dictionary CUSTOM

第二小题 : 逻辑隔离 (10 分 ) OpenFlow Switch1 (PC-A/Netfpga) OpenFlow Switch2 (PC-B/Netfpga) ServerB PC-2. Switching Hub

OpenCascade 的曲面.

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Supplementary Materials on Semaphores

朱晔和你聊 Spring 系列 S1E2: SpringBoot 并不神秘

Build a Key Value Flash Disk Based Storage System. Flash Memory Summit 2017 Santa Clara, CA 1

Software Engineering. Zheng Li( 李征 ) Jing Wan( 万静 )

Logitech ConferenceCam CC3000e Camera 罗技 ConferenceCam CC3000e Camera Setup Guide 设置指南

AvalonMiner Raspberry Pi Configuration Guide. AvalonMiner 树莓派配置教程 AvalonMiner Raspberry Pi Configuration Guide

DEV Office 客户端开发增强

PubMed 简介. PubMed 是美国国立医学图书馆 (NLM) 所属的国家生物技术信息中心 (NCBI) 开发的因特网生物医学信息检索系统

Microsemi - Leading Innovation for China s Hyperscale Data Centers

PTZ PRO 2. Setup Guide 设置指南

OTAD Application Note

Microsoft RemoteFX: USB 和设备重定向 姓名 : 张天民 职务 : 高级讲师 公司 : 东方瑞通 ( 北京 ) 咨询服务有限公司

libde265 HEVC 性能测试报告

CloudStack 4.3 API 开发指南!

Chapter 2: Java OO II. Yang Wang wyang AT njnet.edu.cn

Apache Kafka 源码编译 Spark 大数据博客 -

计算机组成原理第二讲 第二章 : 运算方法和运算器 数据与文字的表示方法 (1) 整数的表示方法. 授课老师 : 王浩宇

实验三十三 DEIGRP 的配置 一 实验目的 二 应用环境 三 实验设备 四 实验拓扑 五 实验要求 六 实验步骤 1. 掌握 DEIGRP 的配置方法 2. 理解 DEIGRP 协议的工作过程

Lecture 3 for pipelining

<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <!--- global properties --> <property>

A Benchmark For Stroke Extraction of Chinese Characters

TDS - 3. Battery Compartment. LCD Screen. Power Button. Hold Button. Body. Sensor. HM Digital, Inc.

Spark Standalone 模式应用程序开发 Spark 大数据博客 -

1. Spring 整合 Jdbc 进行持久层开发

NetScreen 概念与范例. ScreenOS 参考指南 第 7 卷 : 虚拟系统. ScreenOS 编号 SC 修订本 E

VAS 5054A FAQ ( 所有 5054A 整合, 中英对照 )

[ 电子书 ]Spark for Data Science PDF 下载 Spark 大数据博客 -

Air Speaker. Getting started with Logitech UE Air Speaker. 快速入门罗技 UE Air Speaker. Wireless speaker with AirPlay. 无线音箱 (AirPlay 技术 )

XML allows your content to be created in one workflow, at one cost, to reach all your readers XML 的优势 : 只需一次加工和投入, 到达所有读者的手中

1. DWR 1.1 DWR 基础 概念 使用使用 DWR 的步骤. 1 什么是 DWR? Direct Web Remote, 直接 Web 远程 是一个 Ajax 的框架

New Media Data Analytics and Application. Lecture 7: Information Acquisition An Integration Ting Wang

nbns-list netbios-type network next-server option reset dhcp server conflict 1-34

Machine Vision Market Analysis of 2015 Isabel Yang

学习沉淀成长分享 EIGRP. 红茶三杯 ( 朱 SIR) 微博 : Latest update:

3dvia Composer Solidworks

Wireless Presentation Pod

Bi-monthly report. Tianyi Luo

TBarCode OCX Microsoft ActiveX compliant Barcode Control

Keygen Codes For Photoshop Cs6 ->>> DOWNLOAD

Technology: Anti-social Networking 科技 : 反社交网络

漂亮的测试. By Alberto Savoia 代码之美 第七章 史际帆

TW5.0 如何使用 SSL 认证. 先使用 openssl 工具 1 生成 CA 私钥和自签名根证书 (1) 生成 CA 私钥 openssl genrsa -out ca-key.pem 1024

Oriented Scene Text Detection Revisited. Xiang Bai Huazhong University of Science and Technology

Oracle 一体化创新云技术 助力智慧政府信息化战略. Copyright* *2014*Oracle*and/or*its*affiliates.*All*rights*reserved.** *

Decode Zend. Darkness/Airsupply

Chapter 2: Relational Model

FLIGHT INSTRUMENT PANEL

密级 : 博士学位论文. 论文题目基于 ScratchPad Memory 的嵌入式系统优化研究

Stratix V 器件中的收发器配置. Stratix V 器件含有一个专用的收发器物理编码子层 (PCS) 和物理介质附加子层 (PMA) 电路 要实现一个协议, 请使用表 4-1 中所列出的 PHY IP

软件和支持订订 1.1 订阅单位定义 订阅服务费用以称为 单位 的计量标准为依据 下表 1.1 定义了用于计量贵方使用的软件订阅的数量的各种单位 在贵方购买行为所适用的订单中以及在附件中包含了各种软件订阅所适用的具体单位

Chapter 11 SHANDONG UNIVERSITY 1

iphone 4s 尾插排线更换放方法 FIXBAR 此教程只适用于更换 iphone4s 损坏的尾插排线 Written By: xiaohang 2018 bengg.dozuki.com/ Page 1 of 15

public static InetAddress getbyname(string host) public static InetAddress getlocalhost() public static InetAddress[] getallbyname(string host)

Color LaserJet Pro MFP M477 入门指南

MateCam X1 User Manual

2. Introduction to Digital Media Format

Safety Life Cycle Model IEC61508 安全生命周期模型 -IEC61508

测试基础架构 演进之路. 茹炳晟 (Robin Ru) ebay 中国研发中心

The Design of Everyday Things

Skill-building Courses Business Analysis Lesson 3 Problem Solving

White Paper 3 System Level ESD Part II: Implementation of Effective ESD Robust Designs. Industry Council on ESD Target Levels

上汽通用汽车供应商门户网站项目 (SGMSP) User Guide 用户手册 上汽通用汽车有限公司 2014 上汽通用汽车有限公司未经授权, 不得以任何形式使用本文档所包括的任何部分

Presentation Title. By Author The MathWorks, Inc. 1

Chapter2 Instruction Sets

XPages Extensibility API: Free Your Mind! 2011 IBM Corporation

Table of Contents. DS159-ZH LUXEON XR-3020 Product Datasheet Lumileds Holding B.V. All rights reserved.

Flymaple V1.1(SKU:DFR0188)

Congestion Control Mechanisms for Ad-hoc Social Networks 自组织社会网络中的拥塞控制机制

Murrelektronik Connectivity Interface Part I Product range MSDD, cable entry panels MSDD 系列, 电缆穿线板

测试 SFTP 的 问题在归档配置页的 MediaSense

Computer Networks. Wenzhong Li. Nanjing University

China Next Generation Internet (CNGI) project and its impact. MA Yan Beijing University of Posts and Telecommunications 2009/08/06.

JAVA Programming Language Homework V: Overall Review

Epetra_Matrix. August 14, Department of Science and Engineering Computing School of Mathematics School Peking University

Autodesk Backburner 2011 安装手册

Mini Bluetooth Keyboard 迷你蓝牙键盘. instructions 使用指南 (KP BTL)

Command Dictionary -- DAMSTAB

PCI Express. Tx/Rx Solutions

Transcription:

B05_c 基於軟硬整合觀點 IPC 的 Proxy-Stub 设计模式 ( c) By 高煥堂

天子 曹操 地头蛇?

3 包裝 IBinder 接口基於軟硬整合觀點 -- 使用 Proxy-Stub 设计模式

采用 Proxy-Stub 设计模式将 IBinder 接口包装起来, 让 App 与 IBinder 接口不再产生高度相依性

應用程序 (App)

其将 IBinder 接口包装起来, 转换出更好用的新接口 : 桌上新接口 桌腳新接口

Proxy 类提供较好用的 IA 接口给 Client 使用 Stub 类别则是屏蔽了 Binder 基类的 ontransact() 函数, 然后将 IA 接口里的 f1() 和 f2() 函数定义为抽象函数 于是简化了 App 开发的负担 :

應用程序 (App)

e i t

4 谁来写 Proxy 及 Stub 类呢? 基於軟硬整合觀點 -- 地头蛇 (App 开发者 ) 自己写

范例 兹写一个 App 范例, 程序执行时出现画面如下 :

在这个范例里, 定义了一个 IPlayer 接口, 然后规划了 PlayerProxy 和 PlayerStub 两的类, 如下图 :

定义一个新接口 :IPlayer // IPlayer.java package com.misoo.pkgx; public interface IPlayer { void play(); void stop(); String getstatus(); }

撰写一个 Stub 类 :PlayerStub // PlayerStub.java package com.misoo.pkgx; import android.os.binder; import android.os.parcel; public abstract class PlayerStub extends Binder implements IPlayer{ @Override public boolean ontransact(int code, Parcel data, Parcel reply, int flags) throws android.os.remoteexception { reply.writestring(data.readstring()+ " mp3"); if(code == 1) this.play(); else if(code == 2) this.stop(); return true; } public abstract void play(); public abstract void stop(); public abstract String getstatus(); }

撰写一个 Proxy 类 :PlayerProxy // PlayProxy.java private class PlayerProxy implements IPlayer{ private IBinder ib; private String mstatus; PlayerProxy(IBinder ibinder) { ib = ibinder; } public void play(){ Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writestring("playing"); try { ib.transact(1, data, reply, 0); mstatus = reply.readstring(); } catch (Exception e) { e.printstacktrace(); } }

public void stop(){ Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writestring("stop"); try { ib.transact(2, data, reply, 0); mstatus = reply.readstring(); } catch (Exception e) { e.printstacktrace(); } } public String getstatus() { return mstatus; } } }

撰写 mp3binder 类 // mp3binder.java //.. public class mp3binder extends PlayerStub{ private MediaPlayer mplayer = null; private Context ctx; public mp3binder(context cx){ ctx= cx; } public void play(){ if(mplayer!= null) return; mplayer = MediaPlayer.create(ctx, R.raw.test_cbr); try { mplayer.start(); } catch (Exception e) { Log.e("StartPlay", "error: " + e.getmessage(), e); }} public void stop(){ if (mplayer!= null) { mplayer.stop(); mplayer.release(); mplayer = null; }} public String getstatus() { return null; } }

撰写 mp3remoteservice 类 // mp3remoteservice.java package com.misoo.pkgx; import android.app.service; import android.content.intent; import android.os.ibinder; public class mp3remoteservice extends Service { private IBinder mbinder = null; @Override public void oncreate() { mbinder = new mp3binder(getapplicationcontext()); } @Override public IBinder onbind(intent intent) { return mbinder; } }

撰写 mp3remoteservice 类 // ac01.java // public class ac01 extends Activity implements OnClickListener { //. private PlayerProxy pproxy = null; public void oncreate(bundle icicle) { // startservice(new Intent("com.misoo.pkgx.REMOTE_SERVICE")); bindservice(new Intent("com.misoo.pkgx.REMOTE_SERVICE"), mconnection, Context.BIND_AUTO_CREATE); } private ServiceConnection mconnection = new ServiceConnection() { public void onserviceconnected(componentname classname, IBinder ibinder) { pproxy = new PlayerProxy(ibinder); } public void onservicedisconnected(componentname classna){} };

} public void onclick(view v) { switch (v.getid()) { case 101: pproxy.play(); tv.settext(pproxy.getstatus()); break; case 102: pproxy.stop(); tv.settext(pproxy.getstatus()); break; case 103: unbindservice(mconnection); stopservice( new Intent("com.misoo.pkgx.REMOTE_SERVICE")); finish(); break; } }

PlayerStub 类将 ontransact() 函数隐藏起来, 提供一个更具有美感 更亲切的新接口给 mp3binder 类使用 隐藏了 ontransact() 函数之后, mp3binder 类的开发者就不必费心去了解 ontransact() 函数了 于是,PlayerProxy 与 PlayerStub 两个类遥遥相对, 并且将 IPC 细节知识 ( 例如 transact() 和 ontransact() 函数之参数等 ) 包夹起来

~ Continued ~