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