run once and run periodic example work

Dependencies:   JobScheduler

Revision:
8:8a65353ec8f3
Parent:
6:b0bca03d9f3a
Child:
9:27e0a0dd98d1
--- a/source/main.cpp	Tue Jul 11 23:15:38 2017 +0000
+++ b/source/main.cpp	Fri Jul 14 00:01:13 2017 +0000
@@ -4,23 +4,73 @@
 #include "jobService.h"
 #include "schedules.h"
 
-void jobA()
+#include "mbed-trace/mbed_trace.h"
+#define TRACE_GROUP  "main"
+
+ // These are necessary only if thread safety is needed
+static Mutex TracingLock;
+static void tracingWait()
+{
+    TracingLock.lock();
+}
+static void tracingRelease()
+{
+    TracingLock.unlock();
+}
+
+void jobA(void *context)
 {
     printf("Job A\n");
 }
 
-void jobB()
+void jobB(void *context)
 {
     printf("Job B\n");
 }
 
 void runScheduler() 
 {
+    /* Setup tracing */
+    mbed_trace_mutex_wait_function_set( tracingWait ); // only if thread safety is needed
+    mbed_trace_mutex_release_function_set( tracingRelease ); // only if thread safety is needed
+    mbed_trace_init();       // initialize the trace library
+
     JobScheduler::JobService js;
     JobScheduler::Scheduler scheduler(&js);
     
-    js.Register(1, jobA);
-    js.Register(2, jobB);
+    JobScheduler::Error err;
+    err = js.Register(3, NULL, NULL);
+    if (err) {
+        printf("Failed to register job type 1.\n");
+        exit(1);
+    }
+    err = js.Register(1, jobA, NULL);
+    if (err) {
+        printf("Failed to register job type 1.\n");
+        exit(1);
+    }
+    err = js.Register(2, jobB, NULL);
+    if (err) {
+        printf("Failed to register job type 2.\n");
+        exit(1);
+    }
+    
+    JobScheduler::JobType *jt;
+    jt = js.GetJob(1);
+    if (jt == NULL) {
+        printf("Failed to find job type 1.\n");
+        exit(1);
+    }
+    jt = js.GetJob(2);
+    if (jt == NULL) {
+        printf("Failed to find job type 2.\n");
+        exit(1);
+    }
+    jt = js.GetJob(3);
+    if (jt == NULL) {
+        printf("Failed to find job type 2.\n");
+        exit(1);
+    }
     
     scheduler.Start();