#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/threads/SGQueue.hxx>
-#include <simgear/scene/tgdb/TileCache.hxx>
#include <simgear/misc/sg_dir.hxx>
-#include <OpenThreads/Thread>
#ifdef HAVE_SVN_CLIENT_H
# ifdef HAVE_LIBSVN_CLIENT_1
///////////////////////////////////////////////////////////////////////////////
// SGTerraSync::SvnThread /////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-class SGTerraSync::SvnThread : public OpenThreads::Thread
+class SGTerraSync::SvnThread : public SGThread
{
public:
SvnThread();
void setLocalDir(string dir) { _local_dir = stripPath(dir);}
string getLocalDir() { return _local_dir;}
void setUseSvn(bool use_svn) { _use_svn = use_svn;}
+ void setAllowedErrorCount(int errors) {_allowed_errors = errors;}
#ifdef HAVE_SVN_CLIENT_H
void setUseBuiltin(bool built_in) { _use_built_in = built_in;}
volatile int _updated_tile_count;
volatile int _success_count;
volatile int _consecutive_errors;
+ volatile int _allowed_errors;
private:
virtual void run();
_updated_tile_count(0),
_success_count(0),
_consecutive_errors(0),
+ _allowed_errors(6),
#ifdef HAVE_SVN_CLIENT_H
_use_built_in(true),
#endif
<< status
<< "Directory: '" << _local_dir << "'.");
- OpenThreads::Thread::start();
+ SGThread::start();
return true;
}
_busy = false;
}
- if (_consecutive_errors >= 5)
+ if ((_allowed_errors >= 0)&&
+ (_consecutive_errors >= _allowed_errors))
{
_stalled = true;
_stop = true;
last_lat(NOWHERE),
last_lon(NOWHERE),
_terraRoot(root->getNode("/sim/terrasync",true)),
- _tile_cache(NULL)
+ _refreshCb(NULL),
+ _userCbData(NULL)
{
_svnThread = new SvnThread();
}
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);
reinit();
}
_svnThread->setSvnServer(_terraRoot->getStringValue("svn-server",""));
_svnThread->setRsyncServer(_terraRoot->getStringValue("rsync-server",""));
_svnThread->setLocalDir(_terraRoot->getStringValue("scenery-dir",""));
+ _svnThread->setAllowedErrorCount(_terraRoot->getIntValue("max-errors",5));
#ifdef HAVE_SVN_CLIENT_H
_svnThread->setUseBuiltin(_terraRoot->getBoolValue("use-built-in-svn",true));
}
}
- _stalled_node->setBoolValue(_svnThread->_stalled);
+ _stalledNode->setBoolValue(_svnThread->_stalled);
}
void SGTerraSync::bind()
_terraRoot->getNode("use-built-in-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_node = _terraRoot->getNode("stalled", true);
- _stalled_node->setBoolValue(_svnThread->_stalled);
- _stalled_node->setAttribute(SGPropertyNode::PRESERVE,true);
+ _stalledNode = _terraRoot->getNode("stalled", true);
+ _stalledNode->setBoolValue(_svnThread->_stalled);
+ _stalledNode->setAttribute(SGPropertyNode::PRESERVE,true);
}
void SGTerraSync::unbind()
SG_LOG(SG_TERRAIN,SG_ALERT,
"Automatic scenery download/synchronization has stopped.");
}
- _stalled_node->setBoolValue(_svnThread->_stalled);
+ _stalledNode->setBoolValue(_svnThread->_stalled);
}
- if (!_refresh_display->getBoolValue())
+ if (!_refreshDisplay->getBoolValue())
return;
while (_svnThread->hasNewTiles())
void SGTerraSync::refreshScenery(SGPath path,const string& relativeDir)
{
// find tiles to be refreshed
- if (_tile_cache)
+ if (_refreshCb)
{
path.append(relativeDir);
if (path.exists())
{
// reload scenery tile
long index = atoi(tileList[i].file().c_str());
- _tile_cache->refresh_tile(index);
+ _refreshCb(_userCbData, index);
}
}
}
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()
#include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/props/tiedpropertylist.hxx>
-#include <OpenThreads/Thread>
class SGPath;
{
const int NOWHERE = -9999;
-class TileCache;
+typedef void (*SGTerraSyncCallback)(void* userData, long tileIndex);
class SGTerraSync : public SGSubsystem
{
bool isIdle();
bool schedulePosition(int lat, int lon);
- void setTileCache(TileCache* tile_cache);
+ void setTileRefreshCb(SGTerraSyncCallback refreshCb, void* userData = NULL);
protected:
void syncAirportsModels();
int last_lat;
int last_lon;
SGPropertyNode_ptr _terraRoot;
- SGPropertyNode_ptr _refresh_display;
- SGPropertyNode_ptr _stalled_node;
- TileCache* _tile_cache;
+ SGPropertyNode_ptr _refreshDisplay;
+ SGPropertyNode_ptr _stalledNode;
+ SGTerraSyncCallback _refreshCb;
+ void* _userCbData;
simgear::TiedPropertyList _tiedProperties;
};