1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Removed all references to boost::interprocess library

This commit is contained in:
Ivan Savenko 2023-07-27 22:50:50 +03:00
parent e8ee83574c
commit 593b82d178
9 changed files with 6 additions and 158 deletions

View File

@ -117,8 +117,6 @@ int main(int argc, char * argv[])
opts.add_options()
("help,h", "display help and exit")
("version,v", "display version information and exit")
("disable-shm", "force disable shared memory usage")
("enable-shm-uuid", "use UUID for shared memory identifier")
("testmap", po::value<std::string>(), "")
("testsave", po::value<std::string>(), "")
("spectate,s", "enable spectator interface for AI-only games")
@ -241,10 +239,6 @@ int main(int argc, char * argv[])
// Server settings
setSettingBool("session/donotstartserver", "donotstartserver");
// Shared memory options
setSettingBool("session/disable-shm", "disable-shm");
setSettingBool("session/enable-shm-uuid", "enable-shm-uuid");
// Init special testing settings
setSettingInteger("session/serverport", "serverport", 0);
setSettingInteger("general/saveFrequency", "savefrequency", 1);

View File

@ -28,8 +28,6 @@
#elif defined(VCMI_IOS)
#include "ios/utils.h"
#include <dispatch/dispatch.h>
#else
#include "../lib/Interprocess.h"
#endif
#ifdef SINGLE_PROCESS_APP
@ -154,29 +152,6 @@ void CServerHandler::resetStateForLobby(const StartInfo::EMode mode, const std::
myNames = *names;
else
myNames.push_back(settings["general"]["playerName"].String());
#if !defined(VCMI_ANDROID) && !defined(SINGLE_PROCESS_APP)
shm.reset();
if(!settings["session"]["disable-shm"].Bool())
{
std::string sharedMemoryName = "vcmi_memory";
if(settings["session"]["enable-shm-uuid"].Bool())
{
//used or automated testing when multiple clients start simultaneously
sharedMemoryName += "_" + uuid;
}
try
{
shm = std::make_shared<SharedMemory>(sharedMemoryName, true);
}
catch(...)
{
shm.reset();
logNetwork->error("Cannot open interprocess memory. Continue without it...");
}
}
#endif
}
void CServerHandler::startLocalServerAndConnect()
@ -256,19 +231,13 @@ void CServerHandler::startLocalServerAndConnect()
}
logNetwork->info("waiting for server finished...");
androidTestServerReadyFlag = false;
#else
if(shm)
shm->sr->waitTillReady();
#endif
logNetwork->trace("Waiting for server: %d ms", th->getDiff());
th->update(); //put breakpoint here to attach to server before it does something stupid
#if !defined(VCMI_MOBILE)
const ui16 port = shm ? shm->sr->port : 0;
#else
const ui16 port = 0;
#endif
justConnectToServer(localhostAddress, port);
logNetwork->trace("\tConnecting to the server: %d ms", th->getDiff());
@ -925,13 +894,7 @@ void CServerHandler::threadRunServer()
comm += " --lobby-port=" + std::to_string(settings["session"]["port"].Integer());
comm += " --lobby-uuid=" + settings["session"]["hostUuid"].String();
}
if(shm)
{
comm += " --enable-shm";
if(settings["session"]["enable-shm-uuid"].Bool())
comm += " --enable-shm-uuid";
}
comm += " > \"" + logName + '\"';
logGlobal->info("Server command line: %s", comm);

View File

@ -585,7 +585,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/IGameEventsReceiver.h
${MAIN_LIB_DIR}/IHandlerBase.h
${MAIN_LIB_DIR}/int3.h
${MAIN_LIB_DIR}/Interprocess.h
${MAIN_LIB_DIR}/JsonDetail.h
${MAIN_LIB_DIR}/JsonNode.h
${MAIN_LIB_DIR}/JsonRandom.h

View File

