Bluetooth: use updated constants
[chromium-blink-merge.git] / chromeos / dbus / fake_bluetooth_profile_manager_client.cc
blob4c7e0a447b9de05bb774a84018e08388f03887f8
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"
7 #include <map>
8 #include <string>
10 #include "base/bind.h"
11 #include "base/logging.h"
12 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h"
13 #include "dbus/bus.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"
19 namespace chromeos {
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_profile_manager::kErrorInvalidArguments,
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_profile_manager::kErrorAlreadyExists,
50 "Profile already registered");
51 } else {
52 profile_map_[uuid] = profile_path;
53 callback.Run();
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_profile_manager::kErrorInvalidArguments,
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;
77 callback.Run();
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())
99 return NULL;
100 return service_provider_map_[iter->second];
103 } // namespace chromeos