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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
10 #include "base/bind.h"
11 #include "base/logging.h"
12 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h"
14 #include "dbus/message.h"
15 #include "dbus/object_path.h"
16 #include "dbus/object_proxy.h"
17 #include "third_party/cros_system_api/dbus/service_constants.h"
21 const char FakeBluetoothProfileManagerClient::kL2capUuid
[] =
22 "4d995052-33cc-4fdf-b446-75f32942a076";
23 const char FakeBluetoothProfileManagerClient::kRfcommUuid
[] =
24 "3f6d6dbf-a6ad-45fc-9653-47dc912ef70e";
26 FakeBluetoothProfileManagerClient::FakeBluetoothProfileManagerClient() {
29 FakeBluetoothProfileManagerClient::~FakeBluetoothProfileManagerClient() {
32 void FakeBluetoothProfileManagerClient::RegisterProfile(
33 const dbus::ObjectPath
& profile_path
,
34 const std::string
& uuid
,
35 const Options
& options
,
36 const base::Closure
& callback
,
37 const ErrorCallback
& error_callback
) {
38 VLOG(1) << "RegisterProfile: " << profile_path
.value() << ": " << uuid
;
40 // check options for channel & psm
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");
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");
52 profile_map_
[uuid
] = profile_path
;
58 void FakeBluetoothProfileManagerClient::UnregisterProfile(
59 const dbus::ObjectPath
& profile_path
,
60 const base::Closure
& callback
,
61 const ErrorCallback
& error_callback
) {
62 VLOG(1) << "UnregisterProfile: " << profile_path
.value();
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");
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
);
81 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider(
82 FakeBluetoothProfileServiceProvider
* service_provider
) {
83 service_provider_map_
[service_provider
->object_path_
] = service_provider
;
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
);
94 FakeBluetoothProfileServiceProvider
*
95 FakeBluetoothProfileManagerClient::GetProfileServiceProvider(
96 const std::string
& uuid
) {
97 ProfileMap::iterator iter
= profile_map_
.find(uuid
);
98 if (iter
== profile_map_
.end())
100 return service_provider_map_
[iter
->second
];
103 } // namespace chromeos