Changeset 2316

Show
Ignore:
Timestamp:
06/29/07 15:21:26
Author:
murrayc
Message:

2007-06-29 Murray Cumming <murrayc@murrayc.com>

        • libtinymail-maemo/tny-maemo-conic-device.c:

(on_connection_event), (tny_maemo_conic_device_connect):
Use a second mainloop instead of iterating the main mainloop. This
seems more robust and is probably the recommended way to do it.
There is lots of debug output here, which I will remove later after
further investigations.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r2312 r2316  
     12007-06-29  Murray Cumming  <murrayc@murrayc.com> 
     2        * libtinymail-maemo/tny-maemo-conic-device.c:  
     3        (on_connection_event), (tny_maemo_conic_device_connect): 
     4        Use a second mainloop instead of iterating the main mainloop. This  
     5        seems more robust and is probably the recommended way to do it. 
     6        There is lots of debug output here, which I will remove later after  
     7        further investigations. 
     8 
    192007-06-29  Philip Van Hoof  <pvanhoof@gnome.org> 
    210 
  • trunk/libtinymail-maemo/tny-maemo-conic-device.c

    r2309 r2316  
    6060        gboolean        forced; /* Whether the is_online value is forced rather than real. */ 
    6161         
    62         /* When TRUE, we are waiting for the success or failure signal. */ 
    63         gboolean attempting_connection
     62        /* When non-NULL, we are waiting for the success or failure signal. */ 
     63        GMainLoop *loop
    6464         
    6565#ifdef MAEMO_CONIC_DUMMY         
     
    9090} 
    9191 
     92static void  
     93stop_loop(TnyMaemoConicDevice *self) 
     94{ 
     95        TnyMaemoConicDevicePriv *priv 
     96                = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 
     97 
     98        if (priv->loop) { 
     99                g_main_loop_quit (priv->loop); 
     100        } 
     101} 
    92102 
    93103static void 
     
    127137                is_online = TRUE; 
    128138                 
    129                 /* Set this to FALSE to stop blocking  
    130                  * tny_maemo_conic_device_connect(): */ 
    131                 if (priv->attempting_connection) 
    132                         priv->attempting_connection = FALSE; 
     139                /* Stop blocking  
     140                 * tny_maemo_conic_device_connect(), if we are: */ 
     141                stop_loop (device); 
    133142                         
    134143                g_message ("new status: CONNECTED (%s)", priv->iap); 
     
    138147                is_online = FALSE; 
    139148                 
    140                 /* Set this to FALSE to stop blocking  
    141                  * tny_maemo_conic_device_connect(): */ 
    142                 if (priv->attempting_connection) 
    143                         priv->attempting_connection = FALSE; 
     149                /* Stop blocking  
     150                 * tny_maemo_conic_device_connect(), if we are: */ 
     151                stop_loop (device); 
    144152                         
    145153                g_message ("new status: DISCONNECTED"); 
     
    160168} 
    161169 
    162  
    163  
    164170/** 
    165171 * tny_maemo_conic_device_connect: 
     
    188194        g_message ("connecting to %s", iap_id ? iap_id : "<any>"); 
    189195         
     196        priv->loop = g_main_loop_new(NULL, FALSE /* not running immediately. */); 
     197 
     198        gboolean request_failed = FALSE; 
    190199        if (iap_id) { 
    191                 priv->attempting_connection = TRUE; 
    192                  
    193200                if (!con_ic_connection_connect_by_id (priv->cnx, iap_id, CON_IC_CONNECT_FLAG_NONE)) { 
    194201                        g_warning ("could not send connect_by_id dbus message"); 
    195                         return FALSE; 
     202                        request_failed = TRUE; 
    196203                } 
    197204        } else { 
    198                 priv->attempting_connection = TRUE; 
    199                  
     205printf ("debug2\n"); 
    200206                if (!con_ic_connection_connect (priv->cnx, CON_IC_CONNECT_FLAG_NONE)) { 
    201207                        g_warning ("could not send connect dbus message"); 
    202                         return FALSE; 
     208                        request_failed = TRUE; 
    203209                } 
     210printf ("debug3\n"); 
     211        } 
     212 
     213        if (request_failed) { 
     214                g_object_unref (priv->loop); 
     215                priv->loop = NULL; 
    204216        } 
    205217         
     
    207219         * CON_IC_STATUS_DISCONNECTED event: */ 
    208220          
    209         /* When the signal has been handled,  
    210          * attempting_connection will be reset to FALSE. */ 
    211         while (priv->attempting_connection) { 
    212                 /* Iterate the main loop so that the signal can be called. */ 
    213                 if (g_main_context_pending (NULL)) { 
    214                         g_main_context_iteration (NULL, FALSE); 
    215                 } 
    216         } 
    217          
     221printf ("debug4\n"); 
     222        /* This is based on code found in gtk_dialog_run(): */ 
     223        /* GDK_THREADS_LEAVE(); */ 
     224printf ("debug5\n"); 
     225        /* Run until g_main_loop_quit() is called by our signal handler. */ 
     226        g_main_loop_run (priv->loop); 
     227printf ("debug6\n"); 
     228        /* GDK_THREADS_ENTER(); */ 
     229printf ("debug7\n"); 
     230        g_main_loop_unref (priv->loop); 
     231printf ("debug8\n"); 
     232        priv->loop = NULL; 
     233 
    218234        return priv->is_online; 
    219235} 
     
    259275                } 
    260276#endif /* MAEMO_CONIC_DUMMY*/ 
     277 
     278        printf ("DEBUG: %s: end.\n", __FUNCTION__); 
    261279        return TRUE; 
    262280}