Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: chromeos/dbus/fake_bluetooth_media_transport_client.h

Issue 993273002: device/bluetooth: Add I/O watcher for audio data retrieval triggered by state change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added AcquireDelegate function and refactored Acquire/TryAcquire. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_MEDIA_TRANSPORT_CLIENT_H_ 5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_MEDIA_TRANSPORT_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_MEDIA_TRANSPORT_CLIENT_H_ 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_MEDIA_TRANSPORT_CLIENT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/files/file.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "chromeos/chromeos_export.h" 15 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/bluetooth_media_transport_client.h" 16 #include "chromeos/dbus/bluetooth_media_transport_client.h"
16 #include "dbus/object_path.h" 17 #include "dbus/object_path.h"
17 18
18 namespace chromeos { 19 namespace chromeos {
19 20
20 class FakeBluetoothMediaEndpointServiceProvider; 21 class FakeBluetoothMediaEndpointServiceProvider;
21 22
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // otherwise. 70 // otherwise.
70 void SetValid(FakeBluetoothMediaEndpointServiceProvider* endpoint, 71 void SetValid(FakeBluetoothMediaEndpointServiceProvider* endpoint,
71 bool valid); 72 bool valid);
72 73
73 // Set state/volume property to a certain value. 74 // Set state/volume property to a certain value.
74 void SetState(const dbus::ObjectPath& endpoint_path, 75 void SetState(const dbus::ObjectPath& endpoint_path,
75 const std::string& state); 76 const std::string& state);
76 void SetVolume(const dbus::ObjectPath& endpoint_path, 77 void SetVolume(const dbus::ObjectPath& endpoint_path,
77 const uint16_t& volume); 78 const uint16_t& volume);
78 79
79 // Gets the transport path associated with the given endpoint path. 80 // Writes bytes to the input file descriptor, |input_fd|, associated with a
81 // transport object which is bound to |endpoint_path|.
82 void WriteData(const dbus::ObjectPath& endpoint_path,
83 const std::vector<char>& bytes);
84
85 // Retrieves the transport object path bound to |endpoint_path|.
80 dbus::ObjectPath GetTransportPath(const dbus::ObjectPath& endpoint_path); 86 dbus::ObjectPath GetTransportPath(const dbus::ObjectPath& endpoint_path);
81 87
82 // Gets the endpoint path associated with the given transport_path.
83 dbus::ObjectPath GetEndpointPath(const dbus::ObjectPath& transport_path);
84
85 private: 88 private:
86 // This class is used for simulating the scenario where each media endpoint 89 // This class is used for simulating the scenario where each media endpoint
87 // has a corresponding transport path and properties. Once an endpoint is 90 // has a corresponding transport path and properties. Once an endpoint is
88 // assigned with a transport path, an object of Transport is created. 91 // assigned with a transport path, an object of Transport is created.
89 class Transport { 92 struct Transport {
90 public:
91 Transport(const dbus::ObjectPath& transport_path, 93 Transport(const dbus::ObjectPath& transport_path,
92 Properties* transport_properties); 94 Properties* transport_properties);
93 ~Transport(); 95 ~Transport();
94 96
95 // An unique transport path. 97 // An unique transport path.
96 dbus::ObjectPath path; 98 dbus::ObjectPath path;
97 99
98 // The property set bound with |path|. 100 // The property set bound with |path|.
99 scoped_ptr<Properties> properties; 101 scoped_ptr<Properties> properties;
102
103 // This is the internal end of socketpair created for simulation purposes.
104 // |input_fd| will be initialized when Acquire/TryAcquire is called.
105 scoped_ptr<base::File> input_fd;
100 }; 106 };
101 107
102 // Property callback passed while a Properties structure is created. 108 // Property callback passed while a Properties structure is created.
103 void OnPropertyChanged(const std::string& property_name); 109 void OnPropertyChanged(const std::string& property_name);
104 110
111 // Gets the endpoint path associated with the given transport_path.
112 dbus::ObjectPath GetEndpointPath(const dbus::ObjectPath& transport_path);
113
114 // Retrieves the transport structure bound to |endpoint_path|.
115 Transport* GetTransport(const dbus::ObjectPath& endpoint_path);
116
117 // Retrieves the transport structure with |transport_path|.
118 Transport* GetTransportByPath(const dbus::ObjectPath& transport_path);
119
120 // Helper function used by Acquire and TryAcquire to set up the sockpair and
121 // invoke callback/error_callback.
122 void AcquireDelegate(bool try_flag,
armansito 2015/03/13 01:31:42 I'd rename this to AcquireInternal to be more cons
Miao 2015/03/13 19:20:59 Done.
123 const dbus::ObjectPath& object_path,
124 const AcquireCallback& callback,
125 const ErrorCallback& error_callback);
126
105 // Map of endpoints with valid transport. Each pair is composed of an endpoint 127 // Map of endpoints with valid transport. Each pair is composed of an endpoint
106 // path and a Transport structure containing a transport path and its 128 // path and a Transport structure containing a transport path and its
107 // properties. 129 // properties.
108 std::map<dbus::ObjectPath, Transport*> endpoint_to_transport_map_; 130 std::map<dbus::ObjectPath, Transport*> endpoint_to_transport_map_;
109 131
110 // Map of valid transports. Each pair is composed of a transport path as the 132 // Map of valid transports. Each pair is composed of a transport path as the
111 // key and an endpoint path as the value. This map is used to get the 133 // key and an endpoint path as the value. This map is used to get the
112 // corresponding endpoint path when GetProperties() is called. 134 // corresponding endpoint path when GetProperties() is called.
113 std::map<dbus::ObjectPath, dbus::ObjectPath> transport_to_endpoint_map_; 135 std::map<dbus::ObjectPath, dbus::ObjectPath> transport_to_endpoint_map_;
114 136
115 // The path of the media transport object.
116 dbus::ObjectPath object_path_;
117
118 ObserverList<BluetoothMediaTransportClient::Observer> observers_; 137 ObserverList<BluetoothMediaTransportClient::Observer> observers_;
119 138
120 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothMediaTransportClient); 139 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothMediaTransportClient);
121 }; 140 };
122 141
123 } // namespace chromeos 142 } // namespace chromeos
124 143
125 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_MEDIA_TRANSPORT_CLIENT_H_ 144 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_MEDIA_TRANSPORT_CLIENT_H_
OLDNEW
« no previous file with comments | « chromeos/dbus/bluetooth_media_transport_client.cc ('k') | chromeos/dbus/fake_bluetooth_media_transport_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698