busy.c File Reference

#include <glib.h>
#include <stdio.h>
#include "log.h"
#include "ipc.h"
Include dependency graph for busy.c:

Go to the source code of this file.

Data Structures

struct  busy_count_t

Defines

#define UNUSED(x)   (void)(x)

Enumerations

enum  { BACKGROUND, FOREGROUND }

Functions

static void count_ref (gint sender, gint mode)
static void count_unref (gint sender, gint mode)
static void count_set_pid (gint sender, GPid pid)
static void count_remove_pid (GPid pid)
static gint ref_count (gint mode)
static void update (void)
static void show_dialog (gboolean on)
static gboolean delay_dialog_cb (gpointer data)
gboolean busy_add_background (gint sender)
gboolean busy_remove_background (gint sender)
gboolean busy_add_foreground (gint sender, enum busy_dialog dialog_mode, const char *message)
gboolean busy_remove_foreground (gint sender)
gboolean is_busy_foreground ()
gboolean is_busy_background ()
void busy_set_pid (gint sender, GPid pid)
void busy_reset_pid (GPid pid)
static gboolean do_update_rgb_led (gpointer data)

Variables

const gint dialog_delay = 1000
const gint busyled_delay = 1000
static GSList * g_app_counters = NULL
static gchar * g_message = NULL
static guint g_dialog_source = 0
static guint g_background_count = 0
static guint g_foreground_count = 0

Define Documentation

#define UNUSED (  )     (void)(x)

Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 41 of file busy.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
BACKGROUND 
FOREGROUND 

Definition at line 61 of file busy.c.

00062 {
00063     BACKGROUND,
00064     FOREGROUND
00065 };


Function Documentation

gboolean busy_add_background ( gint  sender  ) 

Definition at line 100 of file busy.c.

References BACKGROUND, and count_ref().

Referenced by cb_sys_set_bg_busy(), start_phase_2(), sys_standby(), update_usb_state(), and usb_connect().

