#include <vconf.h>
#include "softap_private.h"
+#include "softap_gdbus.h"
+#include "softap_dlog.h"
static void __handle_softap_on(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data);
-static __softap_sig_t sigs[] = {
+static softap_sig_t sigs[] = {
{0, SIGNAL_NAME_SOFTAP_ON, __handle_softap_on},
{0, SIGNAL_NAME_SOFTAP_OFF, __handle_softap_off},
{0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode},
}
__softap_h *sa = (__softap_h *)user_data;
- GError *g_error = NULL;
- GVariant *g_var;
- guint info;
softap_error_e error;
softap_enabled_cb ecb = sa->enabled_cb;
void *data = sa->enabled_user_data;
return;
}
- g_var = g_dbus_proxy_call_finish(sa->client_bus_proxy, res, &g_error);
- if (g_error) {
- ERR("DBus error [%s]", g_error->message);
- if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
- ++retry < SOFTAP_ERROR_RECOVERY_MAX) {
- g_error_free(g_error);
- softap_enable((softap_h)sa);
- SOFTAP_UNLOCK;
- DBG("-");
- return;
- }
-
- if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
- error = SOFTAP_ERROR_PERMISSION_DENIED;
- else
- error = SOFTAP_ERROR_OPERATION_FAILED;
- g_error_free(g_error);
- } else {
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *g_var = softap_gdbus_proxy_finish(sa->gdbus_handle,
+ res, &gdbus_error);
+ if (g_var != NULL) {
+ guint info;
g_variant_get(g_var, "(u)", &info);
g_variant_unref(g_var);
error = __get_error(info);
if (error != SOFTAP_ERROR_NONE)
ERR("Fail to enable Soft AP (%d)!!", error);
+ } else {
+ if (gdbus_error == GDBUS_ERROR_NO_REPLY
+ && ++retry < SOFTAP_ERROR_RECOVERY_MAX) {
+ softap_enable((softap_h)sa);
+ SOFTAP_UNLOCK;
+ DBG("-");
+ return;
+ }
+ error = gdbus_error == GDBUS_ERROR_ACCESS_DENIED ?
+ SOFTAP_ERROR_PERMISSION_DENIED : SOFTAP_ERROR_OPERATION_FAILED;
}
retry = 0;
-
- sigs[E_SIGNAL_SOFTAP_ON].sig_id = g_dbus_connection_signal_subscribe(sa->client_bus,
- NULL, SOFTAP_SERVICE_INTERFACE, sigs[E_SIGNAL_SOFTAP_ON].name,
- SOFTAP_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
- sigs[E_SIGNAL_SOFTAP_ON].cb, (gpointer)sa, NULL);
+ int sig_id = softap_gdbus_connect_signal(sa->gdbus_handle,
+ sigs[E_SIGNAL_SOFTAP_ON], user_data);
+ if (sig_id >= 0)
+ sigs[E_SIGNAL_SOFTAP_ON].sig_id = sig_id;
if (ecb)
ecb(error, true, data);
}
__softap_h *sa = (__softap_h *)user_data;
- GError *g_error = NULL;
- GVariant *g_var;
- guint info;
softap_error_e error;
softap_disabled_cause_e code = SOFTAP_DISABLED_BY_REQUEST;
softap_disabled_cb dcb = sa->disabled_cb;
return;
}
- g_var = g_dbus_proxy_call_finish(sa->client_bus_proxy, res, &g_error);
- if (g_error) {
- ERR("DBus error [%s]", g_error->message);
- g_error_free(g_error);
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *g_var = softap_gdbus_proxy_finish(sa->gdbus_handle,
+ res, &gdbus_error);
+ if (gdbus_error) {
SOFTAP_UNLOCK;
DBG("-");
return;
} else {
+ guint info;
g_variant_get(g_var, "(u)", &info);
g_variant_unref(g_var);
error = __get_error(info);
ERR("Fail to disable Soft AP (%d)!!", error);
}
- sigs[E_SIGNAL_SOFTAP_OFF].sig_id = g_dbus_connection_signal_subscribe(sa->client_bus,
- NULL, SOFTAP_SERVICE_INTERFACE, sigs[E_SIGNAL_SOFTAP_OFF].name,
- SOFTAP_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
- sigs[E_SIGNAL_SOFTAP_OFF].cb, (gpointer)sa, NULL);
+ int sig_id = softap_gdbus_connect_signal(sa->gdbus_handle,
+ sigs[E_SIGNAL_SOFTAP_OFF], user_data);
+ if (sig_id >= 0)
+ sigs[E_SIGNAL_SOFTAP_OFF].sig_id = sig_id;
if (dcb)
dcb(error, code, data);
return;
}
-
static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
{
return;
}
- GError *g_error = NULL;
- GVariant *g_var;
- guint info;
__softap_h *sa = (__softap_h *)user_data;
- softap_error_e softap_error;
-
- g_var = g_dbus_proxy_call_finish(sa->client_bus_proxy, res, &g_error);
- if (g_error) {
- ERR("DBus fail [%s]\n", g_error->message);
- if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
- softap_error = SOFTAP_ERROR_PERMISSION_DENIED;
- else
- softap_error = SOFTAP_ERROR_OPERATION_FAILED;
- g_error_free(g_error);
- } else {
+ softap_error_e error;
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *g_var = softap_gdbus_proxy_finish(sa->gdbus_handle,
+ res, &gdbus_error);
+ error = _softap_convert_to_error(gdbus_error);
+ if (error == SOFTAP_ERROR_NONE) {
+ guint info;
g_variant_get(g_var, "(u)", &info);
g_variant_unref(g_var);
- softap_error = __get_error(info);
+ error = __get_error(info);
}
if (sa->settings_reloaded_cb == NULL) {
return;
}
- sa->settings_reloaded_cb(softap_error,
+ sa->settings_reloaded_cb(error,
sa->settings_reloaded_user_data);
sa->settings_reloaded_cb = NULL;
return params;
}
-static void __connect_signals(softap_h softap)
-{
- DBG("+");
- _retm_if(softap == NULL, "parameter(softap) is NULL");
-
- __softap_h *sa = (__softap_h *)softap;
- GDBusConnection *connection = sa->client_bus;
- int i = 0;
-
- for (i = E_SIGNAL_SOFTAP_ON; i < E_SIGNAL_MAX; i++) {
- sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection,
- NULL, SOFTAP_SERVICE_INTERFACE, sigs[i].name,
- SOFTAP_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
- sigs[i].cb, softap, NULL);
- }
- DBG("-");
-}
-
-static void __disconnect_signals(softap_h softap)
-{
- DBG("+");
-
- _retm_if(softap == NULL, "parameter(softap) is NULL\n");
-
- __softap_h *sa = (__softap_h *)softap;
- GDBusConnection *connection = sa->client_bus;
-
- int i = 0;
-
- for (i = E_SIGNAL_SOFTAP_ON; i < E_SIGNAL_MAX; i++)
- g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id);
- DBG("-");
-}
-
static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
{
if (path == NULL || ssid == NULL || size == 0)
return true;
}
-int __handle_dbus_error(GError *error)
-{
- if (!error)
- return SOFTAP_ERROR_NONE;
-
- ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
- return (error->code == G_DBUS_ERROR_ACCESS_DENIED) ?
- SOFTAP_ERROR_PERMISSION_DENIED : SOFTAP_ERROR_OPERATION_FAILED;
-}
-
int _softap_enable_dhcp(softap_h softap, char *rangestart, char *rangestop)
{
- GVariant *parameters;
- GError *error = NULL;
- guint result;
-
__softap_h *sa = (__softap_h *)softap;
- GDBusProxy *proxy = sa->client_bus_proxy;
-
- if (rangestart == NULL && rangestop == NULL)
- parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- else
- parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp_with_range",
- g_variant_new("(ss)", rangestart, rangestop),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ GVariant *result = NULL;
+ GVariant *parameters = NULL;
+ const char *method = NULL;
+ if (rangestart == NULL && rangestop == NULL) {
+ parameters = NULL;
+ method = "enable_dhcp";
+ } else {
+ parameters = g_variant_new("(ss)", rangestart, rangestop);
+ method = "enable_dhcp_with_range";
+ }
- result = __handle_dbus_error(error);
- if (result != SOFTAP_ERROR_NONE) {
- g_error_free(error);
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ result = softap_gdbus_proxy_invoke_method_sync(sa->gdbus_handle,
+ method, parameters, &gdbus_error);
+ int ret = _softap_convert_to_error(gdbus_error);
+ if (ret != SOFTAP_ERROR_NONE) {
sa->dhcp_enabled = FALSE;
- return result;
+ return ret;
}
- g_variant_get(parameters, "(u)", &result);
- g_variant_unref(parameters);
+ guint info;
+ g_variant_get(result, "(u)", &info);
+ g_variant_unref(result);
sa->dhcp_enabled = TRUE;
- return SOFTAP_ERROR_NONE;
+ return ret;
}
API int softap_create(softap_h *softap)
"parameter(softap) is NULL\n");
__softap_h *sa = NULL;
- GError *error = NULL;
char ssid[SOFTAP_SSID_MAX_LEN + 1] = {0, };
sa = (__softap_h *) calloc(1, sizeof(__softap_h));
sa->channel = SOFTAP_DEFAULT_CHANNEL;
sa->mode = SOFTAP_WIRELESS_MODE_G;
sa->dhcp_enabled = FALSE;
-
- /* GDbus Setting */
-#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init();
-#endif
- GCancellable *cancellable = g_cancellable_new();
- sa->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
- if (error) {
- ERR("Couldn't connect to the System bus[%s]", error->message);
- g_error_free(error);
- g_cancellable_cancel(cancellable);
- g_object_unref(cancellable);
- g_free(sa->ssid);
- free(sa);
- return SOFTAP_ERROR_OPERATION_FAILED;
- }
- sa->cancellable = cancellable;
-
- sa->client_bus_proxy = g_dbus_proxy_new_sync(sa->client_bus, G_DBUS_PROXY_FLAGS_NONE,
- NULL, SOFTAP_SERVICE_NAME, SOFTAP_SERVICE_OBJECT_PATH,
- SOFTAP_SERVICE_INTERFACE, sa->cancellable, &error);
- if (!sa->client_bus_proxy) {
- if (error) {
- ERR("Fail to create the proxy object because of %s", error->message);
- g_error_free(error);
- }
- g_cancellable_cancel(sa->cancellable);
- g_object_unref(sa->cancellable);
+ sa->gdbus_handle = softap_gdbus_create();
+ if (sa->gdbus_handle == NULL) {
g_free(sa->ssid);
free(sa);
return SOFTAP_ERROR_OPERATION_FAILED;
}
- __connect_signals((softap_h)sa);
-
+ softap_gdbus_connect_signals(sa->gdbus_handle, sigs, (softap_h)sa);
*softap = (softap_h) sa;
_softap_add_handle(sa);
__softap_h *sa = (__softap_h *)softap;
DBG("SoftAP Handle : %p\n", sa);
- __disconnect_signals(softap);
+ softap_gdbus_disconnect_signals(sa->gdbus_handle, sigs);
if (sa->ssid)
free(sa->ssid);
- g_object_unref(sa->cancellable);
- g_object_unref(sa->client_bus_proxy);
- g_object_unref(sa->client_bus);
+ softap_gdbus_destroy(sa->gdbus_handle);
memset(sa, 0x00, sizeof(__softap_h));
_softap_remove_handle(sa);
{
DBG("+");
CHECK_FEATURE_SUPPORTED(SUPPORTED_FEATURE_SOFTAP);
- _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+ _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
"parameter(softap) is NULL");
- __softap_h *sa = (__softap_h *) softap;
- GDBusProxy *proxy = sa->client_bus_proxy;
- GDBusConnection *connection = sa->client_bus;
- GVariant *settings = NULL;
-
- g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
-
- settings = __prepare_softap_settings(softap);
+ __softap_h *sa = (__softap_h *) softap;
+ softap_gdbus_proxy_reset_timeout(sa->gdbus_handle);
+ GVariant *settings = __prepare_softap_settings(softap);
if (!settings) {
ERR("Fail to initialize softap settings\n");
return SOFTAP_ERROR_OPERATION_FAILED;
}
- g_dbus_connection_signal_unsubscribe(connection, sigs[E_SIGNAL_SOFTAP_ON].sig_id);
- g_dbus_proxy_call(proxy, "enable", settings, G_DBUS_CALL_FLAGS_NONE, -1,
- sa->cancellable, (GAsyncReadyCallback) __enabled_cfm_cb, (gpointer)softap);
- g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
+ softap_gdbus_disconnect_signal(sa->gdbus_handle, sigs[E_SIGNAL_SOFTAP_ON].sig_id);
+ softap_gdbus_proxy_invoke_method(sa->gdbus_handle, "enable", settings,
+ (GAsyncReadyCallback) __enabled_cfm_cb, softap);
+ softap_gdbus_proxy_set_timeout(sa->gdbus_handle);
DBG("-");
return SOFTAP_ERROR_NONE;
"parameter(softap) is NULL");
__softap_h *sa = (__softap_h *) softap;
- GDBusProxy *proxy = sa->client_bus_proxy;
- GDBusConnection *connection = sa->client_bus;
-
- g_dbus_connection_signal_unsubscribe(connection, sigs[E_SIGNAL_SOFTAP_OFF].sig_id);
-
- g_dbus_proxy_call(proxy, "disable",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, sa->cancellable,
- (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)softap);
+ softap_gdbus_disconnect_signal(sa->gdbus_handle, sigs[E_SIGNAL_SOFTAP_OFF].sig_id);
+ softap_gdbus_proxy_invoke_method(sa->gdbus_handle,
+ "disable", NULL, (GAsyncReadyCallback) __disabled_cfm_cb, softap);
DBG("-");
return SOFTAP_ERROR_NONE;
"parameter(callback) is NULL\n");
__softap_h *sa = (__softap_h *)softap;
- GDBusProxy *proxy = sa->client_bus_proxy;
- GVariant *settings = NULL;
-
- DBG("+");
+ _retvm_if(sa->settings_reloaded_cb, SOFTAP_ERROR_OPERATION_FAILED,
+ "Operation in progress\n");
- if (sa->settings_reloaded_cb) {
- ERR("Operation in progress\n");
- return SOFTAP_ERROR_OPERATION_FAILED;
- }
-
- settings = __prepare_softap_settings(softap);
- if (!settings) {
- ERR("softap settings initialization failed\n");
- return SOFTAP_ERROR_OPERATION_FAILED;
- }
+ GVariant *settings = __prepare_softap_settings(softap);
+ _retvm_if(settings == NULL, SOFTAP_ERROR_OPERATION_FAILED,
+ "softap settings initialization failed\n");
sa->settings_reloaded_cb = callback;
sa->settings_reloaded_user_data = user_data;
- g_dbus_proxy_call(proxy, "reload_settings", settings,
- G_DBUS_CALL_FLAGS_NONE, -1, sa->cancellable,
- (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)softap);
+ softap_gdbus_proxy_invoke_method(sa->gdbus_handle,
+ "reload_settings", settings, (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)softap);
return SOFTAP_ERROR_NONE;
}
gchar *mac = NULL;
gchar *hostname = NULL;
guint timestamp = 0;
- GError *error = NULL;
- GVariant *result = NULL;
GVariantIter *outer_iter = NULL;
GVariantIter *inner_iter = NULL;
GVariant *station = NULL;
GVariant *value = NULL;
gchar *key = NULL;
int interface = 0;
- int ret = 0;
-
- result = g_dbus_proxy_call_sync(sa->client_bus_proxy, "get_station_info",
- NULL, G_DBUS_CALL_FLAGS_NONE,
- -1, sa->cancellable, &error);
- ret = __handle_dbus_error(error);
- if (ret != SOFTAP_ERROR_NONE) {
- g_error_free(error);
- return ret;
- }
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *result = softap_gdbus_proxy_invoke_method_sync(sa->gdbus_handle,
+ "get_station_info", NULL, &gdbus_error);
g_variant_get(result, "(a(a{sv}))", &outer_iter);
"parameter(passphrase) is NULL\n");
__softap_h *sa = (__softap_h *)softap;
- GDBusProxy *proxy = sa->client_bus_proxy;
- GVariant *parameters = NULL;
- GError *error = NULL;
- int ret = SOFTAP_ERROR_NONE;
-
- parameters = g_dbus_proxy_call_sync(proxy, "get_passphrase",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- ret = __handle_dbus_error(error);
- if (ret != SOFTAP_ERROR_NONE) {
- g_error_free(error);
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *parameters = softap_gdbus_proxy_invoke_method_sync(sa->gdbus_handle,
+ "get_passphrase", NULL, &gdbus_error);
+ int ret = _softap_convert_to_error(gdbus_error);
+ if (ret != SOFTAP_ERROR_NONE)
return ret;
- }
-
- if (parameters != NULL) {
- g_variant_get(parameters, "(su)", passphrase, &ret);
- g_variant_unref(parameters);
- }
-
- DBG("-");
- return ret;
+ g_variant_get(parameters, "(su)", passphrase, &ret);
+ g_variant_unref(parameters);
+ return __get_error(ret);
}
API int softap_push_wps_button(softap_h softap)
"parameter(softap) is NULL");
DBG("+");
-
__softap_h *sa = (__softap_h *)softap;
- GDBusProxy *proxy = sa->client_bus_proxy;
- GVariant *parameters = NULL;
- guint info;
- GError *error = NULL;
- int ret = SOFTAP_ERROR_NONE;
-
- parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- ret = __handle_dbus_error(error);
- if (ret != SOFTAP_ERROR_NONE) {
- g_error_free(error);
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *parameters = softap_gdbus_proxy_invoke_method_sync(sa->gdbus_handle,
+ "push_wps_button", NULL, &gdbus_error);
+ int ret = _softap_convert_to_error(gdbus_error);
+ if (ret != SOFTAP_ERROR_NONE)
return ret;
- }
if (parameters != NULL) {
+ guint info;
g_variant_get(parameters, "(u)", &info);
g_variant_unref(parameters);
- ret = __get_error(info);
+ return __get_error(info);
}
-
- DBG("-");
-
return ret;
}
DBG("+");
__softap_h *sa = (__softap_h *)softap;
- GDBusProxy *proxy = sa->client_bus_proxy;
- GVariant *parameters = NULL;
- guint info;
- GError *error = NULL;
- int ret = SOFTAP_ERROR_NONE;
-
- parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
- g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- ret = __handle_dbus_error(error);
- if (ret != SOFTAP_ERROR_NONE) {
- g_error_free(error);
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *parameters = softap_gdbus_proxy_invoke_method_sync(sa->gdbus_handle,
+ "set_wps_pin", g_variant_new("(s)", wps_pin), &gdbus_error);
+ int ret = _softap_convert_to_error(gdbus_error);
+ if (ret != SOFTAP_ERROR_NONE)
return ret;
- }
if (parameters != NULL) {
+ guint info;
g_variant_get(parameters, "(u)", &info);
g_variant_unref(parameters);
- ret = __get_error(info);
+ return __get_error(info);
}
-
- DBG("-");
-
return ret;
}
return SOFTAP_ERROR_NONE;
}
-
API int softap_get_channel(softap_h softap, int *channel)
{
CHECK_FEATURE_SUPPORTED(SUPPORTED_FEATURE_SOFTAP);
__softap_h *sa = (__softap_h *)softap;
sa->mode = mode;
-
return SOFTAP_ERROR_NONE;
}
_retvm_if(mode == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
"parameter(mode) is NULL\n");
-
__softap_h *sa = (__softap_h *)softap;
*mode = sa->mode;
-
return __get_mode(mode);
}
"parameter(softap) is NULL\n");
__softap_h *sa = (__softap_h *)softap;
- GError *error = NULL;
- GVariant *parameters = NULL;
- GDBusProxy *proxy = sa->client_bus_proxy;
- guint ret;
-
- parameters = g_dbus_proxy_call_sync(proxy, "disable_dhcp",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- ret = __handle_dbus_error(error);
- if (ret != SOFTAP_ERROR_NONE) {
- g_error_free(error);
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *parameters = softap_gdbus_proxy_invoke_method_sync(sa->gdbus_handle,
+ "disable_dhcp", NULL, &gdbus_error);
+ int ret = _softap_convert_to_error(gdbus_error);
+ if (ret != SOFTAP_ERROR_NONE)
return ret;
- }
g_variant_get(parameters, "(u)", &ret);
g_variant_unref(parameters);
-
sa->dhcp_enabled = FALSE;
return SOFTAP_ERROR_NONE;
"parameter(dhcp_enabled) is NULL\n");
__softap_h *sa = (__softap_h *)softap;
- GError *error = NULL;
- GVariant *parameters = NULL;
- GDBusProxy *proxy = sa->client_bus_proxy;
- int ret = SOFTAP_ERROR_NONE;
gboolean enabled = FALSE;
+ softap_gdbus_error_e gdbus_error = GDBUS_ERROR_NONE;
+ GVariant *parameters = softap_gdbus_proxy_invoke_method_sync(sa->gdbus_handle,
+ "get_dhcp_state", NULL, &gdbus_error);
- parameters = g_dbus_proxy_call_sync(proxy, "get_dhcp_state",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- ret = __handle_dbus_error(error);
- if (ret != SOFTAP_ERROR_NONE)
- g_error_free(error);
-
- if (parameters != NULL) {
+ int ret = _softap_convert_to_error(gdbus_error);
+ if (ret == SOFTAP_ERROR_NONE) {
g_variant_get(parameters, "(b)", &enabled);
g_variant_unref(parameters);
}
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <dbus/dbus.h>
+#include <stdlib.h>
+
+#include "softap_gdbus.h"
+#include "softap_dlog.h"
+#include "softap_private.h"
+
+#define SOFTAP_SERVICE_OBJECT_PATH "/MobileapAgent"
+#define SOFTAP_SERVICE_NAME "org.tizen.MobileapAgent"
+#define SOFTAP_SERVICE_INTERFACE "org.tizen.softap"
+
+GCancellable *_create_cancellable()
+{
+ return g_cancellable_new();
+}
+
+void _destroy_cancellable(GCancellable *cancellable)
+{
+ _ret_if(cancellable == NULL);
+ g_cancellable_cancel(cancellable);
+ g_object_unref(cancellable);
+}
+
+GDBusConnection *_create_gdbus_connection(GCancellable *cancellable)
+{
+ GError *error = NULL;
+ GDBusConnection *client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
+ if (error) {
+ ERR("Couldn't connect to the System bus[%s]", error->message);
+ g_error_free(error);
+ return NULL;
+ }
+ return client_bus;
+}
+
+GDBusProxy *_create_gdbus_proxy(GDBusConnection *client_bus, GCancellable *cancellable)
+{
+ GError *error = NULL;
+ GDBusProxy *client_bus_proxy = g_dbus_proxy_new_sync(client_bus,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL, SOFTAP_SERVICE_NAME, SOFTAP_SERVICE_OBJECT_PATH,
+ SOFTAP_SERVICE_INTERFACE, cancellable, &error);
+ if (client_bus_proxy == NULL) {
+ if (error) {
+ ERR("Fail to create the proxy object because of %s", error->message);
+ g_error_free(error);
+ }
+ return NULL;
+ }
+
+ return client_bus_proxy;
+}
+
+softap_gdbus_h *softap_gdbus_create()
+{
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
+#endif
+ softap_gdbus_h *gdbus_handle = (softap_gdbus_h *)calloc(1, sizeof(softap_gdbus_h));
+ _retvm_if(gdbus_handle == NULL, NULL, "Out of memroy");
+
+ gdbus_handle->cancellable = _create_cancellable();
+ gdbus_handle->client_bus = _create_gdbus_connection(gdbus_handle->cancellable);
+ if (gdbus_handle->client_bus == NULL) {
+ softap_gdbus_destroy(gdbus_handle);
+ return NULL;
+ }
+
+ gdbus_handle->client_bus_proxy
+ = _create_gdbus_proxy(gdbus_handle->client_bus, gdbus_handle->cancellable);
+ if (gdbus_handle->client_bus_proxy == NULL) {
+ _destroy_cancellable(gdbus_handle->cancellable);
+ return NULL;
+ }
+
+ return gdbus_handle;
+}
+
+void softap_gdbus_destroy(softap_gdbus_h *softap_gdbus)
+{
+ _retm_if(softap_gdbus == NULL, "softap_gdbus is NULL");
+
+ g_clear_object(&softap_gdbus->cancellable);
+ g_clear_object(&softap_gdbus->client_bus_proxy);
+ g_clear_object(&softap_gdbus->client_bus);
+
+ free(softap_gdbus);
+}
+
+void softap_gdbus_connect_signals(softap_gdbus_h *softap_gdbus, softap_sig_t sigs[], void *user_data)
+{
+ DBG("+");
+ _retm_if(softap_gdbus == NULL, "softap_gdbus is NULL");
+
+ for (int i = E_SIGNAL_SOFTAP_ON; i < E_SIGNAL_MAX; i++) {
+ sigs[i].sig_id = g_dbus_connection_signal_subscribe(softap_gdbus->client_bus,
+ NULL, SOFTAP_SERVICE_INTERFACE, sigs[i].name,
+ SOFTAP_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+ sigs[i].cb, user_data, NULL);
+ }
+ DBG("-");
+}
+
+void softap_gdbus_disconnect_signals(softap_gdbus_h *softap_gdbus, softap_sig_t sigs[])
+{
+ DBG("+");
+ _retm_if(softap_gdbus == NULL, "softap_gdbus is NULL\n");
+
+ for (int i = E_SIGNAL_SOFTAP_ON; i < E_SIGNAL_MAX; i++)
+ g_dbus_connection_signal_unsubscribe(softap_gdbus->client_bus, sigs[i].sig_id);
+ DBG("-");
+}
+
+int softap_gdbus_connect_signal(softap_gdbus_h *softap_gdbus,
+ softap_sig_t signal, void *user_data)
+{
+ _retvm_if(softap_gdbus == NULL, -1, "softap_gdbus is NULL\n");
+ return g_dbus_connection_signal_subscribe(softap_gdbus->client_bus,
+ NULL, SOFTAP_SERVICE_INTERFACE, signal.name,
+ SOFTAP_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+ signal.cb, user_data, NULL);
+}
+
+void softap_gdbus_disconnect_signal(softap_gdbus_h *softap_gdbus, int sig_id)
+{
+ g_dbus_connection_signal_unsubscribe(softap_gdbus->client_bus, sig_id);
+}
+
+void softap_gdbus_proxy_invoke_method(softap_gdbus_h *softap_gdbus,
+ const char *method, GVariant *parameters,
+ GAsyncReadyCallback callback, void *user_data)
+{
+ _retm_if(softap_gdbus == NULL, "softap_gdbus is NULL");
+ _retm_if(method == NULL, "method is NULL");
+
+ g_dbus_proxy_call(softap_gdbus->client_bus_proxy,
+ method, parameters, G_DBUS_CALL_FLAGS_NONE, -1,
+ softap_gdbus->cancellable, callback, (gpointer)user_data);
+}
+
+static softap_gdbus_error_e _convert_gdbus_error(GDBusError error)
+{
+ switch (error) {
+ case G_DBUS_ERROR_NO_REPLY:
+ return GDBUS_ERROR_NO_REPLY;
+ case G_DBUS_ERROR_ACCESS_DENIED:
+ return GDBUS_ERROR_ACCESS_DENIED;
+ default:
+ return GDBUS_ERROR_UNKNOWN;
+ }
+}
+
+GVariant *softap_gdbus_proxy_invoke_method_sync(softap_gdbus_h *softap_gdbus,
+ const char *method, GVariant *parameters, softap_gdbus_error_e *gdbus_error)
+{
+ _retvm_if(softap_gdbus == NULL, NULL, "softap_gdbus is NULL");
+ _retvm_if(method == NULL, NULL, "method is NULL");
+ _retvm_if(gdbus_error == NULL, NULL, "is_denied is NULL");
+
+ GError *error = NULL;
+ GVariant *result = g_dbus_proxy_call_sync(softap_gdbus->client_bus_proxy,
+ method, parameters, G_DBUS_CALL_FLAGS_NONE, -1,
+ softap_gdbus->cancellable, &error);
+
+ if (error) {
+ ERR("DBus error [%s]", error->message);
+ *gdbus_error = _convert_gdbus_error(error->code);
+ g_error_free(error);
+ }
+ return result;
+}
+
+GVariant *softap_gdbus_proxy_finish(softap_gdbus_h *softap_gdbus,
+ GAsyncResult *async_result, softap_gdbus_error_e *gdbus_error)
+{
+ _retvm_if(softap_gdbus == NULL, NULL, "softap_gdbus is NULL");
+ _retvm_if(gdbus_error == NULL, NULL, "gdbus_error is NULL");
+
+ GError *error = NULL;
+ GVariant *result = g_dbus_proxy_call_finish(softap_gdbus->client_bus_proxy,
+ async_result, &error);
+
+ if (error) {
+ ERR("DBus error [%s]", error->message);
+ *gdbus_error = _convert_gdbus_error(error->code);
+ g_error_free(error);
+ }
+ return result;
+}
+
+void softap_gdbus_proxy_set_timeout(softap_gdbus_h *softap_gdbus)
+{
+ _retm_if(softap_gdbus == NULL, "softap_gdbus is NULL");
+ g_dbus_proxy_set_default_timeout(softap_gdbus->client_bus_proxy,
+ DBUS_TIMEOUT_USE_DEFAULT);
+}
+
+void softap_gdbus_proxy_reset_timeout(softap_gdbus_h *softap_gdbus)
+{
+ _retm_if(softap_gdbus == NULL, "softap_gdbus is NULL");
+ g_dbus_proxy_set_default_timeout(softap_gdbus->client_bus_proxy,
+ DBUS_TIMEOUT_INFINITE);
+}