summaryrefslogtreecommitdiff
path: root/SPICEConsoleAPI.h
blob: 9ad54508c42137fc1e68af2da547d96eb942301b (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* ***** BEGIN LICENSE BLOCK *****
 *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 *   The contents of this file are subject to the Mozilla Public License Version
 *   1.1 (the "License"); you may not use this file except in compliance with
 *   the License. You may obtain a copy of the License at
 *   http://www.mozilla.org/MPL/
 *
 *   Software distributed under the License is distributed on an "AS IS" basis,
 *   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 *   for the specific language governing rights and limitations under the
 *   License.
 *
 *   Copyright 2009-2012, Red Hat Inc.
 *   Based on firebreath's plugin example
 *
 *   Contributor(s):
 *   Uri Lublin
 *   Martin Stransky
 *   Peter Hatina
 *
 *   Alternatively, the contents of this file may be used under the terms of
 *   either the GNU General Public License Version 2 or later (the "GPL"), or
 *   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 *   in which case the provisions of the GPL or the LGPL are applicable instead
 *   of those above. If you wish to allow use of your version of this file only
 *   under the terms of either the GPL or the LGPL, and not to allow others to
 *   use your version of this file under the terms of the MPL, indicate your
 *   decision by deleting the provisions above and replace them with the notice
 *   and other provisions required by the GPL or the LGPL. If you do not delete
 *   the provisions above, a recipient may use your version of this file under
 *   the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include <string>
#include <sstream>
#include <boost/weak_ptr.hpp>
#include "JSAPIAuto.h"
#include "BrowserHost.h"
#include "SPICEConsole.h"
#include "controller.h"

#ifndef H_SPICEConsoleAPI
#define H_SPICEConsoleAPI

class SPICEConsoleAPI : public FB::JSAPIAuto
{
public:
    ////////////////////////////////////////////////////////////////////////////
    /// @fn SPICEConsoleAPI::SPICEConsoleAPI(const SPICEConsolePtr& plugin, const FB::BrowserHostPtr host)
    ///
    /// @brief  Constructor for your JSAPI object.
    ///         You should register your methods, properties, and events
    ///         that should be accessible to Javascript from here.
    ///
    /// @see FB::JSAPIAuto::registerMethod
    /// @see FB::JSAPIAuto::registerProperty
    /// @see FB::JSAPIAuto::registerEvent
    ////////////////////////////////////////////////////////////////////////////
    SPICEConsoleAPI(const SPICEConsolePtr& plugin, const FB::BrowserHostPtr& host) :
        m_plugin(plugin),
        m_host(host),
        m_connected_status(-2)
    {
        registerMethod("connect", make_method(this, &SPICEConsoleAPI::connect));
        registerMethod("show", make_method(this, &SPICEConsoleAPI::show));
        registerMethod("disconnect", make_method(this, &SPICEConsoleAPI::disconnect));
        registerMethod("SetLanguageStrings", make_method(this, &SPICEConsoleAPI::SetLanguageStrings));
        registerMethod("ConnectedStatus", make_method(this, &SPICEConsoleAPI::ConnectedStatus));

        registerProperty("SSLChannels",
                         make_property(this,
                                       &SPICEConsoleAPI::get_SSLChannels,
                                       &SPICEConsoleAPI::set_SSLChannels));

        registerAttribute("hostIP", FB::variant());
        registerAttribute("port", FB::variant());
        registerAttribute("SecurePort", FB::variant());
        registerAttribute("Password", FB::variant());
        registerAttribute("CipherSuite", FB::variant());
        registerAttribute("TrustStore", FB::variant());
        registerAttribute("HostSubject", FB::variant());
        registerAttribute("fullScreen", FB::variant());
        registerAttribute("Smartcard", FB::variant());
        registerAttribute("AdminConsole", FB::variant());
        registerAttribute("Title", FB::variant());
        registerAttribute("dynamicMenu", FB::variant());
        registerAttribute("NumberOfMonitors", FB::variant());
        registerAttribute("GuestHostName", FB::variant());
        registerAttribute("HotKey", FB::variant());
        registerAttribute("NoTaskMgrExecution", FB::variant());
        registerAttribute("SendCtrlAltDelete", true);
        registerAttribute("UsbListenPort", FB::variant());
        registerAttribute("UsbAutoShare", true);
        registerAttribute("ColorDepth", FB::variant());
        registerAttribute("DisableEffects", FB::variant());
    }

    ///////////////////////////////////////////////////////////////////////////////
    /// @fn SPICEConsoleAPI::~SPICEConsoleAPI()
    ///
    /// @brief  Destructor.  Remember that this object will not be released until
    ///         the browser is done with it; this will almost definitely be after
    ///         the plugin is released.
    ///////////////////////////////////////////////////////////////////////////////
    virtual ~SPICEConsoleAPI() {};

    SPICEConsolePtr getPlugin();

    // Methods
    void connect();
    void show();
    void disconnect();
    void SetLanguageStrings(const std::string &section,
                            const std::string &lang);
    void SetUsbFilter(const std::string &filter);
    int ConnectedStatus();

    // Properties
    std::string get_SSLChannels() const;
    void set_SSLChannels(const std::string &aSSLChannels);

    // Events
    FB_JSAPI_EVENT(disconnected, 1, (int));

private:
    SPICEConsoleWeakPtr m_plugin;
    FB::BrowserHostPtr m_host;
    std::map<std::string, std::string> m_languages;
    std::string m_usb_filter;
    int m_connected_status;
    SpiceController m_external_controller;
    std::string m_trust_store_file;

    /* Properties */
    std::string m_SSLChannels;

    // Controller communication
    void WriteToPipe(const void *data, uint32_t size);
    void SendInit();
    void SendMsg(uint32_t id);
    void SendMsg(uint32_t id, const std::string &str);
    void SendMsg(uint32_t id, bool value);
    void SendMsg(uint32_t id, uint32_t value);
    template<typename T> void SendValue(uint32_t id, std::string attributeName);

    bool createTrustStore(void);
};

#endif // H_SPICEConsoleAPI