This is Unofficial EPICS BASE Doxygen Site
epics::pvDatabase::PVRecord Class Reference

Base interface for a PVRecord. More...

#include "pvDatabase.h"

+ Inheritance diagram for epics::pvDatabase::PVRecord:
+ Collaboration diagram for epics::pvDatabase::PVRecord:

Public Member Functions

 POINTER_DEFINITIONS (PVRecord)
 
virtual ~PVRecord ()
 
virtual bool init ()
 Optional initialization method. More...
 
virtual void start ()
 Optional method for derived class. More...
 
virtual void process ()
 Optional method for derived class. More...
 
virtual void destroy ()
 DEPRECATED. More...
 
virtual void remove ()
 remove record from database. More...
 
virtual epics::pvAccess::RPCServiceAsync::shared_pointer getService (epics::pvData::PVStructurePtr const &pvRequest)
 Optional method for derived class. More...
 
std::string getRecordName () const
 Get the name of the record. More...
 
PVRecordStructurePtr getPVRecordStructure () const
 Get the top level PVRecordStructure. More...
 
epics::pvData::PVStructurePtr getPVStructure () const
 Get the top level PVStructure. More...
 
PVRecordFieldPtr findPVRecordField (epics::pvData::PVFieldPtr const &pvField)
 Find the PVRecordField for the PVField. More...
 
void lock ()
 Lock the record. More...
 
void unlock ()
 Unlock the record. More...
 
bool tryLock ()
 Try to lock the record. More...
 
void lockOtherRecord (PVRecordPtr const &otherRecord)
 Lock another record. More...
 
bool addPVRecordClient (PVRecordClientPtr const &pvRecordClient)
 Add a client that wants to access the record. More...
 
bool addListener (PVListenerPtr const &pvListener, epics::pvCopy::PVCopyPtr const &pvCopy)
 Add a PVListener. More...
 
void nextMasterPVField (epics::pvData::PVFieldPtr const &pvField)
 PVCopyTraverseMasterCallback method. More...
 
bool removeListener (PVListenerPtr const &pvListener, epics::pvCopy::PVCopyPtr const &pvCopy)
 Remove a listener. More...
 
void beginGroupPut ()
 Begins a group of puts. More...
 
void endGroupPut ()
 Ends a group of puts. More...
 
int getTraceLevel ()
 get trace level (0,1,2) means (nothing,lifetime,process) More...
 
void setTraceLevel (int level)
 set trace level (0,1,2) means (nothing,lifetime,process) More...
 
- Public Member Functions inherited from epics::pvCopy::PVCopyTraverseMasterCallback
 POINTER_DEFINITIONS (PVCopyTraverseMasterCallback)
 
virtual ~PVCopyTraverseMasterCallback ()
 

Static Public Member Functions

static PVRecordPtr create (std::string const &recordName, epics::pvData::PVStructurePtr const &pvStructure)
 Creates a soft record. More...
 

Protected Member Functions

 PVRecord (std::string const &recordName, epics::pvData::PVStructurePtr const &pvStructure)
 Constructor. More...
 
void initPVRecord ()
 Initializes the base class. More...
 

Friends

class PVDatabase
 

Detailed Description

Base interface for a PVRecord.

It is also a complete implementation for soft records. A soft record is a record where method process sets an optional top level timeStamp field to the current time and does nothing else.

Author
mrk
Date
2012.11.20

Definition at line 56 of file pvDatabase.h.

Constructor & Destructor Documentation

epics::pvDatabase::PVRecord::~PVRecord ( )
virtual

The Destructor.

Definition at line 61 of file pvRecord.cpp.

62 {
63  if(traceLevel>0) {
64  cout << "~PVRecord() " << recordName << endl;
65  }
66 }
epics::pvDatabase::PVRecord::PVRecord ( std::string const &  recordName,
epics::pvData::PVStructurePtr const &  pvStructure 
)
protected

