contentLister/inc/timedids.h File Reference

control - handle timed-iDS connection More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tzhead

Defines

#define TZ_FILE   "/etc/localtime"

Enumerations

enum  timedids_connect_reason { connect_after_wakeup, connect_when_running, connect_undefined }

Functions

void timed_ids_init ()
void timed_ids_final ()
gboolean on_timedids_connect_after_wakeup (gpointer p)
void timed_ids_handle_connmgr_quit ()
void timed_ids_handle_reread_settings ()
void timed_ids_handle_recreate_timer (gint interval)
timedids_connect_reason get_timedids_connect_reason ()
void set_timedids_connect_reason (timedids_connect_reason connReason)


Detailed Description

control - handle timed-iDS connection

<File description>="">

Definition in file timedids.h.


Define Documentation

#define TZ_FILE   "/etc/localtime"

Definition at line 33 of file timedids.h.


Enumeration Type Documentation

Enumerator:
connect_after_wakeup 
connect_when_running 
connect_undefined 

Definition at line 35 of file timedids.h.


Function Documentation

timedids_connect_reason get_timedids_connect_reason (  ) 

Definition at line 402 of file timedids.c.

00403 {
00404     return g_connect_reason;
00405 }

gboolean on_timedids_connect_after_wakeup ( gpointer  p  ) 

Definition at line 146 of file timedids.c.

00147 {
00148     CL_LOGPRINTF("entry");
00149 
00150     // Launch connectionMgr to download contents (include software updates if needed)
00151     ctrl_disconnect_wait();
00152     if (g_timedids_settings->swUpdate)
00153     {
00154         ctrl_connect(connectScrDownloadHistory, connect_timed_ids_with_sw);
00155     }
00156     else
00157     {
00158         ctrl_connect(connectScrDownloadHistory, connect_timed_ids_content_only);
00159     }
00160 
00161     display_update_decrease_level(LISTER_EXPOSE_LEVEL);
00162 
00163     return FALSE;
00164 }

Here is the call graph for this function:

void set_timedids_connect_reason ( timedids_connect_reason  connReason  ) 

Definition at line 407 of file timedids.c.

00408 {
00409     g_connect_reason = connReason;
00410 }

void timed_ids_final (  ) 

Definition at line 304 of file timedids.c.

