Helper function added to notify the Android frontend about status changes.

This commit is contained in:
Tobias Brunner
2010-06-24 14:30:05 +02:00
parent 024dd37fa0
commit 94ec9adc10
@@ -71,6 +71,15 @@ typedef enum {
VPN_ERROR_CONNECTION_LOST = 103, VPN_ERROR_CONNECTION_LOST = 103,
} android_vpn_errors_t; } android_vpn_errors_t;
/**
* send a status code back to the Android app
*/
static void send_status(private_android_service_t *this, u_char code)
{
DBG1(DBG_CFG, "status of Android plugin changed: %d", code);
send(this->control, &code, 1, 0);
}
/** /**
* Read a string argument from the Android control socket * Read a string argument from the Android control socket
*/ */
@@ -125,7 +134,9 @@ static job_requeue_t initiate(private_android_service_t *this)
strerror(errno)); strerror(errno));
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
} }
/* the original control socket is not used anymore */
close(this->control); close(this->control);
this->control = fd;
while (TRUE) while (TRUE)
{ {
@@ -218,15 +229,13 @@ static job_requeue_t initiate(private_android_service_t *this)
charon->bus->add_listener(charon->bus, &this->listener);*/ charon->bus->add_listener(charon->bus, &this->listener);*/
/* confirm that we received the request */ /* confirm that we received the request */
u_char code = i; send_status(this, i);
send(fd, &code, 1, 0);
if (charon->controller->initiate(charon->controller, peer_cfg, child_cfg, if (charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
controller_cb_empty, NULL) != SUCCESS) controller_cb_empty, NULL) != SUCCESS)
{ {
DBG1(DBG_CFG, "failed to initiate tunnel"); DBG1(DBG_CFG, "failed to initiate tunnel");
code = VPN_ERROR_CONNECTION_FAILED; send_status(this, VPN_ERROR_CONNECTION_FAILED);
send(fd, &code, 1, 0);
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
} }
property_set("vpn.status", "ok"); property_set("vpn.status", "ok");
@@ -236,6 +245,7 @@ static job_requeue_t initiate(private_android_service_t *this)
METHOD(android_service_t, destroy, void, METHOD(android_service_t, destroy, void,
private_android_service_t *this) private_android_service_t *this)
{ {
close(this->control);
free(this); free(this);
} }