7 #ifndef __plugin_StateCatalog_h__ 8 #define __plugin_StateCatalog_h__ 10 #define FE_STATECATALOG_MESSAGE_PROPERTY "message" 12 #if FE_CPLUSPLUS >= 201103L 13 #define FE_STATECATALOG_CALLBACK 46 m_spStateCatalog(a_spStateCatalog),
49 FEASSERT(m_spStateCatalog.isValid());
50 m_spStateCatalog->safeLockShared();
52 m_serial=m_spStateCatalog->serial();
53 m_flushCount=m_spStateCatalog->flushCount();
74 I32& a_rFlushCount,I32 a_microSleep,
75 volatile BWORD& a_rKeepWaiting):
76 m_spStateCatalog(a_spStateCatalog),
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();
92 I32& a_rFlushCount,I32 a_microSleep=0):
93 m_spStateCatalog(a_spStateCatalog),
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();
107 FEASSERT(m_spStateCatalog.isValid());
110 m_spStateCatalog->safeUnlockShared();
120 {
return getTypeName(a_name,
"value",a_rTypeName); }
126 FEASSERT(m_spStateCatalog.isValid());
128 m_spStateCatalog->getTypeNameUnsafe(
129 a_name,a_property,a_rTypeName):
139 {
return getState(a_name,
"value",a_rValue); }
149 FEASSERT(m_spStateCatalog.isValid());
151 m_spStateCatalog->getStateUnsafe(
152 a_name,a_property,a_rValue):
171 I32
locked(
void)
const {
return m_locked; }
179 I32
serial(
void)
const {
return m_serial; }
218 {
return getTypeName(a_name,
"value",a_rTypeName); }
227 {
return getState(a_name,
"value",a_rValue); }
232 String a_property,T& a_rValue)
const 234 FEASSERT(m_spSnapshotCatalog.isValid());
236 if(!m_spSnapshotCatalog->cataloged(a_name,a_property))
244 m_spSnapshotCatalog->catalogOrException<T>(
251 return e_typeMismatch;
260 { m_spSnapshotCatalog->catalogDump(); }
266 { m_spUpdateCatalog->catalogDump(); }
277 I32
serial(
void)
const {
return m_serial; }
313 m_latestSerial(-1) {}
320 virtual Result start(
void) =0;
322 virtual Result stop(
void) =0;
326 virtual BWORD
started(
void)
const {
return FALSE; }
345 { sendNotifications();
359 volatile BWORD& a_rKeepWaiting,I32 a_microSleep)
373 volatile BWORD& a_rKeepWaiting,I32 a_microSleep)
374 {
return e_unsupported; }
378 {
return getTypeName(a_name,
"value",a_rTypeName); }
390 String a_pattern=
".*")
const;
399 void getStateProperties(
String a_name,
405 {
return getState(a_name,
"value",a_rValue); }
420 String a_property,T& a_rValue)
const;
425 {
return setState(a_name,
"value",a_rValue); }
447 {
return getTypeNameUnsafe(a_name,
"value",a_rTypeName); }
456 {
return getStateUnsafe(a_name,
"value",a_rValue); }
461 String a_property,T& a_rValue)
const;
513 #ifdef FE_STATECATALOG_CALLBACK 514 typedef std::function<void(String,String)> Callback;
544 I32 serial(
void)
const {
return m_serial; }
545 I32 flushCount(
void)
const {
return m_flushCount; }
548 Result sendNotifications(
void);
560 const U8* a_pRawBytes,I32 a_byteCount);
565 void cacheInstanceUpdates(
String a_name,
String a_property,
568 volatile I32 m_serial;
569 volatile I32 m_flushCount;
571 AutoHashMap<I32, sp<Snapshot> > m_snapshotMap;
575 AutoHashMap<String, Array< sp<ListenerI> > > m_listenerMap;
577 #ifdef FE_STATECATALOG_CALLBACK 578 AutoHashMap<String, Array<Callback> > m_callbackMap;
584 Notification(
void) {}
587 m_property(a_property) {}
593 RecursiveMutex m_notificationMutex;
598 if(!cataloged(a_name,a_property))
612 a_rValue=catalogOrException<T>(a_name,a_property);
635 Result result=preGet(a_name,a_property);
642 a_rValue=catalogOrException<T>(a_name,a_property);
644 result=postGet(a_name,a_property);
670 Instance& rInstance=catalogInstance(a_name,a_property);
672 rInstance.create<T>(typeMaster());
673 rInstance.cast<T>()=a_rValue;
675 cacheInstanceUpdates(a_name,a_property,rInstance);
677 return addNotification(a_name,a_property);
686 Result result=preSet(a_name,a_property);
693 updateState(a_name,a_property,a_rValue);
695 result=postSet(a_name,a_property);
715 Result result=preGet(a_name,a_property);
721 a_rValue=catalogOrException<T>(a_name,a_property);
723 result=postGet(a_name,a_property);
746 Result result=preSet(a_name,FE_STATECATALOG_MESSAGE_PROPERTY);
753 updateState(a_name,FE_STATECATALOG_MESSAGE_PROPERTY,a_rValue);
755 result=postSet(a_name,FE_STATECATALOG_MESSAGE_PROPERTY);
768 catalogRemove(a_name,FE_STATECATALOG_MESSAGE_PROPERTY);
778 return e_unsupported;
787 if(!cataloged(a_name))
795 std::deque<String>& rArrayT=
796 catalogOrException< std::deque<String> >(a_name,
"value");
821 Result result=preGet(a_name,
"value");
828 std::deque<String>& rArrayT=
829 catalogOrException< std::deque<String> >(a_name,
"value");
831 a_rValue=rArrayT.front();
834 result=postGet(a_name,
"value");
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
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 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
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