[PATCH 2/3] mbim-proxy: Exit when all devices are removed
Aleksander Morgado
aleksander at aleksander.es
Sun Jul 27 05:00:49 PDT 2014
On Wed, Jul 23, 2014 at 11:21 PM, Greg Suarez <gpsuarez2512 at gmail.com> wrote:
> Exit when all devices are removed instead of when there are no clients
> connected. This is done to allow for --no-close and --no-open options
> in mbimcli.
Pushed to greg/proxy branch, thanks.
> ---
> src/mbim-proxy/mbim-proxy.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/src/mbim-proxy/mbim-proxy.c b/src/mbim-proxy/mbim-proxy.c
> index c65fe3c..5e330eb 100644
> --- a/src/mbim-proxy/mbim-proxy.c
> +++ b/src/mbim-proxy/mbim-proxy.c
> @@ -42,6 +42,7 @@
> static GMainLoop *loop;
> static MbimProxy *proxy;
> static guint timeout_id;
> +static guint client_connected_once = FALSE;
>
> /* Main options */
> static gboolean verbose_flag;
> @@ -147,6 +148,10 @@ stop_loop_cb (void)
> static void
> proxy_n_clients_changed (MbimProxy *_proxy)
> {
> + /* once a client has connected only exit if there are no devices */
> + if (client_connected_once)
> + return;
> +
> if (mbim_proxy_get_n_clients (proxy) == 0) {
> g_assert (timeout_id == 0);
> timeout_id = g_timeout_add_seconds (EMPTY_PROXY_LIFETIME_SECS,
> @@ -160,6 +165,17 @@ proxy_n_clients_changed (MbimProxy *_proxy)
> g_source_remove (timeout_id);
> timeout_id = 0;
> }
> +
> + client_connected_once = TRUE;
> +}
> +
> +static void
> +proxy_n_devices_changed (MbimProxy *_proxy)
> +{
> + if (mbim_proxy_get_n_devices (proxy) == 0) {
> + if (loop)
> + g_main_loop_quit (loop);
> + }
> }
>
> /*****************************************************************************/
> @@ -208,6 +224,10 @@ int main (int argc, char **argv)
> "notify::" MBIM_PROXY_N_CLIENTS,
> G_CALLBACK (proxy_n_clients_changed),
> NULL);
> + g_signal_connect (proxy,
> + "notify::" MBIM_PROXY_N_DEVICES,
> + G_CALLBACK (proxy_n_devices_changed),
> + NULL);
>
> /* Loop */
> loop = g_main_loop_new (NULL, FALSE);
> --
> 1.9.3
>
--
Aleksander
https://aleksander.es
More information about the libmbim-devel
mailing list