int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task) { // 检查是否支持指令 DI * devintr = FindDevInterface(task->GetTaskCode()); if(!devintr) { throw TaskNotSupportedException(); } // int ret; ACE_HANDLE handler; ret = find_handler(node,&handler); if(ret) { ACE_DEBUG((LM_ERROR,"连接指定设备失败!")); return TASK_ERR_CONNECT; } // 执行指令 try { task->_handle = handler; ret = devintr->ExecuteTask(node,task); } catch(...) { // ignore } // 如果指令执行超时,关闭连接 if(release_handler(node,&handler,ret != TASK_SUCCESS)) { ACE_DEBUG((LM_ERROR,"释放连接失败")); } return ret; }
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task) { // 检查是否支持指令 bool free_conn = false; DI devintr = FindDevInterface(task->GetTaskCode()); if(!devintr) { throw TaskNotSupportedException(); } // int ret; ACE_HANDLE handler; ret = find_handler(node,&handler); if(ret) { ACE_DEBUG((LM_ERROR,"连接指定设备失败!")); return TASK_ERR_CONNECT; } // 执行指令 try { task->_handle = handler; ret = devintr->ExecuteTask(node,task); } catch(...) { // ignore } // 如果指令执行超时,关闭连接 if(node->connect_module() == KSGDeviceNode::cm_short_conn || ret != TASK_SUCCESS) { free_conn = true; } try { if(release_handler(node,&handler,free_conn)) { ACE_DEBUG((LM_ERROR,"释放连接失败")); } } catch (...) { ACE_DEBUG((LM_ERROR,"关闭连接异常!")); } return ret; }
void Button< driver >::handle_callback(){ state_t new_state = check_gpio(); // Transition! if(state != new_state){ state = new_state; switch(new_state){ case ST_PRESSED: if(press_handler){ press_handler(press_param); } case ST_RELEASED: if(release_handler){ release_handler(release_param); } } } }
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task) { // 检查是否支持指令 bool free_conn = false; DI devintr = FindDevInterface(task->GetTaskCode()); if(!devintr) { ACE_DEBUG((LM_ERROR,"设备不支持该指令...")); throw TaskNotSupportedException(); } // int ret; ACE_HANDLE handler; ret = find_handler(node,&handler); if(ret) { ACE_DEBUG((LM_ERROR,"连接指定设备失败!")); return TASK_ERR_CONNECT; } // 执行指令 try { task->_handle = handler; ret = devintr->ExecuteTask(node,task); } catch(...) { // ignore } if(node->connect_module() == KSGDeviceNode::cm_short_conn) { free_conn = true; } // 如果指令执行不成功 else { // if(ret != TASK_SUCCESS) { if(ret == TASK_ERR_TIMEOUT) free_conn = true; else { ACE_Time_Value tv(1); int res = ACE::handle_exception_ready(task->_handle,&tv); if(res >0) { // 如果发生异常,则重连 free_conn = true; } else if(res == 0) // 超时 { free_conn = true; } else // 返回错误 { } } } } try { if(release_handler(node,&handler,free_conn)) { ACE_DEBUG((LM_ERROR,"释放连接失败")); } } catch (...) { ACE_DEBUG((LM_ERROR,"关闭连接异常!")); } return ret; }