This is Unofficial EPICS BASE Doxygen Site
pvControl.cpp
Go to the documentation of this file.
1 /* pvControl.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/pvControl.h>
17 
18 namespace epics { namespace pvData {
19 
21 using std::string;
22 
23 string PVControl::noControlFound("No control structure found");
24 string PVControl::notAttached("Not attached to an control structure");
25 
26 bool PVControl::attach(PVFieldPtr const & pvField)
27 {
28  if(pvField->getField()->getType()!=structure) return false;
29  PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
30  pvLow = pvStructure->getSubField<PVDouble>("limitLow");
31  if(pvLow.get()==NULL) return false;
32  pvHigh = pvStructure->getSubField<PVDouble>("limitHigh");
33  if(pvHigh.get()==NULL) {
34  pvLow.reset();
35  return false;
36  }
37  pvMinStep = pvStructure->getSubField<PVDouble>("minStep");
38  if(pvMinStep.get()==NULL) {
39  pvLow.reset();
40  pvHigh.reset();
41  return false;
42  }
43  return true;
44 }
45 
47 {
48  pvLow.reset();
49  pvHigh.reset();
50 }
51 
53  if(pvLow.get()==NULL) return false;
54  return true;
55 }
56 
57 void PVControl::get(Control &control) const
58 {
59  if(pvLow.get()==NULL) {
60  throw std::logic_error(notAttached);
61  }
62  control.setLow(pvLow->get());
63  control.setHigh(pvHigh->get());
64  control.setMinStep(pvMinStep->get());
65 }
66 
67 bool PVControl::set(Control const & control)
68 {
69  if(pvLow.get()==NULL) {
70  throw std::logic_error(notAttached);
71  }
72  if(pvLow->isImmutable() || pvHigh->isImmutable() || pvMinStep->isImmutable()) return false;
73  Control current;
74  get(current);
75  bool returnValue = false;
76  if(current.getLow()!=control.getLow())
77  {
78  pvLow->put(control.getLow());
79  returnValue = true;
80  }
81  if(current.getHigh()!=control.getHigh())
82  {
83  pvHigh->put(control.getHigh());
84  returnValue = true;
85  }
86  if(current.getMinStep()!=control.getMinStep())
87  {
88  pvMinStep->put(control.getMinStep());
89  returnValue = true;
90  }
91  return returnValue;
92 }
93 
94 }}
bool set(Control const &control)
Definition: pvControl.cpp:67
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
void setHigh(double value)
Definition: control.h:63
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
#define NULL
Definition: catime.c:38
double getMinStep() const
Definition: control.h:53
double getHigh() const
Definition: control.h:48
Methods for a control structure.
Definition: control.h:32
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
void setMinStep(double value)
Definition: control.h:68
Class that holds the data for each possible scalar type.
Definition: pvData.h:54
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
double getLow() const
Definition: control.h:43
void setLow(double value)
Definition: control.h:58
void get(Control &control) const
Definition: pvControl.cpp:57
bool attach(PVFieldPtr const &pvField)
Definition: pvControl.cpp:26