1 // Copyright (c) 2012 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. 4 5 #ifndef CHROMEOS_NETWORK_NETWORK_HANDLER_CALLBACKS_H_ 6 #define CHROMEOS_NETWORK_NETWORK_HANDLER_CALLBACKS_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/callback.h" 12 #include "chromeos/chromeos_export.h" 13 #include "chromeos/dbus/dbus_method_call_status.h" 14 15 namespace base { 16 class DictionaryValue; 17 } 18 19 namespace chromeos { 20 namespace network_handler { 21 22 CHROMEOS_EXPORT extern const char kDBusFailedError[]; 23 CHROMEOS_EXPORT extern const char kDBusFailedErrorMessage[]; 24 CHROMEOS_EXPORT extern const char kErrorName[]; 25 CHROMEOS_EXPORT extern const char kErrorDetail[]; 26 CHROMEOS_EXPORT extern const char kDbusErrorName[]; 27 CHROMEOS_EXPORT extern const char kDbusErrorMessage[]; 28 29 // An error callback used by both the configuration handler and the state 30 // handler to receive error results from the API. 31 typedef base::Callback< 32 void(const std::string& error_name, 33 scoped_ptr<base::DictionaryValue> error_data)> ErrorCallback; 34 35 typedef base::Callback< 36 void(const std::string& service_path, 37 const base::DictionaryValue& dictionary)> DictionaryResultCallback; 38 39 typedef base::Callback< 40 void(const std::string& service_path)> StringResultCallback; 41 42 // Create a DictionaryValue for passing to ErrorCallback. 43 CHROMEOS_EXPORT base::DictionaryValue* CreateErrorData( 44 const std::string& path, 45 const std::string& error_name, 46 const std::string& error_detail); 47 48 CHROMEOS_EXPORT base::DictionaryValue* CreateDBusErrorData( 49 const std::string& path, 50 const std::string& error_name, 51 const std::string& error_detail, 52 const std::string& dbus_error_name, 53 const std::string& dbus_error_message); 54 55 // Callback for Shill errors. 56 // |error_name| is the error name passed to |error_callback|. 57 // |path| is the associated object path or blank if not relevant. 58 // |dbus_error_name| and |dbus_error_message| are provided by the DBus handler. 59 // Logs an error and calls |error_callback| if not null. 60 CHROMEOS_EXPORT void ShillErrorCallbackFunction( 61 const std::string& error_name, 62 const std::string& path, 63 const ErrorCallback& error_callback, 64 const std::string& dbus_error_name, 65 const std::string& dbus_error_message); 66 67 // Callback for property getters used by NetworkConfigurationHandler 68 // (for Network Services) and by NetworkDeviceHandler. Used to translate 69 // the DBus Dictionary callback into one that calls the error callback 70 // if |call_status| != DBUS_METHOD_CALL_SUCCESS. 71 CHROMEOS_EXPORT void GetPropertiesCallback( 72 const network_handler::DictionaryResultCallback& callback, 73 const network_handler::ErrorCallback& error_callback, 74 const std::string& path, 75 DBusMethodCallStatus call_status, 76 const base::DictionaryValue& value); 77 78 } // namespace network_handler 79 } // namespace chromeos 80 81 #endif // CHROMEOS_NETWORK_NETWORK_HANDLER_CALLBACKS_H_ 82