Chromium Code Reviews| Index: remoting/host/host_attributes.cc |
| diff --git a/remoting/host/host_attributes.cc b/remoting/host/host_attributes.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e15b364e3acf947894a5113f9550a1b8f77c1639 |
| --- /dev/null |
| +++ b/remoting/host/host_attributes.cc |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/host/host_attributes.h" |
| + |
| +#include <type_traits> |
| + |
| +#include "base/atomicops.h" |
| +#include "base/logging.h" |
| +#include "build/build_config.h" |
| +#if defined(OS_WIN) |
| +#include "remoting/host/host_attributes_win.h" |
| +#else |
| +#include "remoting/host/host_attributes_empty.h" |
| +#endif |
| + |
| +namespace remoting { |
| + |
| +namespace { |
| +static constexpr char kSeparator[] = ","; |
| +} // namespace |
| + |
| +static_assert(std::is_pod<DynamicAttribute>::value, |
| + "DynamicAttribute should be POD."); |
| +static_assert(std::is_pod<StaticAttribute>::value, |
| + "StaticAttribute should be POD."); |
| + |
| +const char* StaticAttribute::name() const { |
| + return attribute.name; |
| +} |
| + |
| +bool StaticAttribute::EvaluatedValue() { |
| + if (evaluated) { |
| + return value; |
| + } else { |
| + value = attribute.value(); |
| + base::subtle::MemoryBarrier(); |
| + evaluated = true; |
| + return value; |
| + } |
| +} |
| + |
| +std::string GetHostAttributes() { |
| + std::string result; |
| + // By using ranged for-loop, MSVC throws error C3316: |
| + // 'const remoting::StaticAttribute [0]': |
| + // an array of unknown size cannot be used in a range-based for statement. |
| + // |
| + // By using arraysize() macro in base/macros.h, it's illegal, |
| + // error: no matching function for call to 'ArraySizeHelper' |
| + // note: candidate template ignored: substitution failure |
| + // [with T = const remoting::StaticAttribute, N = 0]: |
| + // zero-length arrays are not permitted in C++. |
| + // |
| + // So a traditional sizeof is used here. |
| +#define SIZE_OF_ARRAY(x, y) static_cast<int>(sizeof(x) / sizeof(y)) |
|
Sergey Ulanov
2016/11/07 20:11:33
Add something in kDynamicAttributes and use arrays
Hzj_jie
2016/11/08 01:29:53
Done.
|
| + for (int i = 0; |
| + i < SIZE_OF_ARRAY(kStaticAttributes, StaticAttribute); |
| + i++) { |
| + auto& static_attribute = kStaticAttributes[i]; |
| + DCHECK(std::string(static_attribute.name()).find(kSeparator) == |
| + std::string::npos); |
| + if (static_attribute.EvaluatedValue()) { |
| + if (!result.empty()) { |
| + result.append(kSeparator); |
| + } |
| + result.append(static_attribute.name()); |
| + } |
| + } |
| + |
| + for (int i = 0; |
| + i < SIZE_OF_ARRAY(kDynamicAttributes, StaticAttribute); |
|
Sergey Ulanov
2016/11/07 20:11:33
type is wrong here. This macro could be implemente
Hzj_jie
2016/11/08 01:29:54
Done.
|
| + i++) { |
| + const auto& dynamic_attribute = kDynamicAttributes[i]; |
| + DCHECK(std::string(dynamic_attribute.name).find(kSeparator) == |
| + std::string::npos); |
| + if (dynamic_attribute.value()) { |
| + if (!result.empty()) { |
| + result.append(kSeparator); |
| + } |
| + result.append(dynamic_attribute.name); |
| + } |
| + } |
| +#undef SIZE_OF_ARRAY |
| + |
| + return result; |
| +} |
| + |
| +} // namespace remoting |