return err;
}
+static tethering_type_e __convert_to_tethering_type(mobile_ap_type_e type)
+{
+ switch (type) {
+ case MOBILE_AP_TYPE_USB:
+ return TETHERING_TYPE_USB;
+ case MOBILE_AP_TYPE_WIFI:
+ return TETHERING_TYPE_WIFI;
+ case MOBILE_AP_TYPE_BT:
+ return TETHERING_TYPE_BT;
+ case MOBILE_AP_TYPE_P2P:
+ return TETHERING_TYPE_P2P;
+ default:
+ return TETHERING_TYPE_MAX;
+ }
+}
+
+static void __invoke_enable_cb(__tethering_h *th, tethering_type_e type, bool is_requested)
+{
+ if (th == NULL || th->enabled_cb[type] == NULL) {
+ ERR("th or enabled_cb is NULL");
+ return;
+ }
+
+ tethering_enabled_cb ecb = NULL;
+ void *data = NULL;
+
+ if (!_tethering_check_handle(th)) {
+ DBG("Tethering handle is not valid now, ignore it.");
+ return;
+ }
+
+ ecb = th->enabled_cb[type];
+ data = th->enabled_user_data[type];
+ ecb(TETHERING_ERROR_NONE, type, is_requested, data);
+}
+
+static int __get_disabled_cause_by_interface_error(tethering_type_e type)
+{
+ switch (type) {
+ case TETHERING_TYPE_USB:
+ return TETHERING_DISABLED_BY_USB_DISCONNECTION;
+ case TETHERING_TYPE_WIFI:
+ return TETHERING_DISABLED_BY_WIFI_ON;
+ case TETHERING_TYPE_BT:
+ return TETHERING_DISABLED_BY_BT_OFF;
+ default:
+ return TETHERING_DISABLED_BY_OTHERS;
+ }
+}
+
+static void __invoke_disabled_cb(__tethering_h *th, tethering_type_e type, GVariant *parameters)
+{
+ if (th == NULL || th->disabled_cb[type] == NULL) {
+ ERR("th or disabled_cb is NULL");
+ return;
+ }
+
+ tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
+ tethering_disabled_cb dcb = NULL;
+ void *data = NULL;
+ char *buf = NULL;
+
+ if (!_tethering_check_handle(th)) {
+ DBG("Tethering handle is not valid now, ignore it.");
+ return;
+ }
+
+ data = th->disabled_user_data[type];
+
+ g_variant_get(parameters, "(s)", &buf);
+ if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
+ code = __get_disabled_cause_by_interface_error(type);
+ else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
+ code = TETHERING_DISABLED_BY_TIMEOUT;
+
+ dcb(TETHERING_ERROR_NONE, type, code, data);
+ g_free(buf);
+}
+
+static void __invoke_disabled_cbs(__tethering_h *th, tethering_disabled_cause_e code)
+{
+ if (th == NULL) {
+ ERR("th is NULL");
+ return;
+ }
+
+ if (!_tethering_check_handle(th)) {
+ DBG("Tethering handle is not valid now, ignore it.");
+ return;
+ }
+
+ for (tethering_type_e type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
+ tethering_disabled_cb dcb = th->disabled_cb[type];
+ if (dcb == NULL)
+ continue;
+ void *data = th->disabled_user_data[type];
+ dcb(TETHERING_ERROR_NONE, type, code, data);
+ }
+}
+
static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
goto DONE;
}
- if (ap_type == MOBILE_AP_TYPE_USB)
- type = TETHERING_TYPE_USB;
- else if (ap_type == MOBILE_AP_TYPE_WIFI)
- type = TETHERING_TYPE_WIFI;
- else if (ap_type == MOBILE_AP_TYPE_BT)
- type = TETHERING_TYPE_BT;
- else if (ap_type == MOBILE_AP_TYPE_P2P)
- type = TETHERING_TYPE_P2P;
- else {
+ type = __convert_to_tethering_type(ap_type);
+ if (type == TETHERING_TYPE_MAX) {
ERR("Not supported tethering type [%d]\n", ap_type);
goto DONE;
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = 0;
- tethering_disabled_cb dcb = NULL;
- void *data = NULL;
- tethering_disabled_cause_e code = TETHERING_DISABLED_BY_NETWORK_CLOSE;
-
SINFO("Tethering Disabled by network close !");
-
- for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
- dcb = th->disabled_cb[type];
- if (dcb == NULL)
- continue;
- data = th->disabled_user_data[type];
-
- dcb(TETHERING_ERROR_NONE, type, code, data);
- }
-
+ __invoke_disabled_cbs((__tethering_h *)user_data, TETHERING_DISABLED_BY_NETWORK_CLOSE);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = TETHERING_TYPE_WIFI;
- bool is_requested = false;
- tethering_enabled_cb ecb = NULL;
- void *data = NULL;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- ecb = th->enabled_cb[type];
- if (ecb == NULL) {
- TETHERING_UNLOCK;
- return;
- }
-
- data = th->enabled_user_data[type];
-
- ecb(TETHERING_ERROR_NONE, type, is_requested, data);
-
+ __invoke_enable_cb((__tethering_h *)user_data, TETHERING_TYPE_WIFI, false);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = TETHERING_TYPE_WIFI;
- tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
- tethering_disabled_cb dcb = NULL;
- void *data = NULL;
- char *buf = NULL;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- dcb = th->disabled_cb[type];
- if (dcb == NULL) {
- TETHERING_UNLOCK;
- return;
- }
-
- data = th->disabled_user_data[type];
- g_variant_get(parameters, "(s)", &buf);
- if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
- code = TETHERING_DISABLED_BY_WIFI_ON;
- else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
- code = TETHERING_DISABLED_BY_TIMEOUT;
-
- g_free(buf);
- dcb(TETHERING_ERROR_NONE, type, code, data);
-
+ __invoke_disabled_cb((__tethering_h *)user_data, TETHERING_TYPE_WIFI, parameters);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = TETHERING_TYPE_USB;
- bool is_requested = false;
- tethering_enabled_cb ecb = NULL;
- void *data = NULL;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- ecb = th->enabled_cb[type];
- if (ecb == NULL) {
- TETHERING_UNLOCK;
- return;
- }
-
- data = th->enabled_user_data[type];
-
- ecb(TETHERING_ERROR_NONE, type, is_requested, data);
-
+ __invoke_enable_cb((__tethering_h *)user_data, TETHERING_TYPE_USB, false);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = TETHERING_TYPE_USB;
- tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
- tethering_disabled_cb dcb = NULL;
- void *data = NULL;
- char *buf = NULL;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- dcb = th->disabled_cb[type];
- if (dcb == NULL) {
- TETHERING_UNLOCK;
- return;
- }
-
- data = th->disabled_user_data[type];
-
- g_variant_get(parameters, "(s)", &buf);
- if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
- code = TETHERING_DISABLED_BY_USB_DISCONNECTION;
-
- dcb(TETHERING_ERROR_NONE, type, code, data);
- g_free(buf);
-
+ __invoke_disabled_cb((__tethering_h *)user_data, TETHERING_TYPE_USB, parameters);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = TETHERING_TYPE_BT;
- bool is_requested = false;
- tethering_enabled_cb ecb = NULL;
- void *data = NULL;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- ecb = th->enabled_cb[type];
- if (ecb == NULL) {
- TETHERING_UNLOCK;
- return;
- }
-
- data = th->enabled_user_data[type];
-
- ecb(TETHERING_ERROR_NONE, type, is_requested, data);
-
+ __invoke_enable_cb((__tethering_h *)user_data, TETHERING_TYPE_BT, false);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = TETHERING_TYPE_BT;
- tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS;
- tethering_disabled_cb dcb = NULL;
- void *data = NULL;
- char *buf = NULL;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- dcb = th->disabled_cb[type];
- if (dcb == NULL) {
- TETHERING_UNLOCK;
- return;
- }
-
- data = th->disabled_user_data[type];
- g_variant_get(parameters, "(s)", &buf);
- if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
- code = TETHERING_DISABLED_BY_BT_OFF;
- else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT))
- code = TETHERING_DISABLED_BY_TIMEOUT;
-
- dcb(TETHERING_ERROR_NONE, type, code, data);
-
- g_free(buf);
-
+ __invoke_disabled_cb((__tethering_h *)user_data, TETHERING_TYPE_BT, parameters);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = 0;
- tethering_disabled_cb dcb = NULL;
- void *data = NULL;
- tethering_disabled_cause_e code = TETHERING_DISABLED_BY_TIMEOUT;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
- dcb = th->disabled_cb[type];
- if (dcb == NULL)
- continue;
- data = th->disabled_user_data[type];
-
- dcb(TETHERING_ERROR_NONE, type, code, data);
- }
-
+ __invoke_disabled_cbs((__tethering_h *)user_data, TETHERING_DISABLED_BY_TIMEOUT);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = 0;
- tethering_disabled_cb dcb = NULL;
- void *data = NULL;
- tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
- dcb = th->disabled_cb[type];
- if (dcb == NULL)
- continue;
- data = th->disabled_user_data[type];
-
- dcb(TETHERING_ERROR_NONE, type, code, data);
- }
-
+ __invoke_disabled_cbs((__tethering_h *)user_data, TETHERING_DISABLED_BY_LOW_BATTERY);
TETHERING_UNLOCK;
DBG("-\n");
}
{
DBG("+\n");
TETHERING_LOCK;
-
- if (user_data == NULL) {
- ERR("parameter(user_data) is NULL");
- TETHERING_UNLOCK;
- return;
- }
-
- __tethering_h *th = (__tethering_h *)user_data;
- tethering_type_e type = 0;
- tethering_disabled_cb dcb = NULL;
- void *data = NULL;
- tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE;
-
- if (!_tethering_check_handle(th)) {
- DBG("Tethering handle is not valid now, ignore it.");
- TETHERING_UNLOCK;
- return;
- }
-
- for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) {
- dcb = th->disabled_cb[type];
- if (dcb == NULL)
- continue;
- data = th->disabled_user_data[type];
-
- dcb(TETHERING_ERROR_NONE, type, code, data);
- }
-
+ __invoke_disabled_cbs((__tethering_h *)user_data, TETHERING_DISABLED_BY_FLIGHT_MODE);
TETHERING_UNLOCK;
DBG("-\n");
}
while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
if (g_strcmp0(key, "Type") == 0) {
interface = g_variant_get_int32(value);
- if (interface == MOBILE_AP_TYPE_USB)
- client.interface = TETHERING_TYPE_USB;
- else if (interface == MOBILE_AP_TYPE_WIFI)
- client.interface = TETHERING_TYPE_WIFI;
- else if (interface == MOBILE_AP_TYPE_BT)
- client.interface = TETHERING_TYPE_BT;
- else if (interface == MOBILE_AP_TYPE_P2P)
- client.interface = TETHERING_TYPE_P2P;
- else {
+ tethering_type_e converted_type = __convert_to_tethering_type(interface);
+ if (converted_type == TETHERING_TYPE_MAX) {
ERR("Invalid interface\n");
g_free(key);
g_variant_unref(value);
break;
+ } else {
+ client.interface = converted_type;
}
+
DBG("interface is %d\n", client.interface);
if (client.interface != type && (TETHERING_TYPE_ALL != type)) {
g_free(key);