// --------------------------------------------------------------
// Connman Agent Handlers
// --------------------------------------------------------------
- gboolean
- on_handle_release(Agent * /* object */,
- GDBusMethodInvocation * /* invocation */)
+ bool
+ on_handle_release(Agent * object,
+ GDBusMethodInvocation * invocation,
+ gpointer /* user_data */)
{
+ agent_complete_release(object, invocation);
return true;
}
- gboolean
- on_handle_report_error(Agent * /* object */,
- GDBusMethodInvocation * /* invocation */,
- gchar const * /* service */,
- gchar const * /* error */)
+ bool
+ on_handle_report_error(Agent * object,
+ GDBusMethodInvocation * invocation,
+ gchar const * service,
+ gchar const * error,
+ gpointer user_data)
{
+ using namespace ivi::settings;
+ typedef agent::user_data data_type;
+
+ data_type * const data = static_cast<data_type *>(user_data);
+
+ {
+ std::lock_guard<std::mutex> guard(data->lock);
+
+ auto const i = data->info.find(service);
+ if (i != data->info.end()) {
+ auto & response = i->second.response;
+ response.send_error(error);
+ }
+ }
+
+ agent_complete_report_error(object, invocation);
+
return true;
}
- gboolean
- on_handle_request_browser(Agent * /* object */,
- GDBusMethodInvocation * /* invocation */,
+ bool
+ on_handle_request_browser(Agent * object,
+ GDBusMethodInvocation * invocation,
gchar const * /* service */,
- gchar const * /* url */)
+ gchar const * /* url */,
+ gpointer /* user_data */)
{
+ agent_complete_request_browser(object, invocation);
return true;
}
- gboolean
- on_handle_request_input(Agent * /* object */,
- GDBusMethodInvocation * /* invocation */,
+ bool
+ on_handle_request_input(Agent * object,
+ GDBusMethodInvocation * invocation,
gchar const * /* service */,
- GVariant * /* fields */)
+ GVariant * /* fields */,
+ gpointer /* user_data */)
{
+ GVariant * response = nullptr;
+
// The method return value will contain a dictionary of the
// requested input fields.
+ agent_complete_request_input(object, invocation, response);
return true;
}
- gboolean
- on_handle_cancel(Agent * /* object */,
- GDBusMethodInvocation * /* invocation */)
+ bool
+ on_handle_cancel(Agent * object,
+ GDBusMethodInvocation * invocation,
+ gpointer /* user_data */)
{
+ agent_complete_cancel(object, invocation);
return true;
}
}
nullptr))
, interface_(agent_skeleton_new())
, object_path_("/" IVI_SETTINGS_DBUS_NAME "/connman/Agent")
+ , data_()
{
// Construct object path of the form:
// /org/tizen/settingsd/connman/Agent"
g_signal_connect(interface_,
"handle-release",
G_CALLBACK(on_handle_release),
- nullptr);
+ &data_);
g_signal_connect(interface_,
"handle-report-error",
G_CALLBACK(on_handle_report_error),
- nullptr);
+ &data_);
g_signal_connect(interface_,
"handle-request-browser",
G_CALLBACK(on_handle_request_browser),
- nullptr);
+ &data_);
g_signal_connect(interface_,
"handle-request-input",
G_CALLBACK(on_handle_request_input),
- nullptr);
+ &data_);
g_signal_connect(interface_,
"handle-cancel",
G_CALLBACK(on_handle_cancel),
- nullptr);
+ &data_);
+ // Export the interface on the bus.
GError * error = nullptr;
if (!g_dbus_interface_skeleton_export(
G_DBUS_INTERFACE_SKELETON(interface_),
g_bus_unown_name(owner_id_);
}
-char const *
-ivi::settings::agent::object_path() const
+bool
+ivi::settings::agent::register_connect_data(
+ char const * service_path,
+ JsonReader * reader,
+ response_callback const & response)
{
- return object_path_.c_str();
+ std::lock_guard<std::mutex> guard(data_.lock);
+
+ auto const result =
+ data_.info.emplace(std::make_pair(service_path,
+ connect_data(reader, response)));
+
+ return result.second;
}
#include "agent-glue.h"
+#include <settingsd/response_callback.hpp>
+
+
#include <string>
+#include <map>
+#include <mutex>
-#include <gio/gio.h>
namespace ivi
{
/// Destructor.
~agent();
+ /**
+ * Register data that may be needed when handling Connman Agent
+ * method calls.
+ */
+ bool register_connect_data(char const * service_path,
+ JsonReader * reader,
+ response_callback const & response);
+
/// Get D-Bus object path for this @c Agent.
- char const * object_path() const;
+ char const *
+ object_path() const
+ {
+ return object_path_.c_str();
+ }
+
+ /**
+ * @struct connect_data
+ *
+ * @brief Connman Service object-specific connect data.
+ */
+ struct connect_data
+ {
+ connect_data(JsonReader * rd,
+ response_callback const & resp)
+ : reader(static_cast<JsonReader *>(g_object_ref(rd)))
+ , response(resp)
+ {
+ }
+
+ connect_data(connect_data && other)
+ : reader(std::move(other.reader))
+ , response(other.response)
+ {
+ other.reader.reset();
+
+ // Nothing to do with response field.
+ }
+
+ connect_data(connect_data const &) = delete;
+
+ unique_ptr<JsonReader> reader;
+ response_callback response;
+ };
+
+ /**
+ * @struct user_data
+ *
+ * @brief Wrapper for data passed to Connman Agent method
+ * handlers.
+ */
+ struct user_data
+ {
+ /// Synchronize access to the response/request data map.
+ std::mutex lock;
+
+ /**
+ * Map of service D-Bus object path to request/response
+ * data.
+ */
+ std::map<std::string, connect_data> info;
+ };
private:
/// D-Bus object path for this @c Agent.
std::string object_path_;
+ /// Service connect map, data, etc.
+ user_data data_;
+
};
}
}