127c174483a8ae9688d5d4897c19074f62c7f1701James Dong/*
227c174483a8ae9688d5d4897c19074f62c7f1701James Dong * Copyright (C) 2010 The Android Open Source Project
327c174483a8ae9688d5d4897c19074f62c7f1701James Dong *
427c174483a8ae9688d5d4897c19074f62c7f1701James Dong * Licensed under the Apache License, Version 2.0 (the "License");
527c174483a8ae9688d5d4897c19074f62c7f1701James Dong * you may not use this file except in compliance with the License.
627c174483a8ae9688d5d4897c19074f62c7f1701James Dong * You may obtain a copy of the License at
727c174483a8ae9688d5d4897c19074f62c7f1701James Dong *
827c174483a8ae9688d5d4897c19074f62c7f1701James Dong *      http://www.apache.org/licenses/LICENSE-2.0
927c174483a8ae9688d5d4897c19074f62c7f1701James Dong *
1027c174483a8ae9688d5d4897c19074f62c7f1701James Dong * Unless required by applicable law or agreed to in writing, software
1127c174483a8ae9688d5d4897c19074f62c7f1701James Dong * distributed under the License is distributed on an "AS IS" BASIS,
1227c174483a8ae9688d5d4897c19074f62c7f1701James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1327c174483a8ae9688d5d4897c19074f62c7f1701James Dong * See the License for the specific language governing permissions and
1427c174483a8ae9688d5d4897c19074f62c7f1701James Dong * limitations under the License.
1527c174483a8ae9688d5d4897c19074f62c7f1701James Dong */
1627c174483a8ae9688d5d4897c19074f62c7f1701James Dong
175994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber#ifndef A_HANDLER_REFLECTOR_H_
185994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
195994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber#define A_HANDLER_REFLECTOR_H_
205994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
215994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber#include <media/stagefright/foundation/AHandler.h>
225994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
235994b4798b01f3dd340577c9ea9657f09093a770Andreas Hubernamespace android {
245994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
255994b4798b01f3dd340577c9ea9657f09093a770Andreas Hubertemplate<class T>
265994b4798b01f3dd340577c9ea9657f09093a770Andreas Huberstruct AHandlerReflector : public AHandler {
275994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber    AHandlerReflector(T *target)
285994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber        : mTarget(target) {
295994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber    }
305994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
315994b4798b01f3dd340577c9ea9657f09093a770Andreas Huberprotected:
325994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber    virtual void onMessageReceived(const sp<AMessage> &msg) {
335994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber        sp<T> target = mTarget.promote();
345994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber        if (target != NULL) {
355994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber            target->onMessageReceived(msg);
365994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber        }
375994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber    }
385994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
395994b4798b01f3dd340577c9ea9657f09093a770Andreas Huberprivate:
405994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber    wp<T> mTarget;
415994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
425994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber    AHandlerReflector(const AHandlerReflector<T> &);
435994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber    AHandlerReflector<T> &operator=(const AHandlerReflector<T> &);
445994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber};
455994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
465994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber}  // namespace android
475994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber
485994b4798b01f3dd340577c9ea9657f09093a770Andreas Huber#endif  // A_HANDLER_REFLECTOR_H_
49