summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/foundation/ALooperRoster.cpp
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2011-08-25 16:09:06 -0700
committerAndreas Huber <andih@google.com>2011-08-25 16:28:18 -0700
commit5df775d2f509c76e76a46615fca83dba95299f6e (patch)
tree1062b747ad85433dec6dca2093fafb8d2a6d89a7 /media/libstagefright/foundation/ALooperRoster.cpp
parent24245683b9285b0b53c8900f088cf146000501c4 (diff)
downloadframeworks_av-5df775d2f509c76e76a46615fca83dba95299f6e.zip
frameworks_av-5df775d2f509c76e76a46615fca83dba95299f6e.tar.gz
frameworks_av-5df775d2f509c76e76a46615fca83dba95299f6e.tar.bz2
Support for posting messages and synchronously waiting for a response.
Change-Id: Id6c7a08c34fd5cb6c4632f78ece9e7898b29e52c
Diffstat (limited to 'media/libstagefright/foundation/ALooperRoster.cpp')
-rw-r--r--media/libstagefright/foundation/ALooperRoster.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/media/libstagefright/foundation/ALooperRoster.cpp b/media/libstagefright/foundation/ALooperRoster.cpp
index 8aa1b15..e399f2f 100644
--- a/media/libstagefright/foundation/ALooperRoster.cpp
+++ b/media/libstagefright/foundation/ALooperRoster.cpp
@@ -27,7 +27,8 @@
namespace android {
ALooperRoster::ALooperRoster()
- : mNextHandlerID(1) {
+ : mNextHandlerID(1),
+ mNextReplyID(1) {
}
ALooper::handler_id ALooperRoster::registerHandler(
@@ -70,15 +71,19 @@ void ALooperRoster::unregisterHandler(ALooper::handler_id handlerID) {
mHandlers.removeItemsAt(index);
}
-void ALooperRoster::postMessage(
+status_t ALooperRoster::postMessage(
const sp<AMessage> &msg, int64_t delayUs) {
Mutex::Autolock autoLock(mLock);
+ return postMessage_l(msg, delayUs);
+}
+status_t ALooperRoster::postMessage_l(
+ const sp<AMessage> &msg, int64_t delayUs) {
ssize_t index = mHandlers.indexOfKey(msg->target());
if (index < 0) {
LOGW("failed to post message. Target handler not registered.");
- return;
+ return -ENOENT;
}
const HandlerInfo &info = mHandlers.valueAt(index);
@@ -91,10 +96,12 @@ void ALooperRoster::postMessage(
msg->target());
mHandlers.removeItemsAt(index);
- return;
+ return -ENOENT;
}
looper->post(msg, delayUs);
+
+ return OK;
}
void ALooperRoster::deliverMessage(const sp<AMessage> &msg) {
@@ -145,4 +152,38 @@ sp<ALooper> ALooperRoster::findLooper(ALooper::handler_id handlerID) {
return looper;
}
+status_t ALooperRoster::postAndAwaitResponse(
+ const sp<AMessage> &msg, sp<AMessage> *response) {
+ Mutex::Autolock autoLock(mLock);
+
+ uint32_t replyID = mNextReplyID++;
+
+ msg->setInt32("replyID", replyID);
+
+ status_t err = postMessage_l(msg, 0 /* delayUs */);
+
+ if (err != OK) {
+ response->clear();
+ return err;
+ }
+
+ ssize_t index;
+ while ((index = mReplies.indexOfKey(replyID)) < 0) {
+ mRepliesCondition.wait(mLock);
+ }
+
+ *response = mReplies.valueAt(index);
+ mReplies.removeItemsAt(index);
+
+ return OK;
+}
+
+void ALooperRoster::postReply(uint32_t replyID, const sp<AMessage> &reply) {
+ Mutex::Autolock autoLock(mLock);
+
+ CHECK(mReplies.indexOfKey(replyID) < 0);
+ mReplies.add(replyID, reply);
+ mRepliesCondition.broadcast();
+}
+
} // namespace android