00101 {
00102 //    LOGPRINTF("entry");
00103     
00104     count_ref(sender, BACKGROUND);
00105     
00106     return TRUE;
00107 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean busy_add_foreground ( gint  sender,
enum busy_dialog  dialog_mode,
const char *  message 
)

Definition at line 120 of file busy.c.

References BUSY_DIALOG_DELAYED, BUSY_DIALOG_DIRECT, count_ref(), delay_dialog_cb(), dialog_delay, FOREGROUND, g_dialog_source, g_message, LOGPRINTF, and show_dialog().

Referenced by cb_sys_set_busy_led(), cb_sys_set_fg_busy(), child_new(), conn_connect(), do_poweroff(), do_unmount(), main(), on_phase_2_complete(), sys_restart(), and sys_set_card().

00121 {
00122     LOGPRINTF("entry");
00123 
00124     count_ref(sender, FOREGROUND);
00125 
00126     // replace message
00127     if (g_message)
00128     {
00129         g_free(g_message);
00130     }
00131     
00132     if (message)
00133     {
00134         g_message = g_strdup(message);
00135     }
00136     else
00137     {
00138         g_message = NULL;
00139     }
00140     
00141     if (dialog_mode == BUSY_DIALOG_DIRECT)
00142     {
00143         show_dialog(TRUE);
00144     }
00145     else if (dialog_mode == BUSY_DIALOG_DELAYED)
00146     {
00147         if (g_dialog_source == 0)
00148         {
00149             LOGPRINTF("delay %d ms before show busy DIALOG", dialog_delay);
00150             g_dialog_source = g_timeout_add(dialog_delay, delay_dialog_cb, NULL);
00151         }
00152         else
00153         {
00154             LOGPRINTF("already waiting for busy DIALOG");
00155         }
00156     }
00157 
00158     return TRUE;
00159 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean busy_remove_background ( gint  sender  ) 

Definition at line 110 of file busy.c.

References BACKGROUND, and count_unref().

Referenced by cb_sys_reset_bg_busy(), on_usb_read_device_state(), on_usb_read_online(), and start_phase_2().

00111 {
00112 //    LOGPRINTF("entry");
00113     
00114     count_unref(sender, BACKGROUND);
00115 
00116     return TRUE;
00117 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean busy_remove_foreground ( gint  sender  ) 

Definition at line 162 of file busy.c.

References count_unref(), and FOREGROUND.

Referenced by cb_sys_reset_fg_busy(), cb_sys_set_busy_led(), conn_set_initialising(), conn_stop(), on_card_indexed(), on_check_child_window(), on_child_new_timeout(), on_eject_continue(), on_phase_3_complete(), on_usb_connected(), and start_phase_2().

00163 {
00164 //    LOGPRINTF("entry");
00165 
00166     count_unref(sender, FOREGROUND);
00167     
00168     return TRUE;
00169 }

Here is the call graph for this function:

Here is the caller graph for this function:

void busy_reset_pid ( GPid  pid  ) 

Definition at line 200 of file busy.c.

References count_remove_pid().

00201 {
00202 //    LOGPRINTF("entry, pid [%d]", pid);
00203     
00204     count_remove_pid(pid);
00205 }

Here is the call graph for this function:

void busy_set_pid ( gint  sender,
GPid  pid 
)

Definition at line 192 of file busy.c.

References count_set_pid().

00193 {
00194 //    LOGPRINTF("entry, sender [%d] pid [%d]", sender, pid);
00195     
00196     count_set_pid(sender, pid);
00197 }

Here is the call graph for this function:

static void count_ref ( gint  sender,
gint  mode 
) [static]

Definition at line 290 of file busy.c.

References busy_count_t::bg_count, ERRORPRINTF, busy_count_t::fg_count, FOREGROUND, g_app_counters, LOGPRINTF, busy_count_t::sender, and update().

Referenced by busy_add_background(), and busy_add_foreground().

00291 {
00292     LOGPRINTF("entry sender [%d], %s", sender, mode == 0 ? "BACKGROUND" : "FOREGROUND");
00293     
00294     GSList *busy_ptr = g_app_counters;
00295     busy_count_t *cur_busy = NULL;
00296 
00297     // get application from list
00298     while (busy_ptr)
00299     {
00300         cur_busy = (busy_count_t *) busy_ptr->data;
00301 
00302         if (cur_busy->sender == sender)
00303         {
00304             // increment reference count
00305             if (mode == FOREGROUND)
00306             {
00307                 cur_busy->fg_count++;
00308             }
00309             cur_busy->bg_count++;
00310             LOGPRINTF("sender [%d] bg_count [%d] fg_count [%d]", sender, cur_busy->bg_count, cur_busy->fg_count);
00311 
00312             update();
00313             return;
00314         }
00315         busy_ptr = busy_ptr->next;
00316     }
00317     
00318     // application not yet in list, add now
00319     busy_count_t *busy = g_new0 (busy_count_t, 1);
00320     if (!busy)
00321     {
00322         ERRORPRINTF("mem alloc failed");
00323         return;
00324     }
00325     
00326     busy->sender = sender;
00327     if (mode == FOREGROUND)
00328     {
00329         busy->fg_count = 1;
00330     }
00331     busy->bg_count = 1;
00332     
00333     g_app_counters = g_slist_prepend(g_app_counters, busy);
00334     
00335     LOGPRINTF("sender [%d] bg_count [%d] fg_count [%d]", sender, busy->bg_count, busy->fg_count);
00336     update();
00337     return;
00338 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void count_remove_pid ( GPid  pid  )  [static]

Definition at line 380 of file busy.c.

References busy_count_t::bg_count, busy_count_t::fg_count, g_app_counters, LOGPRINTF, busy_count_t::pid, busy_count_t::sender, and update().

Referenced by busy_reset_pid().

00381 {
00382     LOGPRINTF("entry pid [%d]", pid);
00383     
00384     GSList *busy_ptr = g_app_counters;
00385     busy_count_t *cur_busy = NULL;
00386 
00387     // get application from list
00388     while (busy_ptr)
00389     {
00390         cur_busy = (busy_count_t *) busy_ptr->data;
00391         if (cur_busy->pid == pid)
00392         {
00393             LOGPRINTF("found pid [%d] sender [%d] bg count [%d] fg count [%d]", cur_busy->pid, cur_busy->sender, cur_busy->bg_count, cur_busy->fg_count);
00394             g_app_counters = g_slist_delete_link(g_app_counters, busy_ptr);
00395             update();
00396             return;
00397         }
00398         busy_ptr = busy_ptr->next;
00399     }
00400     
00401     return;
00402 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void count_set_pid ( gint  sender,
GPid  pid 
) [static]

Definition at line 253 of file busy.c.

References ERRORPRINTF, g_app_counters, LOGPRINTF, busy_count_t::pid, and busy_count_t::sender.

Referenced by busy_set_pid().

00254 {
00255     LOGPRINTF("entry sender [%d] pid [%d]", sender, pid);
00256     
00257     GSList *busy_ptr = g_app_counters;
00258     busy_count_t *cur_busy = NULL;
00259 
00260     // get application from list
00261     while (busy_ptr)
00262     {
00263         cur_busy = (busy_count_t *) busy_ptr->data;
00264 
00265         if (cur_busy->sender == sender)
00266         {
00267             cur_busy->pid = pid;
00268             return;
00269         }
00270         busy_ptr = busy_ptr->next;
00271     }
00272     
00273     // application not yet in list, add now
00274     busy_count_t *busy = g_new0 (busy_count_t, 1);
00275     if (!busy)
00276     {
00277         ERRORPRINTF("mem alloc failed");
00278         return;
00279     }
00280     
00281     busy->sender = sender;
00282     busy->pid = pid;
00283     
00284     g_app_counters = g_slist_prepend(g_app_counters, busy);
00285     
00286     return;
00287 }

Here is the caller graph for this function:

static void count_unref ( gint  sender,
gint  mode 
) [static]

Definition at line 341 of file busy.c.

References busy_count_t::bg_count, busy_count_t::fg_count, FOREGROUND, g_app_counters, LOGPRINTF, busy_count_t::sender, and update().

Referenced by busy_remove_background(), and busy_remove_foreground().

00342 {
00343     LOGPRINTF("entry sender [%d], mode [%d]", sender, mode);
00344     
00345     GSList *busy_ptr = g_app_counters;
00346     busy_count_t *cur_busy = NULL;
00347 
00348     // get application from list
00349     while (busy_ptr)
00350     {
00351         cur_busy = (busy_count_t *) busy_ptr->data;
00352 
00353         if (cur_busy->sender == sender)
00354         {
00355             // decrement reference count
00356             if (mode == FOREGROUND)
00357             {
00358                 if (cur_busy->fg_count > 0)
00359                 {
00360                     cur_busy->fg_count--;
00361                 }
00362             }
00363             if (cur_busy->bg_count > 0)
00364             {
00365                 cur_busy->bg_count--;
00366             }
00367             
00368             LOGPRINTF("sender [%d] bg_count [%d] fg_count [%d]", sender, cur_busy->bg_count, cur_busy->fg_count);
00369             
00370             update();
00371             return;
00372         }
00373         busy_ptr = busy_ptr->next;
00374     }
00375     
00376     return;
00377 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean delay_dialog_cb ( gpointer  data  )  [static]

Definition at line 233 of file busy.c.

References FOREGROUND, g_dialog_source, LOGPRINTF, ref_count(), show_dialog(), and UNUSED.

Referenced by busy_add_foreground().

00234 {
00235     UNUSED(data);
00236     LOGPRINTF("entry");
00237 
00238     if (ref_count(FOREGROUND) > 0)
00239     {
00240         show_dialog(TRUE);
00241     }
00242     else
00243     {
00244         LOGPRINTF("busy DIALOG not needed anymore");
00245     }
00246     
00247     g_dialog_source = 0;
00248     // remove source
00249     return FALSE;
00250 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean do_update_rgb_led ( gpointer  data  )  [static]

Definition at line 429 of file busy.c.

References sys_update_rgb_led(), and UNUSED.

Referenced by update().

00430 {
00431     UNUSED(data);
00432     sys_update_rgb_led();
00433     return FALSE;
00434 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean is_busy_background ( void   ) 

Definition at line 182 of file busy.c.

References g_background_count.

Referenced by on_idle_timeout().

00183 {
00184     if (g_background_count > 0)
00185     {
00186         return TRUE;
00187     }
00188     return FALSE;
00189 }

Here is the caller graph for this function:

gboolean is_busy_foreground ( void   ) 

File Name : busy.h

Description: Busy functions Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 172 of file busy.c.

References g_foreground_count.

Referenced by sys_update_rgb_led().

00173 {
00174     if (g_foreground_count > 0)
00175     {
00176         return TRUE;
00177     }
00178     return FALSE;
00179 }

Here is the caller graph for this function:

static gint ref_count ( gint  mode  )  [static]

Definition at line 405 of file busy.c.

References FOREGROUND, g_app_counters, and LOGPRINTF.

Referenced by delay_dialog_cb(), and update().

00406 {
00407 //    LOGPRINTF("entry");
00408     
00409     gint count = 0;
00410     GSList *busy_ptr = g_app_counters;
00411     while (busy_ptr)
00412     {
00413         if (mode == FOREGROUND)
00414             count += ((busy_count_t *) busy_ptr->data)->fg_count;
00415         else
00416             count += ((busy_count_t *) busy_ptr->data)->bg_count;
00417         busy_ptr = busy_ptr->next;
00418     }
00419     
00420     if (mode == FOREGROUND)
00421       LOGPRINTF("foreground [%d]", count);
00422     else 
00423       LOGPRINTF("background [%d]", count);
00424     
00425     return count;
00426 }

Here is the caller graph for this function:

static void show_dialog ( gboolean  on  )  [static]

Definition at line 212 of file busy.c.

References g_message, ipc_show_busy(), and LOGPRINTF.

Referenced by busy_add_foreground(), delay_dialog_cb(), and update().

00213 {
00214     static gboolean is_shown = FALSE;
00215     
00216     LOGPRINTF("entry: on [%d] is_shown [%d]", on, is_shown);
00217 
00218     if (on && !is_shown)
00219     {
00220         LOGPRINTF("show busy DIALOG!");
00221         ipc_show_busy(TRUE, g_message);
00222         is_shown = TRUE;
00223     }
00224     else if (!on && is_shown)
00225     {
00226         LOGPRINTF("hide busy DIALOG!");
00227         ipc_show_busy(FALSE, NULL);
00228         is_shown = FALSE;
00229     }
00230 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void update ( void   )  [static]

Definition at line 437 of file busy.c.

References BACKGROUND, busyled_delay, do_update_rgb_led(), FOREGROUND, g_background_count, g_dialog_source, g_foreground_count, LOGPRINTF, ref_count(), show_dialog(), sys_reset_idle_time(), and sys_update_rgb_led().

Referenced by count_ref(), count_remove_pid(), and count_unref().

00438 {
00439     LOGPRINTF("entry: background [%d] foreground [%d]", ref_count(BACKGROUND), ref_count(FOREGROUND));
00440     
00441     guint old_foreground_count = g_foreground_count;
00442     g_background_count = ref_count(BACKGROUND);
00443     g_foreground_count = ref_count(FOREGROUND);
00444     
00445     if (g_background_count == 0)
00446     {
00447         // reset idle because a screen update may follow
00448         // which resets the idle time anyhow
00449         sys_reset_idle_time();
00450     }
00451 
00452     if (g_foreground_count != old_foreground_count)
00453     {
00454         if (g_foreground_count == 1)
00455         {
00456             g_timeout_add(busyled_delay, do_update_rgb_led, NULL);
00457         }
00458         else if (g_foreground_count == 0)
00459         {
00460             if (g_dialog_source)
00461             {
00462                 LOGPRINTF("stop busy dialog timer");
00463                 g_source_remove(g_dialog_source);
00464                 g_dialog_source = 0;
00465             }
00466             sys_update_rgb_led();
00467             show_dialog(FALSE);
00468         }
00469     }
00470 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const gint busyled_delay = 1000

Definition at line 68 of file busy.c.

Referenced by update().

const gint dialog_delay = 1000

Definition at line 67 of file busy.c.

Referenced by busy_add_foreground().

GSList* g_app_counters = NULL [static]

Definition at line 75 of file busy.c.

Referenced by count_ref(), count_remove_pid(), count_set_pid(), count_unref(), and ref_count().

guint g_background_count = 0 [static]

Definition at line 78 of file busy.c.

Referenced by is_busy_background(), and update().

guint g_dialog_source = 0 [static]

Definition at line 77 of file busy.c.

Referenced by busy_add_foreground(), delay_dialog_cb(), and update().

guint g_foreground_count = 0 [static]

Definition at line 79 of file busy.c.

Referenced by is_busy_foreground(), and update().

gchar* g_message = NULL [static]

Definition at line 76 of file busy.c.

Referenced by busy_add_foreground(), and show_dialog().

Generated by  doxygen 1.6.2-20100208