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::Init(dbus::Bus
* bus
) {
35 void FakeBluetoothProfileManagerClient::RegisterProfile(
36 const dbus::ObjectPath
& profile_path
,
37 const std::string
& uuid
,
38 const Options
& options
,
39 const base::Closure
& callback
,
40 const ErrorCallback
& error_callback
) {
41 VLOG(1) << "RegisterProfile: " << profile_path
.value() << ": " << uuid
;
43 // check options for channel & psm
45 ServiceProviderMap::iterator iter
= service_provider_map_
.find(profile_path
);
46 if (iter
== service_provider_map_
.end()) {
47 error_callback
.Run(bluetooth_profile_manager::kErrorInvalidArguments
,
48 "No profile created");
50 ProfileMap::iterator piter
= profile_map_
.find(uuid
);
51 if (piter
!= profile_map_
.end()) {
52 error_callback
.Run(bluetooth_profile_manager::kErrorAlreadyExists
,
53 "Profile already registered");
55 profile_map_
[uuid
] = profile_path
;
61 void FakeBluetoothProfileManagerClient::UnregisterProfile(
62 const dbus::ObjectPath
& profile_path
,
63 const base::Closure
& callback
,
64 const ErrorCallback
& error_callback
) {
65 VLOG(1) << "UnregisterProfile: " << profile_path
.value();
67 ServiceProviderMap::iterator iter
= service_provider_map_
.find(profile_path
);
68 if (iter
!= service_provider_map_
.end()) {
69 error_callback
.Run(bluetooth_profile_manager::kErrorInvalidArguments
,
70 "Profile still registered");
72 for (ProfileMap::iterator piter
= profile_map_
.begin();
73 piter
!= profile_map_
.end(); ++piter
) {
74 if (piter
->second
== profile_path
) {
75 profile_map_
.erase(piter
);
84 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider(
85 FakeBluetoothProfileServiceProvider
* service_provider
) {
86 service_provider_map_
[service_provider
->object_path_
] = service_provider
;
89 void FakeBluetoothProfileManagerClient::UnregisterProfileServiceProvider(
90 FakeBluetoothProfileServiceProvider
* service_provider
) {
91 ServiceProviderMap::iterator iter
=
92 service_provider_map_
.find(service_provider
->object_path_
);
93 if (iter
!= service_provider_map_
.end() && iter
->second
== service_provider
)
94 service_provider_map_
.erase(iter
);
97 FakeBluetoothProfileServiceProvider
*
98 FakeBluetoothProfileManagerClient::GetProfileServiceProvider(
99 const std::string
& uuid
) {
100 ProfileMap::iterator iter
= profile_map_
.find(uuid
);
101 if (iter
== profile_map_
.end())
103 return service_provider_map_
[iter
->second
];
106 } // namespace chromeos