void WorkerThread::run() { set_thread_name(); while (!m_abort_switch.is_aborted()) { if (m_pause_flag.is_set()) { // Wait until the resume event. boost::mutex::scoped_lock lock(m_pause_mutex); while (m_pause_flag.is_set()) m_pause_event.wait(lock); } // Acquire a job. const JobQueue::RunningJobInfo running_job_info = m_job_queue.wait_for_scheduled_job(m_abort_switch); // Handle the case where the job queue is empty. if (running_job_info.first.m_job == nullptr) { if (m_flags & JobManager::KeepRunningOnEmptyQueue) { // Keep the thread running and waiting for new jobs. continue; } else { // Terminate the thread. break; } } // Execute the job. const bool success = execute_job(*running_job_info.first.m_job); // Retire the job. m_job_queue.retire_running_job(running_job_info); // Handle job execution failures. if (!success && !(m_flags & JobManager::KeepRunningOnJobFailure)) { m_job_queue.clear_scheduled_jobs(); break; } } }
int main() { init_shell(); while(1) { char prompt[256]; if(!readcmdline(promptmsg(prompt, 256))) { if (feof(stdin)) { /* End of file (ctrl-d) */ fflush(stdout); printf("\n"); exit(EXIT_SUCCESS); } continue; /* NOOP; user entered return or spaces with return */ } job_t* j; for (j = first_job; j; j = j->next) { /*Execute the new job (initialized with pgID = -1)*/ if (j->pgid == -1) { execute_job(j); } } } }
void get_cap_complete(dps_appctx_t appctx, dps_param_t result, dps_cap_array_t *cap_list) { static char dbg_buf[1000]; jint_t i, j; dps_param_t conf_setting = 0; static struct { char *cap_str; dps_param_t *conf_param; dps_param_t test_value; dps_param_t default_value; } cap_map[] = { { "print qualities", &app_ctx.jconfig.quality, TEST_DPS_QUALITY, DPS_QUALITY_DEFAULT }, { "paper sizes", &app_ctx.jconfig.paper_size, TEST_DPS_PAPER_SIZE, DPS_PAPER_SIZE_DEFAULT }, { "paper types", &app_ctx.jconfig.paper_type, TEST_DPS_PAPER_TYPE, DPS_PAPER_TYPE_DEFAULT }, { "file types", &app_ctx.jconfig.file_type, TEST_DPS_FILE_TYPE, DPS_FILE_TYPE_DEFAULT }, { "date prints", &app_ctx.jconfig.date_print, TEST_DPS_DATE_PRINT, DPS_DATE_PRINT_DEFAULT }, { "filename prints", &app_ctx.jconfig.filename_print, TEST_DPS_FILENAME_PRINT, DPS_FILENAME_PRINT_DEFAULT }, { "image optimizations", &app_ctx.jconfig.image_optimize, TEST_DPS_IMAGE_OPTIMIZE, DPS_IMAGE_OPTIMIZE_DEFAULT }, { "layouts", &app_ctx.jconfig.layout, TEST_DPS_LAYOUT, DPS_LAYOUT_DEFAULT }, { "fixed paper sizes", &app_ctx.jconfig.fixed_size, TEST_DPS_FIXED_SIZE, DPS_FIXED_SIZE_DEFAULT }, { "croppings", &app_ctx.jconfig.cropping, TEST_DPS_CROPPING, DPS_CROPPING_DEFAULT }, }; DECLARE_FNAME("get_cap_complete"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); if (result!=DPS_RESULT_OK || !cap_list || !cap_list->count || app_ctx.current_cap > DPS_CAP_CROPPINGS) { goto NextCapability; } /* Print out supported parameters */ *dbg_buf = 0; i = app_ctx.current_cap; for (j=0; j<cap_list->count; j++) { j_snprintf(dbg_buf, sizeof(dbg_buf)-1, "%s 0x%X", dbg_buf, cap_list->capability[j]); if (cap_map[i].test_value == cap_list->capability[j]) conf_setting = cap_map[i].test_value; } DBG_I(DSLAVE_DPS_API, ("%s: Supported %s: %s\n", fname, cap_map[app_ctx.current_cap].cap_str, dbg_buf)); /* Set print config parameter */ if (conf_setting) { *(cap_map[i].conf_param) = conf_setting; DBG_I(DSLAVE_DPS_API, ("%s:\t0x%X selected\n", fname, conf_setting)); } else { *(cap_map[i].conf_param) = cap_map[i].default_value; DBG_W(DSLAVE_DPS_API, ("%s:\t0x%X is not supported by the printer." " using default (0x%X)\n", fname, cap_map[i].test_value, cap_map[i].default_value)); } NextCapability: if (app_ctx.current_cap >= DPS_CAP_CROPPINGS) { /* Done with capabilities - send a print job */ execute_job(); } else { /* Get more capabilities from printer */ app_ctx.current_cap++; dps_get_capability(app_ctx.dpsh, app_ctx.current_cap, app_ctx.jconfig.paper_size); } }