Constructor.

Parameters
recordNameThe name of the record
pvStructureThe top level PVStructutre

Definition at line 50 of file pvRecord.cpp.

53 : recordName(recordName),
54  pvStructure(pvStructure),
55  depthGroupPut(0),
56  traceLevel(0),
57  isAddListener(false)
58 {
59 }

Member Function Documentation

bool epics::pvDatabase::PVRecord::addListener ( PVListenerPtr const &  pvListener,
epics::pvCopy::PVCopyPtr const &  pvCopy 
)

Add a PVListener.

This must be called before calling pvRecordField.addListener.

Parameters
pvListenerThe listener.
pvCopyThe pvStructure that has the client fields.
Returns
true if the listener was added.

Definition at line 230 of file pvRecord.cpp.

233 {
234  if(traceLevel>1) {
235  cout << "PVRecord::addListener() " << recordName << endl;
236  }
238  pvListenerList.push_back(pvListener);
239  this->pvListener = pvListener;
240  isAddListener = true;
241  pvCopy->traverseMaster(shared_from_this());
242  this->pvListener = PVListenerPtr();;
243  return true;
244 }
std::tr1::shared_ptr< PVListener > PVListenerPtr
Definition: pvDatabase.h:39
bool epics::pvDatabase::PVRecord::addPVRecordClient ( PVRecordClientPtr const &  pvRecordClient)

Add a client that wants to access the record.

Every client that accesses the record must call this so that the client can be notified when the record is deleted.

Parameters
pvRecordClientThe client.
Returns
true if the client is added.

Definition at line 199 of file pvRecord.cpp.

200 {
201  if(traceLevel>1) {
202  cout << "PVRecord::addPVRecordClient() " << recordName << endl;
203  }
205  // clean clientList
206  bool clientListClean = false;
207  while(!clientListClean) {
208  if(clientList.empty()) break;
209  clientListClean = true;
210  std::list<PVRecordClientWPtr>::iterator iter;
211  for (iter = clientList.begin();
212  iter!=clientList.end();
213  iter++ )
214  {
215  PVRecordClientPtr client = iter->lock();
216  if(client) continue;
217  if(traceLevel>1) {
218  cout << "PVRecord::addPVRecordClient() erasing client"
219  << recordName << endl;
220  }
221  clientList.erase(iter);
222  clientListClean = false;
223  break;
224  }
225  }
226  clientList.push_back(pvRecordClient);
227  return true;
228 }
std::tr1::shared_ptr< PVRecordClient > PVRecordClientPtr
Definition: pvDatabase.h:35
Definition: server.h:76
epicsMutexId lock
Definition: server.h:82
void epics::pvDatabase::PVRecord::beginGroupPut ( )

Begins a group of puts.

Definition at line 283 of file pvRecord.cpp.

284 {
285  if(++depthGroupPut>1) return;
286  if(traceLevel>2) {
287  cout << "PVRecord::beginGroupPut() " << recordName << endl;
288  }
289  std::list<PVListenerWPtr>::iterator iter;
290  for (iter = pvListenerList.begin(); iter!=pvListenerList.end(); iter++)
291  {
292  PVListenerPtr listener = iter->lock();
293  if(!listener.get()) continue;
294  listener->beginGroupPut(shared_from_this());
295  }
296 }
std::tr1::shared_ptr< PVListener > PVListenerPtr
Definition: pvDatabase.h:39
PVRecordPtr epics::pvDatabase::PVRecord::create ( std::string const &  recordName,
epics::pvData::PVStructurePtr const &  pvStructure 
)
static

Creates a soft record.

Parameters
recordNameThe name of the record, which is also the channelName.
pvStructureThe top level structure.
Returns
A shared pointer to the newly created record.

Definition at line 38 of file pvRecord.cpp.

