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