1 /* 2 * Copyright (C) 2014 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/KeyedVector.h> 21 #include <utils/Mutex.h> 22 #include <utils/StrongPointer.h> 23 #include <utils/Vector.h> 24 25 #include "Session.h" 26 #include "Utils.h" 27 28 namespace clearkeydrm { 29 30 class SessionLibrary { 31 public: 32 static SessionLibrary* get(); 33 34 const android::sp<Session>& createSession(); 35 36 const android::sp<Session>& findSession( 37 const android::Vector<uint8_t>& sessionId); 38 39 const android::sp<Session>& findSession(const void* data, size_t size); 40 41 void destroySession(const android::sp<Session>& session); 42 43 private: 44 DISALLOW_EVIL_CONSTRUCTORS(SessionLibrary); 45 SessionLibrary()46 SessionLibrary() : mNextSessionId(1) {} 47 48 static android::Mutex sSingletonLock; 49 static SessionLibrary* sSingleton; 50 51 android::Mutex mSessionsLock; 52 uint32_t mNextSessionId; 53 android::KeyedVector<android::Vector<uint8_t>, android::sp<Session> > 54 mSessions; 55 }; 56 57 } // namespace clearkeydrm 58 59 #endif // CLEARKEY_SESSION_LIBRARY_H_ 60