1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h"
6 
7 #include <utility>
8 
9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h"
11 
12 namespace bluez {
13 
BluetoothServiceAttributeValueBlueZ()14 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ()
15     : type_(NULLTYPE), size_(0), value_(base::MakeUnique<base::Value>()) {}
16 
BluetoothServiceAttributeValueBlueZ(Type type,size_t size,std::unique_ptr<base::Value> value)17 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ(
18     Type type,
19     size_t size,
20     std::unique_ptr<base::Value> value)
21     : type_(type), size_(size), value_(std::move(value)) {
22   CHECK_NE(type, SEQUENCE);
23 }
24 
BluetoothServiceAttributeValueBlueZ(std::unique_ptr<Sequence> sequence)25 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ(
26     std::unique_ptr<Sequence> sequence)
27     : type_(SEQUENCE),
28       size_(sequence->size()),
29       sequence_(std::move(sequence)) {}
30 
BluetoothServiceAttributeValueBlueZ(const BluetoothServiceAttributeValueBlueZ & attribute)31 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ(
32     const BluetoothServiceAttributeValueBlueZ& attribute) {
33   *this = attribute;
34 }
35 
36 BluetoothServiceAttributeValueBlueZ& BluetoothServiceAttributeValueBlueZ::
operator =(const BluetoothServiceAttributeValueBlueZ & attribute)37 operator=(const BluetoothServiceAttributeValueBlueZ& attribute) {
38   if (this != &attribute) {
39     type_ = attribute.type_;
40     size_ = attribute.size_;
41     if (attribute.type_ == SEQUENCE) {
42       value_ = nullptr;
43       sequence_ = base::MakeUnique<Sequence>(*attribute.sequence_);
44     } else {
45       value_ = attribute.value_->CreateDeepCopy();
46       sequence_ = nullptr;
47     }
48   }
49   return *this;
50 }
51 
~BluetoothServiceAttributeValueBlueZ()52 BluetoothServiceAttributeValueBlueZ::~BluetoothServiceAttributeValueBlueZ() {}
53 
54 }  // namespace bluez
55