Commit 5449ceb4 authored by Slava Monich's avatar Slava Monich

[connman] Added tethering_changed() notifier callback. JB#41486

Allows to run custom code when tethering is being turned on or off.
parent 53a57306
......@@ -24,6 +24,7 @@
#include <connman/service.h>
#include <connman/ipconfig.h>
#include <connman/technology.h>
#ifdef __cplusplus
extern "C" {
......@@ -55,6 +56,14 @@ struct connman_notifier {
void (*ipconfig_changed) (struct connman_service *service,
struct connman_ipconfig *ipconfig);
void (*idle_state) (bool idle);
void (*tethering_changed) (struct connman_technology *tech, bool on);
/* Placeholders for future extensions */
void (*_reserved[10])(void);
/* api_level will remain zero (and ignored) until we run out of
* the above placeholders. Hopefully, forever. */
int api_level;
};
int connman_notifier_register(struct connman_notifier *notifier);
......
......@@ -905,6 +905,8 @@ void __connman_notifier_service_state_changed(struct connman_service *service,
enum connman_service_state state);
void __connman_notifier_ipconfig_changed(struct connman_service *service,
struct connman_ipconfig *ipconfig);
void __connman_notifier_tethering_changed(struct connman_technology* tech,
bool on);
bool __connman_notifier_is_connected(void);
const char *__connman_notifier_get_state(void);
......
......@@ -368,6 +368,22 @@ void __connman_notifier_ipconfig_changed(struct connman_service *service,
}
}
void __connman_notifier_tethering_changed(struct connman_technology* tech,
bool on)
{
GSList *l = notifier_list;
while (l) {
GSList *next = l->next;
const struct connman_notifier *notifier = l->data;
if (notifier->tethering_changed)
notifier->tethering_changed(tech, on);
l = next;
}
}
int __connman_notifier_init(void)
{
DBG("");
......
......@@ -242,6 +242,14 @@ void connman_technology_tethering_notify(struct connman_technology *technology,
__connman_tethering_set_enabled();
else
__connman_tethering_set_disabled();
/*
* Notify about tethering having been turned off after it's actually
* been turned off.
*/
if (!enabled)
__connman_notifier_tethering_changed(technology, FALSE);
}
static int set_tethering(struct connman_technology *technology,
......@@ -267,6 +275,13 @@ static int set_tethering(struct connman_technology *technology,
(!ident || !passphrase))
return -EINVAL;
/*
* Notify about tethering being turned on before it actually gets
* turned on.
*/
if (enabled)
__connman_notifier_tethering_changed(technology, TRUE);
for (tech_drivers = technology->driver_list; tech_drivers;
tech_drivers = g_slist_next(tech_drivers)) {
struct connman_technology_driver *driver = tech_drivers->data;
......@@ -284,6 +299,16 @@ static int set_tethering(struct connman_technology *technology,
result = err;
}
/*
* Let notificants know that we have failed to turn tethering on.
* Note that we won't be able to do that in case if the driver
* returns -EINPROGRESS and then silently fails to actually turn
* tethering on. There's no API in connman for reporting this kind
* of postponed failures. Oh well..
*/
if (enabled && result < 0 && result != -EINPROGRESS)
__connman_notifier_tethering_changed(technology, FALSE);
return result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment