mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 12:10:52 -06:00
adding parallelconnection
This commit is contained in:
@@ -56,6 +56,10 @@ namespace gui {
|
||||
namespace scripting {
|
||||
class ScriptEngine;
|
||||
}
|
||||
|
||||
namespace network{
|
||||
class OSParallelConnection;
|
||||
}
|
||||
|
||||
class OpenSpaceEngine {
|
||||
public:
|
||||
@@ -77,6 +81,7 @@ public:
|
||||
NetworkEngine* networkEngine();
|
||||
LuaConsole* console();
|
||||
ModuleEngine* moduleEngine();
|
||||
network::OSParallelConnection* parallelConnection();
|
||||
|
||||
gui::GUI* gui();
|
||||
|
||||
@@ -124,6 +129,7 @@ private:
|
||||
LuaConsole* _console;
|
||||
ModuleEngine* _moduleEngine;
|
||||
gui::GUI* _gui;
|
||||
network::OSParallelConnection* _parallelConnection;
|
||||
bool _isMaster;
|
||||
|
||||
SyncBuffer* _syncBuffer;
|
||||
|
||||
126
include/openspace/network/osparallelconnection.h
Normal file
126
include/openspace/network/osparallelconnection.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OSPARALLELCONNECTION_H__
|
||||
#define __OSPARALLELCONNECTION_H__
|
||||
|
||||
//openspace includes
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
//std includes
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#ifdef __WIN32__
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#if defined(__WIN32__) || defined(__MING32__) || defined(__MING64__)
|
||||
typedef size_t _SOCKET;
|
||||
#else
|
||||
typedef int _SOCKET;
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
namespace openspace{
|
||||
|
||||
namespace network{
|
||||
|
||||
class OSParallelConnection : public properties::PropertyOwner {
|
||||
public:
|
||||
|
||||
OSParallelConnection();
|
||||
|
||||
~OSParallelConnection();
|
||||
|
||||
void connect();
|
||||
|
||||
void setPort(const std::string &port);
|
||||
|
||||
std::string port();
|
||||
|
||||
void setAddress(const std::string &address);
|
||||
|
||||
std::string address();
|
||||
|
||||
void setName(const std::string& name);
|
||||
|
||||
std::string name();
|
||||
|
||||
void setSocket(_SOCKET socket);
|
||||
|
||||
_SOCKET socket();
|
||||
|
||||
void setHost(bool host);
|
||||
|
||||
bool isHost();
|
||||
|
||||
bool isRunning();
|
||||
|
||||
void requestHostship();
|
||||
|
||||
enum MessageTypes{
|
||||
Authentication=0,
|
||||
Initialization,
|
||||
Data,
|
||||
HostInfo,
|
||||
InitRequest
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to affect the
|
||||
* remote OS parallel connection. The functions contained are
|
||||
* -
|
||||
* \return The Lua library that contains all Lua functions available to affect the
|
||||
* interaction
|
||||
*/
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
uint32_t _passCode;
|
||||
std::string _password;
|
||||
std::string _port;
|
||||
std::string _address;
|
||||
std::string _name;
|
||||
_SOCKET _clientSocket;
|
||||
std::thread *_thread;
|
||||
std::atomic<bool> _isRunning;
|
||||
std::atomic<bool> _isHost;
|
||||
};
|
||||
} // namespace network
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OSPARALLELCONNECTION_H__
|
||||
@@ -50,6 +50,8 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/externalcontrol/pythonexternalcontrol.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/interaction/externalcontrol/randomexternalcontrol.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/network/networkengine.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/network/osparallelconnection.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/network/osparallelconnection_lua.inl
|
||||
${OPENSPACE_BASE_DIR}/src/properties/matrixproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/optionproperty.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/properties/property.cpp
|
||||
@@ -111,6 +113,7 @@ set(OPENSPACE_HEADER
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/interaction/externalcontrol/pythonexternalcontrol.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/interaction/externalcontrol/randomexternalcontrol.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/network/networkengine.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/network/osparallelconnection.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/matrixproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/numericalproperty.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/properties/numericalproperty.inl
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/network/osparallelconnection.h>
|
||||
|
||||
#include <ghoul/ghoul.h>
|
||||
#include <ghoul/cmdparser/commandlineparser.h>
|
||||
@@ -110,6 +111,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
|
||||
, _gui(new gui::GUI)
|
||||
, _isMaster(false)
|
||||
, _syncBuffer(nullptr)
|
||||
, _parallelConnection(new network::OSParallelConnection)
|
||||
{
|
||||
FactoryManager::initialize();
|
||||
SpiceManager::initialize();
|
||||
@@ -129,6 +131,7 @@ OpenSpaceEngine::~OpenSpaceEngine() {
|
||||
delete _console;
|
||||
delete _moduleEngine;
|
||||
delete _gui;
|
||||
delete _parallelConnection;
|
||||
|
||||
if(_syncBuffer)
|
||||
delete _syncBuffer;
|
||||
@@ -302,6 +305,7 @@ bool OpenSpaceEngine::initialize() {
|
||||
_scriptEngine->addLibrary(interaction::InteractionHandler::luaLibrary());
|
||||
_scriptEngine->addLibrary(LuaConsole::luaLibrary());
|
||||
_scriptEngine->addLibrary(gui::GUI::luaLibrary());
|
||||
_scriptEngine->addLibrary(network::OSParallelConnection::luaLibrary());
|
||||
|
||||
// TODO: Maybe move all scenegraph and renderengine stuff to initializeGL
|
||||
scriptEngine()->initialize();
|
||||
@@ -758,5 +762,10 @@ NetworkEngine* OpenSpaceEngine::networkEngine() {
|
||||
ModuleEngine* OpenSpaceEngine::moduleEngine() {
|
||||
return _moduleEngine;
|
||||
}
|
||||
|
||||
network::OSParallelConnection* OpenSpaceEngine::parallelConnection() {
|
||||
ghoul_assert(_parallelConnection != nullptr, "ParallelConnection is nullptr");
|
||||
return _parallelConnection;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
180
src/network/osparallelconnection.cpp
Normal file
180
src/network/osparallelconnection.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/network/osparallelconnection.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include "osparallelconnection_lua.inl"
|
||||
|
||||
namespace openspace {
|
||||
namespace network{
|
||||
|
||||
OSParallelConnection::OSParallelConnection():
|
||||
_passCode(0),
|
||||
_port(""),
|
||||
_address(""),
|
||||
_name("No name"),
|
||||
_password(""),
|
||||
_clientSocket(0),
|
||||
_thread(nullptr),
|
||||
_isRunning(false),
|
||||
_isHost(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
OSParallelConnection::~OSParallelConnection(){
|
||||
|
||||
}
|
||||
|
||||
void OSParallelConnection::connect(){
|
||||
|
||||
}
|
||||
|
||||
void OSParallelConnection::setPort(const std::string &port){
|
||||
_port = port;
|
||||
}
|
||||
|
||||
std::string OSParallelConnection::port(){
|
||||
return _port;
|
||||
}
|
||||
|
||||
void OSParallelConnection::setAddress(const std::string &address){
|
||||
_address = address;
|
||||
}
|
||||
|
||||
std::string OSParallelConnection::address(){
|
||||
return _address;
|
||||
}
|
||||
|
||||
void OSParallelConnection::setName(const std::string& name){
|
||||
_name = name;
|
||||
}
|
||||
|
||||
std::string OSParallelConnection::name(){
|
||||
return _name;
|
||||
}
|
||||
|
||||
void OSParallelConnection::setSocket(_SOCKET socket){
|
||||
_clientSocket = socket;
|
||||
}
|
||||
|
||||
_SOCKET OSParallelConnection::socket(){
|
||||
return _clientSocket;
|
||||
}
|
||||
|
||||
void OSParallelConnection::setHost(bool host){
|
||||
_isHost.store(host);
|
||||
}
|
||||
|
||||
bool OSParallelConnection::isHost(){
|
||||
return _isHost.load();
|
||||
}
|
||||
|
||||
bool OSParallelConnection::isRunning(){
|
||||
return _isRunning.load();
|
||||
}
|
||||
|
||||
void OSParallelConnection::requestHostship(){
|
||||
|
||||
}
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary OSParallelConnection::luaLibrary() {
|
||||
return {
|
||||
"",
|
||||
{
|
||||
{
|
||||
"setPort",
|
||||
&luascriptfunctions::setPort,
|
||||
"string",
|
||||
"Set the port for the parallel connection"
|
||||
},
|
||||
// {
|
||||
// "clearKeys",
|
||||
// &luascriptfunctions::clearKeys,
|
||||
// "",
|
||||
// "Clear all key bindings"
|
||||
// },
|
||||
// {
|
||||
// "bindKey",
|
||||
// &luascriptfunctions::bindKey,
|
||||
// "string, string",
|
||||
// "Binds a key by name to a lua string command"
|
||||
// },
|
||||
// {
|
||||
// "dt",
|
||||
// &luascriptfunctions::dt,
|
||||
// "",
|
||||
// "Get current frame time"
|
||||
// },
|
||||
// {
|
||||
// "distance",
|
||||
// &luascriptfunctions::distance,
|
||||
// "number",
|
||||
// "Change distance to origin"
|
||||
// },
|
||||
// {
|
||||
// "setInteractionSensitivity",
|
||||
// &luascriptfunctions::setInteractionSensitivity,
|
||||
// "number",
|
||||
// "Sets the global interaction sensitivity"
|
||||
// },
|
||||
// {
|
||||
// "interactionSensitivity",
|
||||
// &luascriptfunctions::interactionSensitivity,
|
||||
// "",
|
||||
// "Gets the current global interaction sensitivity"
|
||||
// },
|
||||
// {
|
||||
// "setInvertRoll",
|
||||
// &luascriptfunctions::setInvertRoll,
|
||||
// "bool",
|
||||
// "Sets the setting if roll movements are inverted"
|
||||
// },
|
||||
// {
|
||||
// "invertRoll",
|
||||
// &luascriptfunctions::invertRoll,
|
||||
// "",
|
||||
// "Returns the status of roll movement inversion"
|
||||
// },
|
||||
// {
|
||||
// "setInvertRotation",
|
||||
// &luascriptfunctions::setInvertRotation,
|
||||
// "bool",
|
||||
// "Sets the setting if rotation movements are inverted"
|
||||
// },
|
||||
// {
|
||||
// "invertRotation",
|
||||
// &luascriptfunctions::invertRotation,
|
||||
// "",
|
||||
// "Returns the status of rotation movement inversion"
|
||||
// }
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace network
|
||||
|
||||
} // namespace openspace
|
||||
55
src/network/osparallelconnection_lua.inl
Normal file
55
src/network/osparallelconnection_lua.inl
Normal file
@@ -0,0 +1,55 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace luascriptfunctions {
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* setPort():
|
||||
* Set the port for parallel connection
|
||||
*/
|
||||
int setPort(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.setPort";
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
if (type != LUA_TSTRING)
|
||||
return luaL_error(L, "Expected string, got %i", type);
|
||||
|
||||
std::string s = luaL_checkstring(L, -1);
|
||||
|
||||
OsEng.parallelConnection()->setPort(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace luascriptfunctions
|
||||
|
||||
} // namespace openspace
|
||||
Reference in New Issue
Block a user