RTI Routing Service  Version 6.0.0
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
ServiceException.hpp
1 /*
2  * $Id$
3  *
4  * (c) Copyright, Real-Time Innovations, 2016-.
5  * All rights reserved.
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  */
11 
12 #ifndef HPP_SERVICE_SERVICE_EXCEPTION_HPP_
13 #define HPP_SERVICE_SERVICE_EXCEPTION_HPP_
14 
15 #include "routingservice/routingservice_log.h"
16 
17 #include <dds/core/types.hpp>
18 #include <dds/core/Exception.hpp>
19 
20 namespace rti { namespace service {
21 
22 static
23 void initialize_exception_message(
24  std::string& message,
25  const char *throwing_context,
26  const RTILogMessage *log_message,
27  va_list ap)
28 {
29  RTIOsapiUtility_snprintf(
30  &message[0],
31  RTI_LOG_MSG_SIZE_MAX,
32  "%s:",
33  throwing_context);
34  RTIOsapiUtility_vsnprintf(
35  &message[0] + strlen(message.c_str()),
36  (size_t) RTI_LOG_MSG_SIZE_MAX - strlen(message.c_str()),
37  log_message->format,
38  ap);
39 }
40 
41 
42 class ServiceException : public std::exception {
43 public:
44 
45  ServiceException(
46  const char *throwing_context,
47  const RTILogMessage *log_message,
48  ...)
49  : message_(RTI_LOG_MSG_SIZE_MAX, '\0'),
50  error_code_(log_message->logNumber)
51  {
52  va_list ap;
53  va_start(ap, log_message);
54  initialize_exception_message(
55  message_,
56  throwing_context,
57  log_message,
58  ap);
59  va_end(ap);
60  }
61 
62  int32_t error_code() const
63  {
64  return error_code_;
65  }
66 
67  virtual const char* what() const throw ()
68  {
69  return message_.c_str();
70  }
71 
72  virtual ~ServiceException() throw ()
73  {
74  }
75 
76 private:
77  ServiceException()
78  {
79  }
80 
81  std::string message_;
82  int32_t error_code_;
83 };
84 
85 } } /* namespace rti::service::service */
86 
87 #define RTI_THROW_SERVICE_EXCEPTION( ...) \
88  throw rti::service::ServiceException(\
89  RTI_FUNCTION_NAME,\
90  __VA_ARGS__)
91 
92 #endif /* HPP_SERVICE_SERVICE_EXCEPTION_HPP_ */

RTI Routing Service Version 6.0.0 Copyright © Sun Mar 3 2019 Real-Time Innovations, Inc