RCFProto
 All Classes Functions Typedefs
Exception.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_EXCEPTION_HPP
20 #define INCLUDE_RCF_EXCEPTION_HPP
21 
22 #include <memory>
23 #include <sstream>
24 #include <stdexcept>
25 #include <string>
26 #include <vector>
27 
28 #include <boost/shared_ptr.hpp>
29 
30 #include <RCF/Export.hpp>
31 #include <RCF/Config.hpp>
32 #include <RCF/Tools.hpp>
33 #include <RCF/TypeTraits.hpp>
34 
35 #include <boost/version.hpp>
36 
37 #if defined(RCF_USE_BOOST_SERIALIZATION) && BOOST_VERSION > 103301
38 #include <boost/serialization/nvp.hpp>
39 #include <boost/serialization/string.hpp>
40 #include <boost/serialization/vector.hpp>
41 #include <boost/archive/basic_text_iarchive.hpp>
42 #endif
43 
44 namespace SF {
45  class Archive;
46 }
47 
48 namespace RCF {
49 
50  RCF_EXPORT std::string toString(const std::exception &e);
51 
52  class RCF_EXPORT Error
53  {
54  public:
55  Error() : mErrorId(0)
56  {
57  }
58 
59  Error(int errorId) : mErrorId(errorId)
60  {
61  }
62 
63  Error(
64  int errorId,
65  const std::string & arg1) :
66  mErrorId(errorId)
67  {
68  mArgs.push_back(arg1);
69  }
70 
71  Error(
72  int errorId,
73  const std::string & arg1,
74  const std::string & arg2) :
75  mErrorId(errorId)
76  {
77  mArgs.push_back(arg1);
78  mArgs.push_back(arg2);
79  }
80 
81  Error(
82  int errorId,
83  const std::string & arg1,
84  const std::string & arg2,
85  const std::string & arg3) :
86  mErrorId(errorId)
87  {
88  mArgs.push_back(arg1);
89  mArgs.push_back(arg2);
90  mArgs.push_back(arg3);
91  }
92 
93  Error(const Error & rhs) : mErrorId(rhs.mErrorId), mArgs(rhs.mArgs)
94  {
95  }
96 
97  int getErrorId() const
98  {
99  return mErrorId;
100  }
101 
102  void setErrorId(int errorId)
103  {
104  mErrorId = errorId;
105  }
106 
107  const std::vector<std::string> & getArgs() const
108  {
109  return mArgs;
110  }
111 
112  std::string getErrorString() const;
113 
114 #ifdef RCF_USE_SF_SERIALIZATION
115  void serialize(SF::Archive & ar);
116 
117 #endif
118 
119 #ifdef RCF_USE_BOOST_SERIALIZATION
120  template<typename Archive>
121  void serialize(Archive & ar, const unsigned int)
122  {
123  ar & mErrorId & mArgs;
124  }
125 #endif
126 
127  private:
128 
129  std::string getRawErrorString() const;
130 
131  int mErrorId;
132  std::vector<std::string> mArgs;
133  };
134 
135  // RCF error codes
136  // range 0-1000 reserved for RCF, remaining range can be used independently of RCF
137 
138  static const int RcfError_Ok = 0;
139  //static const int RcfError_Unspecified = 1;
140  static const int RcfError_ServerMessageLength = 2;
141  static const int RcfError_ClientMessageLength = 3;
142  static const int RcfError_Serialization = 4;
143  static const int RcfError_Deserialization = 5;
144  static const int RcfError_AppException = 6;
145  static const int RcfError_UnknownEndpoint = 8;
146  static const int RcfError_EndpointPassword = 9;
147  static const int RcfError_EndpointDown = 10;
148  static const int RcfError_EndpointRetry = 11;
149  static const int RcfError_ClientConnectTimeout = 16;
150  static const int RcfError_PeerDisconnect = 17;
151  static const int RcfError_ClientCancel = 18;
152  static const int RcfError_PayloadFilterMismatch = 20;
153  static const int RcfError_OpenSslFilterInit = 21;
154  static const int RcfError_OpenSslLoadCert = 22;
155  static const int RcfError_UnknownPublisher = 23;
156  static const int RcfError_UnknownFilter = 24;
157  static const int RcfError_NoServerStub = 25;
158  static const int RcfError_Sspi = 26;
159  static const int RcfError_SspiInit = 28;
160  static const int RcfError_ClientReadTimeout = 30;
161  static const int RcfError_ClientReadFail = 31;
162  static const int RcfError_ClientWriteTimeout = 32;
163  static const int RcfError_ClientWriteFail = 33;
164  static const int RcfError_ClientConnectFail = 34;
165  static const int RcfError_Socket = 36;
166  static const int RcfError_FnId = 37;
167  static const int RcfError_UnknownInterface = 38;
168  static const int RcfError_NoEndpoint = 39;
169  static const int RcfError_TransportCreation = 40;
170  static const int RcfError_FilterCount = 41;
171  static const int RcfError_FilterMessage = 42;
172  static const int RcfError_UnfilterMessage = 43;
173  static const int RcfError_SspiCredentials = 44;
174  static const int RcfError_SspiEncrypt = 45;
175  static const int RcfError_SspiDecrypt = 46;
176  static const int RcfError_SspiImpersonation = 47;
177  static const int RcfError_SocketClose = 49;
178  static const int RcfError_ZlibDeflate = 50;
179  static const int RcfError_ZlibInflate = 51;
180  static const int RcfError_Zlib = 52;
181  static const int RcfError_UnknownSerializationProtocol = 53;
182  static const int SfError_NoCtor = 55;
183  static const int SfError_RefMismatch = 56;
184  static const int SfError_DataFormat = 57;
185  static const int SfError_ReadFailure = 58;
186  static const int SfError_WriteFailure = 59;
187  static const int SfError_BaseDerivedRegistration = 60;
188  static const int SfError_TypeRegistration = 61;
189  static const int RcfError_NonStdException = 62;
190  static const int RcfError_SocketBind = 63;
191  static const int RcfError_Decoding = 64;
192  static const int RcfError_Encoding = 65;
193  static const int RcfError_TokenRequestFailed = 66;
194  static const int RcfError_ObjectFactoryNotFound = 67;
195  static const int RcfError_PortInUse = 68;
196  static const int RcfError_DynamicObjectNotFound = 69;
197  static const int RcfError_VersionMismatch = 70;
198  static const int RcfError_SslCertVerification = 72;
199  static const int RcfError_FiltersLocked = 74;
200  static const int RcfError_Pipe = 75;
201  static const int RcfError_AnySerializerNotFound = 76;
202  static const int RcfError_ConnectionLimitExceeded = 77;
203  static const int RcfError_DeserializationNullPointer = 78;
204  static const int RcfError_PipeNameTooLong = 79;
205  static const int RcfError_PingBack = 80;
206  static const int RcfError_NoPingBackService = 81;
207  static const int RcfError_NoDownload = 82;
208  static const int RcfError_FileOffset = 83;
209  static const int RcfError_NoUpload = 84;
210  static const int RcfError_FileOpen = 85;
211  static const int RcfError_FileRead = 86;
212  static const int RcfError_FileWrite = 87;
213  static const int RcfError_UploadFailed = 88;
214  static const int RcfError_UploadInProgress = 89;
215  static const int RcfError_ConcurrentUpload = 90;
216  static const int RcfError_UploadFileSize = 91;
217  static const int RcfError_AccessDenied = 92;
218  static const int RcfError_PingBackTimeout = 93;
219  static const int RcfError_AllThreadsBusy = 94;
220  static const int RcfError_UnsupportedRuntimeVersion = 95;
221  static const int RcfError_FdSetSize = 97;
222  static const int RcfError_DnsLookup = 98;
223  static const int RcfError_SspiHandshakeExtraData = 99;
224  static const int RcfError_ProtobufWrite = 101;
225  static const int RcfError_ProtobufRead = 102;
226  static const int RcfError_ExtractSlice = 103;
227  static const int RcfError_ServerStubExpired = 104;
228  static const int RcfError_VariantDeserialization = 105;
229  static const int RcfError_SspiAuthFailServer = 106;
230  static const int RcfError_SspiAuthFailClient = 107;
231  static const int RcfError_Win32ApiError = 108;
232  static const int RcfError_SspiLengthField = 109;
233  static const int RcfError_DownloadFailed = 110;
234  static const int RcfError_FileSeek = 111;
235  static const int RcfError_DownloadCancelled = 112;
236  static const int RcfError_ParseSockAddr = 113;
237  static const int RcfError_GetSockName = 114;
238  static const int RcfError_ProtobufWriteSize = 115;
239  static const int RcfError_ProtobufWriteInit = 116;
240  static const int RcfError_ArraySizeMismatch = 117;
241  static const int RcfError_WcharSizeMismatch = 118;
242  static const int RcfError_AnyTypeNotRegistered = 119;
243  static const int RcfError_CryptoApiError = 120;
244  static const int RcfError_ServerStubAccessDenied = 121;
245  static const int RcfError_ApiError = 122;
246  static const int RcfError_HttpProxyPort = 123;
247  static const int RcfError_OpenSslError = 124;
248  static const int RcfError_ProtocolNotSupported = 125;
249  static const int RcfError_ClearCommunicationNotAllowed = 126;
250  static const int RcfError_ThreadingError = 127;
251  static const int RcfError_RcfNotInitialized = 128;
252  static const int RcfError_InvalidHttpMessage = 129;
253  static const int RcfError_HttpRequestContentLength = 130;
254  static const int RcfError_HttpResponseContentLength = 131;
255  static const int RcfError_InvalidOpenSslCertificate = 132;
256  static const int RcfError_InvalidSchannelCertificate = 133;
257  static const int RcfError_HttpConnectFailed = 134;
258  static const int RcfError_SspiImpersonateNoSspi = 135;
259  static const int RcfError_TransportProtocolNotSupported = 136;
260  static const int RcfError_SslNotSupported = 137;
261  static const int RcfError_SessionObjectDoesNotExist = 138;
262  static const int RcfError_UploadAlreadyCompleted = 139;
263  static const int RcfError_FileIndex = 140;
264  static const int RcfError_ConcurrentCalls = 141;
265  static const int RcfError_ParseJsonRpcRequest = 142;
266  static const int RcfError_DllLoad = 143;
267  static const int RcfError_DllFuncLoad = 144;
268  static const int RcfError_UnixDllLoad = 145;
269  static const int RcfError_UnixDllFuncLoad = 146;
270  static const int RcfError_PingBackInterval = 147;
271  static const int RcfError_FileOpenWrite = 148;
272  static const int RcfError_CustomCertValidation = 149;
273  static const int RcfError_SupportedOnWindowsOnly = 150;
274  static const int RcfError_NotSupportedOnWindows = 151;
275  static const int RcfError_NotSupportedInThisBuild = 152;
276 
277 
278  static const int RcfError_User = 1001;
279 
280  // Errors that are no longer in use. We keep them around for backwards
281  // compatibility (interacting with older clients or servers).
282 
283  static const int RcfError_StubAssignment = 19;
284  static const int RcfError_SspiAuthFail = 27;
285  static const int RcfError_UnknownSubscriber = 29;
286  static const int RcfError_Filter = 35;
287  static const int RcfError_NotConnected = 48;
288  static const int RcfError_InvalidErrorMessage = 54;
289 
290 #ifdef _MSC_VER
291 #pragma warning(push)
292 #pragma warning(disable:4100)
293 #pragma warning(disable:4267)
294 #endif
295 
296  template<typename T>
297  std::string numberToString(T t)
298  {
299  std::ostringstream os;
300  os << t;
301  return os.str();
302  }
303 
304  RCF_EXPORT std::string getOsErrorString(int osError);
305 
306  inline Error _RcfError_Ok() { return Error(RcfError_Ok); }
307  //inline Error _RcfError_Unspecified() { return Error(RcfError_Unspecified); }
308  inline Error _RcfError_ServerMessageLength() { return Error(RcfError_ServerMessageLength); }
309 
310  inline Error _RcfError_ClientMessageLength(
311  boost::uint32_t length,
312  std::size_t maxLength) { return Error(RcfError_ClientMessageLength, numberToString(length), numberToString(maxLength)); }
313 
314  inline Error _RcfError_Serialization(
315  const std::string & typeName,
316  const std::string & eType,
317  const std::string & eWhat) { return Error(RcfError_Serialization, typeName, eType, eWhat); }
318 
319  inline Error _RcfError_Deserialization(
320  const std::string & typeName,
321  const std::string & eType,
322  const std::string & eWhat) { return Error(RcfError_Deserialization, typeName, eType, eWhat); }
323 
324  inline Error _RcfError_AppException(
325  const std::string & eType,
326  const std::string & eWhat) { return Error(RcfError_AppException, eType, eWhat); }
327 
328  inline Error _RcfError_UnknownEndpoint() { return Error(RcfError_UnknownEndpoint); }
329  inline Error _RcfError_EndpointPassword() { return Error(RcfError_EndpointPassword); }
330  inline Error _RcfError_EndpointDown() { return Error(RcfError_EndpointDown); }
331  inline Error _RcfError_EndpointRetry() { return Error(RcfError_EndpointRetry); }
332 
333  inline Error _RcfError_ClientConnectTimeout(
334  unsigned int timeoutMs,
335  const std::string endpoint) { return Error(RcfError_ClientConnectTimeout, numberToString(timeoutMs), endpoint); }
336 
337  inline Error _RcfError_PeerDisconnect() { return Error(RcfError_PeerDisconnect); }
338  inline Error _RcfError_ClientCancel() { return Error(RcfError_ClientCancel); }
339  inline Error _RcfError_PayloadFilterMismatch() { return Error(RcfError_PayloadFilterMismatch); }
340 
341  inline Error _RcfError_OpenSslFilterInit(
342  const std::string & opensslErrors) { return Error(RcfError_OpenSslFilterInit, opensslErrors); }
343 
344  inline Error _RcfError_OpenSslLoadCert(
345  const std::string & file,
346  const std::string & opensslErrors) { return Error(RcfError_OpenSslLoadCert, file, opensslErrors); }
347 
348  inline Error _RcfError_UnknownPublisher(
349  const std::string & publisherName) { return Error(RcfError_UnknownPublisher, publisherName); }
350 
351  inline Error _RcfError_UnknownFilter() { return Error(RcfError_UnknownFilter); }
352 
353  inline Error _RcfError_NoServerStub(
354  const std::string & service,
355  const std::string & interface_,
356  int fnId) { return Error(RcfError_NoServerStub, service, interface_, numberToString(fnId)); }
357 
358  inline Error _RcfError_Sspi(
359  const std::string & funcName) { return Error(RcfError_Sspi, funcName); }
360 
361  inline Error _RcfError_SspiInit(
362  const std::string & funcName) { return Error(RcfError_SspiInit, funcName); }
363 
364  inline Error _RcfError_ClientReadTimeout() { return Error(RcfError_ClientReadTimeout); }
365  inline Error _RcfError_ClientReadFail() { return Error(RcfError_ClientReadFail); }
366  inline Error _RcfError_ClientWriteTimeout() { return Error(RcfError_ClientWriteTimeout); }
367  inline Error _RcfError_ClientWriteFail() { return Error(RcfError_ClientWriteFail); }
368  inline Error _RcfError_ClientConnectFail() { return Error(RcfError_ClientConnectFail); }
369 
370  inline Error _RcfError_Socket(
371  const std::string & funcName) { return Error(RcfError_Socket, funcName); }
372 
373  inline Error _RcfError_FnId(int fnId) { return Error(RcfError_FnId, numberToString(fnId)); }
374 
375  inline Error _RcfError_UnknownInterface(
376  const std::string & interface_) { return Error(RcfError_UnknownInterface, interface_); }
377 
378  inline Error _RcfError_NoEndpoint() { return Error(RcfError_NoEndpoint); }
379  inline Error _RcfError_TransportCreation() { return Error(RcfError_TransportCreation); }
380 
381  inline Error _RcfError_FilterCount(
382  std::size_t count,
383  std::size_t max) { return Error(RcfError_FilterCount, numberToString(count), numberToString(max)); }
384 
385  inline Error _RcfError_FilterMessage() { return Error(RcfError_FilterMessage); }
386  inline Error _RcfError_UnfilterMessage() { return Error(RcfError_UnfilterMessage); }
387 
388  inline Error _RcfError_SspiCredentials(
389  const std::string & funcName) { return Error(RcfError_SspiCredentials, funcName); }
390 
391  inline Error _RcfError_SspiEncrypt(
392  const std::string & funcName) { return Error(RcfError_SspiEncrypt, funcName); }
393 
394  inline Error _RcfError_SspiDecrypt(
395  const std::string & funcName) { return Error(RcfError_SspiDecrypt, funcName); }
396 
397  inline Error _RcfError_SspiImpersonation(
398  const std::string & funcName) { return Error(RcfError_SspiImpersonation, funcName); }
399 
400  inline Error _RcfError_SocketClose() { return Error(RcfError_SocketClose); }
401  inline Error _RcfError_ZlibDeflate() { return Error(RcfError_ZlibDeflate); }
402  inline Error _RcfError_ZlibInflate() { return Error(RcfError_ZlibInflate); }
403  inline Error _RcfError_Zlib() { return Error(RcfError_Zlib); }
404 
405  inline Error _RcfError_UnknownSerializationProtocol(
406  int protocol) { return Error(RcfError_UnknownSerializationProtocol, numberToString(protocol)); }
407 
408  inline Error _SfError_NoCtor() { return Error(SfError_NoCtor); }
409  inline Error _SfError_RefMismatch() { return Error(SfError_RefMismatch); }
410  inline Error _SfError_DataFormat() { return Error(SfError_DataFormat); }
411  inline Error _SfError_ReadFailure() { return Error(SfError_ReadFailure); }
412  inline Error _SfError_WriteFailure() { return Error(SfError_WriteFailure); }
413 
414  inline Error _SfError_BaseDerivedRegistration(
415  const std::string & baseType,
416  const std::string & derivedType) { return Error(SfError_BaseDerivedRegistration, baseType, derivedType); }
417 
418  inline Error _SfError_TypeRegistration(
419  const std::string & typeName) { return Error(SfError_TypeRegistration, typeName); }
420 
421  inline Error _RcfError_NonStdException() { return Error(RcfError_NonStdException); }
422 
423  inline Error _RcfError_SocketBind(
424  const std::string & networkInterface,
425  int port) { return Error(RcfError_SocketBind, networkInterface, numberToString(port)); }
426 
427  inline Error _RcfError_Decoding() { return Error(RcfError_Decoding); }
428  inline Error _RcfError_Encoding() { return Error(RcfError_Encoding); }
429  inline Error _RcfError_TokenRequestFailed() { return Error(RcfError_TokenRequestFailed); }
430  inline Error _RcfError_ObjectFactoryNotFound() { return Error(RcfError_ObjectFactoryNotFound); }
431 
432  inline Error _RcfError_PortInUse(
433  const std::string & networkInterface,
434  int port) { return Error(RcfError_PortInUse, networkInterface, numberToString(port)); }
435 
436  inline Error _RcfError_DynamicObjectNotFound(
437  int tokenId) { return Error(RcfError_DynamicObjectNotFound, numberToString(tokenId)); }
438 
439  inline Error _RcfError_VersionMismatch() { return Error(RcfError_VersionMismatch); }
440  inline Error _RcfError_SslCertVerification() { return Error(RcfError_SslCertVerification); }
441  inline Error _RcfError_FiltersLocked() { return Error(RcfError_FiltersLocked); }
442  inline Error _RcfError_Pipe() { return Error(RcfError_Pipe); }
443 
444  inline Error _RcfError_AnySerializerNotFound(
445  const std::string & typeName) { return Error(RcfError_AnySerializerNotFound, typeName); }
446 
447  inline Error _RcfError_ConnectionLimitExceeded() { return Error(RcfError_ConnectionLimitExceeded); }
448  inline Error _RcfError_DeserializationNullPointer() { return Error(RcfError_DeserializationNullPointer); }
449 
450  inline Error _RcfError_PipeNameTooLong(
451  const std::string & pipeName,
452  unsigned int max) { return Error(RcfError_PipeNameTooLong, pipeName, numberToString(max)); }
453 
454  inline Error _RcfError_PingBack() { return Error(RcfError_PingBack); }
455  inline Error _RcfError_NoPingBackService() { return Error(RcfError_NoPingBackService); }
456  inline Error _RcfError_NoDownload() { return Error(RcfError_NoDownload); }
457 
458  inline Error _RcfError_FileOffset(
459  boost::uint64_t expectedPos,
460  boost::uint64_t actualPos) { return Error(RcfError_FileOffset, numberToString(expectedPos), numberToString(actualPos)); }
461 
462  inline Error _RcfError_NoUpload() { return Error(RcfError_NoUpload); }
463 
464  inline Error _RcfError_FileOpen(
465  const std::string & filePath) { return Error(RcfError_FileOpen, filePath); }
466 
467  inline Error _RcfError_FileRead(
468  const std::string & filePath,
469  boost::uint64_t pos) { return Error(RcfError_FileRead, filePath, numberToString(pos)); }
470 
471  inline Error _RcfError_FileWrite(
472  const std::string & filePath,
473  boost::uint64_t pos) { return Error(RcfError_FileWrite, filePath, numberToString(pos)); }
474 
475  inline Error _RcfError_UploadFailed() { return Error(RcfError_UploadFailed); }
476  inline Error _RcfError_UploadInProgress() { return Error(RcfError_UploadInProgress); }
477  inline Error _RcfError_ConcurrentUpload() { return Error(RcfError_ConcurrentUpload); }
478  inline Error _RcfError_UploadFileSize() { return Error(RcfError_UploadFileSize); }
479  inline Error _RcfError_AccessDenied() { return Error(RcfError_AccessDenied); }
480 
481  inline Error _RcfError_PingBackTimeout(
482  unsigned int pingBackIntervalMs) { return Error(RcfError_PingBackTimeout, numberToString(pingBackIntervalMs)); }
483 
484  inline Error _RcfError_AllThreadsBusy() { return Error(RcfError_AllThreadsBusy); }
485 
486  inline Error _RcfError_UnsupportedRuntimeVersion(
487  int requestedVersion,
488  int maxVersion) { return Error(RcfError_UnsupportedRuntimeVersion, numberToString(requestedVersion), numberToString(maxVersion)); }
489 
490  inline Error _RcfError_FdSetSize(
491  unsigned int max) { return Error(RcfError_FdSetSize, numberToString(max)); }
492 
493  inline Error _RcfError_DnsLookup(
494  const std::string & ip) { return Error(RcfError_DnsLookup, ip); }
495 
496  inline Error _RcfError_SspiHandshakeExtraData() { return Error(RcfError_SspiHandshakeExtraData); }
497 
498  inline Error _RcfError_ProtobufWrite(
499  const std::string & typeName) { return Error(RcfError_ProtobufWrite, typeName); }
500 
501  inline Error _RcfError_ProtobufRead(
502  const std::string & typeName) { return Error(RcfError_ProtobufRead, typeName); }
503 
504  inline Error _RcfError_ExtractSlice(
505  std::size_t pos,
506  std::size_t len,
507  std::size_t max) { return Error(RcfError_ExtractSlice, numberToString(pos), numberToString(len), numberToString(max)); }
508 
509  inline Error _RcfError_ServerStubExpired() { return Error(RcfError_ServerStubExpired); }
510 
511  inline Error _RcfError_VariantDeserialization(
512  int index,
513  int max) { return Error(RcfError_VariantDeserialization, numberToString(index), numberToString(max)); }
514 
515  inline Error _RcfError_SspiAuthFailServer() { return Error(RcfError_SspiAuthFailServer); }
516  inline Error _RcfError_SspiAuthFailClient() { return Error(RcfError_SspiAuthFailClient); }
517 
518  inline Error _RcfError_Win32ApiError(
519  const std::string & funcName) { return Error(RcfError_Win32ApiError, funcName); }
520 
521  inline Error _RcfError_SspiLengthField(
522  int length,
523  int maxLength) { return Error(RcfError_Win32ApiError, numberToString(length), numberToString(maxLength)); }
524 
525  inline Error _RcfError_DownloadFailed(
526  const std::string & errMsg) { return Error(RcfError_DownloadFailed, errMsg); }
527 
528  inline Error _RcfError_FileSeek(
529  const std::string & filePath,
530  boost::uint64_t offset) { return Error(RcfError_FileSeek, filePath, numberToString(offset)); }
531 
532  inline Error _RcfError_DownloadCancelled() { return Error(RcfError_DownloadCancelled); }
533 
534  inline Error _RcfError_ParseSockAddr() { return Error(RcfError_ParseSockAddr); }
535 
536  inline Error _RcfError_GetSockName() { return Error(RcfError_GetSockName); }
537 
538  inline Error _RcfError_ProtobufWriteSize(
539  const std::string & typeName) { return Error(RcfError_ProtobufWriteSize, typeName); }
540 
541  inline Error _RcfError_ProtobufWriteInit(
542  const std::string & typeName) { return Error(RcfError_ProtobufWriteInit, typeName); }
543 
544  inline Error _RcfError_RcfError_ArraySizeMismatch(
545  unsigned int actual,
546  unsigned int fromArchive) { return Error(RcfError_ArraySizeMismatch, numberToString(actual), numberToString(fromArchive)); }
547 
548  inline Error _RcfError_WcharSizeMismatch(
549  unsigned int actual,
550  unsigned int fromArchive) { return Error(RcfError_WcharSizeMismatch, numberToString(actual), numberToString(fromArchive)); }
551 
552  inline Error _RcfError_AnyTypeNotRegistered(
553  const std::string typeidName) { return Error(RcfError_AnyTypeNotRegistered, typeidName); }
554 
555  inline Error _RcfError_CryptoApiError(
556  const std::string & funcName) { return Error(RcfError_CryptoApiError, funcName); }
557 
558  inline Error _RcfError_ServerStubAccessDenied() { return Error(RcfError_ServerStubAccessDenied); }
559 
560  inline Error _RcfError_ApiError(
561  const std::string & whichApi) { return Error(RcfError_ApiError, whichApi); }
562 
563  inline Error _RcfError_HttpProxyPort() { return Error(RcfError_HttpProxyPort); }
564 
565  inline Error _RcfError_OpenSslError(
566  const std::string & openSslErrors) { return Error(RcfError_OpenSslError, openSslErrors); }
567 
568  inline Error _RcfError_ProtocolNotSupported() { return Error(RcfError_ProtocolNotSupported); }
569 
570  inline Error _RcfError_ClearCommunicationNotAllowed(
571  const std::string & protocolNames) { return Error(RcfError_ClearCommunicationNotAllowed, protocolNames); }
572 
573  inline Error _RcfError_ThreadingError(
574  const std::string & functionName) { return Error(RcfError_ThreadingError, functionName); }
575 
576  inline Error _RcfError_RcfNotInitialized() { return Error(RcfError_RcfNotInitialized); }
577 
578  inline Error _RcfError_InvalidHttpMessage() { return Error(RcfError_InvalidHttpMessage); }
579 
580  inline Error _RcfError_HttpRequestContentLength(
581  const std::string & httpRequest) { return Error(RcfError_HttpRequestContentLength, httpRequest); }
582 
583  inline Error _RcfError_HttpResponseContentLength(
584  const std::string & httpStatus,
585  const std::string & httpResponse) { return Error(RcfError_HttpResponseContentLength, httpStatus, httpResponse); }
586 
587  inline Error _RcfError_InvalidOpenSslCertificate() { return Error(RcfError_InvalidOpenSslCertificate); }
588  inline Error _RcfError_InvalidSchannelCertificate() { return Error(RcfError_InvalidSchannelCertificate); }
589 
590  inline Error _RcfError_HttpConnectFailed(
591  const std::string & httpStatus,
592  const std::string & httpResponse) { return Error(RcfError_HttpConnectFailed, httpStatus, httpResponse); }
593 
594  inline Error _RcfError_SspiImpersonateNoSspi() { return Error(RcfError_SspiImpersonateNoSspi); }
595 
596  inline Error _RcfError_TransportProtocolNotSupported(
597  const std::string& protocolName) { return Error(RcfError_TransportProtocolNotSupported, protocolName); }
598 
599  inline Error _RcfError_SslNotSupported() { return Error(RcfError_SslNotSupported); }
600 
601  inline Error _RcfError_SessionObjectDoesNotExist(
602  const std::string & objectType) { return Error(RcfError_SessionObjectDoesNotExist, objectType); }
603 
604  inline Error _RcfError_UploadAlreadyCompleted() { return Error(RcfError_UploadAlreadyCompleted); }
605 
606  inline Error _RcfError_FileIndex(
607  boost::uint64_t expectedPos,
608  boost::uint64_t actualPos) { return Error(RcfError_FileOffset, numberToString(expectedPos), numberToString(actualPos)); }
609 
610  inline Error _RcfError_ConcurrentCalls() { return Error(RcfError_ConcurrentCalls); }
611 
612  inline Error _RcfError_ParseJsonRpcRequest() { return Error(RcfError_ParseJsonRpcRequest); }
613 
614  inline Error _RcfError_DllLoad(
615  const std::string & dllName) { return Error(RcfError_DllLoad, dllName); }
616 
617  inline Error _RcfError_DllFuncLoad(
618  const std::string & dllName,
619  const std::string & funcName) { return Error(RcfError_DllFuncLoad, dllName, funcName); }
620 
621  inline Error _RcfError_UnixDllLoad(
622  const std::string & dllName,
623  const std::string & dlerr) { return Error(RcfError_UnixDllLoad, dllName, dlerr); }
624 
625  inline Error _RcfError_UnixDllFuncLoad(
626  const std::string & dllName,
627  const std::string & funcName,
628  const std::string & dlerr) { return Error(RcfError_UnixDllFuncLoad, dllName, funcName, dlerr); }
629 
630  inline Error _RcfError_PingBackInterval(
631  boost::uint32_t requestedIntervalMs,
632  boost::uint32_t minimumIntervalMs) { return Error(RcfError_PingBackInterval, numberToString(requestedIntervalMs), numberToString(minimumIntervalMs) ); }
633 
634  inline Error _RcfError_FileOpenWrite(
635  const std::string & filePath) { return Error(RcfError_FileOpenWrite, filePath); }
636 
637  inline Error _RcfError_CustomCertValidation(
638  const std::string & errorMsg) { return Error(RcfError_CustomCertValidation, errorMsg); }
639 
640  inline Error _RcfError_SupportedOnWindowsOnly(
641  const std::string & className) { return Error(RcfError_SupportedOnWindowsOnly, className); }
642 
643  inline Error _RcfError_NotSupportedOnWindows(
644  const std::string & className) { return Error(RcfError_NotSupportedOnWindows, className); }
645 
646  inline Error _RcfError_NotSupportedInThisBuild(
647  const std::string & className) { return Error(RcfError_NotSupportedInThisBuild, className); }
648 
649 #ifdef _MSC_VER
650 #pragma warning(pop)
651 #endif
652 
653  // RCF subsystem identifiers
654  static const int RcfSubsystem_None = 0;
655  static const int RcfSubsystem_Os = 1;
656  static const int RcfSubsystem_Zlib = 2;
657  static const int RcfSubsystem_OpenSsl = 3;
658  static const int RcfSubsystem_Asio = 4;
659 
660  RCF_EXPORT std::string getErrorString(int rcfError);
661  RCF_EXPORT std::string getSubSystemName(int subSystem);
662  RCF_EXPORT std::string getOsErrorString(int osError);
663 
664  RCF_EXPORT bool shouldDisconnectOnRemoteError(const Error & err);
665 
666  RCF_EXPORT int getRuntimeVersionOfThisRemoteCall();
667 
668  class RCF_EXPORT Exception : public std::runtime_error
669  {
670  public:
671  Exception();
672 
673  Exception(
674  const std::string & what,
675  const std::string & context = "");
676 
677  Exception(
678  Error error,
679  const std::string & what = "",
680  const std::string & context = "");
681 
682  Exception(
683  Error error,
684  int subSystemError,
685  int subSystem = RcfSubsystem_Os,
686  const std::string & what = "",
687  const std::string & context = "");
688 
689  ~Exception() throw();
690 
691  virtual std::auto_ptr<Exception> clone() const
692  {
693  return std::auto_ptr<Exception>(
694  new Exception(*this));
695  }
696 
697  bool good() const;
698  bool bad() const;
699  void clear();
700 
701  const char * what() const throw();
702  const Error & getError() const;
703  int getErrorId() const;
704  std::string getErrorString() const;
705  int getSubSystemError() const;
706  int getSubSystem() const;
707  std::string getSubSystemName() const;
708  std::string getContext() const;
709  std::string getWhat() const;
710 
711  void setContext(const std::string &context);
712  void setWhat(const std::string &what);
713 
714  virtual void throwSelf() const;
715 
716  protected:
717 
718  std::string translate() const;
719 
720  // protected to make serialization of RemoteException simpler
721  protected:
722 
723  std::string mWhat;
724  std::string mContext;
725  Error mError;
726  int mSubSystemError;
727  int mSubSystem;
728 
729  mutable std::string mTranslatedWhat;
730  };
731 
732  typedef boost::shared_ptr<Exception> ExceptionPtr;
733 
734  class RCF_EXPORT RemoteException : public Exception
735  {
736  public:
737  RemoteException();
738 
739  RemoteException(
740  Error remoteError,
741  const std::string & remoteWhat = "",
742  const std::string & remoteContext = "",
743  const std::string & remoteExceptionType = "");
744 
745  RemoteException(
746  Error remoteError,
747  int remoteSubSystemError,
748  int remoteSubSystem,
749  const std::string & remoteWhat = "",
750  const std::string & remoteContext = "",
751  const std::string & remoteExceptionType = "");
752 
753  ~RemoteException() throw();
754 
755  const char *what() const throw();
756 
757  std::string getRemoteExceptionType() const;
758 
759 #ifdef RCF_USE_SF_SERIALIZATION
760 
761  void serialize(SF::Archive & ar);
762 
763 #endif
764 
765 #ifdef RCF_USE_BOOST_SERIALIZATION
766 
767  template<typename Archive>
768  void serialize(Archive &ar, const unsigned int)
769  {
770  int runtimeVersion = getRuntimeVersionOfThisRemoteCall();
771 
772  bool isLoading = boost::is_base_and_derived<
773  boost::archive::detail::basic_iarchive, Archive>::value;
774 
775  if (runtimeVersion <= 7)
776  {
777  int errorId = mError.getErrorId();
778 
779  ar
780  & boost::serialization::make_nvp("What", mWhat)
781  & boost::serialization::make_nvp("Context", mContext)
782  & boost::serialization::make_nvp("Error", errorId)
783  & boost::serialization::make_nvp("Subsystem Error", mSubSystemError)
784  & boost::serialization::make_nvp("Subsystem", mSubSystem)
785  & boost::serialization::make_nvp("Remote Exception Type", mRemoteExceptionType);
786 
787  if (isLoading)
788  {
789  mError.setErrorId(errorId);
790  }
791  }
792  else
793  {
794  ar
795  & boost::serialization::make_nvp("What", mWhat)
796  & boost::serialization::make_nvp("Context", mContext)
797  & boost::serialization::make_nvp("Error", mError)
798  & boost::serialization::make_nvp("Subsystem Error", mSubSystemError)
799  & boost::serialization::make_nvp("Subsystem", mSubSystem)
800  & boost::serialization::make_nvp("Remote Exception Type", mRemoteExceptionType);
801  }
802  }
803 
804 #endif
805 
806  std::auto_ptr<Exception> clone() const;
807 
808  void throwSelf() const;
809 
810  private:
811  std::string mRemoteExceptionType;
812  };
813 
814 #define RCF_DEFINE_EXCEPTION(E, PE) \
815  class E : public PE \
816  { \
817  public: \
818  E( \
819  const std::string &what = "") : \
820  PE(RcfError_User, what) \
821  {} \
822  E( \
823  Error error, \
824  const std::string &what = "") : \
825  PE(error, what) \
826  {} \
827  E( \
828  Error error, \
829  int subSystemError, \
830  int subSystem, \
831  const std::string &what = "") : \
832  PE(error, subSystemError, subSystem, what) \
833  {} \
834  std::auto_ptr<Exception> clone() const \
835  { \
836  return std::auto_ptr<Exception>( \
837  new E(*this)); \
838  } \
839  void throwSelf() const \
840  { \
841  throw *this; \
842  } \
843  ~E() throw() \
844  {} \
845  };
846 
847  RCF_DEFINE_EXCEPTION(SerializationException, Exception)
848  RCF_DEFINE_EXCEPTION(AssertionFailureException, Exception)
849  RCF_DEFINE_EXCEPTION(FilterException, Exception)
850 
851  class RCF_EXPORT VersioningException : public RemoteException
852  {
853  public:
854  VersioningException(
855  boost::uint32_t runtimeVersion,
856  boost::uint32_t archiveVersion);
857 
858  ~VersioningException() throw();
859 
860  boost::uint32_t getRuntimeVersion() const;
861  boost::uint32_t getArchiveVersion() const;
862 
863  std::auto_ptr<Exception> clone() const
864  {
865  return std::auto_ptr<Exception>(
866  new VersioningException(*this));
867  }
868 
869  void throwSelf() const
870  {
871  throw *this;
872  }
873 
874  private:
875  boost::uint32_t mRuntimeVersion;
876  boost::uint32_t mArchiveVersion;
877  };
878 
879 #undef RCF_DEFINE_EXCEPTION
880 
881 } // namespace RCF
882 
883 #endif // ! INCLUDE_RCF_EXCEPTION_HPP