2
* synergy -- mouse and keyboard sharing utility
3
* Copyright (C) 2002 Chris Schoeneman
5
* This package is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* found in the file COPYING that should have accompanied this file.
9
* This package is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
18
#include "OptionTypes.h"
19
#include "ProtocolTypes.h"
20
#include "CNetworkAddress.h"
21
#include "CStringUtil.h"
31
struct iterator_traits<CConfig> {
32
typedef CString value_type;
33
typedef ptrdiff_t difference_type;
34
typedef bidirectional_iterator_tag iterator_category;
35
typedef CString* pointer;
36
typedef CString& reference;
40
//! Server configuration
42
This class holds server configuration information. That includes
43
the names of screens and their aliases, the links between them,
44
and network addresses.
46
Note that case is preserved in screen names but is ignored when
47
comparing names. Screen names and their aliases share a
48
namespace and must be unique.
52
typedef std::map<OptionID, OptionValue> CScreenOptions;
57
CString m_neighbor[kLastDirection - kFirstDirection + 1];
58
CScreenOptions m_options;
60
typedef std::map<CString, CCell, CStringUtil::CaselessCmp> CCellMap;
61
typedef std::map<CString, CString, CStringUtil::CaselessCmp> CNameMap;
64
typedef CCellMap::const_iterator internal_const_iterator;
65
typedef CNameMap::const_iterator all_const_iterator;
66
class const_iterator : std::iterator_traits<CConfig> {
68
explicit const_iterator() : m_i() { }
69
explicit const_iterator(const internal_const_iterator& i) : m_i(i) { }
71
const_iterator& operator=(const const_iterator& i) {
75
CString operator*() { return m_i->first; }
76
const CString* operator->() { return &(m_i->first); }
77
const_iterator& operator++() { ++m_i; return *this; }
78
const_iterator operator++(int) { return const_iterator(m_i++); }
79
const_iterator& operator--() { --m_i; return *this; }
80
const_iterator operator--(int) { return const_iterator(m_i--); }
81
bool operator==(const const_iterator& i) const {
82
return (m_i == i.m_i);
84
bool operator!=(const const_iterator& i) const {
85
return (m_i != i.m_i);
89
internal_const_iterator m_i;
95
//! @name manipulators
100
Adds a screen, returning true iff successful. If a screen or
101
alias with the given name exists then it fails.
103
bool addScreen(const CString& name);
107
Renames a screen. All references to the name are updated.
108
Returns true iff successful.
110
bool renameScreen(const CString& oldName,
111
const CString& newName);
115
Removes a screen. This also removes aliases for the screen and
116
disconnects any connections to the screen. \c name may be an
119
void removeScreen(const CString& name);
121
//! Remove all screens
123
Removes all screens, aliases, and connections.
125
void removeAllScreens();
129
Adds an alias for a screen name. An alias can be used
130
any place the canonical screen name can (except addScreen()).
131
Returns false if the alias name already exists or the canonical
132
name is unknown, otherwise returns true.
134
bool addAlias(const CString& canonical,
135
const CString& alias);
139
Removes an alias for a screen name. It returns false if the
140
alias is unknown or a canonical name, otherwise returns true.
142
bool removeAlias(const CString& alias);
144
//! Remove all aliases
146
This removes all aliases but not the screens.
148
void removeAllAliases();
152
Establishes a one-way connection between opposite edges of two
153
screens. The user will be able to jump from the \c srcSide of
154
screen \c srcName to the opposite side of screen \c dstName
155
when both screens are connected to the server and the user
156
isn't locked to a screen. Returns false if \c srcName is
159
bool connect(const CString& srcName,
161
const CString& dstName);
163
//! Disconnect screens
165
Removes a connection created by connect(). Returns false if
166
\c srcName is unknown.
168
bool disconnect(const CString& srcName,
171
//! Set server address
173
Set the synergy listen addresses. There is no default address so
174
this must be called to run a server using this configuration.
176
void setSynergyAddress(const CNetworkAddress&);
178
//! Set HTTP server address
180
Set the HTTP listen addresses. There is no default address so
181
this must be called to run an HTTP server using this configuration.
183
void setHTTPAddress(const CNetworkAddress&);
185
//! Add a screen option
187
Adds an option and its value to the named screen. Replaces the
188
existing option's value if there is one. Returns true iff \c name
191
bool addOption(const CString& name,
192
OptionID option, OptionValue value);
194
//! Remove a screen option
196
Removes an option and its value from the named screen. Does
197
nothing if the option doesn't exist on the screen. Returns true
198
iff \c name is a known screen.
200
bool removeOption(const CString& name, OptionID option);
202
//! Remove a screen options
204
Removes all options and values from the named screen. Returns true
205
iff \c name is a known screen.
207
bool removeOptions(const CString& name);
213
//! Test screen name validity
215
Returns true iff \c name is a valid screen name.
217
bool isValidScreenName(const CString& name) const;
219
//! Get beginning (canonical) screen name iterator
220
const_iterator begin() const;
221
//! Get ending (canonical) screen name iterator
222
const_iterator end() const;
224
//! Get beginning screen name iterator
225
all_const_iterator beginAll() const;
226
//! Get ending screen name iterator
227
all_const_iterator endAll() const;
229
//! Test for screen name
231
Returns true iff \c name names a screen.
233
bool isScreen(const CString& name) const;
235
//! Test for canonical screen name
237
Returns true iff \c name is the canonical name of a screen.
239
bool isCanonicalName(const CString& name) const;
241
//! Get canonical name
243
Returns the canonical name of a screen or the empty string if
244
the name is unknown. Returns the canonical name if one is given.
246
CString getCanonicalName(const CString& name) const;
250
Returns the canonical screen name of the neighbor in the given
251
direction (set through connect()). Returns the empty string
252
if there is no neighbor in that direction.
254
CString getNeighbor(const CString&, EDirection) const;
256
//! Get the server address
257
const CNetworkAddress& getSynergyAddress() const;
258
//! Get the HTTP server address
259
const CNetworkAddress& getHTTPAddress() const;
261
//! Get the screen options
263
Returns all the added options for the named screen. Returns NULL
264
if the screen is unknown and an empty collection if there are no
267
const CScreenOptions* getOptions(const CString& name) const;
269
//! Compare configurations
270
bool operator==(const CConfig&) const;
271
//! Compare configurations
272
bool operator!=(const CConfig&) const;
274
//! Read configuration
276
Reads a configuration from a stream. Throws XConfigRead on error.
278
friend std::istream& operator>>(std::istream&, CConfig&);
280
//! Write configuration
282
Writes a configuration to a stream.
284
friend std::ostream& operator<<(std::ostream&, const CConfig&);
286
//! Get direction name
288
Returns the name of a direction (for debugging).
290
static const char* dirName(EDirection);
295
static bool readLine(std::istream&, CString&);
296
static OptionValue parseBoolean(const CString&);
297
static OptionValue parseInt(const CString&);
298
static OptionValue parseModifierKey(const CString&);
299
static const char* getOptionName(OptionID);
300
static CString getOptionValue(OptionID, OptionValue);
301
void readSection(std::istream&);
302
void readSectionOptions(std::istream&);
303
void readSectionScreens(std::istream&);
304
void readSectionLinks(std::istream&);
305
void readSectionAliases(std::istream&);
309
CNameMap m_nameToCanonicalName;
310
CNetworkAddress m_synergyAddress;
311
CNetworkAddress m_httpAddress;
312
CScreenOptions m_globalOptions;
315
//! Configuration stream read exception
317
Thrown when a configuration stream cannot be parsed.
319
class XConfigRead : public XBase {
321
XConfigRead(const CString&);
326
virtual CString getWhat() const throw();