Inject SyncBuffer into SyncEngine. Add Doxygen comments for SyncEngine and SyncData

This commit is contained in:
Erik Broberg
2016-09-16 20:32:29 -04:00
parent dd304fee31
commit 7f393a3270
5 changed files with 94 additions and 26 deletions
@@ -51,7 +51,6 @@ class LuaConsole;
class NetworkEngine;
class GUI;
class RenderEngine;
class SyncBuffer;
class ModuleEngine;
class WindowWrapper;
class SettingsEngine;
@@ -161,7 +160,6 @@ private:
// Others
std::unique_ptr<properties::PropertyOwner> _globalPropertyNamespace;
std::unique_ptr<SyncBuffer> _syncBuffer;
bool _isMaster;
double _runTime;
+48 -5
View File
@@ -27,6 +27,7 @@
#include <vector>
#include <memory>
namespace openspace {
@@ -36,25 +37,67 @@ class SyncBuffer;
/**
* Manages a collection of <code>Syncable</code>s and ensures they are synchronized
* over SGCT nodes.
* over SGCT nodes. Encoding/Decoding order is handles internally.
*/
class SyncEngine {
public:
/**
* Dependency injection: a SyncEngine relies on a SyncBuffer to encode the sync data.
*/
SyncEngine(SyncBuffer* syncBuffer);
/**
* Encodes all added Syncables in the injected <code>SyncBuffer</code>.
* This method is only called on the SGCT master node
*/
void encodeSyncables();
/**
* Decodes the <code>SyncBuffer</code> into the added Syncables.
* This method is only called on the SGCT slave nodes
*/
void decodeSyncables();
/**
* Invokes the presync method of all added Syncables
*/
void presync(bool isMaster);
void encode(SyncBuffer* syncBuffer);
void decode(SyncBuffer* syncBuffer);
/**
* Invokes the postsync method of all added Syncables
*/
void postsync(bool isMaster);
/**
* Add a Syncable to be synchronized over the SGCT cluster
*/
void addSyncable(Syncable* syncable);
/**
* Add multiple Syncables to be synchronized over the SGCT cluster
*/
void addSyncables(const std::vector<Syncable*>& syncables);
/**
* Remove a Syncable from being synchronized over the SGCT cluster
*/
void removeSyncable(Syncable* syncable);
private:
/**
* Vector of Syncables. The vectors ensures consistent encode/decode order
*/
std::vector<Syncable*> _syncables;
::std::vector<Syncable*> _syncables;
/**
* Databuffer used in encoding/decoding
*/
std::unique_ptr<SyncBuffer> _syncBuffer;
};
+28 -4
View File
@@ -36,15 +36,17 @@ namespace openspace {
/**
* Interace for synchronizable data
* Interface for synchronizable data
*
* Used by <code>SyncEngine</code> for synchronization
* Used by <code>SyncEngine</code>
*/
class Syncable {
public:
virtual ~Syncable() {};
protected:
// Allowing SyncEngine synchronization methods and at the same time hiding them
// from the used of implementations of the interface
friend class SyncEngine;
virtual void presync(bool isMaster) {};
virtual void encode(SyncBuffer* syncBuffer) = 0;
@@ -52,7 +54,18 @@ protected:
virtual void postsync(bool isMaster) {};
};
/**
* A double buffered implementation of the Syncable interface.
* Users are encouraged to used this class as a default way to synchronize different
* C++ data types using the <code>SyncEngine</code>
*
* This class aims to handle the synchronization parts and yet act like a regular
* instance of T. Implicit casts are supported, however, when accessing member functions or
* or variables, user may have to do explicit casts.
*
* ((T&) t).method();
*
*/
template<class T>
class SyncData : public Syncable {
public:
@@ -60,23 +73,33 @@ public:
SyncData() {};
SyncData(const T& val) : data(val) {};
SyncData(const SyncData<T>& o) : data(o.data) {
// should not be copied!
// Should not have to be copied!
};
/**
* Allowing assignment of data as if
*/
SyncData& operator=(const T& rhs) {
data = rhs;
return *this;
}
/**
* Allow implicit cast to referenced T
*/
operator T&() {
return data;
}
/**
* Allow implicit cast to const referenced T
*/
operator const T&() const {
return data;
}
protected:
virtual void encode(SyncBuffer* syncBuffer) {
_mutex.lock();
syncBuffer->encode(data);
@@ -98,6 +121,7 @@ protected:
}
};
T data;
T doubleBufferedData;
std::mutex _mutex;