|
PVData C++
|
00001 /* 00002 * Copyright information and license terms for this software can be 00003 * found in the file LICENSE that is included with the distribution 00004 */ 00005 #ifndef REFTRACK_H 00006 #define REFTRACK_H 00007 00008 #ifdef __cplusplus 00009 00010 #include <map> 00011 #include <string> 00012 #include <ostream> 00013 00014 #include <stdlib.h> 00015 00016 #include <epicsVersion.h> 00017 00018 #ifndef VERSION_INT 00019 # define VERSION_INT(V,R,M,P) ( ((V)<<24) | ((R)<<16) | ((M)<<8) | (P)) 00020 #endif 00021 00022 #ifndef EPICS_VERSION_INT 00023 # define EPICS_VERSION_INT VERSION_INT(EPICS_VERSION, EPICS_REVISION, EPICS_MODIFICATION, EPICS_PATCH_LEVEL) 00024 #endif 00025 00026 #if EPICS_VERSION_INT>=VERSION_INT(3,15,1,0) 00027 # include <epicsAtomic.h> 00028 # define REFTRACK_USE_ATOMIC 00029 #endif 00030 00031 #ifdef REFTRACK_USE_ATOMIC 00032 # define REFTRACE_INCREMENT(counter) ::epics::atomic::increment(counter) 00033 # define REFTRACE_DECREMENT(counter) ::epics::atomic::decrement(counter) 00034 #else 00035 # define REFTRACE_INCREMENT(counter) do{}while(0) 00036 # define REFTRACE_DECREMENT(counter) do{}while(0) 00037 #endif 00038 00039 #include <shareLib.h> 00040 00041 namespace epics { 00042 00044 epicsShareFunc 00045 void registerRefCounter(const char *name, const size_t* counter); 00046 00048 epicsShareFunc 00049 void unregisterRefCounter(const char *name, const size_t* counter); 00050 00052 epicsShareFunc 00053 size_t readRefCounter(const char *name); 00054 00056 class epicsShareClass RefSnapshot 00057 { 00058 public: 00060 struct Count { 00061 size_t current; 00062 long delta; 00063 Count() :current(0u), delta(0) {} 00064 explicit Count(size_t c, long d) :current(c), delta(d) {} 00065 bool operator==(const Count& o) const 00066 { return current==o.current && delta==o.delta; } 00067 }; 00068 00069 private: 00070 typedef std::map<std::string, Count> cnt_map_t; 00071 cnt_map_t counts; 00072 public: 00073 typedef cnt_map_t::const_iterator iterator; 00074 typedef cnt_map_t::const_iterator const_iterator; 00075 00080 void update(); 00081 00082 const Count& operator[](const std::string& name) const; 00083 00084 iterator begin() const { return counts.begin(); } 00085 iterator end() const { return counts.end(); } 00086 size_t size() const { return counts.size(); } 00087 00088 inline void swap(RefSnapshot& o) 00089 { 00090 counts.swap(o.counts); 00091 } 00092 00098 RefSnapshot operator-(const RefSnapshot& rhs) const; 00099 }; 00100 00102 epicsShareFunc 00103 std::ostream& operator<<(std::ostream& strm, const RefSnapshot& snap); 00104 00107 class epicsShareClass RefMonitor 00108 { 00109 struct Impl; 00110 Impl *impl; 00111 public: 00112 RefMonitor(); 00113 virtual ~RefMonitor(); 00114 00115 void start(double period=10.0); 00116 void stop(); 00117 bool running() const; 00118 00120 void current(); 00121 protected: 00124 virtual void show(const RefSnapshot& snap, bool complete=false); 00125 }; 00126 00127 } // namespace epics 00128 00129 extern "C" { 00130 #endif /* __cplusplus */ 00131 00135 char* epicsRefSnapshotCurrent(); 00136 00137 #ifdef __cplusplus 00138 } 00139 #endif /* __cplusplus */ 00140 00141 #endif // REFTRACK_H
1.7.4