Free Electron
StateCatalog.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __plugin_StateCatalog_h__
8 #define __plugin_StateCatalog_h__
9 
10 #define FE_STATECATALOG_MESSAGE_PROPERTY "message"
11 
12 #if FE_CPLUSPLUS >= 201103L
13 #define FE_STATECATALOG_CALLBACK
14 #endif
15 
16 namespace fe
17 {
18 
19 /**************************************************************************//**
20  @brief Catalog with extensible mirroring
21 
22  This class has some pure virtual methods which must be implemented
23  by derived classes, such as relaying the state across networks.
24 
25  The get/set methods are templated on type.
26 
27  @ingroup plugin
28 *//***************************************************************************/
29 class FE_DL_EXPORT StateCatalog:
30  public ObjectSafeShared<StateCatalog>,
31  public Catalog,
32  public CastableAs<StateCatalog>
33 {
34  public:
35 
36  /** @brief A locking mechanism to get cohesive state
37 
38  While the Atomic persists, the StateCatalog will not update.
39  The Atomic should be released as soon as possible.
40  */
41  class Atomic
42  {
43  public:
44  /// Lock the StateCatalog
45  Atomic(sp<StateCatalog> a_spStateCatalog):
46  m_spStateCatalog(a_spStateCatalog),
47  m_spinCount(0)
48  {
49  FEASSERT(m_spStateCatalog.isValid());
50  m_spStateCatalog->safeLockShared();
51  m_locked=TRUE;
52  m_serial=m_spStateCatalog->serial();
53  m_flushCount=m_spStateCatalog->flushCount();
54  }
55  /** @brief Wait for a state change
56  and then lock the StateCatalog
57 
58  A previous flush count needs to be given
59  as well as a spin counter.
60 
61  This constructor will not return until the
62  flush count of the StateCatalog exceeds the
63  number sent.
64  The reference value is set to the new flush count.
65 
66  A pause time can be specified in micro seconds.
67  If this value is zero, the spin lock is run
68  at full speed.
69 
70  The wait will stop if a_rKeepWaiting is or
71  becomes zero.
72  */
73  Atomic(sp<StateCatalog> a_spStateCatalog,
74  I32& a_rFlushCount,I32 a_microSleep,
75  volatile BWORD& a_rKeepWaiting):
76  m_spStateCatalog(a_spStateCatalog),
77  m_spinCount(0)
78  {
79  FEASSERT(m_spStateCatalog.isValid());
80  m_locked=successful(m_spStateCatalog->lockAfterUpdate(
81  a_rFlushCount,m_spinCount,
82  a_rKeepWaiting,a_microSleep));
83  m_serial=m_spStateCatalog->serial();
84  m_flushCount=m_spStateCatalog->flushCount();
85  }
86  /** @brief Wait for a state change
87  and then lock the StateCatalog
88 
89  This version will always keep waiting.
90  */
91  Atomic(sp<StateCatalog> a_spStateCatalog,
92  I32& a_rFlushCount,I32 a_microSleep=0):
93  m_spStateCatalog(a_spStateCatalog),
94  m_spinCount(0)
95  {
96  BWORD keepWaiting(TRUE);
97  FEASSERT(m_spStateCatalog.isValid());
98  m_locked=successful(m_spStateCatalog->lockAfterUpdate(
99  a_rFlushCount,m_spinCount,
100  keepWaiting,a_microSleep));
101  m_serial=m_spStateCatalog->serial();
102  m_flushCount=m_spStateCatalog->flushCount();
103  }
104  /// Unlock the StateCatalog
105  ~Atomic(void)
106  {
107  FEASSERT(m_spStateCatalog.isValid());
108  if(m_locked)
109  {
110  m_spStateCatalog->safeUnlockShared();
111  }
112  }
113 
114  /** @brief Get state without additional locking
115  (default property)
116 
117  If the lock failed, this method will fail as well.
118  */
119  Result getTypeName(String a_name,String& a_rTypeName) const
120  { return getTypeName(a_name,"value",a_rTypeName); }
121 
122  /// @brief Get state without additional locking
124  String a_property,String& a_rTypeName) const
125  {
126  FEASSERT(m_spStateCatalog.isValid());
127  return m_locked?
128  m_spStateCatalog->getTypeNameUnsafe(
129  a_name,a_property,a_rTypeName):
130  e_notInitialized;
131  }
132 
133  /** @brief Get current state without additional locking
134 
135  If the lock failed, this method will fail as well.
136  */
137  template <class T>
138  Result getState(String a_name,T& a_rValue) const
139  { return getState(a_name,"value",a_rValue); }
140 
141  /** @brief Get current state without additional locking
142 
143  If the lock failed, this method will fail as well.
144  */
145  template <class T>
147  String a_property,T& a_rValue) const
148  {
149  FEASSERT(m_spStateCatalog.isValid());
150  return m_locked?
151  m_spStateCatalog->getStateUnsafe(
152  a_name,a_property,a_rValue):
153  e_notInitialized;
154  }
155 
156  /** @brief Return an indication of how long
157  it took for the state to change
158 
159  A spin count of zero means there was a change
160  already in place before this constructor.
161  Gauging different non-zero values may not be
162  a useful metric.
163  */
164  I32 spinCount(void) const { return m_spinCount; }
165  /** @brief Return TRUE if the lock was successful
166 
167  If the a_keepWaiting argument changed becomes zero,
168  the constructor can return without locking.
169  If so, calls to getState will fail.
170  */
171  I32 locked(void) const { return m_locked; }
172 
173  /** @brief Get the change count
174  from when the Atomic was created
175 
176  The StateCatalog keeps an serial count of how
177  many state changes have occured.
178  */
179  I32 serial(void) const { return m_serial; }
180 
181  /** @brief Get the count of incoming updates
182  from when the Atomic was created
183 
184  An increment of the flushCount corresponds
185  to one flush() call at the sender.
186  Multiple states can be updated on one flush.
187  */
188  I32 flushCount(void) const { return m_flushCount; }
189 
190  private:
191  sp<StateCatalog> m_spStateCatalog;
192  BWORD m_locked;
193  I32 m_spinCount;
194  I32 m_serial;
195  I32 m_flushCount;
196  };
197 
198  /** @brief A fixed copy of state from a StateCatalog
199 
200  The state of a snapshot is frozen and can not be changed.
201  Unlike the Atomic, a Snapshot does not lock the StateCatalog.
202  */
203  class Snapshot:
204  public Counted,
205  public CastableAs<Snapshot>
206  {
207  public:
208  friend class StateCatalog;
209 
210  Snapshot(void):
211  m_serial(-1),
212  m_flushCount(-1) {}
213  virtual ~Snapshot(void) {}
214 
215  /// @brief Get state without any need for locking
216  /// (default property)
217  Result getTypeName(String a_name,String& a_rTypeName) const
218  { return getTypeName(a_name,"value",a_rTypeName); }
219 
220  /// @brief Get state without any need for locking
221  Result getTypeName(String a_name,
222  String a_property,String& a_rTypeName) const;
223 
224  /// Get historical state without any need for locking
225  template <class T>
226  Result getState(String a_name,T& a_rValue) const
227  { return getState(a_name,"value",a_rValue); }
228 
229  /// Get historical state without any need for locking
230  template <class T>
232  String a_property,T& a_rValue) const
233  {
234  FEASSERT(m_spSnapshotCatalog.isValid());
235 
236  if(!m_spSnapshotCatalog->cataloged(a_name,a_property))
237  {
238  return e_cannotFind;
239  }
240 
241  try
242  {
243  a_rValue=
244  m_spSnapshotCatalog->catalogOrException<T>(
245  a_name,a_property);
246 
247  return e_ok;
248  }
249  catch(const Exception& e)
250  {
251  return e_typeMismatch;
252  }
253  }
254 
255  /** @brief Print all the values in the snapshot
256 
257  @internal
258  */
259  void dump(void) const
260  { m_spSnapshotCatalog->catalogDump(); }
261  /** @brief Print new state changes since the snapshot
262 
263  @internal
264  */
265  void dumpUpdates(void) const
266  { m_spUpdateCatalog->catalogDump(); }
267 
268  /** @brief Get the change count
269  from when the snapshot was made
270 
271  The StateCatalog keeps an serial count of how
272  many state changes have occured.
273  Each Snapshot taken stores this serial number,
274  which can be used to compare to other snapshots
275  of the same StateCatalog.
276  */
277  I32 serial(void) const { return m_serial; }
278 
279  /** @brief Get the count of incoming updates
280  from when the snapshot was made
281 
282  An increment of the flushCount corresponds
283  to one flush() call at the sender.
284  Multiple states can be updated on one flush.
285  */
286  I32 flushCount(void) const { return m_flushCount; }
287 
288  private:
289  I32 m_serial;
290  I32 m_flushCount;
291  sp<Catalog> m_spSnapshotCatalog;
292  sp<Catalog> m_spUpdateCatalog;
293  };
294 
295  class ListenerI:
296  virtual public Component,
297  public CastableAs<ListenerI>
298  {
299  public:
300  /** @brief called when add as a ListenerI to a
301  StateCatalog, giving that object and the key
302  it is listening to */
303  virtual void bind(sp<StateCatalog> a_spStateCatalog,
304  String a_name) =0;
305  /** @brief called when a key and property are updated
306  */
307  virtual void notify(String a_name,String a_property) =0;
308  };
309 
310  StateCatalog(void):
311  m_serial(0),
312  m_flushCount(0),
313  m_latestSerial(-1) {}
314 virtual ~StateCatalog(void) {}
315 
316  /// @brief Provide a parsable setup string
317 virtual Result configure(String a_line) { return e_ok; }
318 
319  /// @brief Begin any special behaviors of derived classes
320 virtual Result start(void) =0;
321  /// @brief Cease any special behaviors of derived classes
322 virtual Result stop(void) =0;
323  /// @brief Wait for derived class to begin communication
324 virtual Result waitForConnection(void) { return e_ok; }
325  /// @brief Return TRUE if the special function has begun
326 virtual BWORD started(void) const { return FALSE; }
327  /// @brief Return TRUE if communication is
328  /// currently established
329 virtual BWORD connected(void) const { return FALSE; }
330  /** @brief Indicate how long a connection may remain quiet
331 
332  The default implementation does nothing.
333  This may be used by a derived class
334  to determine when a connection has failed.
335  */
336 virtual void setConnectionTimeout(Real a_seconds) {}
337  /** @brief Indicate the end of some phase of state changes
338 
339  The default implementation does nothing.
340  This may be used by a derived class
341  to trigger a transmission and/or
342  to delineate a single frame in time.
343  */
344 virtual Result flush(void)
345  { sendNotifications();
346  return e_ok; }
347 
348  /** @brief Wait for a state change
349 
350  @internal
351 
352  This method is generally only used by specialized
353  mechanisms, since the Atomic and Snapshot classes
354  neatly present this functionality.
355 
356  See the Atomic constructor for parameter description.
357  */
358 virtual Result waitForUpdate(I32& a_rFlushCount,I32& a_rSpins,
359  volatile BWORD& a_rKeepWaiting,I32 a_microSleep)
360  { return e_ok; }
361 
362  /** @brief Wait for a state change and then lock the mutex
363 
364  @internal
365 
366  This method is generally only used by specialized
367  mechanisms, since the Atomic and Snapshot classes
368  neatly present this functionality.
369 
370  See the Atomic constructor for parameter description.
371  */
372 virtual Result lockAfterUpdate(I32& a_rFlushCount,I32& a_rSpins,
373  volatile BWORD& a_rKeepWaiting,I32 a_microSleep)
374  { return e_unsupported; }
375 
376  /// @brief Get state with mutex (default property)
377  Result getTypeName(String a_name,String& a_rTypeName) const
378  { return getTypeName(a_name,"value",a_rTypeName); }
379 
380  /// @brief Get state with mutex
381  Result getTypeName(String a_name,
382  String a_property,String& a_rTypeName) const;
383 
384  /** @brief Returns keys that match the regex pattern
385 
386  Keys are appended to the given array.
387  Clear the array if only want new values.
388  */
389  void getStateKeys(Array<String> &a_keys,
390  String a_pattern=".*") const;
391 
392  /** @brief Returns properties for a key
393 
394  Properties are appended to the given array.
395  Clear the array if only want new values.
396 
397  Order is arbitrary.
398  */
399  void getStateProperties(String a_name,
400  Array<String> &a_properties) const;
401 
402  /// @brief Get state with mutex (default property)
403  template <class T>
404  Result getState(String a_name,T& a_rValue) const
405  { return getState(a_name,"value",a_rValue); }
406 
407  /// @brief Get state with mutex
408  template <class T>
409  Result getState(String a_name,String a_property,
410  T& a_rValue) const;
411 
412  Result getState(String a_name,String a_property,
413  String& a_rTypeName,String& a_rValue) const;
414 
415  /// @brief Get state with mutex,
416  /// but without calling the internal
417  /// preGet() and postGet() methods
418  template <class T>
419  Result justGetState(String a_name,
420  String a_property,T& a_rValue) const;
421 
422  /// @brief Set state with mutex (default property)
423  template <class T>
424  Result setState(String a_name,const T& a_rValue)
425  { return setState(a_name,"value",a_rValue); }
426 
427  /// @brief Set state with mutex
428  template <class T>
429  Result setState(String a_name,String a_property,
430  const T& a_rValue);
431 
432  /// @brief Set state with mutex (serialized)
433  Result setState(String a_name,String a_property,
434  String a_typeName,String a_value);
435 
436  /// @brief Remove a state, with mutex
437  Result removeState(String a_name,String a_property);
438 
439  /// @brief Remove all properties of a state, with mutex
440  Result removeState(String a_name);
441 
442  /// @brief Set state for entries in a Catalog, with mutex
443  Result overlayState(sp<Catalog> a_spOtherCatalog);
444 
445  /// @brief Get state without mutex
446  Result getTypeNameUnsafe(String a_name,String& a_rTypeName) const
447  { return getTypeNameUnsafe(a_name,"value",a_rTypeName); }
448 
449  /// @brief Get state without mutex (default property)
450  Result getTypeNameUnsafe(String a_name,
451  String a_property,String& a_rTypeName) const;
452 
453  /// @brief Get state without mutex
454  template <class T>
455  Result getStateUnsafe(String a_name,T& a_rValue) const
456  { return getStateUnsafe(a_name,"value",a_rValue); }
457 
458  /// @brief Get state without mutex (default property)
459  template <class T>
460  Result getStateUnsafe(String a_name,
461  String a_property,T& a_rValue) const;
462 
463  /** @brief Grab current state into a fixed snapshot
464 
465  Multiple calls to get a snapshot will get the
466  same snapshot until there is a change to the state
467  of the StateCatalog.
468  */
469  Result snapshot(sp<Snapshot>& a_rspSnapshot);
470 
471  /** @brief Increment the serial index,
472  indicating a collective change of state
473 
474  @internal
475 
476  This is generally only called from
477  derived implementations,
478  such as when new data arrives over a connection.
479  */
480  void incrementSerial(void) { m_serial++; }
481 
482  /** @brief Increment the count of incoming flushes
483  indicating a collective remote change of state
484 
485  @internal
486 
487  This is generally only called from
488  derived implementations,
489  such as when new data arrives over a connection.
490  */
491  void incrementFlushCount(void) { m_flushCount++; }
492 
493  /// @brief Append value to remote queues
494  template <class T>
495  Result sendMessage(String a_name,const T& a_rValue);
496  /// @brief Pop received value from front of queue
497  template <class T>
498  Result nextMessage(String a_name,T& a_rValue);
499 
500  /** @brief Add a ListenerI for a specific key
501 
502  The bind method of the Listener is called once
503  as it is added here.
504 
505  The notify method of the Listener is called
506  every time any property of that key is updated.
507 
508  The notification arguments are
509  the key name and property.
510  */
511  Result addListener(sp<ListenerI> a_spListener,String a_name);
512 
513 #ifdef FE_STATECATALOG_CALLBACK
514  typedef std::function<void(String,String)> Callback;
515 
516  /** @brief Add a Callback for a specific key
517 
518  The callback is called
519  every time any property of that key is updated.
520 
521  The Callback is simply a
522  std::function<void(String,String)
523  which can be assigned to an appropriate
524  lambda function.
525 
526  The callback arguments are the key name and property.
527  */
528  Result addCallback(Callback& a_lambda,String a_name);
529 #endif
530 
531  protected:
532 
533  /// @internal
534 virtual Result preGet(String a_name,String a_property) const;
535  /// @internal
536 virtual Result postGet(String a_name,String a_property) const
537  { return e_ok; }
538 
539  /// @internal
540 virtual Result preSet(String a_name,String a_property) { return e_ok; }
541  /// @internal
542 virtual Result postSet(String a_name,String a_property) { return e_ok; }
543 
544  I32 serial(void) const { return m_serial; }
545  I32 flushCount(void) const { return m_flushCount; }
546 
547  Result addNotification(String a_name,String a_property);
548  Result sendNotifications(void);
549  Result notify(String a_name,String a_property);
550 
551  template <class T>
552  Result updateState(String a_name,String a_property,
553  const T& a_rValue);
554 
555  Result updateState(String a_name,String a_property,
556  String a_typeName,String a_value);
557 
558  Result updateState(String a_name,String a_property,
559  String a_typeName,
560  const U8* a_pRawBytes,I32 a_byteCount);
561 
562  Result clearState(String a_name,String a_property);
563  private:
564 
565  void cacheInstanceUpdates(String a_name,String a_property,
566  Instance& a_rInstance);
567 
568  volatile I32 m_serial;
569  volatile I32 m_flushCount;
570 
571  AutoHashMap<I32, sp<Snapshot> > m_snapshotMap; //* keyed on serial
572  I32 m_latestSerial;
573  sp<Snapshot> m_latestSnapshot;
574 
575  AutoHashMap<String, Array< sp<ListenerI> > > m_listenerMap;
576 
577 #ifdef FE_STATECATALOG_CALLBACK
578  AutoHashMap<String, Array<Callback> > m_callbackMap;
579 #endif
580 
581  class Notification
582  {
583  public:
584  Notification(void) {}
585  Notification(String a_name,String a_property):
586  m_name(a_name),
587  m_property(a_property) {}
588  String m_name;
589  String m_property;
590  };
591 
592  Array<Notification> m_notificationArray;
593  RecursiveMutex m_notificationMutex;
594 };
595 
597 {
598  if(!cataloged(a_name,a_property))
599  {
600  return e_cannotFind;
601  }
602  return e_ok;
603 }
604 
605 template<class T>
607  T& a_rValue) const
608 {
609  safeLockShared();
610  try
611  {
612  a_rValue=catalogOrException<T>(a_name,a_property);
613 
614  safeUnlockShared();
615  return e_ok;
616  }
617  catch(const Exception& e)
618  {
619  safeUnlockShared();
620  return e_cannotFind;
621  }
622  catch(...)
623  {
624  safeUnlockShared();
625  throw;
626  }
627 }
628 
629 template<class T>
631 {
632  safeLockShared();
633  try
634  {
635  Result result=preGet(a_name,a_property);
636  if(failure(result))
637  {
638  safeUnlockShared();
639  return result;
640  }
641 
642  a_rValue=catalogOrException<T>(a_name,a_property);
643 
644  result=postGet(a_name,a_property);
645  if(failure(result))
646  {
647  safeUnlockShared();
648  return result;
649  }
650 
651  safeUnlockShared();
652  return e_ok;
653  }
654  catch(const Exception& e)
655  {
656  safeUnlockShared();
657  return e_cannotFind;
658  }
659  catch(...)
660  {
661  safeUnlockShared();
662  throw;
663  }
664 }
665 
666 template<class T>
667 Result StateCatalog::updateState(String a_name,String a_property,
668  const T& a_rValue)
669 {
670  Instance& rInstance=catalogInstance(a_name,a_property);
671 
672  rInstance.create<T>(typeMaster());
673  rInstance.cast<T>()=a_rValue;
674 
675  cacheInstanceUpdates(a_name,a_property,rInstance);
676 
677  return addNotification(a_name,a_property);
678 }
679 
680 template<class T>
682  const T& a_rValue)
683 {
684  safeLock();
685 
686  Result result=preSet(a_name,a_property);
687  if(failure(result))
688  {
689  safeUnlock();
690  return result;
691  }
692 
693  updateState(a_name,a_property,a_rValue);
694 
695  result=postSet(a_name,a_property);
696  if(failure(result))
697  {
698  safeUnlock();
699  return result;
700  }
701 
702  safeUnlock();
703 
704  sendNotifications();
705 
706  return e_ok;
707 }
708 
709 template<class T>
711  T& a_rValue) const
712 {
713  try
714  {
715  Result result=preGet(a_name,a_property);
716  if(failure(result))
717  {
718  return result;
719  }
720 
721  a_rValue=catalogOrException<T>(a_name,a_property);
722 
723  result=postGet(a_name,a_property);
724  if(failure(result))
725  {
726  return result;
727  }
728 
729  return e_ok;
730  }
731  catch(const Exception& e)
732  {
733  return e_cannotFind;
734  }
735  catch(...)
736  {
737  throw;
738  }
739 }
740 
741 template<class T>
742 Result StateCatalog::sendMessage(String a_name,const T& a_rValue)
743 {
744  safeLock();
745 
746  Result result=preSet(a_name,FE_STATECATALOG_MESSAGE_PROPERTY);
747  if(failure(result))
748  {
749  safeUnlock();
750  return result;
751  }
752 
753  updateState(a_name,FE_STATECATALOG_MESSAGE_PROPERTY,a_rValue);
754 
755  result=postSet(a_name,FE_STATECATALOG_MESSAGE_PROPERTY);
756  if(failure(result))
757  {
758  safeUnlock();
759  return result;
760  }
761 
762  safeUnlock();
763 
764  sendNotifications();
765 
766  safeLock();
767 
768  catalogRemove(a_name,FE_STATECATALOG_MESSAGE_PROPERTY);
769 
770  safeUnlock();
771 
772  return e_ok;
773 }
774 
775 template<class T>
777 {
778  return e_unsupported;
779 }
780 
781 //* NOTE using std::deque<T> as template to Catalog calls may add the allocator
782 template<>
783 inline Result StateCatalog::nextMessage<String>(String a_name,String& a_rValue)
784 {
785  safeLockShared();
786 
787  if(!cataloged(a_name))
788  {
789  safeUnlockShared();
790  return e_cannotFind;
791  }
792 
793  try
794  {
795  std::deque<String>& rArrayT=
796  catalogOrException< std::deque<String> >(a_name,"value");
797  if(rArrayT.size()<1)
798  {
799  safeUnlockShared();
800  return e_readFailed;
801  }
802  }
803  catch(const Exception& e)
804  {
805  FE_MAYBE_UNUSED(e);
806  safeUnlockShared();
807  return e_cannotFind;
808  }
809  catch(...)
810  {
811  safeUnlockShared();
812  throw;
813  }
814 
815  safeUnlockShared();
816 
817  safeLock();
818 
819  try
820  {
821  Result result=preGet(a_name,"value");
822  if(failure(result))
823  {
824  safeUnlock();
825  return result;
826  }
827 
828  std::deque<String>& rArrayT=
829  catalogOrException< std::deque<String> >(a_name,"value");
830 
831  a_rValue=rArrayT.front();
832  rArrayT.pop_front();
833 
834  result=postGet(a_name,"value");
835  if(failure(result))
836  {
837  safeUnlock();
838  return result;
839  }
840  }
841  catch(const Exception& e)
842  {
843  FE_MAYBE_UNUSED(e);
844  safeUnlock();
845  return e_cannotFind;
846  }
847  catch(...)
848  {
849  safeUnlock();
850  throw;
851  }
852 
853  safeUnlock();
854  return e_ok;
855 }
856 
857 } /* namespace fe */
858 
859 #endif /* __plugin_StateCatalog_h__ */
860 
void incrementSerial(void)
Increment the serial index, indicating a collective change of state.
Definition: StateCatalog.h:480
A fixed copy of state from a StateCatalog.
Definition: StateCatalog.h:203
virtual Result flush(void)
Indicate the end of some phase of state changes.
Definition: StateCatalog.h:344
Result getState(String a_name, String a_property, T &a_rValue) const
Get historical state without any need for locking.
Definition: StateCatalog.h:231
virtual Result waitForConnection(void)
Wait for derived class to begin communication.
Definition: StateCatalog.h:324
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
virtual Result postGet(String a_name, String a_property) const
Definition: StateCatalog.h:536
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
virtual Result preSet(String a_name, String a_property)
Definition: StateCatalog.h:540
kernel
Definition: namespace.dox:3
Dictionary of Arbitrary Instances.
Definition: Catalog.h:24
virtual BWORD started(void) const
Return TRUE if the special function has begun.
Definition: StateCatalog.h:326
Result getTypeName(String a_name, String &a_rTypeName) const
Get state without additional locking (default property)
Definition: StateCatalog.h:119
Generic exception carrying a fe::String payload.
Definition: Exception.h:34
Result getState(String a_name, T &a_rValue) const
Get current state without additional locking.
Definition: StateCatalog.h:138
I32 flushCount(void) const
Get the count of incoming updates from when the snapshot was made.
Definition: StateCatalog.h:286
virtual Result lockAfterUpdate(I32 &a_rFlushCount, I32 &a_rSpins, volatile BWORD &a_rKeepWaiting, I32 a_microSleep)
Wait for a state change and then lock the mutex.
Definition: StateCatalog.h:372
void incrementFlushCount(void)
Increment the count of incoming flushes indicating a collective remote change of state.
Definition: StateCatalog.h:491
Result getTypeNameUnsafe(String a_name, String &a_rTypeName) const
Get state without mutex.
Definition: StateCatalog.h:446
Result getState(String a_name, String a_property, T &a_rValue) const
Get current state without additional locking.
Definition: StateCatalog.h:146
Atomic(sp< StateCatalog > a_spStateCatalog)
Lock the StateCatalog.
Definition: StateCatalog.h:45
Result getTypeName(String a_name, String &a_rTypeName) const
Get state without any need for locking (default property)
Definition: StateCatalog.h:217
~Atomic(void)
Unlock the StateCatalog.
Definition: StateCatalog.h:105
virtual void setConnectionTimeout(Real a_seconds)
Indicate how long a connection may remain quiet.
Definition: StateCatalog.h:336
Result sendMessage(String a_name, const T &a_rValue)
Append value to remote queues.
Definition: StateCatalog.h:742
Catalog with extensible mirroring.
Definition: StateCatalog.h:29
Automatically reference-counted string container.
Definition: String.h:128
I32 locked(void) const
Return TRUE if the lock was successful.
Definition: StateCatalog.h:171
BWORD failure(Result result)
Returns TRUE if the result value indicates a failure.
Definition: Result.h:72
Result getTypeName(String a_name, String a_property, String &a_rTypeName) const
Get state without additional locking.
Definition: StateCatalog.h:123
Result getStateUnsafe(String a_name, T &a_rValue) const
Get state without mutex.
Definition: StateCatalog.h:455
Result getState(String a_name, T &a_rValue) const
Get historical state without any need for locking.
Definition: StateCatalog.h:226
virtual Result waitForUpdate(I32 &a_rFlushCount, I32 &a_rSpins, volatile BWORD &a_rKeepWaiting, I32 a_microSleep)
Wait for a state change.
Definition: StateCatalog.h:358
Result justGetState(String a_name, String a_property, T &a_rValue) const
Get state with mutex, but without calling the internal preGet() and postGet() methods.
Definition: StateCatalog.h:606
Wrapper for std::vector.
Definition: Array.h:21
virtual Result postSet(String a_name, String a_property)
Definition: StateCatalog.h:542
Result
Generalized return value indicating success or failure, and why.
Definition: Result.h:24
Result getState(String a_name, T &a_rValue) const
Get state with mutex (default property)
Definition: StateCatalog.h:404
Result setState(String a_name, const T &a_rValue)
Set state with mutex (default property)
Definition: StateCatalog.h:424
Base for all interfacable components.
Definition: Component.h:20
void dump(void) const
Print all the values in the snapshot.
Definition: StateCatalog.h:259
I32 serial(void) const
Get the change count from when the snapshot was made.
Definition: StateCatalog.h:277
I32 serial(void) const
Get the change count from when the Atomic was created.
Definition: StateCatalog.h:179
virtual Result configure(String a_line)
Provide a parsable setup string.
Definition: StateCatalog.h:317
Result getTypeName(String a_name, String &a_rTypeName) const
Get state with mutex (default property)
Definition: StateCatalog.h:377
virtual BWORD connected(void) const
Return TRUE if communication is currently established.
Definition: StateCatalog.h:329
virtual Result preGet(String a_name, String a_property) const
Definition: StateCatalog.h:596
Atomic(sp< StateCatalog > a_spStateCatalog, I32 &a_rFlushCount, I32 a_microSleep=0)
Wait for a state change and then lock the StateCatalog.
Definition: StateCatalog.h:91
void dumpUpdates(void) const
Print new state changes since the snapshot.
Definition: StateCatalog.h:265
BWORD successful(Result result)
Returns TRUE if the result value indicates a success.
Definition: Result.h:62
Atomic(sp< StateCatalog > a_spStateCatalog, I32 &a_rFlushCount, I32 a_microSleep, volatile BWORD &a_rKeepWaiting)
Wait for a state change and then lock the StateCatalog.
Definition: StateCatalog.h:73
I32 flushCount(void) const
Get the count of incoming updates from when the Atomic was created.
Definition: StateCatalog.h:188
Result nextMessage(String a_name, T &a_rValue)
Pop received value from front of queue.
Definition: StateCatalog.h:776
I32 spinCount(void) const
Return an indication of how long it took for the state to change.
Definition: StateCatalog.h:164
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192
A locking mechanism to get cohesive state.
Definition: StateCatalog.h:41
Object level locking for thread safety.
Definition: SafeShared.h:220