71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
// 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 WVCDM_CDM_TEST_TEST_HOST_H_
|
|
#define WVCDM_CDM_TEST_TEST_HOST_H_
|
|
|
|
#include <queue>
|
|
#include <vector>
|
|
|
|
#include "cdm.h"
|
|
|
|
class TestHost : public widevine::Cdm::IStorage,
|
|
public widevine::Cdm::IClock,
|
|
public widevine::Cdm::ITimer {
|
|
public:
|
|
TestHost();
|
|
void Reset();
|
|
|
|
void ElapseTime(int64_t milliseconds);
|
|
int NumTimers() const;
|
|
|
|
void SaveProvisioningInformation() { save_device_cert_ = true; }
|
|
|
|
bool read(const std::string& name, std::string* data) override;
|
|
bool write(const std::string& name, const std::string& data) override;
|
|
bool exists(const std::string& name) override;
|
|
bool remove(const std::string& name) override;
|
|
int32_t size(const std::string& name) override;
|
|
bool list(std::vector<std::string>* names) override;
|
|
|
|
int64_t now() override;
|
|
|
|
void setTimeout(int64_t delay_ms, IClient* client, void* context) override;
|
|
void cancel(IClient* client) override;
|
|
|
|
private:
|
|
struct Timer {
|
|
Timer(int64_t expiry_time, IClient* client, void* context)
|
|
: expiry_time_(expiry_time), client_(client), context_(context) {}
|
|
|
|
bool operator<(const Timer& other) const {
|
|
// We want to reverse the order so that the smallest expiry times go to
|
|
// the top of the priority queue.
|
|
return expiry_time_ > other.expiry_time_;
|
|
}
|
|
|
|
int64_t expiry_time() { return expiry_time_; }
|
|
IClient* client() { return client_; }
|
|
void* context() { return context_; }
|
|
|
|
private:
|
|
int64_t expiry_time_;
|
|
IClient* client_;
|
|
void* context_;
|
|
};
|
|
|
|
int64_t now_;
|
|
std::priority_queue<Timer> timers_;
|
|
|
|
std::string device_cert_;
|
|
bool save_device_cert_;
|
|
|
|
typedef std::map<std::string, std::string> StorageMap;
|
|
StorageMap files_;
|
|
};
|
|
|
|
// Owned and managed by the test runner.
|
|
extern TestHost* g_host;
|
|
|
|
#endif // WVCDM_CDM_TEST_TEST_HOST_H_
|