CheckStatus.cpp
Go to the documentation of this file.
1 /*
2  * OpenSplice DDS
3  *
4  * This software and documentation are Copyright 2006 to 2009 PrismTech
5  * Limited and its licensees. All rights reserved. See file:
6  *
7  * $OSPL_HOME/LICENSE
8  *
9  * for full copyright notice and license terms.
10  *
11  */
12 
13 /************************************************************************
14  * LOGICAL_NAME: CheckStatus.cpp
15  * FUNCTION: OpenSplice Tutorial example code.
16  * MODULE: Tutorial for the C++ programming language.
17  * DATE june 2007.
18  ************************************************************************
19  *
20  * This file contains the implementation for the error handling operations.
21  *
22  ***/
23 
24 #include "rms/provider/CheckStatus.h"
25 #include "rms/base/RmsRuntimeException.h"
26 
27 namespace gov {
28 
29 namespace fnal {
30 
31 namespace cd {
32 
33 namespace rms {
34 
35 namespace provider {
36 
37 /* Array to hold the names for all ReturnCodes. */
38 const char *RetCodeName[13] = {
39  "DDS_RETCODE_OK",
40  "DDS_RETCODE_ERROR",
41  "DDS_RETCODE_UNSUPPORTED",
42  "DDS_RETCODE_BAD_PARAMETER",
43  "DDS_RETCODE_PRECONDITION_NOT_MET",
44  "DDS_RETCODE_OUT_OF_RESOURCES",
45  "DDS_RETCODE_NOT_ENABLED",
46  "DDS_RETCODE_IMMUTABLE_POLICY",
47  "DDS_RETCODE_INCONSISTENT_POLICY",
48  "DDS_RETCODE_ALREADY_DELETED",
49  "DDS_RETCODE_TIMEOUT",
50  "DDS_RETCODE_NO_DATA",
51  "DDS_RETCODE_ILLEGAL_OPERATION" };
52 
53 /**
54  * Returns the name of an error code.
55  **/
56 const char *getErrorName(DDS::ReturnCode_t status)
57 {
58  return RetCodeName[status];
59 }
60 
61 /**
62  * Check the return status for errors. If there is an error, then throw a runtime exception.
63  **/
65  DDS::ReturnCode_t status,
66  const char *info ) {
67 
68 
69  if (status != DDS::RETCODE_OK && status != DDS::RETCODE_NO_DATA) {
70  cerr << "Error in " << info << ": " << getErrorName(status) << endl;
71  GENERATE_RMS_RUNTIME_EXCEPTION ("checkStatus failed");
72  }
73 }
74 
75 /**
76  * Check whether a valid handle has been returned. If not, then throw a runtime exception.
77  **/
79  void *handle,
80  const char *info ) {
81 
82  if (!handle) {
83  cerr << "Error in " << info << ": Creation failed: invalid handle" << endl;
84  GENERATE_RMS_RUNTIME_EXCEPTION ("checkHandle failed");
85  }
86 }
87 
88 } // end of namespace provider
89 
90 } // end of namespace rms
91 
92 } // end of namespace cd
93 
94 } // end of namespace fnal
95 
96 } // end of namespace gov
const char * getErrorName(DDS::ReturnCode_t status)
Definition: CheckStatus.cpp:56
const XML_Char XML_Encoding * info
Definition: expat.h:530
void checkHandle(void *handle, const char *info)
Definition: CheckStatus.cpp:78
int status
Definition: fabricate.py:1613
OStream cerr
Definition: OStream.cxx:7
Definition: fnal.py:1
const char * RetCodeName[13]
Definition: CheckStatus.cpp:38
#define GENERATE_RMS_RUNTIME_EXCEPTION(msg)
void checkStatus(DDS::ReturnCode_t status, const char *info)
Definition: CheckStatus.cpp:64
c cd(1)