summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/test/mock_bluetooth_gatt_notify_session.cc
blob: e4123f67741db1a75d06e85469e36288f1613452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2014 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/test/mock_bluetooth_gatt_notify_session.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"

using testing::Return;

namespace device {

MockBluetoothGattNotifySession::MockBluetoothGattNotifySession(
    const std::string& characteristic_identifier) {
  ON_CALL(*this, GetCharacteristicIdentifier())
      .WillByDefault(Return(characteristic_identifier));
  ON_CALL(*this, IsActive()).WillByDefault(Return(true));
}

MockBluetoothGattNotifySession::~MockBluetoothGattNotifySession() {
}

void MockBluetoothGattNotifySession::StartTestNotifications(
    MockBluetoothAdapter* adapter,
    MockBluetoothGattCharacteristic* characteristic,
    const std::vector<uint8_t>& value) {
  test_notifications_timer_.Start(
      FROM_HERE, base::TimeDelta::FromMilliseconds(10),
      base::Bind(&MockBluetoothGattNotifySession::DoNotify,
                 // base::Timer guarantees it won't call back after its
                 // destructor starts.
                 base::Unretained(this), base::Unretained(adapter),
                 characteristic, value));
}

void MockBluetoothGattNotifySession::StopTestNotifications() {
  test_notifications_timer_.Stop();
}

void MockBluetoothGattNotifySession::DoNotify(
    MockBluetoothAdapter* adapter,
    MockBluetoothGattCharacteristic* characteristic,
    const std::vector<uint8_t>& value) {
  FOR_EACH_OBSERVER(
      BluetoothAdapter::Observer, adapter->GetObservers(),
      GattCharacteristicValueChanged(adapter, characteristic, value));
}

}  // namespace device