Changeset 2057

Show
Ignore:
Timestamp:
05/28/07 13:11:11
Author:
murrayc
Message:

2007-05-28 Murray Cumming <murrayc@murrayc.com>

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

(tny_maemo_conic_device_get_current_iap_id),
(on_dummy_connection_check),
(tny_maemo_conic_device_instance_init),
(tny_maemo_conic_device_finalize): Use a file (/home/murrayc/maemo_conic_dummy_id)
instead of an environment variable to set the dummy ID when using
scratchbox so we can check it for changes every 1 second.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r2055 r2057  
     12007-05-28  Murray Cumming  <murrayc@murrayc.com> 
     2 
     3        * libtinymail-maemo/tny-maemo-conic-device.c: 
     4        (tny_maemo_conic_device_get_current_iap_id), 
     5        (on_dummy_connection_check), 
     6        (tny_maemo_conic_device_instance_init), 
     7        (tny_maemo_conic_device_finalize): Use a file ($HOME/maemo_conic_dummy_id)  
     8        instead of an environment variable to set the dummy ID when using  
     9        scratchbox so we can check it for changes every 1 second. 
     10         
    1112007-05-28  Philip Van Hoof  <pvanhoof@gnome.org> 
    212 
  • trunk/libtinymail-maemo/tny-maemo-conic-device.c

    r2045 r2057  
    3939        gchar *bearer; 
    4040}; 
     41 
     42#define MAEMO_CONIC_DUMMY_IAP_ID_FILENAME "maemo_conic_dummy_id" 
     43static gboolean on_dummy_connection_check (gpointer user_data); 
    4144#endif /* MAEMO_CONIC_DUMMY */ 
    4245 
     
    5053        gchar     *iap; 
    5154        gboolean        forced; /* Whether the is_online value is forced rather than real. */ 
     55         
     56#ifdef MAEMO_CONIC_DUMMY         
     57        gint dummy_env_check_timeout; 
     58#endif /* MAEMO_CONIC_DUMMY */ 
    5259} TnyMaemoConicDevicePriv; 
    5360 
     
    8996 
    9097        g_message (__FUNCTION__); 
    91          
    92 #ifdef MAEMO_CONIC_DUMMY 
    93         /* HACK: outsmarting libconic by emitting signal regardless of the reported connection status */ 
    94         g_signal_emit (device, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 
    95                        0, TRUE); 
    96         return; 
    97 #endif /*MAEMO_CONIC_DUMMY*/ 
    98  
    99          
     98 
    10099        switch (con_ic_connection_event_get_error(event)) { 
    101100        case CON_IC_CONNECTION_ERROR_NONE: 
     
    238237        g_return_val_if_fail (tny_maemo_conic_device_is_online(TNY_DEVICE(self)), NULL); 
    239238 
     239        TnyMaemoConicDevicePriv *priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 
    240240         
    241241        #ifdef MAEMO_CONIC_DUMMY 
    242         /* Allow debuggers to fake a connection change by setting an environment  
    243          * variable. This should match one of the fake iap IDs that we  
    244          * created in tny_maemo_conic_device_get_iap_list(). 
    245          */ 
    246         const gchar *env = g_getenv ("MAEMO_CONIC_DUMMY_IAP_ID"); 
    247         return env; 
    248         #else 
    249         TnyMaemoConicDevicePriv *priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 
     242        if (!(priv->iap)) { 
     243                on_dummy_connection_check (self); 
     244        } 
     245        #endif 
     246         
    250247        return priv->iap; 
    251         #endif 
    252 
     248
     249 
    253250 
    254251 
     
    430427} 
    431428 
     429#ifdef MAEMO_CONIC_DUMMY 
     430static gboolean on_dummy_connection_check (gpointer user_data) 
     431{ 
     432        TnyMaemoConicDevice *self = TNY_MAEMO_CONIC_DEVICE (user_data); 
     433        TnyMaemoConicDevicePriv *priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 
     434                 
     435        /* Check whether the enviroment variable has changed,  
     436         * so we can fake a connection change: */ 
     437        gchar *filename = g_build_filename ( 
     438                g_get_home_dir (),  
     439                MAEMO_CONIC_DUMMY_IAP_ID_FILENAME, 
     440                NULL); 
     441                 
     442        gchar *contents = 0; 
     443        GError* error = 0; 
     444        gboolean test = g_file_get_contents (filename, &contents, NULL, &error); 
     445        if(error) { 
     446                /* printf("%s: error from g_file_get_contents(): %s\n", __FUNCTION__, error->message); */ 
     447                g_error_free (error); 
     448                error = NULL; 
     449        } 
     450         
     451        if (!test || !contents) { 
     452                /* Default to the first debug connection: */ 
     453                contents = g_strdup ("debug id0"); 
     454        } 
     455 
     456        if (!(priv->iap) || (strcmp (contents, priv->iap) != 0)) { 
     457                priv->iap = g_strdup (contents); 
     458                 
     459                printf ("DEBUG: TnyMaemoConicDevice: %s:\n  Dummy connection changing to %s\n", __FUNCTION__, priv->iap); 
     460                g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 
     461                       0, TRUE); 
     462        } 
     463         
     464        g_free (contents); 
     465        g_free (filename); 
     466         
     467        return TRUE; 
     468} 
     469#endif /* MAEMO_CONIC_DUMMY */ 
     470 
     471 
    432472 
    433473static void 
     
    455495        priv->is_online     = FALSE;  
    456496        priv->forced = FALSE; 
    457 
    458  
     497         
     498        #ifdef MAEMO_CONIC_DUMMY 
     499        /* Allow debuggers to fake a connection change by setting an environment  
     500         * variable, which we check ever 1 second. 
     501         * This should match one of the fake iap IDs that we created in  
     502         * tny_maemo_conic_device_get_iap_list(). 
     503         */ 
     504        priv->dummy_env_check_timeout =  
     505                g_timeout_add (1000, on_dummy_connection_check, self); 
     506        #endif /* MAEMO_CONIC_DUMMY */ 
     507
    459508 
    460509 
     
    483532        } 
    484533 
     534        #ifdef MAEMO_CONIC_DUMMY 
     535        if (priv->dummy_env_check_timeout) { 
     536                g_source_remove (priv->dummy_env_check_timeout); 
     537                priv->dummy_env_check_timeout = 0; 
     538        } 
     539        #endif /* MAEMO_CONIC_DUMMY */ 
     540         
    485541        if (priv->iap) { 
    486542                g_free (priv->iap); 
    487543                priv->iap = NULL; 
    488544        } 
     545         
    489546 
    490547        (*parent_class->finalize) (obj);