Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2018 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 CLEARKEY_SESSION_LIBRARY_H_
     18 #define CLEARKEY_SESSION_LIBRARY_H_
     19 
     20 #include <utils/RefBase.h>
     21 #include <utils/Mutex.h>
     22 
     23 #include "ClearKeyTypes.h"
     24 #include "Session.h"
     25 
     26 namespace android {
     27 namespace hardware {
     28 namespace drm {
     29 namespace V1_2 {
     30 namespace clearkey {
     31 
     32 using ::android::sp;
     33 
     34 class SessionLibrary : public RefBase {
     35 public:
     36     static SessionLibrary* get();
     37 
     38     sp<Session> createSession();
     39 
     40     sp<Session> findSession(
     41             const std::vector<uint8_t>& sessionId);
     42 
     43     void destroySession(const sp<Session>& session);
     44 
     45     size_t numOpenSessions() const { return mSessions.size(); }
     46 
     47 private:
     48     CLEARKEY_DISALLOW_COPY_AND_ASSIGN(SessionLibrary);
     49 
     50     SessionLibrary() : mNextSessionId(1) {}
     51 
     52     static Mutex sSingletonLock;
     53     static SessionLibrary* sSingleton;
     54 
     55     Mutex mSessionsLock;
     56     uint32_t mNextSessionId;
     57     std::map<std::vector<uint8_t>, sp<Session> > mSessions;
     58 };
     59 
     60 } // namespace clearkey
     61 } // namespace V1_2
     62 } // namespace drm
     63 } // namespace hardware
     64 } // namespace android
     65 
     66 #endif // CLEARKEY_SESSION_LIBRARY_H_
     67