41 {
42  PVRecordPtr pvRecord(new PVRecord(recordName,pvStructure));
43  if(!pvRecord->init()) {
44  pvRecord.reset();
45  }
46  return pvRecord;
47 }
PVRecord(std::string const &recordName, epics::pvData::PVStructurePtr const &pvStructure)
Constructor.
Definition: pvRecord.cpp:50
std::tr1::shared_ptr< PVRecord > PVRecordPtr
Definition: pvDatabase.h:21
virtual void epics::pvDatabase::PVRecord::destroy ( )
inlinevirtual

DEPRECATED.

Definition at line 92 of file pvDatabase.h.

92 {}
void epics::pvDatabase::PVRecord::endGroupPut ( )

Ends a group of puts.

Definition at line 298 of file pvRecord.cpp.

299 {
300  if(--depthGroupPut>0) return;
301  if(traceLevel>2) {
302  cout << "PVRecord::endGroupPut() " << recordName << endl;
303  }
304  std::list<PVListenerWPtr>::iterator iter;
305  for (iter = pvListenerList.begin(); iter!=pvListenerList.end(); iter++)
306  {
307  PVListenerPtr listener = iter->lock();
308  if(!listener.get()) continue;
309  listener->endGroupPut(shared_from_this());
310  }
311 }
std::tr1::shared_ptr< PVListener > PVListenerPtr
Definition: pvDatabase.h:39
PVRecordFieldPtr epics::pvDatabase::PVRecord::findPVRecordField ( epics::pvData::PVFieldPtr const &  pvField)

Find the PVRecordField for the PVField.

This is called by the pvCopy facility.

Parameters
pvFieldThe PVField.
Returns
The shared pointer to the PVRecordField.

Definition at line 133 of file pvRecord.cpp.

134 {
135  return findPVRecordField(pvRecordStructure,pvField);
136 }
PVRecordFieldPtr findPVRecordField(epics::pvData::PVFieldPtr const &pvField)
Find the PVRecordField for the PVField.
Definition: pvRecord.cpp:133
PVRecordStructurePtr epics::pvDatabase::PVRecord::getPVRecordStructure ( ) const
inline

Get the top level PVRecordStructure.

Returns
The shared pointer.

Definition at line 135 of file pvDatabase.h.

135 { return pvRecordStructure;}
epics::pvData::PVStructurePtr epics::pvDatabase::PVRecord::getPVStructure ( ) const
inline

Get the top level PVStructure.

Returns
The top level PVStructure.

Definition at line 141 of file pvDatabase.h.

141 { return pvStructure;}
std::string epics::pvDatabase::PVRecord::getRecordName ( ) const
inline

Get the name of the record.

Returns
The name.

Definition at line 129 of file pvDatabase.h.

129 { return recordName;}
virtual epics::pvAccess::RPCServiceAsync::shared_pointer epics::pvDatabase::PVRecord::getService ( epics::pvData::PVStructurePtr const &  pvRequest)
inlinevirtual

Optional method for derived class.

Return a service corresponding to the specified request PVStructure.

Parameters
pvRequestThe request PVStructure
Returns
The corresponding service

Definition at line 109 of file pvDatabase.h.

111  {
112  return epics::pvAccess::RPCServiceAsync::shared_pointer();
113  }
int epics::pvDatabase::PVRecord::getTraceLevel ( )
inline

get trace level (0,1,2) means (nothing,lifetime,process)

Returns
the level

Definition at line 233 of file pvDatabase.h.

233 {return traceLevel;}
virtual bool epics::pvDatabase::PVRecord::init ( )
inlinevirtual

Optional initialization method.

A derived method Must call initPVRecord.

Returns
true for success and false for failure.

Reimplemented in epics::pvDatabase::ProcessRecord, epics::pvDatabase::TraceRecord, epics::pvDatabase::AddRecord, and epics::pvDatabase::RemoveRecord.

Definition at line 72 of file pvDatabase.h.

