Start prototyping things
This commit is contained in:
		
							parent
							
								
									e6a85bc03a
								
							
						
					
					
						commit
						ad3af5b7fa
					
				
					 1 changed files with 36 additions and 0 deletions
				
			
		
							
								
								
									
										36
									
								
								src/schedule.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/schedule.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,36 @@
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <hexagram/schedule.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					hexagram_schedule *hexagram_schedule_create(hexagram_table_entry *table,
 | 
				
			||||||
 | 
					                                            size_t count) {
 | 
				
			||||||
 | 
					    hexagram_schedule *schedule;
 | 
				
			||||||
 | 
					    size_t i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((schedule = malloc(sizeof(*schedule) + count * sizeof(hexagram_schedule_slot))) == 0) {
 | 
				
			||||||
 | 
					        goto error_malloc_schedule;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    schedule->timer   = NULL;
 | 
				
			||||||
 | 
					    schedule->current = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (i=0; i<count; i++) {
 | 
				
			||||||
 | 
					        hexagram_schedule_slot *slot = &((hexagram_schedule_slot *)(schedule + 1))[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        slot->interval_us = 0;
 | 
				
			||||||
 | 
					        slot->entry       = &table[i];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return schedule;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					error_malloc_schedule:
 | 
				
			||||||
 | 
					    return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void hexagram_schedule_destroy(hexagram_schedule *schedule) {
 | 
				
			||||||
 | 
					    if (schedule->timer) {
 | 
				
			||||||
 | 
					        timer_delete(schedule->timer);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    free(schedule);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue