Home | History | Annotate | Download | only in mock
      1 /*
      2  * Copyright (C) 2017 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 MOCK_CAS_SESSION_LIBRARY_H_
     18 #define MOCK_CAS_SESSION_LIBRARY_H_
     19 
     20 #include <media/cas/CasAPI.h>
     21 #include <media/stagefright/foundation/ABase.h>
     22 #include <utils/KeyedVector.h>
     23 #include <utils/Mutex.h>
     24 #include <utils/RefBase.h>
     25 
     26 namespace android {
     27 
     28 class MockCasSession : public RefBase {
     29 public:
     30     explicit MockCasSession(CasPlugin *plugin) : mPlugin(plugin) {}
     31     virtual ~MockCasSession() {}
     32 
     33 private:
     34     friend class MockSessionLibrary;
     35 
     36     CasPlugin* mPlugin;
     37 
     38     CasPlugin* getPlugin() const { return mPlugin; }
     39 
     40     DISALLOW_EVIL_CONSTRUCTORS(MockCasSession);
     41 };
     42 
     43 class MockSessionLibrary {
     44 public:
     45     static MockSessionLibrary* get();
     46 
     47     status_t addSession(CasPlugin *plugin, CasSessionId *sessionId);
     48 
     49     sp<MockCasSession> findSession(const CasSessionId& sessionId);
     50 
     51     void destroySession(const CasSessionId& sessionId);
     52 
     53     void destroyPlugin(CasPlugin *plugin);
     54 
     55 private:
     56     static Mutex sSingletonLock;
     57     static MockSessionLibrary* sSingleton;
     58 
     59     Mutex mSessionsLock;
     60     uint32_t mNextSessionId;
     61     KeyedVector<CasSessionId, sp<MockCasSession> > mIDToSessionMap;
     62 
     63     MockSessionLibrary();
     64     DISALLOW_EVIL_CONSTRUCTORS(MockSessionLibrary);
     65 };
     66 } // namespace android
     67 
     68 #endif // MOCK_CAS_SESSION_LIBRARY_H_
     69