// ============================================================================
// Process the message queue of the Task
// ============================================================================    
void AcquisitionTask::process_message(yat::Message& msg) throw (Tango::DevFailed) 
{
    try
    {
        switch ( msg.type() )
        {
            //-----------------------------------------------------------------------------------------------
            case yat::TASK_INIT:
            {
                INFO_STREAM << "-> yat::TASK_INIT" << endl;

                try
                {
                    m_acq_conf = msg.get_data<AcqConfig>();                    
                    set_state(Tango::STANDBY);    
                    set_status(string("Waiting for request ..."));
                }
                catch( Tango::DevFailed& df )
                {
                    ERROR_STREAM << df <<endl;
                    set_state(Tango::FAULT);
                    set_status(string(df.errors[0].desc));    
                    throw;
                }
            }
            break;
                
            //-----------------------------------------------------------------------------------------------
            case yat::TASK_EXIT:
            {
                INFO_STREAM << "-> yat::TASK_EXIT" << endl;
                try
                {
                    set_state(Tango::INIT);    
                    set_status(string("Acquisition is Stopped."));    
                }
                catch( Tango::DevFailed& df )
                {
                    ERROR_STREAM << df <<endl;
                    set_state(Tango::FAULT);    
                    set_status(string(df.errors[0].desc));
                }                
            }
            break;

            //-----------------------------------------------------------------------------------------------            
            case DEVICE_SNAP_MSG:
            {
                INFO_STREAM << "-> yat::DEVICE_SNAP_MSG" << endl;
                try
                {                
                    set_state(Tango::RUNNING);    
                    set_status(string("Acquisition is Running in snap mode..."));                    
                    m_acq_conf.ct->prepareAcq();
                    m_acq_conf.ct->startAcq();
                }
                catch(Tango::DevFailed &df)
                {
                    ERROR_STREAM << df << endl;
                    on_abort(df);                            
                }
                catch(Exception& e)
                {
                    ERROR_STREAM << e.getErrMsg() << endl;
                    on_abort(e.getErrMsg());                            
                }                    
            }
            break;
        
            //-----------------------------------------------------------------------------------------------            
            case DEVICE_START_MSG:
            {
                INFO_STREAM << "-> yat::DEVICE_START_MSG" << endl;
                try
                {                
                    set_state(Tango::RUNNING);    
                    set_status(string("Acquisition is Running in video mode ..."));
                    m_acq_conf.ct->video()->startLive();
                }
                catch(Tango::DevFailed &df)
                {
                    ERROR_STREAM << df << endl;
                    on_abort(df);                            
                }
                catch(Exception& e)
                {
                    ERROR_STREAM << e.getErrMsg() << endl;
                    on_abort(e.getErrMsg());                            
                }                    
            }
            break;
        
            //----------------------------------------------------------------------------------------------- 
            case DEVICE_STOP_MSG:
            {
                INFO_STREAM << "-> yat::DEVICE_STOP_MSG" << endl;
                try
                {
                    m_acq_conf.ct->stopAcq();
                    m_acq_conf.ct->resetStatus(false);
                    set_state(Tango::STANDBY);
                    set_status(string("Waiting for request ..."));                
                    INFO_STREAM << "Acquisition is Stopped." << endl;
                }
                catch(Tango::DevFailed &df)
                {
                    ERROR_STREAM << df << endl;
                    on_abort(df);                            
                }
                catch(Exception& e)
                {
                    ERROR_STREAM << e.getErrMsg() << endl;
                    on_abort(e.getErrMsg());                            
                }                    
            }
            break;
        
            //----------------------------------------------------------------------------------------------- 
            case DEVICE_ABORT_MSG:
            {
                INFO_STREAM << "-> yat::DEVICE_ABORT_MSG" << endl;
                //display here the final status, otherwise is overwrited.
                set_state(Tango::FAULT);
                set_status(m_acq_conf.abort_status_message);
                INFO_STREAM << "Acquisition is Aborted." << endl;    
            }
            break;
        
            //-----------------------------------------------------------------------------------------------
        }
    }
    catch( yat::Exception& ex )
    {
        //- TODO Error Handling
        INFO_STREAM<<ex.errors[0].desc<<endl;
        throw;
    }
}
// ============================================================================
// UnsolicitedMsgReader::handle_message
// ============================================================================
void UnsolicitedMsgReader::handle_message (yat::Message& _msg)
	throw (yat::Exception)
{
  YAT_TRACE("galil::UnsolicitedMsgReader::handle_message"); 

  //- The Task's lock_ is locked
	//-------------------------------------------------------------------

	//- YAT_LOG("UnsolicitedMsgReader::handle_message::receiving msg " << _msg.to_string());

	//- handle msg
  switch (_msg.type())
	{

	  //- THREAD_INIT ----------------------
	  case yat::TASK_INIT:
	    {
  	    //- "initialization" code goes here
  	    YAT_LOG("UnsolicitedMsgReader::handle_message::THREAD_INIT::thread is starting up");
      } 
		  break;

		//- THREAD_EXIT ----------------------
		case yat::TASK_EXIT:
		  {
  			//- "release" code goes here
  			YAT_LOG("UnsolicitedMsgReader::handle_message::THREAD_EXIT::thread is quitting");
      }
			break;

		//- THREAD_PERIODIC ------------------
		case yat::TASK_PERIODIC:
		  {
		    //- enter critical section
		    yat::AutoMutex<yat::Mutex> guard(this->Task::m_lock);
		    
		    //- get unsolicited msg
		    try
		    {
  		    //- code relative to the task's periodic job goes here
  		    //- YAT_LOG("UnsolicitedMsgReader::handle_message::handling THREAD_PERIODIC msg");
          std::string unsolicited_msg;
          this->hw_io()->out(unsolicited_msg);
          if (unsolicited_msg.size())
          {
            YAT_LOG("***************************************************************************");
            YAT_LOG("* UnsolicitedMsgReader::got the following unsolicited msg from controller *");
            YAT_LOG("***************************************************************************");
            YAT_LOG("unsolicited msg length..." << unsolicited_msg.size());
            YAT_LOG("unsolicited msg.........." << unsolicited_msg);
            YAT_LOG("***************************************************************************");
          }
        }
        catch (Tango::DevFailed& te)
	      {
	        YAT_LOG("UnsolicitedMsgReader::handle_message::TANGO exception caught");
	        _TANGO_TO_YAT_EXCEPTION(te, ye);
	        throw ye;  
	      }
	      catch (...)
	      {		
	        YAT_LOG("UnsolicitedMsgReader::handle_message::UNKNOWN exception caught");
	        throw;  
	      }
      }
		  break;

  	default:
  		//- YAT_LOG("UnsolicitedMsgReader::handle_message::unhandled msg type received");
  		break;
	}

	//- YAT_LOG("UnsolicitedMsgReader::handle_message::message_handler:msg " << _msg.to_string() << " successfully handled");
}
Ejemplo n.º 3
0
void Camera::handle_message(yat::Message& msg) throw ( yat::Exception)
{
    DEB_MEMBER_FUNCT();
    try
    {
        switch (msg.type())
        {

                //-----------------------------------------------------
            case yat::TASK_INIT:
            {
                DEB_TRACE() << "Camera::->TASK_INIT";
                //NOP
            }
                break;

                //-----------------------------------------------------
            case yat::TASK_EXIT:
            {
                DEB_TRACE() << "Camera::->TASK_EXIT";
                try
                {
                    //- abort acquisition
                    DEB_TRACE() << "Send command abort";
                    _sendCmdAndReceiveAnswer("abort");

                    //-  Delete device allocated objects
                    DEB_TRACE() << "Disconnect from MARCCD socket server";
                    m_sock.disconnect();

                    //- yat internal cooking
                    DEB_TRACE() << "Terminate yat::socket";
                    yat::Socket::terminate();
                }
                catch (yat::SocketException & ySe)
                {
                    std::stringstream ssError;
                    for (unsigned i = 0; i < ySe.errors.size(); i++)
                    {
                        ssError << ySe.errors[i].desc << std::endl;
                    }

                    THROW_HW_ERROR(Error) << ssError.str();
                }
                catch (...)
                {
                    THROW_HW_ERROR(Error) << "Camera::TASK_EXIT : Unknown Exception";
                }
            }
                break;

                //-----------------------------------------------------
            case yat::TASK_TIMEOUT:
            {
                DEB_TRACE() << "Camera::->TASK_TIMEOUT";
                //NOP
            }
                break;

                //------------------------------------------------------
            case yat::TASK_PERIODIC:
            {
                DEB_TRACE() << "Camera::->TASK_PERIODIC";
                //NOP
            }
                break;

                //------------------------------------------------------
            case START_MSG:
            {
                DEB_TRACE() << "Camera::->START_MSG";

                try
                {
                    DEB_TRACE() << "Perform acquisition sequence ...";
                    _performAcquisitionSequence();
                }
                catch (yat::SocketException & ySe)
                {
                    m_nb_frames = 0; // This will stop the reader                    
                    std::stringstream ssError;
                    for (unsigned i = 0; i < ySe.errors.size(); i++)
                    {
                        ssError << ySe.errors[i].desc << std::endl;
                    }

                    THROW_HW_ERROR(Error) << ssError.str();
                }
                catch (...)
                {
                    THROW_HW_ERROR(Error) << "Camera::START_MSG : Unknown Exception";
                }
            }
                break;

                //-----------------------------------------------------
            case STOP_MSG:
            {
                DEB_TRACE() << "Camera::->STOP_MSG";

                try
                {
                    DEB_TRACE() << "Perform stop sequence ...";
                    _performStopSequence();
                }
                catch (yat::SocketException & ySe)
                {
                    m_nb_frames = 0; // This will stop the reader                    
                    std::stringstream ssError;
                    for (unsigned i = 0; i < ySe.errors.size(); i++)
                    {
                        ssError << ySe.errors[i].desc << std::endl;
                    }

                    THROW_HW_ERROR(Error) << ssError.str();
                }
                catch (...)
                {
                    THROW_HW_ERROR(Error) << "Camera::STOP_MSG : Unknown Exception";
                }
            }
                break;

                //-----------------------------------------------------
            case BACKGROUND_FRAME_MSG:
            {
                DEB_TRACE() << "Camera::->BACKGROUND_FRAME_MSG";

                try
                {
                    DEB_TRACE() << "Perform background frame ...";
                    _performBackgroundFrame();
                }
                catch (yat::SocketException & ySe)
                {
                    m_nb_frames = 0; // This will stop the reader                    
                    std::stringstream ssError;
                    for (unsigned i = 0; i < ySe.errors.size(); i++)
                    {
                        ssError << ySe.errors[i].desc << std::endl;
                    }

                    THROW_HW_ERROR(Error) << ssError.str();
                }
                catch (...)
                {
                    THROW_HW_ERROR(Error) << "Camera::BACKGROUND_FRAME_MSG : Unknown Exception";
                }
            }
                break;
        }
    }
    catch (yat::Exception& ex)
    {
        DEB_ERROR() << "Camera::handle_message : " << ex.errors[0].desc;
        THROW_HW_ERROR(Error) << "Camera::handle_message : " << ex.errors[0].desc;
    }
    catch (...)
    {
        DEB_ERROR() << "Camera::handle_message : " << "YAT Task Unknown error ! ";
        THROW_HW_ERROR(Error) << "Camera::handle_message : " << "YAT Task Unknown error ! ";
    }
}
Ejemplo n.º 4
0
// ============================================================================
// Consumer::handle_message
// ============================================================================
void Consumer::handle_message (yat::Message& _msg)
{
	//- YAT_TRACE("Consumer::handle_message");

	//- handle msg
  switch (_msg.type())
	{
	  //- TASK_INIT ----------------------
	  case yat::TASK_INIT:
	    {
  	    //- "initialization" code goes here
  	    YAT_LOG("Consumer::handle_message::TASK_INIT::task is starting up");
        this->ctrl_msg_counter++;
      } 
		  break;
		//- TASK_EXIT ----------------------
		case yat::TASK_EXIT:
		  {
  			//- "release" code goes here
  			YAT_LOG("Consumer::handle_message::TASK_EXIT::task is quitting");
        this->ctrl_msg_counter++;
      }
			break;
		//- TASK_PERIODIC ------------------
		case yat::TASK_PERIODIC:
		  {
  		  //- code relative to the task's periodic job goes here
  		  YAT_LOG("Consumer::handle_message::handling TASK_PERIODIC msg");
      }
		  break;
		//- TASK_TIMEOUT -------------------
		case yat::TASK_TIMEOUT:
		  {
  		  //- code relative to the task's tmo handling goes here
  		  YAT_LOG("Consumer::handle_message::handling TASK_TIMEOUT msg");
      }
		  break;
		//- USER_DEFINED_MSG -----------------
		case kDUMMY_MSG:
		  {
  		  //- YAT_LOG("Consumer::handle_message::handling kDUMMY_MSG user msg");
        this->user_msg_counter++;
#if defined (YAT_DEBUG)
        if (_msg.id() < last_msg_id)
          this->wrong_order_msg_counter++;
        else
          this->lost_msg_counter += _msg.id() - (this->last_msg_id + 1);
#endif
        //- simulate some time consuming activity
        yat::ThreadingUtilities::sleep(0, 10000);
  		}
  		break;
    //- kDATA_MSG -------------------
    case kDATA_MSG:
      {
        //- code relative to the task's tmo handling goes here
        SharedBuffer* sb = _msg.detach_data<SharedBuffer>();
        YAT_LOG("got a SharedBuffer containing " << sb->length() << " elements");
        sb->release();
      }
      break;
  	default:
  		YAT_LOG("Consumer::handle_message::unhandled msg type received");
  		break;
	}
#if defined (YAT_DEBUG)
  this->last_msg_id = _msg.id();
#endif
}