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