00305 {
00306     CL_LOGPRINTF("entry");
00307  
00308     if (g_timedids_settings->enable)
00309     {
00310         // Re-create RTC alarm interrupt
00311         time_t utc_second = time(NULL);
00312         int local_second = (utc_second + g_current_tzoffset) % SECONDS_OF_DAY;
00313 
00314         int i;
00315         for(i=0; i<g_timedids_settings->timeCnt; i++)
00316         {
00317             if (g_timedids_settings->timeSet[i] > local_second)
00318             {
00319                 break;
00320             }
00321         }
00322 
00323         if (i == g_timedids_settings->timeCnt)
00324         {
00325             i = 0;
00326         }
00327         
00328         int utc_alarm = g_timedids_settings->timeSet[i] - g_current_tzoffset;
00329         if (utc_alarm < 0)
00330         {
00331             utc_alarm += SECONDS_OF_DAY;
00332         }
00333         else if (utc_alarm > SECONDS_OF_DAY)
00334         {
00335             utc_alarm -= SECONDS_OF_DAY;
00336         }
00337 
00338         struct rtc_time rtc_tm;
00339         memset(&rtc_tm, 0, sizeof(struct rtc_time));
00340         rtc_tm.tm_hour = utc_alarm / 3600;
00341         rtc_tm.tm_min  = utc_alarm / 60 % 60;
00342         rtc_tm.tm_sec  = utc_alarm % 60;
00343        
00344         // Open device
00345         int rtc, ret;
00346         rtc = open ("/dev/rtc", O_RDWR);
00347         if (rtc == -1)
00348         {
00349             CL_ERRORPRINTF("Can NOT open /dev/rtc");
00350             return;
00351         }
00352 
00353         // Re-set RTC alarm to the next timeset in registry
00354         ret = ioctl(rtc, RTC_ALM_SET, &rtc_tm);
00355         if (ret == -1)
00356         {
00357             CL_ERRORPRINTF("Can NOT set RTC alarm");
00358             return;
00359         }
00360 
00361         CL_WARNPRINTF("RTC Alarm is set to %02d:%02d:%02d\n", rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
00362         
00363         // Re-enable RTC alarm interrupt
00364         ret = ioctl(rtc, RTC_AIE_ON, 0);
00365         if (ret == -1)
00366         {
00367             CL_ERRORPRINTF("Can NOT enable RTC alarm interrupt");
00368             return;
00369         }
00370 
00371         close(rtc);
00372     }
00373     
00374     erRegFreeTimedIds(g_timedids_settings);
00375 }

Here is the call graph for this function:

void timed_ids_handle_connmgr_quit (  ) 

Definition at line 230 of file timedids.c.

00231 {
00232     CL_LOGPRINTF("entry");
00233     switch (g_connect_reason)
00234     {
00235         case connect_after_wakeup:
00236             if (g_timedids_settings->switchOff)
00237             {
00238                 // Shut down iLiad, and also create RTC alarm for the next trigger point
00239                 ctrl_shutdown();
00240             }
00241             else
00242             {
00243                 create_timedids_trigger();
00244 
00245                 button_block_all_keys(FALSE);
00246             }
00247             break;
00248         case connect_when_running:
00249             // Create time-out event for the next trigger point
00250             create_timedids_trigger();
00251             break;
00252         default:
00253             break;
00254     }
00255 }

Here is the call graph for this function:

void timed_ids_handle_recreate_timer ( gint  interval  ) 

Definition at line 218 of file timedids.c.

00219 {
00220     if (g_timeout_source_id > 0)
00221     {
00222         g_source_remove(g_timeout_source_id);
00223         g_timeout_source_id = 0;
00224     }
00225 
00226     g_timeout_source_id = g_timeout_add(interval * 60 * 1000,
00227             on_idle_connect_start_background, (gpointer)connect_timed_ids_background);
00228 }

Here is the call graph for this function:

void timed_ids_handle_reread_settings (  ) 

Definition at line 257 of file timedids.c.

00258 {
00259     CL_LOGPRINTF("entry");
00260 
00261     // Re-read timed-iDS connection settings
00262     regTimedIds_t* stored_timedids_settings = NULL;
00263     if ((stored_timedids_settings = read_timedids_settings()) == NULL)
00264     {
00265         CL_ERRORPRINTF("Can NOT read timed-iDS connection settings");
00266         return;
00267     }
00268 
00269     int new_tzoffset = get_current_tz_offset();
00270     gboolean settings_changed = FALSE;
00271 
00272     if (memcmp(stored_timedids_settings, g_timedids_settings, sizeof(regTimedIds_t)) != 0)
00273     {
00274         // User changed timed-iDS connection settings
00275         *g_timedids_settings = *stored_timedids_settings;
00276         settings_changed = TRUE;
00277     }
00278     if (new_tzoffset != g_current_tzoffset)
00279     {
00280         // User changed timezone
00281         g_current_tzoffset = new_tzoffset;
00282         settings_changed = TRUE;
00283     }
00284 
00285     if (settings_changed)
00286     {
00287         // First, remove current time-out trigger
00288         if (g_timeout_source_id > 0)
00289         {
00290             g_source_remove(g_timeout_source_id);
00291             g_timeout_source_id = 0;
00292         }
00293 
00294         // Second, re-create time-out trigger if timed-iDS enabled
00295         if (g_timedids_settings->enable)
00296         {
00297             create_timedids_trigger();
00298         }
00299     }
00300 
00301     erRegFreeTimedIds(stored_timedids_settings);    
00302 }

Here is the call graph for this function:

void timed_ids_init (  ) 

Definition at line 85 of file timedids.c.

00086 {
00087     CL_LOGPRINTF("entry");
00088     
00089     // Check if we are waken up by RTC alarm interrupt or not
00090     // Get settings from registry
00091     if ((g_timedids_settings = read_timedids_settings()) == NULL)
00092     {
00093         CL_ERRORPRINTF("Can NOT read timed-iDS connection settings");
00094         return;
00095     }
00096 
00097     // Get current timezone offset
00098     g_current_tzoffset = get_current_tz_offset();
00099 
00100     if (!g_timedids_settings->enable)
00101     {
00102         // Nothing to do
00103         return;
00104     }
00105 
00106     time_t utc_second = time(NULL);
00107     struct tm* tm_local =  localtime(&utc_second);
00108     int local_second = tm_local->tm_hour * 3600 + tm_local->tm_min * 60 + tm_local->tm_sec;
00109     
00110     gboolean wakeup_by_alarm = FALSE;
00111     int i;
00112     for (i=0; i<g_timedids_settings->timeCnt; i++)
00113     {
00114         // If current time is <90 seconds later than 1 alarm time,
00115         // then we think we are being waken up by alarm interrupt
00116         if (local_second > g_timedids_settings->timeSet[i] &&
00117             local_second - g_timedids_settings->timeSet[i] <= 90)
00118         {
00119             wakeup_by_alarm = TRUE;
00120             break;
00121         }
00122     }
00123 
00124     if (wakeup_by_alarm)
00125     {
00126         // The iLiad is waken up by RTC alarm interrupt
00127         handle_wakeup();
00128     }
00129     else
00130     {
00131         // Normal startup
00132         handle_normal_startup();
00133     }
00134 }

Here is the call graph for this function:


Generated on Sun Dec 14 17:13:02 2008 by  doxygen 1.5.6