This is Unofficial EPICS BASE Doxygen Site
pvAlarm.cpp
Go to the documentation of this file.
1 /* pvAlarm.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 #include <string>
10 #include <stdexcept>
11 
12 #define epicsExportSharedSymbols
13 #include <pv/pvType.h>
14 #include <pv/pvIntrospect.h>
15 #include <pv/pvData.h>
16 #include <pv/pvAlarm.h>
17 
19 using std::string;
20 
21 namespace epics { namespace pvData {
22 
23 string PVAlarm::noAlarmFound("No alarm structure found");
24 string PVAlarm::notAttached("Not attached to an alarm structure");
25 
26 bool PVAlarm::attach(PVFieldPtr const & pvField)
27 {
28  if(pvField->getField()->getType()!=structure) return false;
29  PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
30  pvSeverity = pvStructure->getSubField<PVInt>("severity");
31  if(pvSeverity.get()==NULL) return false;
32  pvStatus = pvStructure->getSubField<PVInt>("status");
33  if(pvStatus.get()==NULL) {
34  pvSeverity.reset();
35  return false;
36  }
37  pvMessage = pvStructure->getSubField<PVString>("message");
38  if(pvMessage.get()==NULL) {
39  pvSeverity.reset();
40  pvStatus.reset();
41  return false;
42  }
43  return true;
44 }
45 
47 {
48  pvSeverity.reset();
49  pvStatus.reset();
50  pvMessage.reset();
51 }
52 
54 {
55  if(pvSeverity.get()==NULL) return false;
56  return true;
57 }
58 
59 void PVAlarm::get(Alarm & alarm) const
60 {
61  if(pvSeverity.get()==NULL) {
62  throw std::logic_error(notAttached);
63  }
64  alarm.setSeverity(AlarmSeverityFunc::getSeverity(pvSeverity->get()));
65  alarm.setStatus(AlarmStatusFunc::getStatus(pvStatus->get()));
66  alarm.setMessage(pvMessage->get());
67 }
68 
69 bool PVAlarm::set(Alarm const & alarm)
70 {
71  if(pvSeverity.get()==NULL) {
72  throw std::logic_error(notAttached);
73  }
74  if(pvSeverity->isImmutable() || pvMessage->isImmutable()) return false;
75  Alarm current;
76  get(current);
77  bool returnValue = false;
78  if(current.getSeverity()!=alarm.getSeverity())
79  {
80  pvSeverity->put(alarm.getSeverity());
81  returnValue = true;
82  }
83  if(current.getStatus()!=alarm.getStatus())
84  {
85  pvStatus->put(alarm.getStatus());
86  returnValue = true;
87  }
88  if(current.getMessage()!=alarm.getMessage())
89  {
90  pvMessage->put(alarm.getMessage());
91  returnValue = true;
92  }
93  return returnValue;
94 }
95 
96 }}
Methods for manipulating alarm.
Definition: alarm.h:105
void setMessage(std::string const &value)
Definition: alarm.h:121
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
bool attach(PVFieldPtr const &pvField)
Definition: pvAlarm.cpp:26
bool set(Alarm const &alarm)
Definition: pvAlarm.cpp:69
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
#define NULL
Definition: catime.c:38
static AlarmSeverity getSeverity(int value)
Definition: alarm.cpp:25
std::string getMessage() const
Definition: alarm.h:116
void get(Alarm &alarm) const
Definition: pvAlarm.cpp:59
PVString is special case, since it implements SerializableArray.
Definition: pvData.h:521
void setSeverity(AlarmSeverity value)
Definition: alarm.h:132
AlarmStatus getStatus() const
Definition: alarm.cpp:109
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
void setStatus(AlarmStatus value)
Definition: alarm.h:143
Class that holds the data for each possible scalar type.
Definition: pvData.h:54
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
AlarmSeverity getSeverity() const
Definition: alarm.cpp:58
static AlarmStatus getStatus(int value)
Definition: alarm.cpp:70