|
@@ -8,8 +8,16 @@ Dispatch_device_base::Dispatch_device_base()
|
|
{
|
|
{
|
|
m_dispatch_device_status = DISPATCH_DEVICE_UNKNOW;
|
|
m_dispatch_device_status = DISPATCH_DEVICE_UNKNOW;
|
|
m_device_id = -1;
|
|
m_device_id = -1;
|
|
|
|
+ m_device_key = -1;
|
|
|
|
+ m_dispatch_device_type = DISPATCH_DEVICE_UNKNOWN;
|
|
|
|
|
|
mp_execute_thread = NULL;
|
|
mp_execute_thread = NULL;
|
|
|
|
+
|
|
|
|
+ m_device_one_level_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
|
|
|
|
+ m_device_two_level_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
|
|
|
|
+ m_device_three_level_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
|
|
|
|
+
|
|
|
|
+ m_break_flag = false;
|
|
}
|
|
}
|
|
|
|
|
|
Dispatch_device_base::~Dispatch_device_base()
|
|
Dispatch_device_base::~Dispatch_device_base()
|
|
@@ -90,8 +98,14 @@ Error_manager Dispatch_device_base::execute_task(std::shared_ptr<Task_Base> p_ta
|
|
m_dispatch_device_status = DISPATCH_DEVICE_THREE_LEVEL_WORK;
|
|
m_dispatch_device_status = DISPATCH_DEVICE_THREE_LEVEL_WORK;
|
|
m_execute_condition.notify_all(true);
|
|
m_execute_condition.notify_all(true);
|
|
//通知 thread_work 子线程启动。
|
|
//通知 thread_work 子线程启动。
|
|
-
|
|
|
|
//只签收,并不一定进入工作状态, 在线程真正的执行的时候,才改为工作中, (执行线程可能会先处理更高优先级的任务单)
|
|
//只签收,并不一定进入工作状态, 在线程真正的执行的时候,才改为工作中, (执行线程可能会先处理更高优先级的任务单)
|
|
|
|
+
|
|
|
|
+ //当接受2级任务时, 标记位改为true
|
|
|
|
+ if ( dispatch_task_level == DISPATCH_TASK_TWO_LEVEL )
|
|
|
|
+ {
|
|
|
|
+ m_break_flag = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
if ( t_result != Error_code::SUCCESS )
|
|
if ( t_result != Error_code::SUCCESS )
|
|
@@ -118,81 +132,78 @@ Error_manager Dispatch_device_base::check_task_type(std::shared_ptr<Task_Base> p
|
|
//判断能否执行任务
|
|
//判断能否执行任务
|
|
Error_manager Dispatch_device_base::check_task_level(Dispatch_task_level dispatch_task_level)
|
|
Error_manager Dispatch_device_base::check_task_level(Dispatch_task_level dispatch_task_level)
|
|
{
|
|
{
|
|
- std::cout << " huli test ::::79798798798798 " << " m_dispatch_device_status = " << m_dispatch_device_status << std::endl;
|
|
|
|
//加锁
|
|
//加锁
|
|
std::unique_lock<std::mutex> t_lock(m_lock);
|
|
std::unique_lock<std::mutex> t_lock(m_lock);
|
|
- std::cout << " huli test ::::1312312312312312 " << " m_dispatch_device_status = " << m_dispatch_device_status << std::endl;
|
|
|
|
-std::cout << " huli test :::: " << " 123123123213 = " << 123123123213 << std::endl;
|
|
|
|
//只有当状态 不是正在执行当前等级的任务,并且当前等级的任务为空. 此时返回成功, 才能接受新的任务
|
|
//只有当状态 不是正在执行当前等级的任务,并且当前等级的任务为空. 此时返回成功, 才能接受新的任务
|
|
if ( m_dispatch_device_status >= DISPATCH_DEVICE_READY && m_dispatch_device_status <= DISPATCH_DEVICE_THREE_LEVEL_WORK )
|
|
if ( m_dispatch_device_status >= DISPATCH_DEVICE_READY && m_dispatch_device_status <= DISPATCH_DEVICE_THREE_LEVEL_WORK )
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 1 << std::endl;
|
|
|
|
|
|
+ {
|
|
switch ( dispatch_task_level )
|
|
switch ( dispatch_task_level )
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 2 << std::endl;
|
|
|
|
|
|
+ {
|
|
case DISPATCH_TASK_ONE_LEVEL:
|
|
case DISPATCH_TASK_ONE_LEVEL:
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 3 << std::endl;
|
|
|
|
|
|
+ {
|
|
if ( mp_device_one_level_task.get() == NULL )
|
|
if ( mp_device_one_level_task.get() == NULL )
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 4 << std::endl;
|
|
|
|
|
|
+ {
|
|
//一级任务直接插入
|
|
//一级任务直接插入
|
|
if ( m_dispatch_device_status == DISPATCH_DEVICE_READY ||
|
|
if ( m_dispatch_device_status == DISPATCH_DEVICE_READY ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_TWO_LEVEL_OVER ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_TWO_LEVEL_OVER ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_TWO_LEVEL_WORK ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_TWO_LEVEL_WORK ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_THREE_LEVEL_OVER ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_THREE_LEVEL_OVER ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_THREE_LEVEL_WORK )
|
|
m_dispatch_device_status == DISPATCH_DEVICE_THREE_LEVEL_WORK )
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 5 << std::endl;
|
|
|
|
|
|
+ {
|
|
return Error_code::SUCCESS;
|
|
return Error_code::SUCCESS;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 6 << std::endl;
|
|
|
|
|
|
+ {
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_TASK_LEVEL_ERROR, Error_level::MINOR_ERROR,
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_TASK_LEVEL_ERROR, Error_level::MINOR_ERROR,
|
|
" Dispatch_device_base::check_task_level 1 error ");
|
|
" Dispatch_device_base::check_task_level 1 error ");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 7 << std::endl;
|
|
|
|
|
|
+ {
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_TASK_REPEAT, Error_level::MINOR_ERROR,
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_TASK_REPEAT, Error_level::MINOR_ERROR,
|
|
" Dispatch_device_base::check_task_level 2 error ");
|
|
" Dispatch_device_base::check_task_level 2 error ");
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
case DISPATCH_TASK_TWO_LEVEL:
|
|
case DISPATCH_TASK_TWO_LEVEL:
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 8 << std::endl;
|
|
|
|
|
|
+ {
|
|
if ( mp_device_two_level_task.get() == NULL )
|
|
if ( mp_device_two_level_task.get() == NULL )
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 9 << std::endl;
|
|
|
|
|
|
+ {
|
|
//二级任务如果打断了一级任务, 那么要通知一级任务暂停, 后续一级任务会重新执行
|
|
//二级任务如果打断了一级任务, 那么要通知一级任务暂停, 后续一级任务会重新执行
|
|
if ( m_dispatch_device_status == DISPATCH_DEVICE_READY )
|
|
if ( m_dispatch_device_status == DISPATCH_DEVICE_READY )
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 10 << std::endl;
|
|
|
|
|
|
+ {
|
|
return Error_code::SUCCESS;
|
|
return Error_code::SUCCESS;
|
|
}
|
|
}
|
|
else if ( ( m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_WORK ||
|
|
else if ( ( m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_WORK ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_OVER ) && mp_device_one_level_task.get() != NULL)
|
|
m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_OVER ) && mp_device_one_level_task.get() != NULL)
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 11 << std::endl;
|
|
|
|
|
|
+ {
|
|
mp_device_one_level_task->set_task_statu(Task_Base::Task_statu::TASK_STOP);
|
|
mp_device_one_level_task->set_task_statu(Task_Base::Task_statu::TASK_STOP);
|
|
return Error_code::SUCCESS;
|
|
return Error_code::SUCCESS;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 12 << std::endl;
|
|
|
|
|
|
+ {
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_TASK_LEVEL_ERROR, Error_level::MINOR_ERROR,
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_TASK_LEVEL_ERROR, Error_level::MINOR_ERROR,
|
|
" Dispatch_device_base::check_task_level 3 error ");
|
|
" Dispatch_device_base::check_task_level 3 error ");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 13 << std::endl;
|
|
|
|
|
|
+ {
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_TASK_REPEAT, Error_level::MINOR_ERROR,
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_TASK_REPEAT, Error_level::MINOR_ERROR,
|
|
" Dispatch_device_base::check_task_level 4 error ");
|
|
" Dispatch_device_base::check_task_level 4 error ");
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
case DISPATCH_TASK_THREE_LEVEL:
|
|
case DISPATCH_TASK_THREE_LEVEL:
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 14 << std::endl;
|
|
|
|
|
|
+ {
|
|
if ( ( m_dispatch_device_status == DISPATCH_DEVICE_READY ||
|
|
if ( ( m_dispatch_device_status == DISPATCH_DEVICE_READY ||
|
|
m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_OVER ) && mp_device_three_level_task.get() == NULL)
|
|
m_dispatch_device_status == DISPATCH_DEVICE_ONE_LEVEL_OVER ) && mp_device_three_level_task.get() == NULL)
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 15 << std::endl;
|
|
|
|
|
|
+ {
|
|
return Error_code::SUCCESS;
|
|
return Error_code::SUCCESS;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
default:
|
|
default:
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 16 << std::endl;
|
|
|
|
|
|
+ {
|
|
return Error_manager(Error_code::PARAMETER_ERROR, Error_level::MINOR_ERROR,
|
|
return Error_manager(Error_code::PARAMETER_ERROR, Error_level::MINOR_ERROR,
|
|
" Dispatch_device_base::check_task 5 PARAMETER_ERROR ");
|
|
" Dispatch_device_base::check_task 5 PARAMETER_ERROR ");
|
|
break;
|
|
break;
|
|
@@ -202,14 +213,14 @@ std::cout << " huli test :::: " << " 123123123213 = " << 123123123213 << std::en
|
|
" Dispatch_device_base::check_task is busy 6 ");
|
|
" Dispatch_device_base::check_task is busy 6 ");
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {std::cout << " huli test :::: " << " 123123123213 = " << 17 << std::endl;
|
|
|
|
|
|
+ {
|
|
// std::cout << " huli test :::: " << " 777777777777777777777777777777777777 = " << 777 << std::endl;
|
|
// std::cout << " huli test :::: " << " 777777777777777777777777777777777777 = " << 777 << std::endl;
|
|
// std::cout << " huli test :::: " << " m_dispatch_device_status = " << m_dispatch_device_status << std::endl;
|
|
// std::cout << " huli test :::: " << " m_dispatch_device_status = " << m_dispatch_device_status << std::endl;
|
|
// std::cout << " huli test :::: " << " id = " << m_device_id << std::endl;
|
|
// std::cout << " huli test :::: " << " id = " << m_device_id << std::endl;
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
|
|
return Error_manager(Error_code::DISPATCH_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
|
|
" Dispatch_device_base::check_task 7 error ");
|
|
" Dispatch_device_base::check_task 7 error ");
|
|
}
|
|
}
|
|
- std::cout << " huli test :::: " << " 123123123213 = " << 18 << std::endl;
|
|
|
|
|
|
+
|
|
return Error_code::SUCCESS;
|
|
return Error_code::SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -509,10 +520,15 @@ Error_manager Dispatch_device_base::change_task_level(Dispatch_task_level dispat
|
|
" Dispatch_device_base::change_task_level PARAMRTER ERROR ");
|
|
" Dispatch_device_base::change_task_level PARAMRTER ERROR ");
|
|
}
|
|
}
|
|
std::unique_lock<std::mutex> t_lock(m_lock);
|
|
std::unique_lock<std::mutex> t_lock(m_lock);
|
|
|
|
+ //只能在原任务结束的时候升级, 否则返回 return Error_code::NODATA; 通知上级重试
|
|
switch ( dispatch_task_level_source )
|
|
switch ( dispatch_task_level_source )
|
|
{
|
|
{
|
|
case DISPATCH_TASK_ONE_LEVEL:
|
|
case DISPATCH_TASK_ONE_LEVEL:
|
|
{
|
|
{
|
|
|
|
+ if ( m_dispatch_device_status != DISPATCH_DEVICE_ONE_LEVEL_OVER )
|
|
|
|
+ {
|
|
|
|
+ return Error_code::NODATA;
|
|
|
|
+ }
|
|
tp_command_key_source = & m_device_one_level_command_key;
|
|
tp_command_key_source = & m_device_one_level_command_key;
|
|
tp_process_type_source = & m_device_one_level_process_type;
|
|
tp_process_type_source = & m_device_one_level_process_type;
|
|
tp_task_source = & mp_device_one_level_task;
|
|
tp_task_source = & mp_device_one_level_task;
|
|
@@ -520,6 +536,10 @@ Error_manager Dispatch_device_base::change_task_level(Dispatch_task_level dispat
|
|
}
|
|
}
|
|
case DISPATCH_TASK_TWO_LEVEL:
|
|
case DISPATCH_TASK_TWO_LEVEL:
|
|
{
|
|
{
|
|
|
|
+ if ( m_dispatch_device_status != DISPATCH_DEVICE_TWO_LEVEL_OVER )
|
|
|
|
+ {
|
|
|
|
+ return Error_code::NODATA;
|
|
|
|
+ }
|
|
tp_command_key_source = & m_device_two_level_command_key;
|
|
tp_command_key_source = & m_device_two_level_command_key;
|
|
tp_process_type_source = & m_device_two_level_process_type;
|
|
tp_process_type_source = & m_device_two_level_process_type;
|
|
tp_task_source = & mp_device_two_level_task;;
|
|
tp_task_source = & mp_device_two_level_task;;
|
|
@@ -527,6 +547,10 @@ Error_manager Dispatch_device_base::change_task_level(Dispatch_task_level dispat
|
|
}
|
|
}
|
|
case DISPATCH_TASK_THREE_LEVEL:
|
|
case DISPATCH_TASK_THREE_LEVEL:
|
|
{
|
|
{
|
|
|
|
+ if ( m_dispatch_device_status != DISPATCH_DEVICE_THREE_LEVEL_OVER )
|
|
|
|
+ {
|
|
|
|
+ return Error_code::NODATA;
|
|
|
|
+ }
|
|
tp_command_key_source = & m_device_three_level_command_key;
|
|
tp_command_key_source = & m_device_three_level_command_key;
|
|
tp_process_type_source = & m_device_three_level_process_type;
|
|
tp_process_type_source = & m_device_three_level_process_type;
|
|
tp_task_source = & mp_device_three_level_task;;
|
|
tp_task_source = & mp_device_three_level_task;;
|
|
@@ -607,6 +631,14 @@ int Dispatch_device_base::get_device_id()
|
|
return m_device_id;
|
|
return m_device_id;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+bool Dispatch_device_base::get_break_flag()
|
|
|
|
+{
|
|
|
|
+ return m_break_flag;
|
|
|
|
+}
|
|
|
|
+void Dispatch_device_base::set_break_flag(bool break_flag)
|
|
|
|
+{
|
|
|
|
+ m_break_flag = break_flag;
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
//执行外界任务的执行函数
|
|
//执行外界任务的执行函数
|