/** * @brief This thread represents a print spooler which directly talks to a single printer * @param param * The PRINT_SPOOL_PARAM this printer should pull its jobs from, casted to a void* * @return NULL * * This function should loop forever. The basic process is as follows: * 1) pop a print job from this threads queue * 2) if it is NULL return * 3) print to the log file that printing of the job is starting * 4) call the print method on the printer object of the param and check the return * 5) handel errors correctly * 6) destroy the print job and get the next */ void *spooler(void* param) { struct PRINTER_SPOOLER_PARAM* params = malloc(sizeof(struct PRINTER_SPOOLER_PARAM)); params = (struct PRINTER_SPOOLER_PARAM*)param; queue_t queue = params->print_queue_list; printer_t printer = params->printer_driver; struct arguments arguments = params->arguments; queue_ends_t q_ends = QUEUE_HEAD; print_job_t* popped; FILE *file; char *str; while(1){ popped = queue_pop(queue, q_ends); if (popped == NULL){ printer_uninstall(printer); return NULL; } file = fopen(arguments.log_file_name, "a"); if(file == NULL){ fprintf(stderr, "%s: error opening log file\n", __func__); exit(-1); } asprintf(&str, "Starting to print job %s\n", popped->job_name); fputs(str,file); fclose(file); printer_print(printer, popped); } }
int main(int argc, char* argv[]) { struct arguments arguments; arguments.list = 0; arguments.output_file_name = ""; arguments.description = ""; arguments.driver = ""; argp_parse(&argp, argc, argv, 0, 0, &arguments); if(arguments.list == 1) { int num = 3; printer_driver_t** list = printer_list_drivers(&num); return 0; } else { return printer_print(NULL, arguments.driver, "cli-job", arguments.description, "DATA"); } }