From aff2b717fd0e7679e61ce552229aefc6a66b4b6f Mon Sep 17 00:00:00 2001 From: Serhii Hadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com> Date: Tue, 29 Nov 2022 21:00:37 +0200 Subject: [PATCH] Single app for server and client (#7239) * Remove unused files * Add synergy-core * Update ChangeLog * Fix compilation * Fix code smell * Add ability to run synergy-core using synergyd for windows --- ChangeLog | 1 + src/cmd/CMakeLists.txt | 1 + src/cmd/synergy-core/CMakeLists.txt | 30 +++++ src/cmd/synergy-core/synergy-core.cpp | 69 +++++++++++ src/lib/platform/MSWindowsWatchdog.cpp | 3 +- src/lib/synergy/App.cpp | 2 +- src/lib/synergy/ArgParser.cpp | 8 ++ src/lib/synergy/DaemonApp.cpp | 19 ++- src/lib/synergy/PortableTaskBarReceiver.cpp | 121 -------------------- src/lib/synergy/PortableTaskBarReceiver.h | 96 ---------------- 10 files changed, 126 insertions(+), 224 deletions(-) create mode 100644 src/cmd/synergy-core/CMakeLists.txt create mode 100644 src/cmd/synergy-core/synergy-core.cpp delete mode 100644 src/lib/synergy/PortableTaskBarReceiver.cpp delete mode 100644 src/lib/synergy/PortableTaskBarReceiver.h diff --git a/ChangeLog b/ChangeLog index bb438e62c..ac4beaa5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ Bug fixes: Enhancements: - #7222 Ability to initiate non-TLS connection from server - #7225 Ability to initiate TLS connection from server +- #7239 Single app for server and client 1.14.5 ====== diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 7156ac9d6..0f5c58672 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -18,3 +18,4 @@ add_subdirectory(synergyd) add_subdirectory(synergyc) add_subdirectory(synergys) add_subdirectory(syntool) +add_subdirectory(synergy-core) diff --git a/src/cmd/synergy-core/CMakeLists.txt b/src/cmd/synergy-core/CMakeLists.txt new file mode 100644 index 000000000..e91b01418 --- /dev/null +++ b/src/cmd/synergy-core/CMakeLists.txt @@ -0,0 +1,30 @@ +# synergy -- mouse and keyboard sharing utility +# Copyright (C) 2012-2022 Symless Ltd. +# Copyright (C) 2009 Nick Bolton +# +# This package is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# found in the file LICENSE that should have accompanied this file. +# +# This package is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(sources + synergy-core.cpp +) + +add_executable(synergy-core ${sources}) +target_link_libraries(synergy-core + arch base client common io mt net ipc platform server synlib ${libs}) + +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + install (TARGETS synergy-core DESTINATION ${SYNERGY_BUNDLE_BINARY_DIR}) +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + install (TARGETS synergy-core DESTINATION bin) +endif() + diff --git a/src/cmd/synergy-core/synergy-core.cpp b/src/cmd/synergy-core/synergy-core.cpp new file mode 100644 index 000000000..567b6b8ad --- /dev/null +++ b/src/cmd/synergy-core/synergy-core.cpp @@ -0,0 +1,69 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2012-2022 Symless Ltd. + * Copyright (C) 2002 Chris Schoeneman + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "synergy/ClientApp.h" +#include "synergy/ServerApp.h" +#include "arch/Arch.h" +#include "base/Log.h" +#include "base/EventQueue.h" +#include + +void showHelp() +{ + std::cout<<"Usage: synergy-core [...options]"< --help for more information."< 1 && argv[1] == std::string("server")); +} + +bool isClient(int argc, char** argv) +{ + return (argc > 1 && argv[1] == std::string("client")); +} + +int main(int argc, char** argv) +{ +#if SYSAPI_WIN32 + ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); +#endif + + Arch arch; + arch.init(); + + Log log; + EventQueue events; + + if (isServer(argc, argv)) { + ServerApp app(&events, nullptr); + return app.run(argc, argv); + } + else if (isClient(argc, argv)) { + ClientApp app(&events, nullptr); + return app.run(argc, argv); + } + else { + showHelp(); + } + + return 0; +} diff --git a/src/lib/platform/MSWindowsWatchdog.cpp b/src/lib/platform/MSWindowsWatchdog.cpp index 6c9750cf1..78520b6ed 100644 --- a/src/lib/platform/MSWindowsWatchdog.cpp +++ b/src/lib/platform/MSWindowsWatchdog.cpp @@ -611,7 +611,8 @@ MSWindowsWatchdog::shutdownExistingProcesses() if (entry.th32ProcessID != 0) { if (_stricmp(entry.szExeFile, "synergyc.exe") == 0 || - _stricmp(entry.szExeFile, "synergys.exe") == 0) { + _stricmp(entry.szExeFile, "synergys.exe") == 0 || + _stricmp(entry.szExeFile, "synergy-core.exe") == 0) { HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); shutdownProcess(handle, entry.th32ProcessID, 10); diff --git a/src/lib/synergy/App.cpp b/src/lib/synergy/App.cpp index 1e36734d2..e31eb0b03 100644 --- a/src/lib/synergy/App.cpp +++ b/src/lib/synergy/App.cpp @@ -215,7 +215,7 @@ App::initApp(int argc, const char** argv) // load configuration loadConfig(); - if (!argsBase().m_disableTray) { + if (!argsBase().m_disableTray && m_createTaskBarReceiver) { // create a log buffer so we can show the latest message // as a tray icon tooltip diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp index 646da8400..a9bf1055d 100644 --- a/src/lib/synergy/ArgParser.cpp +++ b/src/lib/synergy/ArgParser.cpp @@ -67,6 +67,10 @@ ArgParser::parseServerArgs(lib::synergy::ServerArgs& args, int argc, const char* else if (isArg(i, argc, argv, "", "--serial-key", 1)) { args.m_serial = SerialKey(argv[++i]); } + else if (isArg(i, argc, argv, nullptr, "server")) { + ++i; + continue; + } else { LOG((CLOG_PRINT "%s: unrecognized option `%s'" BYE, args.m_pname, argv[i], args.m_pname)); return false; @@ -120,6 +124,10 @@ ArgParser::parseClientArgs(lib::synergy::ClientArgs& args, int argc, const char* else if (isArg(i, argc, argv, nullptr, "--host")) { args.m_hostMode = true; } + else if (isArg(i, argc, argv, nullptr, "client")) { + ++i; + continue; + } else { if (i + 1 == argc) { args.m_synergyAddress = argv[i]; diff --git a/src/lib/synergy/DaemonApp.cpp b/src/lib/synergy/DaemonApp.cpp index 8f6e4f518..d9ae4465a 100644 --- a/src/lib/synergy/DaemonApp.cpp +++ b/src/lib/synergy/DaemonApp.cpp @@ -72,6 +72,19 @@ updateSetting(const IpcMessage& message) } } +bool +isServerCommandLine(const std::vector& cmd) +{ + auto isServer = false; + + if (cmd.size() > 1) { + isServer = (cmd[0].find("synergys") != String::npos) || + (cmd[0].find("synergy-core") != String::npos && cmd[1] == "server"); + } + + return isServer; +} + }//namespace DaemonApp* DaemonApp::s_instance = NULL; @@ -324,15 +337,11 @@ DaemonApp::handleIpcMessage(const Event& e, void*) ArgParser::splitCommandString(command, argsArray); ArgParser argParser(NULL); const char** argv = argParser.getArgv(argsArray); - int argc = static_cast(argsArray.size()); - bool server = argsArray[0].find("synergys") != String::npos; - - if (server) { + if (isServerCommandLine(argsArray)) { auto serverArgs = new lib::synergy::ServerArgs(); argParser.parseServerArgs(*serverArgs, argc, argv); - } else { auto clientArgs = new lib::synergy::ClientArgs(); diff --git a/src/lib/synergy/PortableTaskBarReceiver.cpp b/src/lib/synergy/PortableTaskBarReceiver.cpp deleted file mode 100644 index d103960aa..000000000 --- a/src/lib/synergy/PortableTaskBarReceiver.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. - * Copyright (C) 2003 Chris Schoeneman - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "synergy/PortableTaskBarReceiver.h" -#include "mt/Lock.h" -#include "base/String.h" -#include "base/IEventQueue.h" -#include "arch/Arch.h" -#include "common/Version.h" - -// -// PortableTaskBarReceiver -// - -PortableTaskBarReceiver::PortableTaskBarReceiver(IEventQueue* events) : - m_state(kNotRunning), - m_events(events) -{ - // do nothing -} - -PortableTaskBarReceiver::~PortableTaskBarReceiver() -{ - // do nothing -} - -void -PortableTaskBarReceiver::updateStatus(INode* node, const String& errorMsg) -{ - { - // update our status - m_errorMessage = errorMsg; - if (node == NULL) { - if (m_errorMessage.empty()) { - m_state = kNotRunning; - } - else { - m_state = kNotWorking; - } - } - else { - m_state = kNotConnected; - } - - // let subclasses have a go - onStatusChanged(node); - } - - // tell task bar - ARCH->updateReceiver(this); -} - -PortableTaskBarReceiver::EState -PortableTaskBarReceiver::getStatus() const -{ - return m_state; -} - -const String& -PortableTaskBarReceiver::getErrorMessage() const -{ - return m_errorMessage; -} - -void -PortableTaskBarReceiver::quit() -{ - m_events->addEvent(Event(Event::kQuit)); -} - -void -PortableTaskBarReceiver::onStatusChanged(INode*) -{ - // do nothing -} - -void -PortableTaskBarReceiver::lock() const -{ - // do nothing -} - -void -PortableTaskBarReceiver::unlock() const -{ - // do nothing -} - -std::string -PortableTaskBarReceiver::getToolTip() const -{ - switch (m_state) { - case kNotRunning: - return synergy::string::sprintf("%s: Not running", kAppVersion); - - case kNotWorking: - return synergy::string::sprintf("%s: %s", - kAppVersion, m_errorMessage.c_str()); - - case kNotConnected: - return synergy::string::sprintf("%s: Unknown", kAppVersion); - - default: - return ""; - } -} diff --git a/src/lib/synergy/PortableTaskBarReceiver.h b/src/lib/synergy/PortableTaskBarReceiver.h deleted file mode 100644 index ab8e6c0c0..000000000 --- a/src/lib/synergy/PortableTaskBarReceiver.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. - * Copyright (C) 2003 Chris Schoeneman - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "synergy/INode.h" -#include "arch/IArchTaskBarReceiver.h" -#include "base/log_outputters.h" -#include "base/EventTypes.h" -#include "base/Event.h" -#include "base/String.h" -#include "common/stdvector.h" - -class IEventQueue; - -//! Implementation of IArchTaskBarReceiver for the synergy server -class PortableTaskBarReceiver : public IArchTaskBarReceiver { -public: - PortableTaskBarReceiver(IEventQueue* events); - virtual ~PortableTaskBarReceiver(); - - //! @name manipulators - //@{ - - //! Update status - /*! - Determine the status and query required information from the server. - */ - void updateStatus(INode*, const String& errorMsg); - - //@} - - // IArchTaskBarReceiver overrides - virtual void showStatus() = 0; - virtual void runMenu(int x, int y) = 0; - virtual void primaryAction() = 0; - virtual void lock() const; - virtual void unlock() const; - virtual const Icon getIcon() const = 0; - virtual std::string getToolTip() const; - -protected: - typedef std::vector Clients; - enum EState { - kNotRunning, - kNotWorking, - kNotConnected, - kConnected, - kMaxState - }; - - //! Get status - EState getStatus() const; - - //! Get error message - const String& getErrorMessage() const; - - //! Quit app - /*! - Causes the application to quit gracefully - */ - void quit(); - - //! Status change notification - /*! - Called when status changes. The default implementation does - nothing. - */ - virtual void onStatusChanged(INode* node); - -private: - EState m_state; - String m_errorMessage; - - String m_server; - Clients m_clients; - - IEventQueue* m_events; -}; - -IArchTaskBarReceiver* createTaskBarReceiver(const BufferedLogOutputter* logBuffer, IEventQueue* events);