72 {initPVRecord(); return true;}
void initPVRecord()
Initializes the base class.
Definition: pvRecord.cpp:110
void epics::pvDatabase::PVRecord::initPVRecord ( )
protected

Initializes the base class.

Must be called by derived classes.

Definition at line 110 of file pvRecord.cpp.

111 {
112  PVRecordStructurePtr parent;
113  pvRecordStructure = PVRecordStructurePtr(
114  new PVRecordStructure(pvStructure,parent,shared_from_this()));
115  pvRecordStructure->init();
116  PVFieldPtr pvField = pvStructure->getSubField("timeStamp");
117  if(pvField) pvTimeStamp.attach(pvField);
118 }
std::tr1::shared_ptr< PVRecordStructure > PVRecordStructurePtr
Definition: pvDatabase.h:31
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
Interface for a field that is a structure.
Definition: pvDatabase.h:365
bool attach(PVFieldPtr const &pvField)
Definition: pvTimeStamp.cpp:26
void epics::pvDatabase::PVRecord::lock ( )

Lock the record.

Any code must lock while accessing a record.

Definition at line 164 of file pvRecord.cpp.

164  {
165  if(traceLevel>2) {
166  cout << "PVRecord::lock() " << recordName << endl;
167  }
168  mutex.lock();
169 }
void epics::pvDatabase::PVRecord::lockOtherRecord ( PVRecordPtr const &  otherRecord)

Lock another record.

A client that holds the lock for one record can lock one other record. A client must not call this if the client already has the lock for more then one record.

Parameters
otherRecordThe other record to lock.

Definition at line 185 of file pvRecord.cpp.

186 {
187  if(traceLevel>2) {
188  cout << "PVRecord::lockOtherRecord() " << recordName << endl;
189  }
190  if(this<otherRecord.get()) {
191  otherRecord->lock();
192  return;
193  }
194  unlock();
195  otherRecord->lock();
196  lock();
197 }
void lock()
Lock the record.
Definition: pvRecord.cpp:164
void unlock()
Unlock the record.
Definition: pvRecord.cpp:171
void epics::pvDatabase::PVRecord::nextMasterPVField ( epics::pvData::PVFieldPtr const &  pvField)
virtual

PVCopyTraverseMasterCallback method.

Parameters
pvFieldThe next client field.

Implements epics::pvCopy::PVCopyTraverseMasterCallback.

Definition at line 246 of file pvRecord.cpp.

247 {
248  PVRecordFieldPtr pvRecordField = findPVRecordField(pvField);
249  PVListenerPtr listener = pvListener.lock();
250  if(!listener.get()) return;
251  if(isAddListener) {
252  pvRecordField->addListener(listener);
253  } else {
254  pvRecordField->removeListener(listener);
255  }
256 }
std::tr1::shared_ptr< PVListener > PVListenerPtr
Definition: pvDatabase.h:39
std::tr1::shared_ptr< PVRecordField > PVRecordFieldPtr
Definition: pvDatabase.h:26
PVRecordFieldPtr findPVRecordField(epics::pvData::PVFieldPtr const &pvField)
Find the PVRecordField for the PVField.
Definition: pvRecord.cpp:133
epics::pvDatabase::PVRecord::POINTER_DEFINITIONS ( PVRecord  )
void epics::pvDatabase::PVRecord::process ( )
virtual

Optional method for derived class.

It is the method that makes a record smart. If it encounters errors it should raise alarms and/or call the message method provided by the base class. If the pvStructure has a top level timeStamp, the base class sets the timeStamp to the current time.

Reimplemented in epics::pvDatabase::ProcessRecord, epics::pvDatabase::TraceRecord, epics::pvDatabase::AddRecord, and epics::pvDatabase::RemoveRecord.

Definition at line 120 of file pvRecord.cpp.

