00001 /* 00002 * This file is part of contentLister. 00003 * 00004 * contentLister is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * contentLister is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00040 #include <stdio.h> 00041 #include <glib.h> 00042 00043 #include "contentListerLog.h" 00044 #include "pincodeIdleTime.h" 00045 00046 00047 static accumulateIdleTime_t *g_accumulate_idle_time = NULL; 00048 00049 // internally functions forward declarations 00050 //static gboolean accumulate_idle_time_increase(gpointer internal); 00051 static void accumulate_idle_time_set(gint value); 00052 00053 void accumulate_idle_time_begin() 00054 { 00055 CL_LOGPRINTF("ACCUMULATE_IDLE_TIME_BEGIN"); 00056 accumulateIdleTime_t *idle_time = NULL; 00057 00058 if (NULL != g_accumulate_idle_time) 00059 { 00060 accumulate_idle_time_end(); 00061 } 00062 00063 idle_time = g_new0(accumulateIdleTime_t, 1); 00064 g_return_if_fail(NULL != idle_time); 00065 00066 // set the default value 00067 idle_time->milliseconds = 0; 00068 idle_time->threshold = 0; // default no threshold 00069 idle_time->callback_on_threshold = NULL; 00070 idle_time->internal = TIMEOUT_INTERNAL; 00071 // idle_time->timeout_handler_id = g_timeout_add( idle_time->internal, 00072 // accumulate_idle_time_increase, 00073 // (gpointer) idle_time->internal ); 00074 00075 g_accumulate_idle_time = idle_time; 00076 } 00077 00078 void accumulate_idle_time_end() 00079 { 00080 CL_LOGPRINTF("ACCUMULATE_IDLE_TIME_END"); 00081 00082 if (g_accumulate_idle_time) 00083 { 00084 if (g_accumulate_idle_time->timeout_handler_id) 00085 { 00086 g_source_remove(g_accumulate_idle_time->timeout_handler_id); 00087 } 00088 g_free(g_accumulate_idle_time); 00089 g_accumulate_idle_time = NULL; 00090 } 00091 } 00092 00093 // because in future user can decide how many milliseconds being idle for 00094 // let device go to screen lock or power down 00095 void accumulate_idle_time_set_threshold(gint threshold) 00096 { 00097 accumulateIdleTime_t *idle_time = g_accumulate_idle_time; 00098 00099 if (idle_time) 00100 { 00101 idle_time->threshold = threshold; 00102 } 00103 } 00104 00105 // in pincode's case, callback functions can be "go to screen lock" or "power down" 00106 void accumulate_idle_time_set_callback(on_threshold_t * func) 00107 { 00108 accumulateIdleTime_t *idle_time = g_accumulate_idle_time; 00109 00110 if (idle_time) 00111 { 00112 idle_time->callback_on_threshold = func; 00113 } 00114 } 00115 00116 // normally, call it to zero idle time when there are user activities happened 00117 void accumulate_idle_time_reset() 00118 { 00119 CL_LOGPRINTF("ACCUMULATE_IDLE_TIME_SET"); 00120 00121 accumulate_idle_time_set(0); 00122 } 00123 00124 // internal functions 00125 /**** 00126 static gboolean accumulate_idle_time_increase(gpointer internal) 00127 { 00128 accumulateIdleTime_t *idle_time = g_accumulate_idle_time; 00129 00130 if (idle_time) 00131 { 00132 idle_time->milliseconds += (gint) internal; 00133 00134 // if reached the threshold, call callback_on_threshold 00135 if (0 != idle_time->threshold) 00136 { 00137 if (idle_time->milliseconds >= idle_time->threshold) 00138 { 00139 if (idle_time->callback_on_threshold) 00140 { 00141 idle_time->callback_on_threshold(); 00142 accumulate_idle_time_end(); 00143 } 00144 } 00145 } 00146 return TRUE; 00147 } 00148 else 00149 { 00150 return FALSE; 00151 } 00152 } 00153 ****/ 00154 00155 static void accumulate_idle_time_set(gint value) 00156 { 00157 accumulateIdleTime_t *idle_time = g_accumulate_idle_time; 00158 00159 if (idle_time) 00160 { 00161 idle_time->milliseconds = value; 00162 } 00163 } 00164 00165 gint accumulate_idle_time_get() 00166 { 00167 gint ms = 0; 00168 accumulateIdleTime_t *idle_time = g_accumulate_idle_time; 00169 00170 if (idle_time) 00171 { 00172 ms = idle_time->milliseconds; 00173 } 00174 return ms; 00175 }