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"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h"
12 #include "dbus/message.h"
13 #include "dbus/object_proxy.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h"
18 const char FakeBluetoothProfileManagerClient::kL2capUuid
[] =
19 "4d995052-33cc-4fdf-b446-75f32942a076";
20 const char FakeBluetoothProfileManagerClient::kRfcommUuid
[] =
21 "3f6d6dbf-a6ad-45fc-9653-47dc912ef70e";
22 const char FakeBluetoothProfileManagerClient::kUnregisterableUuid
[] =
23 "00000000-0000-0000-0000-000000000000";
25 FakeBluetoothProfileManagerClient::FakeBluetoothProfileManagerClient() {
28 FakeBluetoothProfileManagerClient::~FakeBluetoothProfileManagerClient() {
31 void FakeBluetoothProfileManagerClient::Init(dbus::Bus
* bus
) {
34 void FakeBluetoothProfileManagerClient::RegisterProfile(
35 const dbus::ObjectPath
& profile_path
,
36 const std::string
& uuid
,
37 const Options
& options
,
38 const base::Closure
& callback
,
39 const ErrorCallback
& error_callback
) {
40 VLOG(1) << "RegisterProfile: " << profile_path
.value() << ": " << uuid
;
42 if (uuid
== kUnregisterableUuid
) {
43 base::MessageLoop::current()->PostTask(
44 FROM_HERE
, base::Bind(error_callback
,
45 bluetooth_profile_manager::kErrorInvalidArguments
,
46 "Can't register this UUID"));
50 // check options for channel & psm
52 ServiceProviderMap::iterator iter
= service_provider_map_
.find(profile_path
);
53 if (iter
== service_provider_map_
.end()) {
54 error_callback
.Run(bluetooth_profile_manager::kErrorInvalidArguments
,
55 "No profile created");
57 ProfileMap::iterator piter
= profile_map_
.find(uuid
);
58 if (piter
!= profile_map_
.end()) {
59 error_callback
.Run(bluetooth_profile_manager::kErrorAlreadyExists
,
60 "Profile already registered");
62 profile_map_
[uuid
] = profile_path
;
63 base::MessageLoop::current()->PostTask(FROM_HERE
, callback
);
68 void FakeBluetoothProfileManagerClient::UnregisterProfile(
69 const dbus::ObjectPath
& profile_path
,
70 const base::Closure
& callback
,
71 const ErrorCallback
& error_callback
) {
72 VLOG(1) << "UnregisterProfile: " << profile_path
.value();
74 ServiceProviderMap::iterator iter
= service_provider_map_
.find(profile_path
);
75 if (iter
== service_provider_map_
.end()) {
76 error_callback
.Run(bluetooth_profile_manager::kErrorInvalidArguments
,
77 "Profile not registered");
79 for (ProfileMap::iterator piter
= profile_map_
.begin();
80 piter
!= profile_map_
.end(); ++piter
) {
81 if (piter
->second
== profile_path
) {
82 profile_map_
.erase(piter
);
87 base::MessageLoop::current()->PostTask(FROM_HERE
, callback
);
91 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider(
92 FakeBluetoothProfileServiceProvider
* service_provider
) {
93 service_provider_map_
[service_provider
->object_path_
] = service_provider
;
96 void FakeBluetoothProfileManagerClient::UnregisterProfileServiceProvider(
97 FakeBluetoothProfileServiceProvider
* service_provider
) {
98 ServiceProviderMap::iterator iter
=
99 service_provider_map_
.find(service_provider
->object_path_
);
100 if (iter
!= service_provider_map_
.end() && iter
->second
== service_provider
)
101 service_provider_map_
.erase(iter
);
104 FakeBluetoothProfileServiceProvider
*
105 FakeBluetoothProfileManagerClient::GetProfileServiceProvider(
106 const std::string
& uuid
) {
107 ProfileMap::iterator iter
= profile_map_
.find(uuid
);
108 if (iter
== profile_map_
.end())
110 return service_provider_map_
[iter
->second
];
113 } // namespace chromeos