Line data Source code
1 :
2 : /* Copyright (c) 2010-2016, Stefan Eilemann <eile@eyescale.ch>
3 : * Daniel Nachbaur <danielnachbaur@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #include "error.h"
20 :
21 : #include "errorRegistry.h"
22 : #include "global.h"
23 :
24 : #include <co/dataIStream.h>
25 : #include <co/dataOStream.h>
26 :
27 : namespace eq
28 : {
29 : namespace fabric
30 : {
31 :
32 : namespace
33 : {
34 1904 : struct ErrorData
35 : {
36 : const uint32_t code;
37 : const std::string text;
38 : };
39 :
40 56 : ErrorData _errors[] = {
41 : { ERROR_FBO_UNSUPPORTED, "Framebuffer objects not supported" },
42 : { ERROR_FRAMEBUFFER_STATUS, "Error querying framebuffer status" },
43 : { ERROR_FRAMEBUFFER_UNSUPPORTED, "Unsupported framebuffer format" },
44 : { ERROR_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
45 : "Framebuffer incomplete, missing attachment" },
46 : { ERROR_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
47 : "Framebuffer incomplete, incomplete attachment" },
48 : { ERROR_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
49 : "Framebuffer incomplete, attached images must have same dimensions" },
50 : { ERROR_FRAMEBUFFER_INCOMPLETE_FORMATS,
51 : "Framebuffer incomplete, attached images must have same format" },
52 : { ERROR_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER,
53 : "Framebuffer incomplete, missing draw buffer" },
54 : { ERROR_FRAMEBUFFER_INCOMPLETE_READ_BUFFER,
55 : "Framebuffer incomplete, missing read buffer" },
56 : { ERROR_FRAMEBUFFER_INITIALIZED, "FBO already initialized" },
57 : { ERROR_FRAMEBUFFER_INVALID_SIZE, "FBO size not supported" },
58 : { ERROR_FRAMEBUFFER_INVALID_SAMPLES, "Multisampled FBO not supported" },
59 :
60 : { ERROR_WINDOWSYSTEM_UNKNOWN, "Unknown windowing system" },
61 :
62 : { ERROR_NODE_LAUNCH, "Execution of node launch command failed" },
63 : { ERROR_NODE_CONNECT, "Node process did not start" },
64 :
65 : { ERROR_PIPE_NODE_NOTRUNNING, "Node not running" },
66 :
67 : { ERROR_SYSTEMPIPE_PIXELFORMAT_NOTFOUND,
68 : "Can't find temporary pixel format" },
69 : { ERROR_SYSTEMPIPE_CREATECONTEXT_FAILED,
70 : "Can't create temporary OpenGL context" },
71 : { ERROR_SYSTEMPIPE_CREATEWINDOW_FAILED, "Can't create temporary window" },
72 :
73 : { ERROR_AGLPIPE_DISPLAYS_NOTFOUND, "Can't get display identifier list" },
74 : { ERROR_AGLPIPE_DEVICE_NOTFOUND, "Can't get display identifier for device"},
75 :
76 : { ERROR_GLXPIPE_DEVICE_NOTFOUND, "Can't open display" },
77 : { ERROR_GLXPIPE_GLX_NOTFOUND, "Display does not support GLX" },
78 : { ERROR_GLXPIPE_GLXEWINIT_FAILED, "Pipe GLXEW initialization failed" },
79 :
80 : { ERROR_WGL_CREATEAFFINITYDC_FAILED, "Can't create affinity DC" },
81 : { ERROR_WGLPIPE_ENUMDISPLAYS_FAILED, "Can't enumerate display devices" },
82 : { ERROR_WGLPIPE_CREATEDC_FAILED, "Can't create device context" },
83 : { ERROR_WGLPIPE_ENUMGPUS_FAILED, "Can't enumerate GPU" },
84 : { ERROR_WGLPIPE_REGISTERCLASS_FAILED,
85 : "Can't register temporary window class" },
86 : { ERROR_WGLPIPE_SETPF_FAILED, "Can't set temporary pixel format" },
87 : { ERROR_WGLPIPE_WGLEWINIT_FAILED, "Pipe WGLEW initialization failed" },
88 :
89 : { ERROR_WINDOW_PIPE_NOTRUNNING, "Pipe not running" },
90 : { ERROR_WINDOW_PVP_INVALID, "Invalid window pixel viewport" },
91 :
92 : { ERROR_SYSTEMWINDOW_PIXELFORMAT_NOTFOUND,
93 : "Can't find matching pixel format" },
94 : { ERROR_SYSTEMWINDOW_NO_PIXELFORMAT, "Missing pixel format" },
95 : { ERROR_SYSTEMWINDOW_ARB_FLOAT_FB_REQUIRED,
96 : "Floating-point framebuffer not supported" },
97 :
98 : { ERROR_AGLWINDOW_NO_CONTEXT, "Missing AGL context" },
99 : { ERROR_AGLWINDOW_CREATECONTEXT_FAILED, "Can't create AGL context" },
100 : { ERROR_AGLWINDOW_CREATEPBUFFER_FAILED, "Can't create AGL PBuffer" },
101 : { ERROR_AGLWINDOW_SETPBUFFER_FAILED, "Can't set AGL PBuffer" },
102 : { ERROR_AGLWINDOW_CREATEWINDOW_FAILED, "Can't create Carbon window" },
103 : { ERROR_AGLWINDOW_SETWINDOW_FAILED, "Can't set Carbon window" },
104 :
105 : { ERROR_GLXWINDOW_NO_DRAWABLE, "Missing GLX drawable" },
106 : { ERROR_GLXWINDOW_NO_DISPLAY, "Missing X11 display connection" },
107 : { ERROR_GLXWINDOW_CREATECONTEXT_FAILED, "Can't create glX context" },
108 : { ERROR_GLXWINDOW_CREATEWINDOW_FAILED, "Can't create X11 window" },
109 : { ERROR_GLXWINDOW_GLXQUERYVERSION_FAILED, "Can't get GLX version" },
110 : { ERROR_GLXWINDOW_GLX_1_3_REQUIRED, "Need at least GLX 1.3" },
111 : { ERROR_GLXWINDOW_NO_FBCONFIG, "Can't find FBConfig for visual" },
112 : { ERROR_GLXWINDOW_NO_VISUAL, "FBConfig has no associated visual" },
113 : { ERROR_GLXWINDOW_CREATEPBUFFER_FAILED, "Can't create glX PBuffer" },
114 : { ERROR_GLXWINDOW_FBCONFIG_REQUIRED,
115 : "Can't find FBConfig functions (GLX 1.3 or GLX_SGIX_fbconfig" },
116 :
117 : { ERROR_WGLWINDOW_NO_DRAWABLE, "Missing WGL drawable" },
118 : { ERROR_WGLWINDOW_SETPIXELFORMAT_FAILED, "Can't set window pixel format" },
119 : { ERROR_WGLWINDOW_REGISTERCLASS_FAILED, "Can't register window class" },
120 : { ERROR_WGLWINDOW_FULLSCREEN_FAILED, "Can't switch to fullscreen mode" },
121 : { ERROR_WGLWINDOW_CREATEWINDOW_FAILED, "Can't create window" },
122 : { ERROR_WGLWINDOW_ARB_PBUFFER_REQUIRED, "WGL_ARB_pbuffer not supported" },
123 : { ERROR_WGLWINDOW_CREATEPBUFFER_FAILED, "Can't create PBuffer" },
124 : { ERROR_WGLWINDOW_SETAFFINITY_PF_FAILED, "Can't set affinity pixel format"},
125 : { ERROR_WGLWINDOW_CHOOSE_PF_ARB_FAILED,
126 : "Can't choose pixel format using ARB extension"},
127 : { ERROR_WGLWINDOW_CREATECONTEXT_FAILED, "Can't create WGL context" },
128 :
129 : { ERROR_CHANNEL_WINDOW_NOTRUNNING, "Window not running" },
130 :
131 : { ERROR_PBO_UNSUPPORTED, "Pixel Buffer Objects not supported" },
132 : { ERROR_PBO_NOT_INITIALIZED, "PBO is not initialized" },
133 : { ERROR_PBO_SIZE_TOO_SMALL, "PBO size is too small, it has to be > 0" },
134 : { ERROR_PBO_TYPE_UNSUPPORTED, "Unsupported PBO type" },
135 :
136 : { 0, "" } // last!
137 28 : };
138 : }
139 :
140 12 : void _initErrors()
141 : {
142 12 : eq::fabric::ErrorRegistry& registry =eq::fabric::Global::getErrorRegistry();
143 816 : for( size_t i=0; _errors[i].code != 0; ++i )
144 804 : registry.setString( _errors[i].code, _errors[i].text );
145 12 : }
146 :
147 12 : void _exitErrors()
148 : {
149 12 : eq::fabric::ErrorRegistry& registry =eq::fabric::Global::getErrorRegistry();
150 816 : for( size_t i=0; _errors[i].code != 0; ++i )
151 804 : registry.eraseString( _errors[i].code );
152 12 : }
153 :
154 6 : Error::Error()
155 : : _code( ERROR_NONE )
156 6 : , _originator()
157 6 : {}
158 :
159 10 : Error::Error( const uint32_t code, const uint128_t& originator )
160 : : _code( code )
161 10 : , _originator( originator )
162 10 : {}
163 :
164 0 : Error& Error::operator = ( const ErrorCode code )
165 : {
166 0 : _code = code;
167 0 : return *this;
168 : }
169 :
170 2 : Error::operator bool_t() const
171 : {
172 2 : return _code != ERROR_NONE ? &Error::bool_true : 0;
173 : }
174 :
175 6 : bool Error::operator ! () const
176 : {
177 6 : return _code == ERROR_NONE;\
178 : }
179 :
180 30 : uint32_t Error::getCode() const
181 : {
182 30 : return _code;
183 : }
184 :
185 0 : const uint128_t& Error::getOriginator() const
186 : {
187 0 : return _originator;
188 : }
189 :
190 0 : bool Error::operator == ( const Error& rhs ) const
191 : {
192 0 : return _code == rhs._code;
193 : }
194 :
195 0 : bool Error::operator != ( const Error& rhs ) const
196 : {
197 0 : return _code != rhs._code;
198 : }
199 :
200 0 : bool Error::operator == ( const uint32_t code ) const
201 : {
202 0 : return _code == code;
203 : }
204 :
205 0 : bool Error::operator != ( const uint32_t code ) const
206 : {
207 0 : return _code != code;
208 : }
209 :
210 0 : void Error::serialize( co::DataOStream& os ) const
211 : {
212 0 : os << _code << _originator;
213 0 : }
214 :
215 0 : void Error::deserialize( co::DataIStream& is )
216 : {
217 0 : is >> _code >> _originator;
218 0 : }
219 :
220 12 : std::ostream& operator << ( std::ostream& os, const Error& error )
221 : {
222 12 : const ErrorRegistry& registry = Global::getErrorRegistry();
223 12 : const std::string& text = registry.getString( error.getCode( ));
224 :
225 12 : if( text.empty( ))
226 0 : return os << "error 0x" << std::hex << uint32_t( error.getCode( ))
227 0 : << std::dec;
228 :
229 12 : return os << text << " (0x" << std::hex << uint32_t( error.getCode( ))
230 12 : << std::dec << ")";
231 : }
232 :
233 : } // fabric
234 84 : } // eq
|