// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary // source code may only be used and distributed under the Widevine Master // License Agreement. #ifndef WIDEVINE_CAS_SESSION_MAP_H #define WIDEVINE_CAS_SESSION_MAP_H #include #include #include #include #include #include "cas_types.h" #include "widevine_cas_session.h" namespace wvcas { typedef std::map CasSessionMap; // WidevineCasSessionMap is a singleton. It used as a shared resource used by // both cas and descrambler plugins. Cas sessions are created by the cas plugin, // and can be *discovered* by descrambler plugins. class WidevineCasSessionMap { public: virtual ~WidevineCasSessionMap() {} // Adds a new Widevine cas session to the map. // Returns true if the session is successfully added to the map, false // otherwise. bool AddSession(const WvCasSessionId& cas_session_id, CasSessionPtr session); // Obtain a shared pointer to a cas session. If the session does not exist in // the map, the returned pointer == nullptr. CasSessionPtr GetSession(const WvCasSessionId& cas_session_id) const; // Remove an entry in the map. void RemoveSession(const WvCasSessionId& cas_session_id); // Retrieves all the session ids. std::vector GetAllSessions() const; // Returns a reference to the map. static WidevineCasSessionMap& instance(); WidevineCasSessionMap(const WidevineCasSessionMap&) = delete; WidevineCasSessionMap& operator=(const WidevineCasSessionMap&) = delete; private: WidevineCasSessionMap() {} CasSessionMap map_; mutable std::mutex lock_; }; } // namespace wvcas #endif // WIDEVINE_CAS_SESSION_MAP_H