1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2002 Chris Schoeneman
|
---|
4 | *
|
---|
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.
|
---|
8 | *
|
---|
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.
|
---|
13 | */
|
---|
14 |
|
---|
15 | #ifndef XARCH_H
|
---|
16 | #define XARCH_H
|
---|
17 |
|
---|
18 | #include "common.h"
|
---|
19 | #include "stdstring.h"
|
---|
20 |
|
---|
21 | //! Generic thread exception
|
---|
22 | /*!
|
---|
23 | Exceptions derived from this class are used by the multithreading
|
---|
24 | library to perform stack unwinding when a thread terminates. These
|
---|
25 | exceptions must always be rethrown by clients when caught.
|
---|
26 | */
|
---|
27 | class XThread { };
|
---|
28 |
|
---|
29 | //! Thread exception to cancel
|
---|
30 | /*!
|
---|
31 | Thrown to cancel a thread. Clients must not throw this type, but
|
---|
32 | must rethrow it if caught (by XThreadCancel, XThread, or ...).
|
---|
33 | */
|
---|
34 | class XThreadCancel : public XThread { };
|
---|
35 |
|
---|
36 | /*!
|
---|
37 | \def RETHROW_XTHREAD
|
---|
38 | Convenience macro to rethrow an XThread exception but ignore other
|
---|
39 | exceptions. Put this in your catch (...) handler after necessary
|
---|
40 | cleanup but before leaving or returning from the handler.
|
---|
41 | */
|
---|
42 | #define RETHROW_XTHREAD \
|
---|
43 | try { throw; } catch (XThread&) { throw; } catch (...) { }
|
---|
44 |
|
---|
45 | //! Lazy error message string evaluation
|
---|
46 | /*!
|
---|
47 | This class encapsulates platform dependent error string lookup.
|
---|
48 | Platforms subclass this type, taking an appropriate error code
|
---|
49 | type in the c'tor and overriding eval() to return the error
|
---|
50 | string for that error code.
|
---|
51 | */
|
---|
52 | class XArchEval {
|
---|
53 | public:
|
---|
54 | XArchEval() { }
|
---|
55 | virtual ~XArchEval() { }
|
---|
56 |
|
---|
57 | virtual XArchEval* clone() const throw() = 0;
|
---|
58 |
|
---|
59 | virtual std::string eval() const throw() = 0;
|
---|
60 | };
|
---|
61 |
|
---|
62 | //! Generic exception architecture dependent library
|
---|
63 | class XArch {
|
---|
64 | public:
|
---|
65 | XArch(XArchEval* adoptedEvaluator) : m_eval(adoptedEvaluator) { }
|
---|
66 | XArch(const std::string& msg) : m_eval(NULL), m_what(msg) { }
|
---|
67 | XArch(const XArch& e) : m_eval(e.m_eval != NULL ? e.m_eval->clone() : NULL),
|
---|
68 | m_what(e.m_what) { }
|
---|
69 | ~XArch() { delete m_eval; }
|
---|
70 |
|
---|
71 | std::string what() const throw();
|
---|
72 |
|
---|
73 | private:
|
---|
74 | XArchEval* m_eval;
|
---|
75 | mutable std::string m_what;
|
---|
76 | };
|
---|
77 |
|
---|
78 | // Macro to declare XArch derived types
|
---|
79 | #define XARCH_SUBCLASS(name_, super_) \
|
---|
80 | class name_ : public super_ { \
|
---|
81 | public: \
|
---|
82 | name_(XArchEval* adoptedEvaluator) : super_(adoptedEvaluator) { } \
|
---|
83 | name_(const std::string& msg) : super_(msg) { } \
|
---|
84 | }
|
---|
85 |
|
---|
86 | //! Generic network exception
|
---|
87 | /*!
|
---|
88 | Exceptions derived from this class are used by the networking
|
---|
89 | library to indicate various errors.
|
---|
90 | */
|
---|
91 | XARCH_SUBCLASS(XArchNetwork, XArch);
|
---|
92 |
|
---|
93 | //! Operation was interrupted
|
---|
94 | XARCH_SUBCLASS(XArchNetworkInterrupted, XArchNetwork);
|
---|
95 |
|
---|
96 | //! Network insufficient permission
|
---|
97 | XARCH_SUBCLASS(XArchNetworkAccess, XArchNetwork);
|
---|
98 |
|
---|
99 | //! Network insufficient resources
|
---|
100 | XARCH_SUBCLASS(XArchNetworkResource, XArchNetwork);
|
---|
101 |
|
---|
102 | //! No support for requested network resource/service
|
---|
103 | XARCH_SUBCLASS(XArchNetworkSupport, XArchNetwork);
|
---|
104 |
|
---|
105 | //! Network I/O error
|
---|
106 | XARCH_SUBCLASS(XArchNetworkIO, XArchNetwork);
|
---|
107 |
|
---|
108 | //! Network address is unavailable or not local
|
---|
109 | XARCH_SUBCLASS(XArchNetworkNoAddress, XArchNetwork);
|
---|
110 |
|
---|
111 | //! Network address in use
|
---|
112 | XARCH_SUBCLASS(XArchNetworkAddressInUse, XArchNetwork);
|
---|
113 |
|
---|
114 | //! No route to address
|
---|
115 | XARCH_SUBCLASS(XArchNetworkNoRoute, XArchNetwork);
|
---|
116 |
|
---|
117 | //! Socket not connected
|
---|
118 | XARCH_SUBCLASS(XArchNetworkNotConnected, XArchNetwork);
|
---|
119 |
|
---|
120 | //! Remote read end of socket has closed
|
---|
121 | XARCH_SUBCLASS(XArchNetworkShutdown, XArchNetwork);
|
---|
122 |
|
---|
123 | //! Remote end of socket has disconnected
|
---|
124 | XARCH_SUBCLASS(XArchNetworkDisconnected, XArchNetwork);
|
---|
125 |
|
---|
126 | //! Remote end of socket refused connection
|
---|
127 | XARCH_SUBCLASS(XArchNetworkConnectionRefused, XArchNetwork);
|
---|
128 |
|
---|
129 | //! Remote end of socket is not responding
|
---|
130 | XARCH_SUBCLASS(XArchNetworkTimedOut, XArchNetwork);
|
---|
131 |
|
---|
132 | //! Generic network name lookup erros
|
---|
133 | XARCH_SUBCLASS(XArchNetworkName, XArchNetwork);
|
---|
134 |
|
---|
135 | //! The named host is unknown
|
---|
136 | XARCH_SUBCLASS(XArchNetworkNameUnknown, XArchNetworkName);
|
---|
137 |
|
---|
138 | //! The named host is known but has no address
|
---|
139 | XARCH_SUBCLASS(XArchNetworkNameNoAddress, XArchNetworkName);
|
---|
140 |
|
---|
141 | //! Non-recoverable name server error
|
---|
142 | XARCH_SUBCLASS(XArchNetworkNameFailure, XArchNetworkName);
|
---|
143 |
|
---|
144 | //! Temporary name server error
|
---|
145 | XARCH_SUBCLASS(XArchNetworkNameUnavailable, XArchNetworkName);
|
---|
146 |
|
---|
147 | //! The named host is known but no supported address
|
---|
148 | XARCH_SUBCLASS(XArchNetworkNameUnsupported, XArchNetworkName);
|
---|
149 |
|
---|
150 | //! Generic daemon exception
|
---|
151 | /*!
|
---|
152 | Exceptions derived from this class are used by the daemon
|
---|
153 | library to indicate various errors.
|
---|
154 | */
|
---|
155 | XARCH_SUBCLASS(XArchDaemon, XArch);
|
---|
156 |
|
---|
157 | //! Could not daemonize
|
---|
158 | XARCH_SUBCLASS(XArchDaemonFailed, XArchDaemon);
|
---|
159 |
|
---|
160 | //! Could not install daemon
|
---|
161 | XARCH_SUBCLASS(XArchDaemonInstallFailed, XArchDaemon);
|
---|
162 |
|
---|
163 | //! Could not uninstall daemon
|
---|
164 | XARCH_SUBCLASS(XArchDaemonUninstallFailed, XArchDaemon);
|
---|
165 |
|
---|
166 | //! Attempted to uninstall a daemon that was not installed
|
---|
167 | XARCH_SUBCLASS(XArchDaemonUninstallNotInstalled, XArchDaemonUninstallFailed);
|
---|
168 |
|
---|
169 |
|
---|
170 | #endif
|
---|