Commit bc18e08d authored by Marco De Marco's avatar Marco De Marco
Browse files

State and status handling fix

parent aa4d76de
Loading
Loading
Loading
Loading
+98 −76
Original line number Original line Diff line number Diff line
@@ -61,10 +61,12 @@ EventThread::SP EventThread::create(FitsImporter* fitsImporter_p,
//==============================================================================
//==============================================================================
//	EventThread::start()
//	EventThread::start()
//==============================================================================
//==============================================================================
void EventThread::start() throw(std::runtime_error)	
void EventThread::start()
{
{
	DEBUG_STREAM << "EventThread::start()" << endl;
	DEBUG_STREAM << "EventThread::start()" << endl;


    try
    {
        initEventBuffer();
        initEventBuffer();


        initINotify();
        initINotify();
@@ -75,6 +77,19 @@ void EventThread::start() throw(std::runtime_error)


        initThreadGroup();
        initThreadGroup();
    }
    }
    catch(std::exception& ex)
    {
        std::stringstream error_stream;
        error_stream << "Event thread not running " << ex.what();
        writeState(Tango::ALARM);
        writeStatus(error_stream.str());
    }
    catch(...)
    {
        writeState(Tango::ALARM);
        writeStatus("Event thread unknown exception");
    }
}


//==============================================================================
//==============================================================================
//	EventThread::stop()
//	EventThread::stop()
@@ -119,6 +134,30 @@ std::string EventThread::readStatus()
    return m_status;
    return m_status;
}
}


//==============================================================================
//      EventThread::writeState()
//==============================================================================
void EventThread::writeState(Tango::DevState state)
{
    DEBUG_STREAM << "Client::writeState()" << endl;

    boost::mutex::scoped_lock stateLock(m_stateMutex);

    m_state = state;
}

//==============================================================================
//      EventThread::writeStatus()
//==============================================================================
void EventThread::writeStatus(std::string status)
{
    DEBUG_STREAM << "Client::writeStatus()" << endl;

    boost::mutex::scoped_lock statusLock(m_statusMutex);

    m_status = status;
}

//==============================================================================
//==============================================================================
//	EventThread::initEventBuffer()
//	EventThread::initEventBuffer()
//==============================================================================
//==============================================================================
@@ -264,28 +303,19 @@ void EventThread::eventLoop()
			{
			{
				if(errno != EINTR && errno != EAGAIN)
				if(errno != EINTR && errno != EAGAIN)
				{
				{
                    boost::mutex::scoped_lock stateLock(m_stateMutex);   
                    writeState(Tango::ALARM);
                    m_state = Tango::ALARM;
                    writeStatus("Event thread error on watch path read");

                    boost::mutex::scoped_lock statusLock(m_statusMutex);    
                    m_status = "Event thread error on watch path read";
				}
				}
				else
				else
                {
                {
                    boost::mutex::scoped_lock stateLock(m_stateMutex);   
                    writeState(Tango::ON);
                    m_state = Tango::ON;
                    writeStatus("Event thread running");

                    boost::mutex::scoped_lock statusLock(m_statusMutex);    
                    m_status = "Event thread running";                
                }
                }
			}
			}
			else
			else
            {
            {
                boost::mutex::scoped_lock stateLock(m_stateMutex);   
                writeState(Tango::ON);
                m_state = Tango::ON;
                writeStatus("Event thread new data found");

                boost::mutex::scoped_lock statusLock(m_statusMutex);    
                m_status = "Event thread new data found";                
            }
            }


            struct inotify_event *event;
            struct inotify_event *event;
@@ -316,30 +346,22 @@ void EventThread::eventLoop()
		{
		{
            DEBUG_STREAM << "EventThread::eventLoop() stopping loop" << endl;
            DEBUG_STREAM << "EventThread::eventLoop() stopping loop" << endl;


            boost::mutex::scoped_lock stateLock(m_stateMutex);   
            writeState(Tango::OFF);
            m_state = Tango::OFF;
            writeStatus("Event thread not running");
    
            boost::mutex::scoped_lock statusLock(m_statusMutex);    
            m_status = "Event thread not running"; 


			break;
			break;
		}
		}
        catch(std::exception& ex)
        catch(std::exception& ex)
        {
        {
            boost::mutex::scoped_lock stateLock(m_stateMutex);   
            std::stringstream error_stream;
            m_state = Tango::ALARM;
            error_stream << "Event thread not running " << ex.what();

            writeState(Tango::ALARM);
            boost::mutex::scoped_lock statusLock(m_statusMutex);    
            writeStatus(error_stream.str());
            m_status = "Event thread ";
            m_status.append(ex.what()); 
        }
        }
		catch(...)
		catch(...)
		{
		{
            boost::mutex::scoped_lock stateLock(m_stateMutex);   
            writeState(Tango::ALARM);
            m_state = Tango::ALARM;
            writeStatus("Event thread unknown exception");

            boost::mutex::scoped_lock statusLock(m_statusMutex);    
            m_status = "Event thread unknown exception";
		}
		}
	} //while
	} //while
}
}
+38 −25
Original line number Original line Diff line number Diff line
@@ -46,20 +46,33 @@ protected:


public:
public:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	[Public] Users methods		
//	[Public] Class creation method
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
	static EventThread::SP create(FitsImporter*, Configuration::SP,
	static EventThread::SP create(FitsImporter*, Configuration::SP,
            Instrument::SPVector, Instrument::SP);
            Instrument::SPVector, Instrument::SP);


	virtual void start() throw(std::runtime_error);
//------------------------------------------------------------------------------
//  [Public] Thread management methods
//------------------------------------------------------------------------------
	virtual void start();


	virtual void stop();
	virtual void stop();


//------------------------------------------------------------------------------
//  [Public] Read state and status methods
//------------------------------------------------------------------------------
    virtual Tango::DevState readState();
    virtual Tango::DevState readState();


    virtual std::string readStatus();
    virtual std::string readStatus();


protected:
protected:
//------------------------------------------------------------------------------
//  [Protected] Write state and status methods
//------------------------------------------------------------------------------
    virtual void writeState(Tango::DevState);

    virtual void writeStatus(std::string);

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	[Protected] Utilities methods
//	[Protected] Utilities methods
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------