123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- #include "StdAfx.h"
- #include "CResultManager.h"
- void CIdentifyTask::SetFeeder(IFeeder * feeder)
- {
- this->feeder = feeder;
- }
- IFeeder * CIdentifyTask::GetFeeder()
- {
- return feeder;
- }
- UnhandledPageInfo * CIdentifyTask::getUnhandledPageManager()
- {
- return &unhandleds;
- }
- CResultManager * CIdentifyTask::getResultBufferManager()
- {
- return &result;
- }
- CIdentifyTask::~CIdentifyTask()
- {
- }
- CIdentifyTask::CIdentifyTask()
- {
- feeder = NULL;
- unhandleds.unhandled_page_count = 0;
- unhandleds.first_unhandled_page_index = 0;
- unhandleds.m_stop = false;
- unhandleds.task = this;
- unhandleds.result = &result;
- unhandleds.bOnlineCard = false;
- result.reset();
- result.open();
- }
- CIdentifyTaskManager::~CIdentifyTaskManager()
- {
- for (int i = 0; i < tasks0.size(); i++)
- {
- delete tasks0[i];
- }
- }
- void CIdentifyTaskManager::doneTask(CIdentifyTask* task)
- {
- if (handle_task_index >= 0)handle_task_index--;
- if (task == main_task){ main_task = NULL; }
- for (int i = 0; i < tasks.size(); i++)
- {
- if (task == tasks[i]){ tasks.erase(tasks.begin() + i); }
- }
- for (int i = 0; i < tasks0.size(); i++)
- {
- if (task == tasks0[i]){ tasks0.erase(tasks0.begin() + i); }
- }
- delete task;
- }
- CIdentifyTask* CIdentifyTaskManager::getCurrentHandleTask()
- {
- if (handle_task_index >= 0)return tasks[handle_task_index];
- return main_task;
- }
- CIdentifyTask* CIdentifyTaskManager::getNextIdentifyTask()
- {
- if (idenfity_task_index >= 0)idenfity_task_index--;
- return getCurrentIdentifyTask();
- }
- CIdentifyTask* CIdentifyTaskManager::getCurrentIdentifyTask()
- {
- if (idenfity_task_index >= 0)return tasks[idenfity_task_index];
- return main_task;
- }
- CIdentifyTask* CIdentifyTaskManager::MainTask()
- {
- return main_task;
- }
- void CIdentifyTaskManager::setMainTask(CIdentifyTask* task)
- {
- main_task = task;
- }
- void CIdentifyTaskManager::ExcuTask(CIdentifyTask* task)
- {
- tasks.push_back(task);
- idenfity_task_index++;
- handle_task_index++;
- }
- CIdentifyTask* CIdentifyTaskManager::createTask()
- {
- CIdentifyTask* task = new CIdentifyTask();
- tasks0.push_back(task);
- return task;
- }
- CIdentifyTaskManager::CIdentifyTaskManager()
- {
- main_task = NULL;
- idenfity_task_index = -1;
- handle_task_index = -1;
- }
- void CResultManager::setIdentifyComplete(bool iscomplete)
- {
- identify_complete = iscomplete;
- }
- result_buffer_state * CResultManager::getBufferstate(void * result)
- {
- int buffer_index = -1;
- for (int i = 0; i < max_result_buffer_count; i++)
- {
- if (result == this->result[i]){ buffer_index = i; break; }
- }
- return buffer_index < 0 ? NULL : &m_buffer_state[buffer_index];
- }
- void CResultManager::FreeResult(identify::result::OMR_RESULT * &result)
- {
- for (int i = 0; i < this->result.size(); i++)
- {
- if (this->result[i] == result){
- this->result[i]->reset();
- m_buffer_state[i] = unused;
- result = NULL;
- break;
- }
- }
- }
- identify::result::OMR_RESULT * CResultManager::GetResult(BOOL wait)
- {
- do
- {
- if (m_buffer_state[m_next_result_index] == identified){
- m_buffer_state[m_next_result_index] = handling;
- identify::result::OMR_RESULT *ret = (identify::result::OMR_RESULT *)result[m_next_result_index];
- m_next_result_index = (m_next_result_index + 1) % max_result_buffer_count;
- return ret;
- }
- if (identify_complete&&m_buffer_state[m_next_result_index] == unused)return NULL;
- if (wait)Sleep(10);
- } while (wait);
- return NULL;
- }
- identify::result::OMR_RESULT * CResultManager::getNextResult()
- {
- identify::result::OMR_RESULT * out_result = NULL;
- int buffer_index = -1;
- do{
- for (int i = 0; i < max_result_buffer_count; i++)
- {
- int _index = (m_next_result_index + i) % max_result_buffer_count;
- if (m_buffer_state[_index] != unused) continue;
- out_result = result[_index];
- buffer_index = _index;
- m_buffer_state[buffer_index] = identifing;
- break;
- }
- if (out_result == NULL)Sleep(10);
- } while (out_result == NULL);
- return out_result;
- }
- void CResultManager::open()
- {
- m_result_buffer.resize(m_buffer_len);
- for (int i = 0; i < m_buffer_len; i++)
- {
- result[i] = &m_result_buffer[i];
- m_buffer_state[i] = unused;
- }
- }
- void CResultManager::reset()
- {
- m_next_result_index = 0;
- }
- CResultManager::~CResultManager()
- {
- }
- CResultManager::CResultManager(int buffer_len /*=max_result_buffer_count*/)
- {
- m_buffer_len = buffer_len;
- m_next_result_index = 0;
- identify_complete = false;
- result.resize(buffer_len, NULL);
- m_buffer_state.resize(buffer_len, unused);
- }
|