mirror of
https://github.com/debauchee/barrier.git
synced 2024-11-25 08:42:52 +03:00
d2135af0d9
CServer to the primary screen when the configuration changes so it can make necessary adjustments (the win32 primary screen must tell the hook dll about the new jump zones). changed includes of some std c++ library files to go through our own include files. these wrap the include with stuff to keep vc++ quiet when compiling at warning level 4, which is what it does now. it also works around missing <istream> and <ostream> on g++2.96. added missing std:: where necessary. g++ doesn't really support namespaces so it lets references without the namespace slip through. added workaround or fix. not sure if istringstream::str(string) should reset eofbit. it does on g++ but does not on vc++. added clear() after str() so it works either way. added low-level keyboard hook to win32. if available (it's only available on NT SP3 and up) it allows us to catch and handle alt+tab, alt+esc, ctrl+esc, and windows key hot keys. i think that leaves only ctrl+alt+del and accessibility functions uncaught on those systems.
138 lines
2.1 KiB
C++
138 lines
2.1 KiB
C++
#include "CServer.h"
|
|
#include "CConfig.h"
|
|
#include "CLog.h"
|
|
#include "CMutex.h"
|
|
#include "CNetwork.h"
|
|
#include "CThread.h"
|
|
#include "stdfstream.h"
|
|
#include <assert.h>
|
|
|
|
//
|
|
// config file stuff
|
|
//
|
|
|
|
static const char* s_configFileName = "synergy.conf";
|
|
|
|
|
|
//
|
|
// logging thread safety
|
|
//
|
|
|
|
static CMutex* s_logMutex = NULL;
|
|
|
|
static void logLock(bool lock)
|
|
{
|
|
assert(s_logMutex != NULL);
|
|
|
|
if (lock) {
|
|
s_logMutex->lock();
|
|
}
|
|
else {
|
|
s_logMutex->unlock();
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
// main
|
|
//
|
|
|
|
void realMain()
|
|
{
|
|
// initialize threading library
|
|
CThread::init();
|
|
|
|
// make logging thread safe
|
|
CMutex logMutex;
|
|
s_logMutex = &logMutex;
|
|
CLog::setLock(&logLock);
|
|
|
|
// initialize network library
|
|
CNetwork::init();
|
|
|
|
CServer* server = NULL;
|
|
try {
|
|
CConfig config;
|
|
{
|
|
log((CLOG_DEBUG "opening configuration"));
|
|
std::ifstream configStream(s_configFileName);
|
|
if (!configStream) {
|
|
throw XConfigRead("cannot open configuration");
|
|
}
|
|
configStream >> config;
|
|
log((CLOG_DEBUG "configuration read successfully"));
|
|
}
|
|
|
|
server = new CServer();
|
|
server->setConfig(config);
|
|
server->run();
|
|
delete server;
|
|
CNetwork::cleanup();
|
|
CLog::setLock(NULL);
|
|
s_logMutex = NULL;
|
|
}
|
|
catch (...) {
|
|
delete server;
|
|
CNetwork::cleanup();
|
|
CLog::setLock(NULL);
|
|
s_logMutex = NULL;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
// platform dependent entry points
|
|
//
|
|
|
|
#if defined(CONFIG_PLATFORM_WIN32)
|
|
|
|
#include "CMSWindowsScreen.h"
|
|
|
|
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
|
{
|
|
CMSWindowsScreen::init(instance);
|
|
|
|
if (__argc != 1) {
|
|
CString msg = "no arguments allowed. exiting.";
|
|
MessageBox(NULL, msg.c_str(), "error", MB_OK | MB_ICONERROR);
|
|
return 1;
|
|
}
|
|
|
|
try {
|
|
realMain();
|
|
return 0;
|
|
}
|
|
catch (XBase& e) {
|
|
log((CLOG_CRIT "failed: %s", e.what()));
|
|
CString msg = "failed: ";
|
|
msg += e.what();
|
|
MessageBox(NULL, msg.c_str(), "error", MB_OK | MB_ICONERROR);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
if (argc != 1) {
|
|
fprintf(stderr, "usage: %s\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
try {
|
|
realMain();
|
|
return 0;
|
|
}
|
|
catch (XBase& e) {
|
|
log((CLOG_CRIT "failed: %s", e.what()));
|
|
fprintf(stderr, "failed: %s\n", e.what());
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
#endif
|