Files
android/libwvdrmengine/cdm/metrics/include/value_metric.h
Rahul Frias 387147dffe Merges to android Pi release (part 2)
These are a set of CLs merged from the wv cdm repo to the android repo.

* Update service certificate.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/28065 ]

  The updated service certificate fixes a number of failing tests.
  There are still some that fail, apparently due to mismatches
  with key set IDs and usage tables.

  Also updated QA server URL to point to QA proxy (although neither
  can be used by this client).

  Also fixed segfault in CdmTest.ListUsageRecords.

* Add CDM APIs for Handling Service Certificates.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/28064 ]

  The responsibility for managing Service Certificates has been moved
  out of the CDM. Instead, provide CDM and CdmEngine methods to generate
  a service certificate request message, and handle a service certificate
  response. The API client can use these calls if it needs to get the
  service certificate from the License Server.

  These functions assume the request and response are base64 (web-safe)
  encoded (see b/37481392). Not all servers are operating this way yet.
  Any adaptations for non-compliant servers is handled outside the CDM.
  See test WvCdmEnginePreProvTest::ServiceCertificateRequestResponse in
  cdm_engine_test.cpp for an example of this.

  These changes also eliminate the stored init_data and deferred
  license type which were used to perform a service certificate request
  during a license request.

* Fix and rename ClosesSessionWithoutReturningError test.

  Author: Edwin Wong <edwinwong@google.com>

  [ Merge of http://go/wvgerrit/27880 ]

  ClosesSessionWithoutReturningError should not check for
  Status::OK since it is expecting an error code back.
  The test is renamed to ClosesSessionWithError.

  Test: libwvdrmdrmplugin_hidl_test

  BUG: 62205215

* Get rid of default service certificate.

  Author: Gene Morgan <gmorgan@google.com>

  [ Merge of http://go/wvgerrit/27981 ]

  Instead, we need at least two service certs - one for the QA/Test
  servers, and one for UAT (and prod?)

  There are still some issues around the signature verififcation
  of the service cert, and in license_unittest.cpp, the use
  of the default service cert has been commented out.  I don't know
  why this test needs a service cert.  If it really does, then the
  same mechanism that is used elsewhere for selecting a specific
  server type will be needed here.

BUG: 71650075
Test: Not currently passing. Will be addressed in a subsequent
      commit in the chain.

Change-Id: Ieab815fb202c809ad5714cd0364c4bdfa068f77d
2018-01-16 19:22:48 -08:00

107 lines
3.0 KiB
C++

// Copyright 2017 Google Inc. All Rights Reserved.
//
// This file contains the declarations for the Metric class and related
// types.
#ifndef WVCDM_METRICS_VALUE_METRIC_H_
#define WVCDM_METRICS_VALUE_METRIC_H_
#include <stdint.h>
#include <string>
#include "metric_serialization.h"
namespace wvcdm {
namespace metrics {
// Private namespace for some helper implementation functions.
namespace impl {
// These helper functions map the templated ValueMetric class
// Serialize call to the MetricSerializer explicit calls.
template<typename T>
void Serialize(MetricSerializer* serializer,
const std::string& metric_name, const T& t);
inline void SerializeError(MetricSerializer* serializer,
const std::string& metric_name,
const int& error_code) {
serializer->SetInt32(metric_name + "/error", error_code);
}
} // namespace impl
// The Metric class supports storing a single value which can be overwritten.
// the Metric class also supports the MetricSerializer interface through
// which the value can be serialized. If the value was never given a value
// or an error code, then the metric will not serialize anything.
//
// Example Usage:
// Metric<string> cdm_version("drm/cdm/version")
// .Record("a.b.c.d");
//
// MyMetricSerializerImpl serialzer;
// cdm_version.Serialize(&serializer);
//
// Example Error Usage:
//
// Metric<string> cdm_version("drm/cdm/version")
// .SetError(error_code);
//
// Note that serialization is the same. But the ValueMetric will serialize
// the error code to <metric_name>/error instead of just <metric_name>.
template<typename T>
class ValueMetric : public MetricSerializable {
public:
// Constructs a metric with the given metric name.
explicit ValueMetric(const std::string& metric_name)
: metric_name_(metric_name), error_code_(0),
has_error_(false), has_value_(false) {}
// Serialize the metric name and value using the given serializer.
// Caller owns |serializer| which cannot be null.
virtual void Serialize(MetricSerializer* serializer) {
if (has_value_) {
impl::Serialize(serializer, metric_name_, value_);
} else if (has_error_) {
impl::SerializeError(serializer, metric_name_, error_code_);
} else {
// Do nothing if there is no value and no error.
}
}
// Record the value of the metric.
void Record(const T& value) {
value_ = value;
has_value_ = true;
has_error_ = false;
}
// Set the error code if an error was encountered.
void SetError(int error_code) {
error_code_ = error_code;
has_value_ = false;
has_error_ = true;
}
// Get the current value of the metric.
const T& GetValue() { return value_; }
// Clears the indicators that the metric or error was set.
void Clear() {
has_value_ = false;
has_error_ = false;
}
private:
std::string metric_name_;
T value_;
int error_code_;
bool has_error_;
bool has_value_;
};
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_VALUE_METRIC_H_