OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/bluetooth_profile_manager_client.h" | 5 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "dbus/bus.h" | 9 #include "dbus/bus.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
11 #include "dbus/object_path.h" | 11 #include "dbus/object_path.h" |
12 #include "dbus/object_proxy.h" | 12 #include "dbus/object_proxy.h" |
13 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
14 | 14 |
15 namespace chromeos { | 15 namespace chromeos { |
16 | 16 |
17 const char BluetoothProfileManagerClient::kNoResponseError[] = | 17 const char BluetoothProfileManagerClient::kNoResponseError[] = |
18 "org.chromium.Error.NoResponse"; | 18 "org.chromium.Error.NoResponse"; |
19 | 19 |
20 | 20 |
21 BluetoothProfileManagerClient::Options::Options() | 21 BluetoothProfileManagerClient::Options::Options() { |
22 : role(SYMMETRIC), | |
23 require_authentication(false), | |
24 require_authorization(false), | |
25 auto_connect(true) { | |
26 } | 22 } |
27 | 23 |
28 BluetoothProfileManagerClient::Options::~Options() { | 24 BluetoothProfileManagerClient::Options::~Options() { |
29 } | 25 } |
30 | 26 |
31 // The BluetoothProfileManagerClient implementation used in production. | 27 // The BluetoothProfileManagerClient implementation used in production. |
32 class BluetoothProfileManagerClientImpl | 28 class BluetoothProfileManagerClientImpl |
33 : public BluetoothProfileManagerClient { | 29 : public BluetoothProfileManagerClient { |
34 public: | 30 public: |
35 BluetoothProfileManagerClientImpl() : weak_ptr_factory_(this) {} | 31 BluetoothProfileManagerClientImpl() : weak_ptr_factory_(this) {} |
(...skipping 13 matching lines...) Expand all Loading... |
49 | 45 |
50 dbus::MessageWriter writer(&method_call); | 46 dbus::MessageWriter writer(&method_call); |
51 writer.AppendObjectPath(profile_path); | 47 writer.AppendObjectPath(profile_path); |
52 writer.AppendString(uuid); | 48 writer.AppendString(uuid); |
53 | 49 |
54 dbus::MessageWriter array_writer(NULL); | 50 dbus::MessageWriter array_writer(NULL); |
55 writer.OpenArray("{sv}", &array_writer); | 51 writer.OpenArray("{sv}", &array_writer); |
56 | 52 |
57 dbus::MessageWriter dict_writer(NULL); | 53 dbus::MessageWriter dict_writer(NULL); |
58 | 54 |
59 // Always send Name, even if empty string. | 55 // Send Name if provided. |
60 array_writer.OpenDictEntry(&dict_writer); | 56 if (options.name.get() != NULL) { |
61 dict_writer.AppendString(bluetooth_profile_manager::kNameOption); | 57 array_writer.OpenDictEntry(&dict_writer); |
62 dict_writer.AppendVariantOfString(options.name); | 58 dict_writer.AppendString(bluetooth_profile_manager::kNameOption); |
63 array_writer.CloseContainer(&dict_writer); | 59 dict_writer.AppendVariantOfString(*(options.name)); |
| 60 array_writer.CloseContainer(&dict_writer); |
| 61 } |
64 | 62 |
65 // Don't send Service if not provided. | 63 // Send Service if provided. |
66 if (options.service.length()) { | 64 if (options.service.get() != NULL) { |
67 dbus::MessageWriter dict_writer(NULL); | 65 dbus::MessageWriter dict_writer(NULL); |
68 array_writer.OpenDictEntry(&dict_writer); | 66 array_writer.OpenDictEntry(&dict_writer); |
69 dict_writer.AppendString(bluetooth_profile_manager::kServiceOption); | 67 dict_writer.AppendString(bluetooth_profile_manager::kServiceOption); |
70 dict_writer.AppendVariantOfString(options.service); | 68 dict_writer.AppendVariantOfString(*(options.service)); |
71 array_writer.CloseContainer(&dict_writer); | 69 array_writer.CloseContainer(&dict_writer); |
72 } | 70 } |
73 | 71 |
74 // Don't send the default Role since there's no value for it. | 72 // Send Role if not the default value. |
75 if (options.role != SYMMETRIC) { | 73 if (options.role != SYMMETRIC) { |
76 dbus::MessageWriter dict_writer(NULL); | 74 dbus::MessageWriter dict_writer(NULL); |
77 array_writer.OpenDictEntry(&dict_writer); | 75 array_writer.OpenDictEntry(&dict_writer); |
78 dict_writer.AppendString(bluetooth_profile_manager::kRoleOption); | 76 dict_writer.AppendString(bluetooth_profile_manager::kRoleOption); |
79 if (options.role == CLIENT) | 77 if (options.role == CLIENT) |
80 dict_writer.AppendVariantOfString( | 78 dict_writer.AppendVariantOfString( |
81 bluetooth_profile_manager::kClientRoleOption); | 79 bluetooth_profile_manager::kClientRoleOption); |
82 else if (options.role == SERVER) | 80 else if (options.role == SERVER) |
83 dict_writer.AppendVariantOfString( | 81 dict_writer.AppendVariantOfString( |
84 bluetooth_profile_manager::kServerRoleOption); | 82 bluetooth_profile_manager::kServerRoleOption); |
85 else | 83 else |
86 dict_writer.AppendVariantOfString(""); | 84 dict_writer.AppendVariantOfString(""); |
87 array_writer.CloseContainer(&dict_writer); | 85 array_writer.CloseContainer(&dict_writer); |
88 } | 86 } |
89 | 87 |
90 // Don't send Channel unless given. | 88 // Send Channel if provided. |
91 if (options.channel) { | 89 if (options.channel.get() != NULL) { |
92 dbus::MessageWriter dict_writer(NULL); | 90 dbus::MessageWriter dict_writer(NULL); |
93 array_writer.OpenDictEntry(&dict_writer); | 91 array_writer.OpenDictEntry(&dict_writer); |
94 dict_writer.AppendString(bluetooth_profile_manager::kChannelOption); | 92 dict_writer.AppendString(bluetooth_profile_manager::kChannelOption); |
95 dict_writer.AppendVariantOfUint16(options.channel); | 93 dict_writer.AppendVariantOfUint16(*(options.channel)); |
96 array_writer.CloseContainer(&dict_writer); | 94 array_writer.CloseContainer(&dict_writer); |
97 } | 95 } |
98 | 96 |
99 // Don't send PSM unless given. | 97 // Send PSM if provided. |
100 if (options.psm) { | 98 if (options.psm.get() != NULL) { |
101 dbus::MessageWriter dict_writer(NULL); | 99 dbus::MessageWriter dict_writer(NULL); |
102 array_writer.OpenDictEntry(&dict_writer); | 100 array_writer.OpenDictEntry(&dict_writer); |
103 dict_writer.AppendString(bluetooth_profile_manager::kPSMOption); | 101 dict_writer.AppendString(bluetooth_profile_manager::kPSMOption); |
104 dict_writer.AppendVariantOfUint16(options.psm); | 102 dict_writer.AppendVariantOfUint16(*(options.psm)); |
105 array_writer.CloseContainer(&dict_writer); | 103 array_writer.CloseContainer(&dict_writer); |
106 } | 104 } |
107 | 105 |
108 // Always send RequireAuthentication, RequireAuthorization and AutoConnect. | 106 // Send RequireAuthentication if provided. |
109 array_writer.OpenDictEntry(&dict_writer); | 107 if (options.require_authentication.get() != NULL) { |
110 dict_writer.AppendString( | 108 array_writer.OpenDictEntry(&dict_writer); |
111 bluetooth_profile_manager::kRequireAuthenticationOption); | 109 dict_writer.AppendString( |
112 dict_writer.AppendVariantOfBool(options.require_authentication); | 110 bluetooth_profile_manager::kRequireAuthenticationOption); |
113 array_writer.CloseContainer(&dict_writer); | 111 dict_writer.AppendVariantOfBool(*(options.require_authentication)); |
| 112 array_writer.CloseContainer(&dict_writer); |
| 113 } |
114 | 114 |
115 array_writer.OpenDictEntry(&dict_writer); | 115 // Send RequireAuthorization if provided. |
116 dict_writer.AppendString( | 116 if (options.require_authorization.get() != NULL) { |
117 bluetooth_profile_manager::kRequireAuthorizationOption); | 117 array_writer.OpenDictEntry(&dict_writer); |
118 dict_writer.AppendVariantOfBool(options.require_authorization); | 118 dict_writer.AppendString( |
119 array_writer.CloseContainer(&dict_writer); | 119 bluetooth_profile_manager::kRequireAuthorizationOption); |
| 120 dict_writer.AppendVariantOfBool(*(options.require_authorization)); |
| 121 array_writer.CloseContainer(&dict_writer); |
| 122 } |
120 | 123 |
121 array_writer.OpenDictEntry(&dict_writer); | 124 // Send AutoConnect if provided. |
122 dict_writer.AppendString( | 125 if (options.auto_connect.get() != NULL) { |
123 bluetooth_profile_manager::kAutoConnectOption); | 126 array_writer.OpenDictEntry(&dict_writer); |
124 dict_writer.AppendVariantOfBool(options.auto_connect); | 127 dict_writer.AppendString( |
125 array_writer.CloseContainer(&dict_writer); | 128 bluetooth_profile_manager::kAutoConnectOption); |
| 129 dict_writer.AppendVariantOfBool(*(options.auto_connect)); |
| 130 array_writer.CloseContainer(&dict_writer); |
| 131 } |
126 | 132 |
127 // Don't send ServiceRecord if not provided. | 133 // Send ServiceRecord if provided. |
128 if (options.service_record.length()) { | 134 if (options.service_record.get() != NULL) { |
129 dbus::MessageWriter dict_writer(NULL); | 135 dbus::MessageWriter dict_writer(NULL); |
130 array_writer.OpenDictEntry(&dict_writer); | 136 array_writer.OpenDictEntry(&dict_writer); |
131 dict_writer.AppendString(bluetooth_profile_manager::kServiceRecordOption); | 137 dict_writer.AppendString(bluetooth_profile_manager::kServiceRecordOption); |
132 dict_writer.AppendVariantOfString(options.service_record); | 138 dict_writer.AppendVariantOfString(*(options.service_record)); |
133 array_writer.CloseContainer(&dict_writer); | 139 array_writer.CloseContainer(&dict_writer); |
134 } | 140 } |
135 | 141 |
136 // Don't send Version if not provided. | 142 // Send Version if provided. |
137 if (options.version) { | 143 if (options.version.get() != NULL) { |
138 dbus::MessageWriter dict_writer(NULL); | 144 dbus::MessageWriter dict_writer(NULL); |
139 array_writer.OpenDictEntry(&dict_writer); | 145 array_writer.OpenDictEntry(&dict_writer); |
140 dict_writer.AppendString(bluetooth_profile_manager::kVersionOption); | 146 dict_writer.AppendString(bluetooth_profile_manager::kVersionOption); |
141 dict_writer.AppendVariantOfUint16(options.version); | 147 dict_writer.AppendVariantOfUint16(*(options.version)); |
142 array_writer.CloseContainer(&dict_writer); | 148 array_writer.CloseContainer(&dict_writer); |
143 } | 149 } |
144 | 150 |
145 // Don't send Features if not provided. | 151 // Send Features if provided. |
146 if (options.features) { | 152 if (options.features.get() != NULL) { |
147 dbus::MessageWriter dict_writer(NULL); | 153 dbus::MessageWriter dict_writer(NULL); |
148 array_writer.OpenDictEntry(&dict_writer); | 154 array_writer.OpenDictEntry(&dict_writer); |
149 dict_writer.AppendString(bluetooth_profile_manager::kFeaturesOption); | 155 dict_writer.AppendString(bluetooth_profile_manager::kFeaturesOption); |
150 dict_writer.AppendVariantOfUint16(options.features); | 156 dict_writer.AppendVariantOfUint16(*(options.features)); |
151 array_writer.CloseContainer(&dict_writer); | 157 array_writer.CloseContainer(&dict_writer); |
152 } | 158 } |
153 | 159 |
154 writer.CloseContainer(&array_writer); | 160 writer.CloseContainer(&array_writer); |
155 | 161 |
156 object_proxy_->CallMethodWithErrorCallback( | 162 object_proxy_->CallMethodWithErrorCallback( |
157 &method_call, | 163 &method_call, |
158 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 164 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
159 base::Bind(&BluetoothProfileManagerClientImpl::OnSuccess, | 165 base::Bind(&BluetoothProfileManagerClientImpl::OnSuccess, |
160 weak_ptr_factory_.GetWeakPtr(), callback), | 166 weak_ptr_factory_.GetWeakPtr(), callback), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 237 } |
232 | 238 |
233 BluetoothProfileManagerClient::~BluetoothProfileManagerClient() { | 239 BluetoothProfileManagerClient::~BluetoothProfileManagerClient() { |
234 } | 240 } |
235 | 241 |
236 BluetoothProfileManagerClient* BluetoothProfileManagerClient::Create() { | 242 BluetoothProfileManagerClient* BluetoothProfileManagerClient::Create() { |
237 return new BluetoothProfileManagerClientImpl(); | 243 return new BluetoothProfileManagerClientImpl(); |
238 } | 244 } |
239 | 245 |
240 } // namespace chromeos | 246 } // namespace chromeos |
OLD | NEW |