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

Side by Side Diff: chromeos/dbus/fake_bluetooth_profile_manager_client.cc

Issue 14487002: Bluetooth: Profile support for Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unit tests, and class comments Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" 5 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
6 6
7 #include <map>
8 #include <string>
9
7 #include "base/bind.h" 10 #include "base/bind.h"
8 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h"
9 #include "dbus/bus.h" 13 #include "dbus/bus.h"
10 #include "dbus/message.h" 14 #include "dbus/message.h"
11 #include "dbus/object_path.h" 15 #include "dbus/object_path.h"
12 #include "dbus/object_proxy.h" 16 #include "dbus/object_proxy.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 17 #include "third_party/cros_system_api/dbus/service_constants.h"
14 18
15 namespace chromeos { 19 namespace chromeos {
16 20
21 const char FakeBluetoothProfileManagerClient::kL2capUuid[] =
22 "4d995052-33cc-4fdf-b446-75f32942a076";
23 const char FakeBluetoothProfileManagerClient::kRfcommUuid[] =
24 "3f6d6dbf-a6ad-45fc-9653-47dc912ef70e";
25
17 FakeBluetoothProfileManagerClient::FakeBluetoothProfileManagerClient() { 26 FakeBluetoothProfileManagerClient::FakeBluetoothProfileManagerClient() {
18 } 27 }
19 28
20 FakeBluetoothProfileManagerClient::~FakeBluetoothProfileManagerClient() { 29 FakeBluetoothProfileManagerClient::~FakeBluetoothProfileManagerClient() {
21 } 30 }
22 31
23 void FakeBluetoothProfileManagerClient::RegisterProfile( 32 void FakeBluetoothProfileManagerClient::RegisterProfile(
24 const dbus::ObjectPath& profile_path, 33 const dbus::ObjectPath& profile_path,
25 const std::string& uuid, 34 const std::string& uuid,
26 const Options& options, 35 const Options& options,
27 const base::Closure& callback, 36 const base::Closure& callback,
28 const ErrorCallback& error_callback) { 37 const ErrorCallback& error_callback) {
29 VLOG(1) << "RegisterProfile: " << profile_path.value() << ": " << uuid; 38 VLOG(1) << "RegisterProfile: " << profile_path.value() << ": " << uuid;
30 callback.Run(); 39
40 // check options for channel & psm
41
42 ServiceProviderMap::iterator iter = service_provider_map_.find(profile_path);
43 if (iter == service_provider_map_.end()) {
44 error_callback.Run(bluetooth_adapter::kErrorFailed,
45 "No profile created");
46 } else {
47 ProfileMap::iterator piter = profile_map_.find(uuid);
48 if (piter != profile_map_.end()) {
49 error_callback.Run(bluetooth_adapter::kErrorAlreadyExists,
50 "Profile already registered");
51 } else {
52 profile_map_[uuid] = profile_path;
53 callback.Run();
54 }
55 }
31 } 56 }
32 57
33 void FakeBluetoothProfileManagerClient::UnregisterProfile( 58 void FakeBluetoothProfileManagerClient::UnregisterProfile(
34 const dbus::ObjectPath& profile_path, 59 const dbus::ObjectPath& profile_path,
35 const base::Closure& callback, 60 const base::Closure& callback,
36 const ErrorCallback& error_callback) { 61 const ErrorCallback& error_callback) {
37 VLOG(1) << "UnregisterProfile: " << profile_path.value(); 62 VLOG(1) << "UnregisterProfile: " << profile_path.value();
38 callback.Run(); 63
64 ServiceProviderMap::iterator iter = service_provider_map_.find(profile_path);
65 if (iter != service_provider_map_.end()) {
66 error_callback.Run(bluetooth_adapter::kErrorFailed,
67 "Profile still registered");
68 } else {
69 for (ProfileMap::iterator piter = profile_map_.begin();
70 piter != profile_map_.end(); ++piter) {
71 if (piter->second == profile_path) {
72 profile_map_.erase(piter);
73 break;
74 }
75 }
76
77 callback.Run();
78 }
79 }
80
81 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider(
82 FakeBluetoothProfileServiceProvider* service_provider) {
83 service_provider_map_[service_provider->object_path_] = service_provider;
84 }
85
86 void FakeBluetoothProfileManagerClient::UnregisterProfileServiceProvider(
87 FakeBluetoothProfileServiceProvider* service_provider) {
88 ServiceProviderMap::iterator iter =
89 service_provider_map_.find(service_provider->object_path_);
90 if (iter != service_provider_map_.end() && iter->second == service_provider)
91 service_provider_map_.erase(iter);
92 }
93
94 FakeBluetoothProfileServiceProvider*
95 FakeBluetoothProfileManagerClient::GetProfileServiceProvider(
96 const std::string& uuid) {
97 ProfileMap::iterator iter = profile_map_.find(uuid);
98 if (iter == profile_map_.end())
99 return NULL;
100 return service_provider_map_[iter->second];
39 } 101 }
40 102
41 } // namespace chromeos 103 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_bluetooth_profile_manager_client.h ('k') | chromeos/dbus/fake_bluetooth_profile_service_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698