osgEarth 2.1.1
Public Member Functions | Private Attributes

osgEarth::TaskThread Struct Reference

List of all members.

Public Member Functions

 TaskThread (TaskRequestQueue *queue)
bool getDone ()
void setDone (bool done)
void run ()
int cancel ()

Private Attributes

osg::ref_ptr< TaskRequestQueue_queue
osg::ref_ptr< TaskRequest_request
volatile bool _done

Detailed Description

Definition at line 147 of file TaskService.


Constructor & Destructor Documentation

TaskThread::TaskThread ( TaskRequestQueue queue)

Definition at line 168 of file TaskService.cpp.

                                                :
_queue( queue ),
_done( false )
{
    //nop
}

Member Function Documentation

int TaskThread::cancel ( )

Definition at line 221 of file TaskService.cpp.

{
    if ( isRunning() )
    {
        _done = true;  

        if (_request.valid())
        {
            _request->cancel();
        }

        while( isRunning() )
        {        
            OpenThreads::Thread::YieldCurrentThread();
        }
    }
    return 0;
}
bool osgEarth::TaskThread::getDone ( ) [inline]

Definition at line 150 of file TaskService.

{ return _done;}
void TaskThread::run ( )

Definition at line 176 of file TaskService.cpp.

{
    while( !_done )
    {
        _request = _queue->get();

        if ( _done )
            break;

        if (_request.valid())
        { 
            // discard a completed or canceled request:
            if ( _request->getState() != TaskRequest::STATE_PENDING )
            {
                _request->cancel();
            }

            else if ( !_request->wasCanceled() )
            {
                if ( _request->getProgressCallback() )
                    _request->getProgressCallback()->onStarted();

                _request->setState( TaskRequest::STATE_IN_PROGRESS );
                _request->run();

                //OE_INFO << LC << "Task \"" << _request->getName() << "\" runtime = " << _request->runTime() << " s." << std::endl;
            }
            else
            {
                //OE_INFO << LC << "Task \"" << _request->getName() << "\" was cancelled before it ran." << std::endl;
            }
            
            _request->setState( TaskRequest::STATE_COMPLETED );

            // signal the completion of a request.
            if ( _request->getProgressCallback() )
                _request->getProgressCallback()->onCompleted();

            // Release the request
            _request = 0;
        }
    }
}
void osgEarth::TaskThread::setDone ( bool  done) [inline]

Definition at line 151 of file TaskService.

{ _done = done; }

Member Data Documentation

volatile bool osgEarth::TaskThread::_done [private]

Definition at line 158 of file TaskService.

Definition at line 156 of file TaskService.

Definition at line 157 of file TaskService.


The documentation for this struct was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines