104 lines
3.7 KiB
C++
104 lines
3.7 KiB
C++
// Copyright 2017 Google LLC. All rights reserved.
|
|
|
|
#ifndef VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_CPP_WVPL_LICENSE_SERVER_SDK_WVPL_LICENSE_COUNTER_H_
|
|
#define VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_CPP_WVPL_LICENSE_SERVER_SDK_WVPL_LICENSE_COUNTER_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include "absl/synchronization/mutex.h"
|
|
#include "sdk/external/cpp/wvpl/common/wvpl_types.h"
|
|
#include "protos/public/provisioned_device_info.pb.h"
|
|
#include "protos/public/sdk_stats.pb.h"
|
|
|
|
namespace video_widevine_server {
|
|
namespace wv_pl_sdk {
|
|
|
|
// Maintains and manages license status values organized by system Id, make and
|
|
// models. The class is thread safe.
|
|
class WvPLLicenseCounter {
|
|
public:
|
|
WvPLLicenseCounter();
|
|
virtual ~WvPLLicenseCounter();
|
|
|
|
// Handles the usage counting for the license status. Status values are
|
|
// counted based on make/model inforamtion contained in |device_info|.
|
|
WvPLStatus LogLicenseStatus(
|
|
const video_widevine::ProvisionedDeviceInfo& device_info,
|
|
const WvPLStatus& status);
|
|
|
|
// Copies usage data from internal buffers into the protobuf |counter_proto|.
|
|
// The internal data is flushed from memory if |flush_data| is true,
|
|
// otherwise usage data remains and will accumulate.
|
|
WvPLStatus FlushDataToProto(
|
|
bool flush_data,
|
|
video_widevine::DeviceLicenseCounterRequest* counter_proto);
|
|
|
|
// Setting |flag| to true will only count operations resulting in errors.
|
|
// Otherwise successes and errors are counted.
|
|
void set_limit_usage_stats_to_errors_only(const bool flag) {
|
|
limit_usage_stats_to_errors_only_ = flag;
|
|
}
|
|
|
|
bool limit_usage_stats_to_errors_only() const {
|
|
return limit_usage_stats_to_errors_only_;
|
|
}
|
|
|
|
private:
|
|
friend class WvPLLicenseCounterTest;
|
|
friend class WvPLSessionTest;
|
|
|
|
// Copies content from |system_id_counter_data| into the protobuf
|
|
// |system_id_counter_proto|.
|
|
WvPLStatus LogUsageSystemIdDataToProto(
|
|
const WvPLSystemIdCounterData& system_id_counter_data,
|
|
video_widevine::DeviceLicenseCounterBySystemId* system_id_counter_proto);
|
|
|
|
// Copies content from |make_counter_data| into the protobuf
|
|
// |make_counter_proto|.
|
|
WvPLStatus LogUsageDeviceMakeDataToProto(
|
|
const WvPLDeviceMakeCounterData& make_counter_data,
|
|
video_widevine::DeviceLicenseCounterByMake* make_counter_proto);
|
|
|
|
// Copies content from |model_counter_data| into the protobuf
|
|
// |model_counter_proto|.
|
|
WvPLStatus LogUsageDeviceModelDataToProto(
|
|
const WvPLDeviceModelCounterData& model_counter_data,
|
|
video_widevine::DeviceLicenseCounterByModel* model_counter_proto);
|
|
|
|
// Copies content from |status_counter_data| into the protobuf
|
|
// |status_counter_proto|.
|
|
WvPLStatus LogUsageLicenseStatusDataToProto(
|
|
const WvPLLicenseStatusCounterData& status_counter_data,
|
|
video_widevine::DeviceLicenseCounterByStatus* status_counter_proto);
|
|
|
|
const WvPLCounterData* counter_data() const {
|
|
absl::WriterMutexLock lock(const_cast<absl::Mutex*>(&counter_data_lock_));
|
|
return counter_data_.get();
|
|
}
|
|
|
|
virtual time_t start_time()
|
|
ABSL_EXCLUSIVE_LOCKS_REQUIRED(counter_data_lock_) {
|
|
return counter_data_->start_time_utc_;
|
|
}
|
|
|
|
virtual time_t end_time() ABSL_EXCLUSIVE_LOCKS_REQUIRED(counter_data_lock_) {
|
|
return counter_data_->end_time_utc_;
|
|
}
|
|
|
|
// Collect usage status only for errors.
|
|
bool limit_usage_stats_to_errors_only_;
|
|
|
|
video_widevine::DeviceLicenseCounterRequest counter_proto_;
|
|
absl::Mutex counter_data_lock_;
|
|
std::unique_ptr<WvPLCounterData> counter_data_
|
|
ABSL_GUARDED_BY(counter_data_lock_);
|
|
};
|
|
|
|
} // namespace wv_pl_sdk
|
|
} // namespace video_widevine_server
|
|
|
|
#endif // VIDEO_WIDEVINE_EXPORT_SDK_EXTERNAL_CPP_WVPL_LICENSE_SERVER_SDK_WVPL_LICENSE_COUNTER_H_
|