2024-12-09 19:27:50 +01:00
|
|
|
#ifndef PLANNER
|
|
|
|
#define PLANNER
|
2024-12-12 16:08:19 +01:00
|
|
|
#include "llist.h"
|
2024-12-11 01:08:31 +01:00
|
|
|
#include <stdint.h>
|
2024-12-10 22:06:49 +01:00
|
|
|
#include <time.h>
|
|
|
|
|
2024-12-11 01:08:31 +01:00
|
|
|
/*
|
|
|
|
* task subject struct used to track different tasks
|
2024-12-12 16:08:19 +01:00
|
|
|
d* create new task with taskNew(name, time_t created, time_t deadline, int
|
2024-12-11 01:08:31 +01:00
|
|
|
* priority, uint64_t spare)
|
|
|
|
*
|
|
|
|
* should be freed by user
|
|
|
|
*
|
|
|
|
* used to interface with human and store data
|
|
|
|
*/
|
|
|
|
typedef struct Task {
|
2024-12-10 22:06:49 +01:00
|
|
|
char *name;
|
|
|
|
time_t created;
|
|
|
|
time_t deadline;
|
|
|
|
int priority;
|
2024-12-11 01:08:31 +01:00
|
|
|
uint64_t spare;
|
|
|
|
} Task;
|
2024-12-10 22:06:49 +01:00
|
|
|
|
2024-12-11 01:08:31 +01:00
|
|
|
/*
|
|
|
|
* allocates and returns Task (free after use)
|
|
|
|
* returns NULL on failure
|
|
|
|
*/
|
|
|
|
Task *newTask(char *n, time_t c, time_t d, int p, uint64_t sp);
|
|
|
|
|
2024-12-11 03:51:32 +01:00
|
|
|
/*
|
|
|
|
* compare function for Task
|
|
|
|
*/
|
2024-12-12 16:08:19 +01:00
|
|
|
int cmpTaskN(const void *a, const void *b);
|
|
|
|
int cmpTaskP(const void *a, const void *b);
|
2024-12-11 03:09:54 +01:00
|
|
|
|
2024-12-11 13:41:31 +01:00
|
|
|
/*
|
|
|
|
* return allocated string representation of Task
|
|
|
|
*/
|
|
|
|
char *taskToStr(Task *t);
|
2024-12-11 13:03:28 +01:00
|
|
|
/*
|
|
|
|
* prints human readable str of Task to stdout
|
|
|
|
*/
|
|
|
|
void printTask(Task *s);
|
2024-12-12 16:24:19 +01:00
|
|
|
void llistFreeT(llist *head);
|
2024-12-11 13:03:28 +01:00
|
|
|
|
2024-12-11 14:06:29 +01:00
|
|
|
/*
|
|
|
|
* create deepCopy of task
|
|
|
|
* !! r->name is malloced
|
|
|
|
*/
|
|
|
|
Task *copyTask(Task *t);
|
|
|
|
|
2024-12-11 01:08:31 +01:00
|
|
|
/*
|
|
|
|
* Event struct contains task and planned time frame
|
|
|
|
*
|
|
|
|
* used to create timetable
|
|
|
|
*
|
|
|
|
* eventNew(task, start, end, spare)
|
2024-12-11 13:03:28 +01:00
|
|
|
* task: pointer to task (Alloced with newTask)
|
|
|
|
* plannedStartTime: time_t
|
|
|
|
* plannedEndTime: time_t
|
|
|
|
* uint64_t spare var
|
2024-12-11 01:08:31 +01:00
|
|
|
*
|
|
|
|
*/
|
2024-12-10 22:06:49 +01:00
|
|
|
typedef struct Event {
|
2024-12-11 01:08:31 +01:00
|
|
|
Task *task;
|
2024-12-10 22:06:49 +01:00
|
|
|
time_t plannedStartTime;
|
|
|
|
time_t plannedEndTime;
|
2024-12-11 01:08:31 +01:00
|
|
|
uint64_t spare; // spare var
|
2024-12-10 22:06:49 +01:00
|
|
|
} Event;
|
2024-12-11 01:08:31 +01:00
|
|
|
/*
|
|
|
|
* allocates and returns Event (free after use)
|
|
|
|
* returns NULL on failure
|
|
|
|
*/
|
|
|
|
Event *newEvent(Task *t, time_t s, time_t e, uint64_t sp);
|
2024-12-11 03:51:32 +01:00
|
|
|
/*
|
|
|
|
* compare function for Event
|
|
|
|
*/
|
2024-12-12 16:24:19 +01:00
|
|
|
void freeEvent(Event *e);
|
|
|
|
void llistFreeE(llist *head);
|
2024-12-12 16:08:19 +01:00
|
|
|
int cmpEvent(const void *a, const void *b);
|
|
|
|
/*
|
|
|
|
* takes llist of tasks and returns llist of events
|
|
|
|
*/
|
2024-12-13 17:32:41 +01:00
|
|
|
llist *genPlan(llist *head, time_t timeAvail);
|
2024-12-09 19:27:50 +01:00
|
|
|
|
2024-12-15 12:53:33 +01:00
|
|
|
int exportiCal(llist *head);
|
|
|
|
|
2024-12-09 19:27:50 +01:00
|
|
|
#endif // !PLANNER
|