dynamic task allocation
[mTask.git] / client / client.c
index 59c611f..ce1d1f2 100644 (file)
@@ -45,7 +45,12 @@ void read_message(void)
                        break;
                case MSG_DEL_TASK:
                        debug("Receiving a delete task request");
-                       task_delete();
+                       c = read16();
+                       task_delete(c);
+                       //Write acknowledgement
+                       write_byte('d');
+                       write16(c);
+                       write_byte('\n');
                        break;
                case MSG_GET_TASK:
                        debug("Receiving a task");
@@ -79,13 +84,10 @@ void loop(void)
 #endif
        debug("Loop");
 
-       struct task *t;
-       long cyclestart;
-
        read_message();
 
        //Run tasks
-       cyclestart = getmillis();
+       unsigned long cyclestart = getmillis();
        for(struct task *t = task_head(); t != NULL; t = task_next(t)){
                //interrupt task
                if(is_interrupt_task(t) && had_interrupt(t)){
@@ -97,9 +99,9 @@ void loop(void)
                        run_task(t);
 
                        //Oneshot task, thus disable
-//                     if(t->interval == 0){
-//                             curtask->used = false;
-//                     }
+                       if(t->interval == 0){
+                               task_delete(t->taskid);
+                       }
                        t->lastrun = cyclestart;
                }
        }