OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shill_third_party_vpn_driver_client.h" | 5 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/stl_util.h" | |
10 #include "chromeos/dbus/shill_third_party_vpn_observer.h" | 12 #include "chromeos/dbus/shill_third_party_vpn_observer.h" |
11 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
12 #include "dbus/message.h" | 14 #include "dbus/message.h" |
13 #include "dbus/object_proxy.h" | 15 #include "dbus/object_proxy.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 17 |
16 namespace chromeos { | 18 namespace chromeos { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
(...skipping 29 matching lines...) Expand all Loading... | |
49 const ShillClientHelper::ErrorCallback& error_callback) override; | 51 const ShillClientHelper::ErrorCallback& error_callback) override; |
50 | 52 |
51 void UpdateConnectionState( | 53 void UpdateConnectionState( |
52 const std::string& object_path_value, | 54 const std::string& object_path_value, |
53 const uint32_t connection_state, | 55 const uint32_t connection_state, |
54 const base::Closure& callback, | 56 const base::Closure& callback, |
55 const ShillClientHelper::ErrorCallback& error_callback) override; | 57 const ShillClientHelper::ErrorCallback& error_callback) override; |
56 | 58 |
57 void SendPacket( | 59 void SendPacket( |
58 const std::string& object_path_value, | 60 const std::string& object_path_value, |
59 const std::string& ip_packet, | 61 const std::vector<char>& ip_packet, |
60 const base::Closure& callback, | 62 const base::Closure& callback, |
61 const ShillClientHelper::ErrorCallback& error_callback) override; | 63 const ShillClientHelper::ErrorCallback& error_callback) override; |
62 | 64 |
63 protected: | 65 protected: |
64 void Init(dbus::Bus* bus) override { bus_ = bus; } | 66 void Init(dbus::Bus* bus) override { bus_ = bus; } |
65 | 67 |
66 ShillThirdPartyVpnDriverClient::TestInterface* GetTestInterface() override { | 68 ShillThirdPartyVpnDriverClient::TestInterface* GetTestInterface() override { |
67 return nullptr; | 69 return nullptr; |
68 } | 70 } |
69 | 71 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface, | 240 dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface, |
239 shill::kUpdateConnectionStateFunction); | 241 shill::kUpdateConnectionStateFunction); |
240 dbus::MessageWriter writer(&method_call); | 242 dbus::MessageWriter writer(&method_call); |
241 writer.AppendUint32(connection_state); | 243 writer.AppendUint32(connection_state); |
242 GetHelper(object_path_value) | 244 GetHelper(object_path_value) |
243 ->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); | 245 ->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); |
244 } | 246 } |
245 | 247 |
246 void ShillThirdPartyVpnDriverClientImpl::SendPacket( | 248 void ShillThirdPartyVpnDriverClientImpl::SendPacket( |
247 const std::string& object_path_value, | 249 const std::string& object_path_value, |
248 const std::string& ip_packet, | 250 const std::vector<char>& ip_packet, |
249 const base::Closure& callback, | 251 const base::Closure& callback, |
250 const ShillClientHelper::ErrorCallback& error_callback) { | 252 const ShillClientHelper::ErrorCallback& error_callback) { |
251 dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface, | 253 dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface, |
252 shill::kSendPacketFunction); | 254 shill::kSendPacketFunction); |
253 dbus::MessageWriter writer(&method_call); | 255 dbus::MessageWriter writer(&method_call); |
254 writer.AppendArrayOfBytes(reinterpret_cast<const uint8_t*>(ip_packet.data()), | 256 static_assert(sizeof(uint8_t) == sizeof(char), |
255 ip_packet.size()); | 257 "Can't reinterpret ip_packet if char is not a byte."); |
bartfab (slow)
2015/01/19 17:57:17
Nit: char is always a byte. But a byte is not nece
pneubeck (no reviews)
2015/01/19 18:04:28
Done.
| |
258 writer.AppendArrayOfBytes( | |
259 reinterpret_cast<const uint8_t*>(vector_as_array(&ip_packet)), | |
260 ip_packet.size()); | |
256 GetHelper(object_path_value) | 261 GetHelper(object_path_value) |
257 ->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); | 262 ->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); |
258 } | 263 } |
259 | 264 |
260 // static | 265 // static |
261 void ShillThirdPartyVpnDriverClientImpl::OnPacketReceived( | 266 void ShillThirdPartyVpnDriverClientImpl::OnPacketReceived( |
262 base::WeakPtr<HelperInfo> helper_info, | 267 base::WeakPtr<HelperInfo> helper_info, |
263 dbus::Signal* signal) { | 268 dbus::Signal* signal) { |
264 if (!helper_info || !helper_info->observer()) | 269 if (!helper_info || !helper_info->observer()) |
265 return; | 270 return; |
266 | 271 |
267 dbus::MessageReader reader(signal); | 272 dbus::MessageReader reader(signal); |
268 const uint8_t* data = nullptr; | 273 const uint8_t* data = nullptr; |
269 size_t length = 0; | 274 size_t length = 0; |
270 if (reader.PopArrayOfBytes(&data, &length)) { | 275 if (reader.PopArrayOfBytes(&data, &length)) { |
271 helper_info->observer()->OnPacketReceived( | 276 helper_info->observer()->OnPacketReceived( |
272 std::string(reinterpret_cast<const char*>(data), length)); | 277 std::vector<char>(data, data + length)); |
273 } | 278 } |
274 } | 279 } |
275 | 280 |
276 // static | 281 // static |
277 void ShillThirdPartyVpnDriverClientImpl::OnPlatformMessage( | 282 void ShillThirdPartyVpnDriverClientImpl::OnPlatformMessage( |
278 base::WeakPtr<HelperInfo> helper_info, | 283 base::WeakPtr<HelperInfo> helper_info, |
279 dbus::Signal* signal) { | 284 dbus::Signal* signal) { |
280 if (!helper_info || !helper_info->observer()) | 285 if (!helper_info || !helper_info->observer()) |
281 return; | 286 return; |
282 | 287 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 | 335 |
331 ShillThirdPartyVpnDriverClient::~ShillThirdPartyVpnDriverClient() { | 336 ShillThirdPartyVpnDriverClient::~ShillThirdPartyVpnDriverClient() { |
332 } | 337 } |
333 | 338 |
334 // static | 339 // static |
335 ShillThirdPartyVpnDriverClient* ShillThirdPartyVpnDriverClient::Create() { | 340 ShillThirdPartyVpnDriverClient* ShillThirdPartyVpnDriverClient::Create() { |
336 return new ShillThirdPartyVpnDriverClientImpl(); | 341 return new ShillThirdPartyVpnDriverClientImpl(); |
337 } | 342 } |
338 | 343 |
339 } // namespace chromeos | 344 } // namespace chromeos |
OLD | NEW |