1 /*
2  * synergy -- mouse and keyboard sharing utility
3  * Copyright (C) 2012-2016 Symless Ltd.
4  * Copyright (C) 2002 Chris Schoeneman
5  *
6  * This package is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * found in the file LICENSE that should have accompanied this file.
9  *
10  * This package is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include "synergy/App.h"
22 
23 namespace synergy { class Screen; }
24 class Event;
25 class Client;
26 class NetworkAddress;
27 class Thread;
28 namespace lib {
29     namespace synergy {
30         class ClientArgs;
31     }
32 }
33 
34 class ClientApp : public App {
35 public:
36     ClientApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver);
37     virtual ~ClientApp();
38 
39     // Parse client specific command line arguments.
40     void parseArgs(int argc, const char* const* argv);
41 
42     // Prints help specific to client.
43     void help();
44 
45     // Returns arguments that are common and for client.
args()46     lib::synergy::ClientArgs& args() const { return (lib::synergy::ClientArgs&)argsBase(); }
47 
48     const char* daemonName() const;
49     const char* daemonInfo() const;
50 
51     // TODO: move to server only (not supported on client)
loadConfig()52     void loadConfig() { }
loadConfig(const String & pathname)53     bool loadConfig(const String& pathname) { return false; }
54 
55     int foregroundStartup(int argc, char** argv);
56     int standardStartup(int argc, char** argv);
57     int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup);
58     synergy::Screen* createScreen();
59     void updateStatus();
60     void updateStatus(const String& msg);
61     void resetRestartTimeout();
62     double nextRestartTimeout();
63     void handleScreenError(const Event&, void*);
64     synergy::Screen* openClientScreen();
65     void closeClientScreen(synergy::Screen* screen);
66     void handleClientRestart(const Event&, void* vtimer);
67     void scheduleClientRestart(double retryTime);
68     void handleClientConnected(const Event&, void*);
69     void handleClientFailed(const Event& e, void*);
70     void handleClientRefused(const Event& e, void*);
71     void handleClientDisconnected(const Event&, void*);
72     Client* openClient(const String& name, const NetworkAddress& address,
73                 synergy::Screen* screen);
74     void closeClient(Client* client);
75     bool startClient();
76     void stopClient();
77     int mainLoop();
78     void startNode();
79 
instance()80     static ClientApp& instance() { return (ClientApp&)App::instance(); }
81 
getClientPtr()82     Client* getClientPtr() { return m_client; }
83 
84 private:
85     Client*            m_client;
86     synergy::Screen*   m_clientScreen;
87     NetworkAddress*    m_serverAddress;
88     size_t             m_lastServerAddressIndex = 0;
89 };
90