Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / fake_bluetooth_gatt_service_client.h
1 // Copyright 2014 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 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/bluetooth_gatt_service_client.h"
15 #include "dbus/object_path.h"
16 #include "dbus/property.h"
17
18 namespace chromeos {
19
20 // FakeBluetoothGattServiceClient simulates the behavior of the Bluetooth Daemon
21 // GATT service objects and is used in test cases in place of a mock and on the
22 // Linux desktop.
23 class CHROMEOS_EXPORT FakeBluetoothGattServiceClient
24     : public BluetoothGattServiceClient {
25  public:
26   struct Properties : public BluetoothGattServiceClient::Properties {
27     explicit Properties(const PropertyChangedCallback& callback);
28     virtual ~Properties();
29
30     // dbus::PropertySet override
31     virtual void Get(dbus::PropertyBase* property,
32                      dbus::PropertySet::GetCallback callback) OVERRIDE;
33     virtual void GetAll() OVERRIDE;
34     virtual void Set(dbus::PropertyBase* property,
35                      dbus::PropertySet::SetCallback callback) OVERRIDE;
36   };
37
38   FakeBluetoothGattServiceClient();
39   virtual ~FakeBluetoothGattServiceClient();
40
41   // DBusClient override.
42   virtual void Init(dbus::Bus* bus) OVERRIDE;
43
44   // BluetoothGattServiceClient overrides.
45   virtual void AddObserver(Observer* observer) OVERRIDE;
46   virtual void RemoveObserver(Observer* observer) OVERRIDE;
47   virtual std::vector<dbus::ObjectPath> GetServices() OVERRIDE;
48   virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
49       OVERRIDE;
50
51   // Makes a service visible for device with object path |device_path|. Note
52   // that only one instance of a specific service is simulated at a time. Hence,
53   // this method will fail, if the service is already visible.
54   void ExposeHeartRateService(const dbus::ObjectPath& device_path);
55   void HideHeartRateService();
56
57   // Final object path components and the corresponding UUIDs of the GATT
58   // services that we emulate. Service paths are hierarchical to Bluetooth
59   // device paths, so if the path component is "service0000", and the device
60   // path is "/org/foo/device0", the service path is
61   // "/org/foo/device0/service0000".
62   static const char kHeartRateServicePathComponent[];
63   static const char kHeartRateServiceUUID[];
64
65  private:
66   // Property callback passed when we create Properties structures.
67   void OnPropertyChanged(const dbus::ObjectPath& object_path,
68                          const std::string& property_name);
69
70   // Notifies observers.
71   void NotifyServiceAdded(const dbus::ObjectPath& object_path);
72   void NotifyServiceRemoved(const dbus::ObjectPath& object_path);
73
74   // Static properties we return. As long as a service is exposed, this will be
75   // non-null. Otherwise it will be null.
76   scoped_ptr<Properties> heart_rate_service_properties_;
77   std::string heart_rate_service_path_;
78
79   // List of observers interested in event notifications from us.
80   ObserverList<Observer> observers_;
81
82   DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattServiceClient);
83 };
84
85 }  // namespace chromeos
86
87 #endif  // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_