From 91556d2de8081ff5325dfe6aa7c2995e0d039281 Mon Sep 17 00:00:00 2001
From: Android Partner Docs
Fast Message Queues are supported only in C++.
Android supports two queue types:
+Android supports two queue types (known as flavors):
MQDescriptor
object obtained from the first side. The
MQDescriptor
object is sent over a HIDL RPC call to the process
that will hold the second end of the message queue. The
-MQDescriptor
contains information about the queue:
+MQDescriptor
contains information about the queue, including:
<T, flavor>
), which includes the
+HIDL-defined type of
+queue elements and the queue flavor (synchronized or unsynchronized).The MQDescriptor
object can be used to construct a
@@ -172,8 +173,15 @@ of blocking read/write calls:
true
.true
. For example:
++// For an unsynchronized FMQ that supports blocking +mFmqUnsynchronizedBlocking = + new (std::nothrow) MessageQueue<uint16_t, kUnsynchronizedWrite> + (kNumElementsInQueue, true /* enable blocking operations */); ++
EventFlag
object between multiple queues
and allows specifying the notification bit masks to be used. In this case, the
@@ -285,12 +293,12 @@ notification bits. Similarly, writeblocking()
will fail if
To wait on multiple queues at once, use an EventFlag
object's
wait()
method to wait on a bitmask of notifications. The
wait()
method returns a status word with the bits that caused the
-wake up set. Using the information, the user can then check the corresponding
-queue to see whether it has enough space or data for the desired write or read
-operation and perform a nonblocking read()
/write()
-followed by a call to the EventFlag
's wake()
method if
-a notification is desired after the same. For a definition of the
-EventFlag
abstraction, refer to
+wake up set. This information is then used to verify the corresponding queue has
+enough space or data for the desired write/read operation and perform a
+nonblocking write()
/read()
. To get a post operation
+notification, use another call to the EventFlag
's
+wake()
method. For a definition of the EventFlag
+abstraction, refer to
system/libfmq/include/fmq/EventFlag.h
.
read
/write
/readBlocking
/writeBlocking()
APIs take a pointer to an input/output buffer as an argument and use
memcpy()
calls internally to copy data between the same and the
-FMQ ring buffer. To improve performance, Android O includes a set of APIs that
-provide direct pointer access into the ring buffer, eliminating the need to use
-memcpy
calls.
+FMQ ring buffer. To improve performance, Android 8.0 and higher include a set of
+APIs that provide direct pointer access into the ring buffer, eliminating the
+need to use memcpy
calls.
Use the following public APIs for zero copy FMQ operations:
@@ -323,8 +331,9 @@ read/write is possible. If the read or write is possible thememTx
struct is populated with base pointers that can be used for direct pointer
access into the ring buffer shared memory.MemRegion
struct contains details about a block of memory,
-i.e. a base pointer and length in terms of T
(where the FMQ is
-templatized to T
).T
(length of the memory block in terms of the HIDL-defined
+type of the message queue).
MemTransaction
struct contains two MemRegion
structs, first
and second
as a read or write into
the ring buffer may require a wrap around to the beginning of the queue. This
@@ -404,7 +413,7 @@ event flag pointer (using getEventFlagWord()
) from a
use that flag to create the necessary EventFlag
object.MessageQueue
getDesc()
method to get a
descriptor object..hal
file, give a method a parameter of type
+.hal
file, give the method a parameter of type
fmq_sync
or fmq_unsync
where T
is a
suitable HIDL-defined type. Use this to send the object returned by
getDesc()
to the receiving process.In HIDL, structs may not be forward-declared, making user-defined, self-referential data types impossible (e.g., you cannot describe a linked list -or a tree in HIDL). Most existing (pre-Android O) HALs have limited use of +or a tree in HIDL). Most existing (pre-Android 8.x) HALs have limited use of forward declarations, which can be removed by rearranging data structure declarations.
This restriction allows data structures to be copied by-value with a simple
deep-copy, rather than keeping track of pointer values that may occur multiple
times in a self-referential data structure. If the same data is passed twice,
-such as with two method parameters or vec<T>
's that point to
+such as with two method parameters or vec<T>
s that point to
the same data, two separate copies are made and delivered.
native_handle_t
.
In earlier versions of Android, native handles were created using the same
functions present in
libcutils.
-In Android O, these functions are now copied to the
+In Android 8.0 and higher, these functions are now copied to the
android::hardware::hidl
namespace or moved to the NDK. HIDL
autogenerated code serializes and deserializes these functions automatically,
without involvement from user-written code.
hidl_handle
object as an argument, the caller
-retains ownership of the file descriptors contained in the
-native_handle_t
it wraps, and must close them when it is done with
-them. Likewise, when returning a hidl_handle
object (by passing it
-into a _cb
function), the process returning it retains ownership of
-the file descriptors contained in the native_handle_t
it wraps, and
-must close them when it is done with them.hidl_handle
object, the
-transport owns the file descriptors inside the
-native_handle_t
it wraps; the receiver can use them as-is during
-the transaction callback, but must clone the native handle if it wants to keep
-using its file descriptors beyond the callback. The transport will automatically
+hidl_handle
object as an
+argument retains ownership of the file descriptors contained in the
+native_handle_t
it wraps; the caller must close these file
+descriptors when it is done with them.hidl_handle
+object (by passing it into a _cb
function) retains ownership of the
+file descriptors contained in the native_handle_t
wrapped by the
+object; the process must close these file descriptors when it is done with them.
+hidl_handle
has
+ownership of the file descriptors inside the native_handle_t
+wrapped by the object; the receiver can use these file descriptors as-is during
+the transaction callback, but must clone the native handle to use the file
+descriptors beyond the callback. The transport will automatically
close()
the file descriptors when the transaction is done.import android.hardware.foo@1.0;
).
Every HIDL package contains a types.hal
file with UDTs share
-among all interfaces participating in that package. HIDL types are always
-public; regardless of whether a UDT is declared in types.hal
or
-within an interface declaration, these types are accessible outside of the scope
-where they are defined. types.hal
is not meant to describe the
-public API of a package, but rather to host UDTs used by all interfaces within
-the package. Due to the nature of HIDL, all UDTs are a part of the interface.
-
Every HIDL package contains a types.hal
file containing UDTs
+that are shared among all interfaces participating in that package. HIDL types
+are always public; regardless of whether a UDT is declared in
+types.hal
or within an interface declaration, these types are
+accessible outside of the scope where they are defined. types.hal
+is not meant to describe the public API of a package, but rather to host UDTs
+used by all interfaces within the package. Due to the nature of HIDL, all UDTs
+are a part of the interface.
types.hal
consists of UDTs and import
statements.
Because types.hal
is made available to every interface of the
@@ -584,13 +584,13 @@ redundant.
fromFooToBar()
it inherits from @1.0::IQuux
; it simply
lists the new method it adds fromBarToFoo()
. In HIDL, inherited
methods may not be declared again in the child interfaces, so
-for IQuux
it would not be an option to declare
-fromFooToBar()
explicitly.
+the IQuux
interface cannot declare the fromFooToBar()
+method explicitly.
+If a method implementation needs to fall back to the method implementation of
+the base class, the fallback must be in the implementation.
Sometimes interface names must rename the extending interface. We recommend -- cgit v1.2.3