121 {
122  if(traceLevel>2) {
123  cout << "PVRecord::process() " << recordName << endl;
124  }
125  if(pvTimeStamp.isAttached()) {
126  pvTimeStamp.get(timeStamp);
127  timeStamp.getCurrent();
128  pvTimeStamp.set(timeStamp);
129  }
130 }
void get(TimeStamp &timeStamp) const
Definition: pvTimeStamp.cpp:61
bool set(TimeStamp const &timeStamp)
Definition: pvTimeStamp.cpp:70
void epics::pvDatabase::PVRecord::remove ( )
virtual

remove record from database.

Remove the PVRecord. Release any resources used and get rid of listeners and requesters. If derived class overrides this then it must call PVRecord::remove() after it has destroyed any resorces it uses.

Definition at line 98 of file pvRecord.cpp.

99 {
100  if(traceLevel>0) {
101  cout << "PVRecord::remove() " << recordName << endl;
102  }
103  unlistenClients();
105  PVDatabasePtr pvDatabase(PVDatabase::getMaster());
106  if(pvDatabase) pvDatabase->removeFromMap(shared_from_this());
107  pvTimeStamp.detach();
108 }
std::tr1::shared_ptr< PVDatabase > PVDatabasePtr
Definition: pvDatabase.h:43
static PVDatabasePtr getMaster()
Get the master database.
Definition: pvDatabase.cpp:38
bool epics::pvDatabase::PVRecord::removeListener ( PVListenerPtr const &  pvListener,
epics::pvCopy::PVCopyPtr const &  pvCopy 
)

Remove a listener.

Parameters
pvListenerThe listener.
pvCopyThe pvStructure that has the client fields.
Returns
true if the listener was removed.

Definition at line 258 of file pvRecord.cpp.

261 {
262  if(traceLevel>1) {
263  cout << "PVRecord::removeListener() " << recordName << endl;
264  }
266  std::list<PVListenerWPtr>::iterator iter;
267  for (iter = pvListenerList.begin(); iter!=pvListenerList.end(); iter++ )
268  {
269  PVListenerPtr listener = iter->lock();
270  if(!listener.get()) continue;
271  if(listener.get()==pvListener.get()) {
272  pvListenerList.erase(iter);
273  this->pvListener = pvListener;
274  isAddListener = false;
275  pvCopy->traverseMaster(shared_from_this());
276  this->pvListener = PVListenerPtr();
277  return true;
278  }
279  }
280  return false;
281 }
std::tr1::shared_ptr< PVListener > PVListenerPtr
Definition: pvDatabase.h:39
void epics::pvDatabase::PVRecord::setTraceLevel ( int  level)
inline

set trace level (0,1,2) means (nothing,lifetime,process)

Parameters
levelThe level

Definition at line 238 of file pvDatabase.h.

238 {traceLevel = level;}
virtual void epics::pvDatabase::PVRecord::start ( )
inlinevirtual

Optional method for derived class.

It is called before record is added to database.

Definition at line 78 of file pvDatabase.h.

78 {}
bool epics::pvDatabase::PVRecord::tryLock ( )

Try to lock the record.

If true then just like lock. If falseclient can not access record. Code can try to simultaneously hold the lock for more than two records by calling this method but must be willing to accept failure.

Returns
true if the record is locked.

Definition at line 178 of file pvRecord.cpp.

178  {
179  if(traceLevel>2) {
180  cout << "PVRecord::tryLock() " << recordName << endl;
181  }
182  return mutex.tryLock();
183 }
void epics::pvDatabase::PVRecord::unlock ( )

Unlock the record.

The code that calls lock must unlock when done accessing the record.

Definition at line 171 of file pvRecord.cpp.

171  {
172  if(traceLevel>2) {
173  cout << "PVRecord::unlock() " << recordName << endl;
174  }
175  mutex.unlock();
176 }

Friends And Related Function Documentation

friend class PVDatabase
friend

Definition at line 255 of file pvDatabase.h.


The documentation for this class was generated from the following files: