This is Unofficial EPICS BASE Doxygen Site
status.cpp
Go to the documentation of this file.
1 /*status.cpp*/
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #define epicsExportSharedSymbols
10 #include <pv/epicsException.h>
11 #include <pv/serializeHelper.h>
12 #include <pv/status.h>
13 
14 using std::string;
15 
16 namespace epics { namespace pvData {
17 
18 const char* Status::StatusTypeName[] = { "OK", "WARNING", "ERROR", "FATAL" };
19 
20 Status Status::Ok;
21 
22 Status::Status(StatusType type, string const & message) :
23  m_statusType(type), m_message(message)
24 {
25  if (type == STATUSTYPE_OK)
26  throw std::invalid_argument("type == STATUSTYPE_OK");
27 }
28 
29 Status::Status(StatusType type, string const & message, string const & stackDump) :
30  m_statusType(type), m_message(message), m_stackDump(stackDump)
31 {
32  if (type == STATUSTYPE_OK)
33  throw std::invalid_argument("type == STATUSTYPE_OK");
34 }
35 
36 void Status::maximize(const Status& o)
37 {
38  if(m_statusType < o.m_statusType) {
39  m_statusType = o.m_statusType;
40  m_message = o.m_message;
41  m_stackDump = o.m_stackDump;
42  }
43 }
44 
45 void Status::serialize(ByteBuffer *buffer, SerializableControl *flusher) const
46 {
47  flusher->ensureBuffer(1);
48  if (m_statusType == STATUSTYPE_OK)
49  {
50  // special code for okStatus (optimization)
51  buffer->putByte((int8)-1);
52  }
53  else
54  {
55  buffer->putByte((int8)m_statusType);
56  SerializeHelper::serializeString(m_message, buffer, flusher);
57  SerializeHelper::serializeString(m_stackDump, buffer, flusher);
58  }
59 }
60 
62 {
63  flusher->ensureData(1);
64  int8 typeCode = buffer->getByte();
65  if (typeCode == (int8)-1)
66  {
67  // in most of the cases status will be OK, we statistically optimize
68  if (m_statusType != STATUSTYPE_OK)
69  {
70  m_statusType = STATUSTYPE_OK;
71  m_message.clear();
72  m_stackDump.clear();
73  }
74  }
75  else
76  {
77  m_statusType = (StatusType)typeCode;
78  m_message = SerializeHelper::deserializeString(buffer, flusher);
79  m_stackDump = SerializeHelper::deserializeString(buffer, flusher);
80  }
81 }
82 
83 void Status::dump(std::ostream& o) const
84 {
85  o << "Status [type=" << Status::StatusTypeName[m_statusType];
86  if (!m_message.empty())
87  o << ", message=" << m_message;
88  if (!m_stackDump.empty())
89  o << ", stackDump=" << std::endl << m_stackDump;
90  o << ']';
91 }
92 
93 }}
int8_t int8
Definition: pvType.h:75
void deserialize(ByteBuffer *buffer, DeserializableControl *flusher)
Definition: status.cpp:61
void dump(std::ostream &o) const
Definition: status.cpp:83
EPICS_ALWAYS_INLINE int8 getByte()
Definition: byteBuffer.h:617
static std::string deserializeString(ByteBuffer *buffer, DeserializableControl *control)
static Status Ok
Definition: status.h:47
pvd::StructureConstPtr type
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
Callback class for deserialization.
Definition: serialize.h:89
void serialize(ByteBuffer *buffer, SerializableControl *flusher) const
Definition: status.cpp:45
void maximize(const Status &o)
Definition: status.cpp:36
EPICS_ALWAYS_INLINE void putByte(int8 value)
Definition: byteBuffer.h:525
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
Definition: byteBuffer.h:233
static const char * StatusTypeName[]
Definition: status.h:45
static void serializeString(const std::string &value, ByteBuffer *buffer, SerializableControl *flusher)
virtual void ensureBuffer(std::size_t size)=0
Callback class for serialization.
Definition: serialize.h:34
virtual void ensureData(std::size_t size)=0