@ -1,84 +0,0 @@
/*
* Interprocess.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include <boost/interprocess/sync/interprocess_condition.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
VCMI_LIB_NAMESPACE_BEGIN
struct ServerReady
{
bool ready;
uint16_t port; //ui16?
boost::interprocess::interprocess_mutex mutex;
boost::interprocess::interprocess_condition cond;
ServerReady()
{
ready = false;
port = 0;
}
void waitTillReady()
{
boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> slock(mutex);
while(!ready)
{
cond.wait(slock);
}
}
void setToReadyAndNotify(const uint16_t Port)
{
{
boost::unique_lock<boost::interprocess::interprocess_mutex> lock(mutex);
ready = true;
port = Port;
}
cond.notify_all();
}
};
struct SharedMemory
{
std::string name;
boost::interprocess::shared_memory_object smo;
boost::interprocess::mapped_region * mr;
ServerReady * sr;
SharedMemory(const std::string & Name, bool initialize = false)
: name(Name)
{
if(initialize)
{
//if the application has previously crashed, the memory may not have been removed. to avoid problems - try to destroy it
boost::interprocess::shared_memory_object::remove(name.c_str());
}
smo = boost::interprocess::shared_memory_object(boost::interprocess::open_or_create, name.c_str(), boost::interprocess::read_write);
smo.truncate(sizeof(ServerReady));
mr = new boost::interprocess::mapped_region(smo,boost::interprocess::read_write);
if(initialize)
sr = new(mr->get_address())ServerReady();
else
sr = reinterpret_cast<ServerReady*>(mr->get_address());
};
~SharedMemory()
{
delete mr;
boost::interprocess::shared_memory_object::remove(name.c_str());
}
};
VCMI_LIB_NAMESPACE_END

View File

@ -19,7 +19,6 @@ class CampaignState;
class CMapInfo;
struct PlayerInfo;
class PlayerColor;
struct SharedMemory;
/// Struct which describes the name, the color, the starting bonus of a player
struct DLL_LINKAGE PlayerSettings
@ -157,7 +156,6 @@ struct DLL_LINKAGE LobbyInfo : public LobbyState
{
boost::mutex stateMutex;
std::string uuid;
std::shared_ptr<SharedMemory> shm;
LobbyInfo() {}

View File

@ -25,7 +25,6 @@
#include "WaterAdopter.h"
#include "WaterProxy.h"
#include "TownPlacer.h"
#include <boost/interprocess/sync/scoped_lock.hpp>
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -19,8 +19,8 @@
#include "BitmapHandler.h"
#include "Animation.h"
#include "boost/filesystem/path.hpp"
#include "boost/locale.hpp"
#include <boost/filesystem/path.hpp>
#include <boost/locale.hpp>
void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversionOptions)
{

View File

@ -33,8 +33,6 @@
#include <jni.h>
#include <android/log.h>
#include "lib/CAndroidVMHelper.h"
#elif !defined(VCMI_IOS)
#include "../lib/Interprocess.h"
#endif
#include "../lib/VCMI_Lib.h"
#include "../lib/VCMIDirs.h"
@ -142,9 +140,9 @@ CVCMIServer::CVCMIServer(boost::program_options::variables_map & opts)
catch(...)
{
logNetwork->info("Port %d is busy, trying to use random port instead", port);
if(cmdLineOptions.count("run-by-client") && !cmdLineOptions.count("enable-shm"))
if(cmdLineOptions.count("run-by-client"))
{
logNetwork->error("Cant pass port number to client without shared memory!", port);
logNetwork->error("Port must be specified when run-by-client is used!!");
exit(0);
}
acceptor = std::make_shared<TAcceptor>(*io, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0));
@ -166,17 +164,6 @@ void CVCMIServer::run()
if(!restartGameplay)
{
this->announceLobbyThread = std::make_unique<boost::thread>(&CVCMIServer::threadAnnounceLobby, this);
#if !defined(VCMI_MOBILE)
if(cmdLineOptions.count("enable-shm"))
{
std::string sharedMemoryName = "vcmi_memory";
if(cmdLineOptions.count("enable-shm-uuid") && cmdLineOptions.count("uuid"))
{
sharedMemoryName += "_" + cmdLineOptions["uuid"].as<std::string>();
}
shm = std::make_shared<SharedMemory>(sharedMemoryName);
}
#endif
startAsyncAccept();
if(!remoteConnectionsThread && cmdLineOptions.count("lobby"))
@ -189,11 +176,6 @@ void CVCMIServer::run()
CAndroidVMHelper vmHelper;
vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "onServerReady");
#endif
#elif !defined(VCMI_IOS)
if(shm)
{
shm->sr->setToReadyAndNotify(port);
}
#endif
}
@ -993,8 +975,6 @@ static void handleCommandOptions(int argc, const char * argv[], boost::program_o
("version,v", "display version information and exit")
("run-by-client", "indicate that server launched by client on same machine")
("uuid", po::value<std::string>(), "")
("enable-shm-uuid", "use UUID for shared memory identifier")
("enable-shm", "enable usage of shared memory")
("port", po::value<ui16>(), "port at which server will listen to connections from client")
("lobby", po::value<std::string>(), "address to remote lobby")
("lobby-port", po::value<ui16>(), "port at which server connect to remote lobby")

View File

@ -23,7 +23,6 @@ VCMI_LIB_NAMESPACE_BEGIN
class CMapInfo;
struct CPackForLobby;
struct SharedMemory;
struct StartInfo;
struct LobbyInfo;