aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/barrier/ClientApp.h
blob: d1db8d05ff3d4c657d14c9ad4b6bb8c06d809d04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * barrier -- mouse and keyboard sharing utility
 * Copyright (C) 2012-2016 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 <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "barrier/App.h"

namespace barrier { class Screen; }
class Event;
class Client;
class NetworkAddress;
class ClientArgs;

class ClientApp : public App {
public:
    ClientApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver);
    virtual ~ClientApp();

    // Parse client specific command line arguments.
    void parseArgs(int argc, const char* const* argv);

    // Prints help specific to client.
    void help();

    // Returns arguments that are common and for client.
    ClientArgs& args() const { return (ClientArgs&)argsBase(); }

    const char* daemonName() const;
    const char* daemonInfo() const;

    // TODO: move to server only (not supported on client)
    void loadConfig() { }
    bool loadConfig(const String& pathname) { return false; }

    int foregroundStartup(int argc, char** argv);
    int standardStartup(int argc, char** argv);
    int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup);
    barrier::Screen* createScreen();
    void updateStatus();
    void updateStatus(const String& msg);
    void resetRestartTimeout();
    double nextRestartTimeout();
    void handleScreenError(const Event&, void*);
    barrier::Screen* openClientScreen();
    void closeClientScreen(barrier::Screen* screen);
    void handleClientRestart(const Event&, void* vtimer);
    void scheduleClientRestart(double retryTime);
    void handleClientConnected(const Event&, void*);
    void handleClientFailed(const Event& e, void*);
    void handleClientDisconnected(const Event&, void*);
    Client* openClient(const String& name, const NetworkAddress& address,
                barrier::Screen* screen);
    void closeClient(Client* client);
    bool startClient();
    void stopClient();
    int mainLoop();
    void startNode();

    static ClientApp& instance() { return (ClientApp&)App::instance(); }

    Client* getClientPtr() { return m_client; }

private:
    Client*            m_client;
    barrier::Screen*m_clientScreen;
    NetworkAddress*    m_serverAddress;
};