}
///////////////////////////////////////////////////////////////////////////////
-// WaitingSyncItem ////////////////////////////////////////////////////////////
+// SyncItem ////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-class WaitingSyncItem
+class SyncItem
{
public:
enum Type
Failed
};
- WaitingSyncItem() :
+ SyncItem() :
_dir(),
_type(Stop),
_status(Invalid)
{
}
- WaitingSyncItem(string dir, Type ty) :
+ SyncItem(string dir, Type ty) :
_dir(dir),
_type(ty),
_status(Waiting)
busy(false)
{}
- WaitingSyncItem currentItem;
+ SyncItem currentItem;
bool isNewDirectory;
- std::queue<WaitingSyncItem> queue;
+ std::queue<SyncItem> queue;
std::auto_ptr<SVNRepository> repository;
SGTimeStamp stamp;
bool busy; ///< is the slot working or idle
* @brief translate a sync item type into one of the available slots.
* This provides the scheduling / balancing / prioritising between slots.
*/
-static unsigned int syncSlotForType(WaitingSyncItem::Type ty)
+static unsigned int syncSlotForType(SyncItem::Type ty)
{
switch (ty) {
- case WaitingSyncItem::Tile: return SYNC_SLOT_TILES;
- case WaitingSyncItem::SharedModels:
- case WaitingSyncItem::AirportData:
+ case SyncItem::Tile: return SYNC_SLOT_TILES;
+ case SyncItem::SharedModels:
+ case SyncItem::AirportData:
return SYNC_SLOT_SHARED_DATA;
default:
return SYNC_SLOT_SHARED_DATA;
bool start();
bool isIdle() {return !_busy; }
- void request(const WaitingSyncItem& dir) {waitingTiles.push_front(dir);}
+ void request(const SyncItem& dir) {waitingTiles.push_front(dir);}
bool isDirty() { bool r = _is_dirty;_is_dirty = false;return r;}
bool hasNewTiles() { return !_freshTiles.empty();}
- WaitingSyncItem getNewTile() { return _freshTiles.pop_front();}
+ SyncItem getNewTile() { return _freshTiles.pop_front();}
void setSvnServer(string server) { _svn_server = stripPath(server);}
void setExtSvnUtility(string svn_util) { _svn_command = simgear::strutils::strip(svn_util);}
// external model run and helpers
void runExternal();
- void syncPathExternal(const WaitingSyncItem& next);
+ void syncPathExternal(const SyncItem& next);
bool runExternalSyncCommand(const char* dir);
// internal mode run and helpers
// commond helpers between both internal and external models
- bool isPathCached(const WaitingSyncItem& next) const;
+ bool isPathCached(const SyncItem& next) const;
void initCompletedTilesPersistentCache();
void writeCompletedTilesPersistentCache() const;
- void updated(WaitingSyncItem item, bool isNewDirectory);
- void fail(WaitingSyncItem failedItem);
+ void updated(SyncItem item, bool isNewDirectory);
+ void fail(SyncItem failedItem);
bool _use_built_in;
HTTP::Client _http;
volatile bool _is_dirty;
volatile bool _stop;
- SGBlockingDeque <WaitingSyncItem> waitingTiles;
+ SGBlockingDeque <SyncItem> waitingTiles;
CompletedTiles _completedTiles;
- SGBlockingDeque <WaitingSyncItem> _freshTiles;
+ SGBlockingDeque <SyncItem> _freshTiles;
bool _use_svn;
string _svn_server;
string _svn_command;
// set stop flag and wake up the thread with an empty request
_stop = true;
- WaitingSyncItem w(string(), WaitingSyncItem::Stop);
+ SyncItem w(string(), SyncItem::Stop);
request(w);
join();
_running = false;
{
while (!_stop)
{
- WaitingSyncItem next = waitingTiles.pop_front();
+ SyncItem next = waitingTiles.pop_front();
if (_stop)
break;
_cache_hits++;
SG_LOG(SG_TERRAIN, SG_DEBUG,
"Cache hit for: '" << next._dir << "'");
- next._status = WaitingSyncItem::Cached;
+ next._status = SyncItem::Cached;
_freshTiles.push_back(next);
_is_dirty = true;
continue;
} // of thread running loop
}
-void SGTerraSync::SvnThread::syncPathExternal(const WaitingSyncItem& next)
+void SGTerraSync::SvnThread::syncPathExternal(const SyncItem& next)
{
_busy = true;
SGPath path( _local_dir );
if (res == SVNRepository::SVN_ERROR_NOT_FOUND) {
// this is fine, but maybe we should use a different return code
// in the future to higher layers can distinguish this case
- slot.currentItem._status = WaitingSyncItem::NotFound;
+ slot.currentItem._status = SyncItem::NotFound;
_freshTiles.push_back(slot.currentItem);
_is_dirty = true;
} else if (res != SVNRepository::SVN_NO_ERROR) {
// drain the waiting tiles queue into the sync slot queues.
while (!waitingTiles.empty()) {
- WaitingSyncItem next = waitingTiles.pop_front();
+ SyncItem next = waitingTiles.pop_front();
if (isPathCached(next)) {
_cache_hits++;
SG_LOG(SG_TERRAIN, SG_DEBUG, "TerraSync Cache hit for: '" << next._dir << "'");
- next._status = WaitingSyncItem::Cached;
+ next._status = SyncItem::Cached;
_freshTiles.push_back(next);
_is_dirty = true;
continue;
} // of thread running loop
}
-bool SGTerraSync::SvnThread::isPathCached(const WaitingSyncItem& next) const
+bool SGTerraSync::SvnThread::isPathCached(const SyncItem& next) const
{
CompletedTiles::const_iterator ii = _completedTiles.find( next._dir );
if (ii == _completedTiles.end()) {
return (ii->second > now);
}
-void SGTerraSync::SvnThread::fail(WaitingSyncItem failedItem)
+void SGTerraSync::SvnThread::fail(SyncItem failedItem)
{
time_t now = time(0);
_consecutive_errors++;
_fail_count++;
- failedItem._status = WaitingSyncItem::Failed;
+ failedItem._status = SyncItem::Failed;
_freshTiles.push_back(failedItem);
_completedTiles[ failedItem._dir ] = now + UpdateInterval::FailedAttempt;
_is_dirty = true;
}
-void SGTerraSync::SvnThread::updated(WaitingSyncItem item, bool isNewDirectory)
+void SGTerraSync::SvnThread::updated(SyncItem item, bool isNewDirectory)
{
time_t now = time(0);
_consecutive_errors = 0;
SG_LOG(SG_TERRAIN,SG_INFO,
"Successfully synchronized directory '" << item._dir << "'");
- item._status = WaitingSyncItem::Updated;
- if (item._type == WaitingSyncItem::Tile) {
+ item._status = SyncItem::Updated;
+ if (item._type == SyncItem::Tile) {
_updated_tile_count++;
}
while (_svnThread->hasNewTiles())
{
- WaitingSyncItem next = _svnThread->getNewTile();
+ SyncItem next = _svnThread->getNewTile();
- if (next._type == WaitingSyncItem::Tile) {
+ if (next._type == SyncItem::Tile) {
if (_activeTileDirs.find(next._dir) == _activeTileDirs.end()) {
SG_LOG(SG_TERRAIN, SG_INFO, "TTTTTTTT: finished tile not found in active set!: " << next._dir);
}
{
ostringstream dir;
dir << "Airports/" << synced_other;
- WaitingSyncItem w(dir.str(), WaitingSyncItem::AirportData);
+ SyncItem w(dir.str(), SyncItem::AirportData);
_svnThread->request( w );
}
}
- WaitingSyncItem w("Models", WaitingSyncItem::SharedModels);
+ SyncItem w("Models", SyncItem::SharedModels);
_svnThread->request( w );
}
}
_activeTileDirs.insert(dir);
- WaitingSyncItem w(dir, WaitingSyncItem::Tile);
+ SyncItem w(dir, SyncItem::Tile);
_svnThread->request( w );
}
}