runtime/plc_Linux_main.c
changeset 49 45dc6a944ab6
child 53 805abb954de2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/runtime/plc_Linux_main.c	Fri Sep 21 17:48:34 2007 +0200
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <signal.h>
+
+
+void timer_notify(sigval_t val)
+{
+    struct timespec CURRENT_TIME;
+    clock_gettime(CLOCK_REALTIME, &CURRENT_TIME);
+    __run();
+}
+
+void catch_signal(int sig)
+{
+  signal(SIGTERM, catch_signal);
+  signal(SIGINT, catch_signal);
+  printf("Got Signal %d\n",sig);
+}
+
+int main(int argc,char **argv)
+{
+    timer_t timer;
+    struct sigevent sigev;
+    long tv_nsec = 1000000 * (maxval(common_ticktime__,1)%1000);
+    time_t tv_sec = common_ticktime__/1000;
+    struct itimerspec timerValues;
+    
+    memset (&sigev, 0, sizeof (struct sigevent));
+    memset (&timerValues, 0, sizeof (struct itimerspec));
+    sigev.sigev_value.sival_int = 0;
+    sigev.sigev_notify = SIGEV_THREAD;
+    sigev.sigev_notify_attributes = NULL;
+    sigev.sigev_notify_function = timer_notify;
+    timerValues.it_value.tv_sec = tv_sec;
+    timerValues.it_value.tv_nsec = tv_nsec;
+    timerValues.it_interval.tv_sec = tv_sec;
+    timerValues.it_interval.tv_nsec = tv_nsec;
+
+    __init();
+
+    timer_create (CLOCK_REALTIME, &sigev, &timer);
+    timer_settime (timer, 0, &timerValues, NULL);
+    
+    /* install signal handler for manual break */
+    signal(SIGTERM, catch_signal);
+    signal(SIGINT, catch_signal);
+    
+    pause();
+    
+    timer_delete (timer);
+
+    __cleanup();
+    
+    return 0;
+}