Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_IMEDIADEATHNOTIFIER_H
     18 #define ANDROID_IMEDIADEATHNOTIFIER_H
     19 
     20 #include <utils/threads.h>
     21 #include <media/IMediaPlayerService.h>
     22 #include <utils/SortedVector.h>
     23 
     24 namespace android {
     25 
     26 class IMediaDeathNotifier: virtual public RefBase
     27 {
     28 public:
     29     IMediaDeathNotifier() { addObitRecipient(this); }
     30     virtual ~IMediaDeathNotifier() { removeObitRecipient(this); }
     31 
     32     virtual void died() = 0;
     33     static const sp<IMediaPlayerService> getMediaPlayerService();
     34 
     35 private:
     36     IMediaDeathNotifier &operator=(const IMediaDeathNotifier &);
     37     IMediaDeathNotifier(const IMediaDeathNotifier &);
     38 
     39     static void addObitRecipient(const wp<IMediaDeathNotifier>& recipient);
     40     static void removeObitRecipient(const wp<IMediaDeathNotifier>& recipient);
     41 
     42     class DeathNotifier: public IBinder::DeathRecipient
     43     {
     44     public:
     45                 DeathNotifier() {}
     46         virtual ~DeathNotifier();
     47 
     48         virtual void binderDied(const wp<IBinder>& who);
     49     };
     50 
     51     friend class DeathNotifier;
     52 
     53     static  Mutex                                   sServiceLock;
     54     static  sp<IMediaPlayerService>                 sMediaPlayerService;
     55     static  sp<DeathNotifier>                       sDeathNotifier;
     56     static  SortedVector< wp<IMediaDeathNotifier> > sObitRecipients;
     57 };
     58 
     59 }; // namespace android
     60 
     61 #endif // ANDROID_IMEDIADEATHNOTIFIER_H
     62