more work on scripting synchronization and state saving

This commit is contained in:
Joakim Kilby
2015-07-05 17:21:23 +02:00
parent 72dbf1ecc9
commit d76e18d9ee
2 changed files with 58 additions and 0 deletions

View File

@@ -40,6 +40,7 @@
#include <thread>
#include <sstream>
#include <mutex>
#include <map>
#ifdef __WIN32__
#ifndef WIN32_LEAN_AND_MEAN
@@ -90,6 +91,8 @@ namespace openspace{
void preSynchronization();
void scriptMessage(const std::string propIdentifier, const std::string propValue);
enum MessageTypes{
Authentication=0,
Initialization,
@@ -171,6 +174,8 @@ namespace openspace{
void threadManagement();
std::string scriptFromPropertyAndValue(const std::string property, const std::string value);
uint32_t _passCode;
std::string _port;
std::string _address;
@@ -192,6 +197,7 @@ namespace openspace{
network::datamessagestructures::TimeKeyframe _latestTimeKeyframe;
std::mutex _timeKeyframeMutex;
std::atomic<bool> _latestTimeKeyframeValid;
std::map<std::string, std::string> _currentState;
};
} // namespace network

View File

@@ -1004,6 +1004,58 @@ namespace openspace {
}
}
void ParallelConnection::scriptMessage(const std::string propIdentifier, const std::string propValue){
//save script as current state
_currentState[propIdentifier] = propValue;
//construct script
std::string script = scriptFromPropertyAndValue(propIdentifier, propValue);
//create a script message
network::datamessagestructures::ScriptMessage sm;
sm._script = script;
sm._scriptlen = static_cast<uint16_t>(script.length());
//create a buffer for the script
std::vector<char> sbuffer;
//fill the script buffer
sm.serialize(sbuffer);
//get the size of the keyframebuffer
uint16_t msglen = static_cast<uint16_t>(sbuffer.size());
//the type of message
uint16_t type = static_cast<uint16_t>(network::datamessagestructures::ScriptData);
//create the full buffer
std::vector<char> buffer;
buffer.reserve(headerSize() + sizeof(type) + sizeof(msglen) + msglen);
//write header
writeHeader(buffer, MessageTypes::Data);
//type of message
buffer.insert(buffer.end(), reinterpret_cast<char*>(&type), reinterpret_cast<char*>(&type) + sizeof(type));
//size of message
buffer.insert(buffer.end(), reinterpret_cast<char*>(&msglen), reinterpret_cast<char*>(&msglen) + sizeof(msglen));
//actual message
buffer.insert(buffer.end(), sbuffer.begin(), sbuffer.end());
//send message
queMessage(buffer);
}
std::string ParallelConnection::scriptFromPropertyAndValue(const std::string property, const std::string value){
//consruct script
std::string script = "openspace.setPropertyValue(\"" + property + ",\"" + value + "\")";
return script;
}
void ParallelConnection::broadcast(){
//while we're still connected and we're the host