Index: device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc |
diff --git a/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc b/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2a6a71a7c97e0f7e6bbf3455f1a691dd7112bbd5 |
--- /dev/null |
+++ b/device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc |
@@ -0,0 +1,60 @@ |
+// 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 "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" |
+ |
+#include <vector> |
+ |
+#include "base/values.h" |
+ |
+namespace bluez { |
+ |
+BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( |
+ Type type, |
+ size_t size, |
+ base::Value* value) |
+ : type_(type), size_(size) { |
+ CHECK_NE(type, SEQUENCE); |
+ value_.value = value; |
+} |
+ |
+BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( |
+ Type type, |
+ size_t size, |
+ Sequence* sequence) |
+ : type_(type), size_(size) { |
+ CHECK_EQ(type, SEQUENCE); |
xiyuan
2016/06/22 15:53:05
Since SEQUENCE is the only allowed type, why not o
rkc
2016/06/22 21:06:36
Makes sense.
Done.
|
+ CHECK_EQ(sequence->size(), size); |
xiyuan
2016/06/22 15:53:05
Same here. It seems we can init |size_| with seque
rkc
2016/06/22 21:06:36
Done.
|
+ this->value_.sequence = sequence; |
+} |
+ |
+BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( |
+ const BluetoothServiceAttributeValueBlueZ& attribute) { |
+ this->type_ = attribute.type_; |
+ this->size_ = attribute.size_; |
+ |
+ if (attribute.type_ != SEQUENCE) { |
+ this->value_.value = attribute.value_.value->DeepCopy(); |
+ return; |
+ } |
+ |
+ this->value_.sequence = |
+ new std::vector<BluetoothServiceAttributeValueBlueZ>(); |
+ for (const auto& v : *attribute.value_.sequence) |
xiyuan
2016/06/22 15:53:05
Can we do:
this->value_.sequence = new std::vec
rkc
2016/06/22 21:06:36
Done.
|
+ this->value_.sequence->push_back(v); |
+} |
+ |
+BluetoothServiceAttributeValueBlueZ::~BluetoothServiceAttributeValueBlueZ() { |
+ // value_ is a union of two pointers, so we can check either. |
+ if (!value_.value) |
+ return; |
+ |
+ if (type_ == SEQUENCE) { |
+ delete value_.sequence; |
+ } else { |
+ delete value_.value; |
+ } |
+} |
+ |
+} // namespace bluez |