ALooperRoster.h revision 30873bfd08255e2c4e98ff5732ffff2838772617
19258b6bc66e09368ada54001f619d53b4fc976d5ager@chromium.org/*
29a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * Copyright (C) 2010 The Android Open Source Project
39a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com *
49a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * Licensed under the Apache License, Version 2.0 (the "License");
59a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * you may not use this file except in compliance with the License.
69a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * You may obtain a copy of the License at
79a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com *
89a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com *      http://www.apache.org/licenses/LICENSE-2.0
99a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com *
109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * Unless required by applicable law or agreed to in writing, software
119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * distributed under the License is distributed on an "AS IS" BASIS,
129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * See the License for the specific language governing permissions and
149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com * limitations under the License.
159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com */
169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com#ifndef A_LOOPER_ROSTER_H_
189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com#define A_LOOPER_ROSTER_H_
209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com#include <media/stagefright/foundation/ALooper.h>
229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com#include <utils/KeyedVector.h>
239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comnamespace android {
259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comstruct ALooperRoster {
279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    ALooperRoster();
289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    ALooper::handler_id registerHandler(
30196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org            const sp<ALooper> looper, const sp<AHandler> &handler);
31196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org
329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    void unregisterHandler(ALooper::handler_id handlerID);
334b0feeef5d01dbc2948080b4f69daa37e1083461machenbach@chromium.org    void unregisterStaleHandlers();
344b0feeef5d01dbc2948080b4f69daa37e1083461machenbach@chromium.org
359a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    status_t postMessage(const sp<AMessage> &msg, int64_t delayUs = 0);
369a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    void deliverMessage(const sp<AMessage> &msg);
379a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    status_t postAndAwaitResponse(
399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com            const sp<AMessage> &msg, sp<AMessage> *response);
409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
419a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    void postReply(uint32_t replyID, const sp<AMessage> &reply);
42b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org
43b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org    sp<ALooper> findLooper(ALooper::handler_id handlerID);
44b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org
459a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comprivate:
469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    struct HandlerInfo {
47b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org        wp<ALooper> mLooper;
489a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        wp<AHandler> mHandler;
499a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    };
503a37e9b96c768f6b5b6b09542e1cb1a1ece7a022ager@chromium.org
51b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org    Mutex mLock;
529a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    KeyedVector<ALooper::handler_id, HandlerInfo> mHandlers;
539a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    ALooper::handler_id mNextHandlerID;
549a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    uint32_t mNextReplyID;
559a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    Condition mRepliesCondition;
569a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
57b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org    KeyedVector<uint32_t, sp<AMessage> > mReplies;
58b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org
59b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org    status_t postMessage_l(const sp<AMessage> &msg, int64_t delayUs);
60b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org
61b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org    DISALLOW_EVIL_CONSTRUCTORS(ALooperRoster);
629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
63b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org
64b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org}  // namespace android
659a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com#endif  // A_LOOPER_ROSTER_H_
679a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com