Replace OpenThreads with SGThread to avoid useless OSG dependency.
Untangle SG subsystems by replacing direct TileCache call with callback.
This commit is contained in:
@@ -59,9 +59,7 @@
|
|||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/misc/strutils.hxx>
|
#include <simgear/misc/strutils.hxx>
|
||||||
#include <simgear/threads/SGQueue.hxx>
|
#include <simgear/threads/SGQueue.hxx>
|
||||||
#include <simgear/scene/tgdb/TileCache.hxx>
|
|
||||||
#include <simgear/misc/sg_dir.hxx>
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
#include <OpenThreads/Thread>
|
|
||||||
|
|
||||||
#ifdef HAVE_SVN_CLIENT_H
|
#ifdef HAVE_SVN_CLIENT_H
|
||||||
# ifdef HAVE_LIBSVN_CLIENT_1
|
# ifdef HAVE_LIBSVN_CLIENT_1
|
||||||
@@ -141,7 +139,7 @@ public:
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// SGTerraSync::SvnThread /////////////////////////////////////////////////////
|
// SGTerraSync::SvnThread /////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
class SGTerraSync::SvnThread : public OpenThreads::Thread
|
class SGTerraSync::SvnThread : public SGThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SvnThread();
|
SvnThread();
|
||||||
@@ -162,6 +160,7 @@ public:
|
|||||||
void setLocalDir(string dir) { _local_dir = stripPath(dir);}
|
void setLocalDir(string dir) { _local_dir = stripPath(dir);}
|
||||||
string getLocalDir() { return _local_dir;}
|
string getLocalDir() { return _local_dir;}
|
||||||
void setUseSvn(bool use_svn) { _use_svn = use_svn;}
|
void setUseSvn(bool use_svn) { _use_svn = use_svn;}
|
||||||
|
void setAllowedErrorCount(int errors) {_allowed_errors = errors;}
|
||||||
|
|
||||||
#ifdef HAVE_SVN_CLIENT_H
|
#ifdef HAVE_SVN_CLIENT_H
|
||||||
void setUseBuiltin(bool built_in) { _use_built_in = built_in;}
|
void setUseBuiltin(bool built_in) { _use_built_in = built_in;}
|
||||||
@@ -175,6 +174,7 @@ public:
|
|||||||
volatile int _updated_tile_count;
|
volatile int _updated_tile_count;
|
||||||
volatile int _success_count;
|
volatile int _success_count;
|
||||||
volatile int _consecutive_errors;
|
volatile int _consecutive_errors;
|
||||||
|
volatile int _allowed_errors;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void run();
|
virtual void run();
|
||||||
@@ -222,6 +222,7 @@ SGTerraSync::SvnThread::SvnThread() :
|
|||||||
_updated_tile_count(0),
|
_updated_tile_count(0),
|
||||||
_success_count(0),
|
_success_count(0),
|
||||||
_consecutive_errors(0),
|
_consecutive_errors(0),
|
||||||
|
_allowed_errors(6),
|
||||||
#ifdef HAVE_SVN_CLIENT_H
|
#ifdef HAVE_SVN_CLIENT_H
|
||||||
_use_built_in(true),
|
_use_built_in(true),
|
||||||
#endif
|
#endif
|
||||||
@@ -344,7 +345,7 @@ bool SGTerraSync::SvnThread::start()
|
|||||||
<< status
|
<< status
|
||||||
<< "Directory: '" << _local_dir << "'.");
|
<< "Directory: '" << _local_dir << "'.");
|
||||||
|
|
||||||
OpenThreads::Thread::start();
|
SGThread::start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,7 +557,8 @@ void SGTerraSync::SvnThread::run()
|
|||||||
_busy = false;
|
_busy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_consecutive_errors >= 5)
|
if ((_allowed_errors >= 0)&&
|
||||||
|
(_consecutive_errors >= _allowed_errors))
|
||||||
{
|
{
|
||||||
_stalled = true;
|
_stalled = true;
|
||||||
_stop = true;
|
_stop = true;
|
||||||
@@ -670,7 +672,8 @@ SGTerraSync::SGTerraSync(SGPropertyNode_ptr root) :
|
|||||||
last_lat(NOWHERE),
|
last_lat(NOWHERE),
|
||||||
last_lon(NOWHERE),
|
last_lon(NOWHERE),
|
||||||
_terraRoot(root->getNode("/sim/terrasync",true)),
|
_terraRoot(root->getNode("/sim/terrasync",true)),
|
||||||
_tile_cache(NULL)
|
_refreshCb(NULL),
|
||||||
|
_userCbData(NULL)
|
||||||
{
|
{
|
||||||
_svnThread = new SvnThread();
|
_svnThread = new SvnThread();
|
||||||
}
|
}
|
||||||
@@ -684,7 +687,7 @@ SGTerraSync::~SGTerraSync()
|
|||||||
|
|
||||||
void SGTerraSync::init()
|
void SGTerraSync::init()
|
||||||
{
|
{
|
||||||
_refresh_display = _terraRoot->getNode("refresh-display",true);
|
_refreshDisplay = _terraRoot->getNode("refresh-display",true);
|
||||||
_terraRoot->getNode("built-in-svn-available",true)->setBoolValue(svn_built_in_available);
|
_terraRoot->getNode("built-in-svn-available",true)->setBoolValue(svn_built_in_available);
|
||||||
reinit();
|
reinit();
|
||||||
}
|
}
|
||||||
@@ -703,6 +706,7 @@ void SGTerraSync::reinit()
|
|||||||
_svnThread->setSvnServer(_terraRoot->getStringValue("svn-server",""));
|
_svnThread->setSvnServer(_terraRoot->getStringValue("svn-server",""));
|
||||||
_svnThread->setRsyncServer(_terraRoot->getStringValue("rsync-server",""));
|
_svnThread->setRsyncServer(_terraRoot->getStringValue("rsync-server",""));
|
||||||
_svnThread->setLocalDir(_terraRoot->getStringValue("scenery-dir",""));
|
_svnThread->setLocalDir(_terraRoot->getStringValue("scenery-dir",""));
|
||||||
|
_svnThread->setAllowedErrorCount(_terraRoot->getIntValue("max-errors",5));
|
||||||
|
|
||||||
#ifdef HAVE_SVN_CLIENT_H
|
#ifdef HAVE_SVN_CLIENT_H
|
||||||
_svnThread->setUseBuiltin(_terraRoot->getBoolValue("use-built-in-svn",true));
|
_svnThread->setUseBuiltin(_terraRoot->getBoolValue("use-built-in-svn",true));
|
||||||
@@ -727,7 +731,7 @@ void SGTerraSync::reinit()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_stalled_node->setBoolValue(_svnThread->_stalled);
|
_stalledNode->setBoolValue(_svnThread->_stalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SGTerraSync::bind()
|
void SGTerraSync::bind()
|
||||||
@@ -745,9 +749,9 @@ void SGTerraSync::bind()
|
|||||||
_terraRoot->getNode("use-built-in-svn", true)->setAttribute(SGPropertyNode::USERARCHIVE,false);
|
_terraRoot->getNode("use-built-in-svn", true)->setAttribute(SGPropertyNode::USERARCHIVE,false);
|
||||||
_terraRoot->getNode("use-svn", true)->setAttribute(SGPropertyNode::USERARCHIVE,false);
|
_terraRoot->getNode("use-svn", true)->setAttribute(SGPropertyNode::USERARCHIVE,false);
|
||||||
// stalled is used as a signal handler (to connect listeners triggering GUI pop-ups)
|
// stalled is used as a signal handler (to connect listeners triggering GUI pop-ups)
|
||||||
_stalled_node = _terraRoot->getNode("stalled", true);
|
_stalledNode = _terraRoot->getNode("stalled", true);
|
||||||
_stalled_node->setBoolValue(_svnThread->_stalled);
|
_stalledNode->setBoolValue(_svnThread->_stalled);
|
||||||
_stalled_node->setAttribute(SGPropertyNode::PRESERVE,true);
|
_stalledNode->setAttribute(SGPropertyNode::PRESERVE,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SGTerraSync::unbind()
|
void SGTerraSync::unbind()
|
||||||
@@ -774,10 +778,10 @@ void SGTerraSync::update(double)
|
|||||||
SG_LOG(SG_TERRAIN,SG_ALERT,
|
SG_LOG(SG_TERRAIN,SG_ALERT,
|
||||||
"Automatic scenery download/synchronization has stopped.");
|
"Automatic scenery download/synchronization has stopped.");
|
||||||
}
|
}
|
||||||
_stalled_node->setBoolValue(_svnThread->_stalled);
|
_stalledNode->setBoolValue(_svnThread->_stalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_refresh_display->getBoolValue())
|
if (!_refreshDisplay->getBoolValue())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (_svnThread->hasNewTiles())
|
while (_svnThread->hasNewTiles())
|
||||||
@@ -794,7 +798,7 @@ void SGTerraSync::update(double)
|
|||||||
void SGTerraSync::refreshScenery(SGPath path,const string& relativeDir)
|
void SGTerraSync::refreshScenery(SGPath path,const string& relativeDir)
|
||||||
{
|
{
|
||||||
// find tiles to be refreshed
|
// find tiles to be refreshed
|
||||||
if (_tile_cache)
|
if (_refreshCb)
|
||||||
{
|
{
|
||||||
path.append(relativeDir);
|
path.append(relativeDir);
|
||||||
if (path.exists())
|
if (path.exists())
|
||||||
@@ -808,7 +812,7 @@ void SGTerraSync::refreshScenery(SGPath path,const string& relativeDir)
|
|||||||
{
|
{
|
||||||
// reload scenery tile
|
// reload scenery tile
|
||||||
long index = atoi(tileList[i].file().c_str());
|
long index = atoi(tileList[i].file().c_str());
|
||||||
_tile_cache->refresh_tile(index);
|
_refreshCb(_userCbData, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -816,9 +820,10 @@ void SGTerraSync::refreshScenery(SGPath path,const string& relativeDir)
|
|||||||
|
|
||||||
bool SGTerraSync::isIdle() {return _svnThread->isIdle();}
|
bool SGTerraSync::isIdle() {return _svnThread->isIdle();}
|
||||||
|
|
||||||
void SGTerraSync::setTileCache(TileCache* tile_cache)
|
void SGTerraSync::setTileRefreshCb(SGTerraSyncCallback refreshCb, void* userCbData)
|
||||||
{
|
{
|
||||||
_tile_cache = tile_cache;
|
_refreshCb = refreshCb;
|
||||||
|
_userCbData = userCbData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SGTerraSync::syncAirportsModels()
|
void SGTerraSync::syncAirportsModels()
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
#include <simgear/props/tiedpropertylist.hxx>
|
#include <simgear/props/tiedpropertylist.hxx>
|
||||||
#include <OpenThreads/Thread>
|
|
||||||
|
|
||||||
class SGPath;
|
class SGPath;
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ namespace simgear
|
|||||||
{
|
{
|
||||||
const int NOWHERE = -9999;
|
const int NOWHERE = -9999;
|
||||||
|
|
||||||
class TileCache;
|
typedef void (*SGTerraSyncCallback)(void* userData, long tileIndex);
|
||||||
|
|
||||||
class SGTerraSync : public SGSubsystem
|
class SGTerraSync : public SGSubsystem
|
||||||
{
|
{
|
||||||
@@ -48,7 +47,7 @@ public:
|
|||||||
|
|
||||||
bool isIdle();
|
bool isIdle();
|
||||||
bool schedulePosition(int lat, int lon);
|
bool schedulePosition(int lat, int lon);
|
||||||
void setTileCache(TileCache* tile_cache);
|
void setTileRefreshCb(SGTerraSyncCallback refreshCb, void* userData = NULL);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void syncAirportsModels();
|
void syncAirportsModels();
|
||||||
@@ -63,9 +62,10 @@ private:
|
|||||||
int last_lat;
|
int last_lat;
|
||||||
int last_lon;
|
int last_lon;
|
||||||
SGPropertyNode_ptr _terraRoot;
|
SGPropertyNode_ptr _terraRoot;
|
||||||
SGPropertyNode_ptr _refresh_display;
|
SGPropertyNode_ptr _refreshDisplay;
|
||||||
SGPropertyNode_ptr _stalled_node;
|
SGPropertyNode_ptr _stalledNode;
|
||||||
TileCache* _tile_cache;
|
SGTerraSyncCallback _refreshCb;
|
||||||
|
void* _userCbData;
|
||||||
simgear::TiedPropertyList _tiedProperties;
|
simgear::TiedPropertyList _tiedProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user