This is Unofficial EPICS BASE Doxygen Site
pvTimeStamp.cpp
Go to the documentation of this file.
1 /* pvTimeStamp.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/timeStamp.h>
15 #include <pv/pvData.h>
16 #include <pv/pvTimeStamp.h>
17 
19 using std::string;
20 
21 namespace epics { namespace pvData {
22 
23 string PVTimeStamp::noTimeStamp("No timeStamp structure found");
24 string PVTimeStamp::notAttached("Not attached to a timeStamp structure");
25 
26 bool PVTimeStamp::attach(PVFieldPtr const & pvField)
27 {
28  if(pvField->getField()->getType()!=structure) return false;
30  PVStructure* pvStructure = xxx.get();
31  while(true) {
32  PVLongPtr pvLong = pvStructure->getSubField<PVLong>("secondsPastEpoch");
33  if(pvLong) {
34  pvSecs = pvLong;
35  pvNano = pvStructure->getSubField<PVInt>("nanoseconds");
36  pvUserTag = pvStructure->getSubField<PVInt>("userTag");
37  }
38  if(pvSecs
39  && pvNano
40  && pvUserTag) return true;
41  detach();
42  // look up the tree for a timeSyamp
43  pvStructure = pvStructure->getParent();
44  if(pvStructure==NULL) break;
45  }
46  return false;
47 }
48 
50 {
51  pvSecs.reset();
52  pvUserTag.reset();
53  pvNano.reset();
54 }
55 
57  if(pvSecs.get()==NULL) return false;
58  return true;
59 }
60 
61 void PVTimeStamp::get(TimeStamp & timeStamp) const
62 {
63  if(pvSecs.get()==NULL) {
64  throw std::logic_error(notAttached);
65  }
66  timeStamp.put(pvSecs->get(),pvNano->get());
67  timeStamp.setUserTag(pvUserTag->get());
68 }
69 
70 bool PVTimeStamp::set(TimeStamp const & timeStamp)
71 {
72  if(pvSecs.get()==NULL) {
73  throw std::logic_error(notAttached);
74  }
75  if(pvSecs->isImmutable() || pvNano->isImmutable()) return false;
76  TimeStamp current;
77  get(current);
78  bool returnValue = false;
79  if(current.getSecondsPastEpoch()!=timeStamp.getSecondsPastEpoch())
80  {
81  pvSecs->put(timeStamp.getSecondsPastEpoch());
82  returnValue = true;
83  }
84  if(current.getNanoseconds()!=timeStamp.getNanoseconds())
85  {
86  pvNano->put(timeStamp.getNanoseconds());
87  returnValue = true;
88  }
89  if(current.getUserTag()!=timeStamp.getUserTag())
90  {
91  pvUserTag->put(timeStamp.getUserTag());
92  returnValue = true;
93  }
94  return returnValue;
95 }
96 
97 }}
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
#define NULL
Definition: catime.c:38
void get(TimeStamp &timeStamp) const
Definition: pvTimeStamp.cpp:61
std::tr1::shared_ptr< PVLong > PVLongPtr
Definition: pvData.h:508
int32 getNanoseconds() const
Definition: timeStamp.h:91
void put(int64 secondsPastEpoch, int32 nanoseconds=0)
Definition: timeStamp.h:108
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
int32 getUserTag() const
Definition: timeStamp.h:96
Class that holds the data for each possible scalar type.
Definition: pvData.h:54
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
void setUserTag(int32 userTag)
Definition: timeStamp.h:101
int64 getSecondsPastEpoch() const
Definition: timeStamp.h:78
bool attach(PVFieldPtr const &pvField)
Definition: pvTimeStamp.cpp:26
Methods for manipulating timeStamp.
Definition: timeStamp.h:43
bool set(TimeStamp const &timeStamp)
Definition: pvTimeStamp.cpp:70