From 5e148658775056d3e01945d06a019ac26aa70c69 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 23 May 2013 12:29:55 +0000 Subject: [PATCH] Refactored the idle mechanism to fix problems with the vnc thread going idle when it shouldn't have. --- src/osgPlugins/vnc/ReaderWriterVNC.cpp | 76 +++++++++++++------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/osgPlugins/vnc/ReaderWriterVNC.cpp b/src/osgPlugins/vnc/ReaderWriterVNC.cpp index c0496da17..419d3c7b6 100644 --- a/src/osgPlugins/vnc/ReaderWriterVNC.cpp +++ b/src/osgPlugins/vnc/ReaderWriterVNC.cpp @@ -34,7 +34,6 @@ class LibVncImage : public osgWidget::VncImage virtual bool sendPointerEvent(int x, int y, int buttonMask); - double getTimeOfLastUpdate() const { return _timeOfLastUpdate; } double getTimeOfLastRender() const { return _timeOfLastRender; } double time() const { return osg::Timer::instance()->time_s(); } @@ -43,8 +42,6 @@ class LibVncImage : public osgWidget::VncImage virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp); - void updated(); - static rfbBool resizeImage(rfbClient* client); static void updateImage(rfbClient* client,int x,int y,int w,int h); @@ -56,10 +53,8 @@ class LibVncImage : public osgWidget::VncImage std::string _username; std::string _password; - double _timeOfLastUpdate; double _timeOfLastRender; - bool _active; osg::ref_ptr _inactiveBlock; protected: @@ -88,39 +83,39 @@ class LibVncImage : public osgWidget::VncImage { do { - if (_image->_active) + // OSG_NOTICE<<"RfThread::run()"<updated(); + OSG_NOTICE<<"HandleRFBServerMessage returned non zero value."<updated(); } else { + // OSG_NOTICE<<"Timed out"<time(); + double timeBeforeIdle = 0.1; + + if (currentTime > _image->getTimeOfLastRender()+timeBeforeIdle) + { + //OSG_NOTICE<<"New: Time to idle"<_inactiveBlock->reset(); _image->_inactiveBlock->block(); - } - - - double deltaTime = _image->getTimeOfLastRender() - _image->getTimeOfLastUpdate(); - if (deltaTime<-0.01) - { - //OSG_NOTICE<<"Inactive"<_active = false; + //OSG_NOTICE<<" Finished block."<_active = true; + //OSG_NOTICE<<"New: Should still be active"<serverHost = strdup(hostname.c_str()); + size_t pos = hostname.find(":"); + if (pos == std::string::npos) + { + _client->serverHost = strdup(hostname.c_str()); + } + else + { + _client->serverHost = strdup(hostname.substr(0, pos).c_str()); + _client->serverPort = atoi(hostname.substr(pos+1).c_str()); + } - // _client->serverPort = ; // _client->appData.qualityLevel = ; // _client->appData.encodings = ; // _client->appData.compressLevel = ; @@ -317,8 +320,9 @@ rfbBool LibVncImage::resizeImage(rfbClient* client) void LibVncImage::updateImage(rfbClient* client,int x,int y,int w,int h) { - osg::Image* image = (osg::Image*)(rfbClientGetClientData(client, 0)); - image->dirty(); + LibVncImage* image = (LibVncImage*)(rfbClientGetClientData(client, 0)); + + image->dirty(); } bool LibVncImage::sendPointerEvent(int x, int y, int buttonMask) @@ -344,15 +348,11 @@ bool LibVncImage::sendKeyEvent(int key, bool keyDown) void LibVncImage::setFrameLastRendered(const osg::FrameStamp*) { + _timeOfLastRender = time(); - - if (!_active) _inactiveBlock->release(); - _active = true; -} - -void LibVncImage::updated() -{ - _timeOfLastUpdate = time(); + + // release block + _inactiveBlock->release(); } class ReaderWriterVNC : public osgDB::ReaderWriter