00001 #include "sa_sensor_mark.h" 00002 00003 #if __MARK_ENABLED__ 00004 00005 #include "er_errors.h" 00006 #include "ld_logging.h" 00007 #include "sa_sensor_list_log_db.h" 00008 #include "ut_timer.h" 00009 00010 #include "common/error_list.h" 00011 #include "common/logging.h" 00012 #include "common/platform_error.h" 00013 #include "common/utilities.h" 00014 00015 #include <errno.h> 00016 #include <stdlib.h> 00017 #include <sys/time.h> 00018 #include <time.h> 00019 00020 struct _sa_Sensor_mark { 00021 ut_Timer* timer; 00022 LogDb* log; // not owned, no refcounting 00023 }; 00024 00025 static void timerCallback(void* userdata, GError* timerError); 00026 00027 static gboolean setTimer(sa_Sensor_mark* self, GError** error) 00028 { 00029 int wait_secs = 10 * 60; 00030 return ut_Timer_set_after(self->timer, wait_secs, error); 00031 } 00032 00033 // Takes ownership of any timerError. 00034 static void timerCallback(void* userdata, GError* timerError) 00035 { 00036 sa_Sensor_mark* self = (sa_Sensor_mark*)userdata; 00037 00038 if (timerError) 00039 goto fail; 00040 00041 // Log "sensor" event. 00042 { 00043 //logt("MARK"); 00044 GError* localError = NULL; 00045 if (!log_db_log_mark(self->log, "mark", &localError)) { 00046 gx_txtlog_fatal_error_free(localError); 00047 return; 00048 } 00049 } 00050 00051 // Schedule next timer event. 00052 if (!setTimer(self, &timerError)) { 00053 goto fail; 00054 } 00055 return; 00056 00057 fail: 00058 { 00059 gx_dblog_fatal_error_free(self->log, timerError); 00060 } 00061 } 00062 00063 EXTERN_C sa_Sensor_mark* sa_Sensor_mark_new(LogDb* log, GError** error) 00064 { 00065 sa_Sensor_mark* self = g_try_new0(sa_Sensor_mark, 1); 00066 if (G_UNLIKELY(!self)) { 00067 if (error) *error = gx_error_no_memory; 00068 return NULL; 00069 } 00070 self->log = log; 00071 self->timer = ut_Timer_new(self, &timerCallback, error); 00072 if (!self->timer) { 00073 sa_Sensor_mark_destroy(self); 00074 return NULL; 00075 } 00076 return self; 00077 } 00078 00079 EXTERN_C void sa_Sensor_mark_destroy(sa_Sensor_mark* self) 00080 { 00081 if (self) { 00082 if (self->timer) { 00083 sa_Sensor_mark_stop(self); 00084 ut_Timer_destroy(self->timer); 00085 } 00086 g_free(self); 00087 } 00088 } 00089 00090 EXTERN_C gboolean sa_Sensor_mark_start(sa_Sensor_mark* self, GError** error) 00091 { 00092 if (!sa_Sensor_mark_is_active(self)) { 00093 //logt("START MARK"); 00094 if (!log_db_log_mark(self->log, "start", error)) // begin mark 00095 return FALSE; 00096 00097 if (!setTimer(self, error)) 00098 return FALSE; 00099 } 00100 return TRUE; 00101 } 00102 00103 EXTERN_C void sa_Sensor_mark_stop(sa_Sensor_mark* self) 00104 { 00105 if (sa_Sensor_mark_is_active(self)) { 00106 ut_Timer_cancel(self->timer); 00107 //logt("END MARK"); 00108 log_db_log_mark(self->log, "stop", NULL); // end mark 00109 } 00110 } 00111 00112 EXTERN_C gboolean sa_Sensor_mark_is_active(sa_Sensor_mark* self) 00113 { 00114 return ut_Timer_is_active(self->timer); 00115 } 00116 00117 #endif /* __MARK_ENABLED__ */ 00118 00119 /** 00120 00121 sa_sensor_mark.c 00122 00123 Copyright 2009 Helsinki Institute for Information Technology (HIIT) 00124 and the authors. All rights reserved. 00125 00126 Authors: Tero Hasu <tero.hasu@hut.fi> 00127 00128 Permission is hereby granted, free of charge, to any person 00129 obtaining a copy of this software and associated documentation files 00130 (the "Software"), to deal in the Software without restriction, 00131 including without limitation the rights to use, copy, modify, merge, 00132 publish, distribute, sublicense, and/or sell copies of the Software, 00133 and to permit persons to whom the Software is furnished to do so, 00134 subject to the following conditions: 00135 00136 The above copyright notice and this permission notice shall be 00137 included in all copies or substantial portions of the Software. 00138 00139 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00140 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00141 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00142 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00143 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00144 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00145 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00146 SOFTWARE. 00147 00148 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:56 2011 by Doxygen 1.6.1