|
|
|
Modern Operating Systems by Herbert Bos and Andrew S. Tanenb...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf
Showing 853-854 out of 1137
Modern Operating Systems by Herbert Bos and Andrew...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Modern Operating Systems by Herbert...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Page 853
822
CASE STUDY 1: UNIX, LINUX, AND ANDROID
CHAP. 10
Process 1
Binder1b
Binder1b
Binder1b
Parcel
transact()
BinderProxy
(Handle 2)
BinderProxy
(Handle 3)
onTransact()
Parcel
Binder1b
Binder2b
Binder2a
Process 1
Process 2
Process 2
Handle 1
Handle 1
Handle 2
Handle 3
Handle 3
Handle 3
Handle 2
Transaction
Transaction
To: Handle 2
From: Process 1
To: Binder2a
From: Process 1
Data
Data
Data
Data
Data
Data
Data
Data
Kernel
Figure 10-46.
Binder
user-space API.
The bulk of this work is in the last two steps. This is the
unmarshalling
and
marshalling
code that is needed to turn how we’d prefer to program—using sim-
ple method calls—into the operations that are needed to execute an IPC.
This is
boring and error-prone code to write, so we’d like to let the computer take care of
that for us.
Binder Interfaces and AIDL
The final piece of
Binder
IPC is the one that is most often used, a high-level in-
terface-based programming model.
Instead of dealing with
Binder
objects and
Parcel
data, here we get to think in terms of interfaces and methods.
The main piece of this layer is a command-line tool called
AIDL
(for
Android
Interface Definition Language
). This tool is an interface compiler, taking an ab-
stract description of an interface and generating from it the source code necessary
to define that interface and implement the appropriate marshalling and unmar-
shalling code needed to make remote calls with it.
Figure 10-47 shows a simple example of an interface defined in AIDL.
This
interface is called
IExample
and contains a single method,
print
, which takes a sin-
gle String argument.
package com.example
interface IExample {
void print(String msg);
}
Figure 10-47.
Simple interface described in AIDL.
Page 854
SEC. 10.8
ANDROID
823
An interface description like that in Fig. 10-47 is compiled by AIDL to gener-
ate three Java-language classes illustrated in Fig. 10-48:
1.
IExample
supplies the Java-language interface definition.
2.
IExample.Stub
is the base class for implementations of this inter-
face. It inherits from
Binder
, meaning it can be the recipient of IPC
calls; it inherits from
IExample
, since this is the interface being im-
plemented. The purpose of this class is to perform unmarshalling:
turn incoming
onTransact
calls in to the appropriate method call of
IExample
.
A subclass of it is then responsible only for implementing
the
IExample
methods.
3.
IExample.Proxy
is the other side of an IPC call, responsible for per-
forming marshalling of the call.
It is a concrete implementation of
IExample
, implementing each method of it to transform the call into
the appropriate
Parcel
contents and send it off through a
transact
call
on an
IBinder
it is communicating with.
Binder
IExample
IExample.Stub
IExample.Proxy
IBinder
Figure 10-48.
Binder
interface inheritance hierarchy.
With these classes in place, there is no longer any need to worry about the
mechanics of an IPC.
Implementors of the
IExample
interface simply derive from
IExample.Stub
and implement the interface methods as they normally would. Cal-
lers will receive an
IExample
interface that is implemented by
IExample.Proxy
, al-
lowing them to make regular calls on the interface.
The way these pieces work together to perform a complete IPC operation is
shown in Fig. 10-49.
A simple
print
call on an
IExample
interface turns into:
1.
IExample.Proxy
marshals the method call into a
Parcel
, calling
trans-
act
on the underlying
BinderProxy
.
2.
BinderProxy
constructs a kernel transaction and delivers it to the ker-
nel through an
ioctl
call.
3.
The kernel transfers the transaction to the intended process, delivering
it to a thread that is waiting in its own
ioctl
call.
Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Operating_Systems
Course:
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades
Students also viewed documents
lab 18.docx
lab_18.docx
Course
Course
3
Module5QuizSTA2023.d...
Module5QuizSTA2023.docx.docx
Course
Course
10
Week 7 Test Math302....
Week_7_Test_Math302.docx.docx
Course
Course
30
Chapter 1 Assigment ...
Chapter_1_Assigment_Questions.docx.docx
Course
Course
5
Week 4 tests.docx.do...
Week_4_tests.docx.docx
Course
Course
23
Week 6 tests.docx.do...
Week_6_tests.docx.docx
Course
Course
106