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
28namespace clearkeydrm {
29
30class SessionLibrary {
31public:
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    void destroySession(const android::sp<Session>& session);
40
41private:
42    DISALLOW_EVIL_CONSTRUCTORS(SessionLibrary);
43
44    SessionLibrary() : mNextSessionId(1) {}
45
46    static android::Mutex sSingletonLock;
47    static SessionLibrary* sSingleton;
48
49    android::Mutex mSessionsLock;
50    uint32_t mNextSessionId;
51    android::DefaultKeyedVector<android::Vector<uint8_t>, android::sp<Session> >
52            mSessions;
53};
54
55} // namespace clearkeydrm
56
57#endif // CLEARKEY_SESSION_LIBRARY_H_
58