Program Listing for File reftrack.h

Return to documentation for file (src/misc/pv/reftrack.h)

/*
 * Copyright information and license terms for this software can be
 * found in the file LICENSE that is included with the distribution
 */
#ifndef REFTRACK_H
#define REFTRACK_H

#ifdef __cplusplus

#include <map>
#include <string>
#include <ostream>

#include <stdlib.h>

#include <epicsVersion.h>
#include <epicsAtomic.h>

#define REFTRACE_INCREMENT(counter) ::epics::atomic::increment(counter)
#define REFTRACE_DECREMENT(counter) ::epics::atomic::decrement(counter)

#include <shareLib.h>

namespace epics {

epicsShareFunc
void registerRefCounter(const char *name, const size_t* counter);

epicsShareFunc
void unregisterRefCounter(const char *name, const size_t* counter);

epicsShareFunc
size_t readRefCounter(const char *name);

class epicsShareClass RefSnapshot
{
public:
    struct Count {
        size_t current;
        long delta;
        Count() :current(0u), delta(0) {}
        explicit Count(size_t c, long d) :current(c), delta(d) {}
        bool operator==(const Count& o) const
        { return current==o.current && delta==o.delta; }
    };

private:
    typedef std::map<std::string, Count> cnt_map_t;
    cnt_map_t counts;
public:
    typedef cnt_map_t::const_iterator iterator;
    typedef cnt_map_t::const_iterator const_iterator;

    void update();

    const Count& operator[](const std::string& name) const;

    iterator begin() const { return counts.begin(); }
    iterator end() const { return counts.end(); }
    size_t size() const { return counts.size(); }

    inline void swap(RefSnapshot& o)
    {
        counts.swap(o.counts);
    }

    RefSnapshot operator-(const RefSnapshot& rhs) const;
};

epicsShareFunc
std::ostream& operator<<(std::ostream& strm, const RefSnapshot& snap);

class epicsShareClass RefMonitor
{
    struct Impl;
    Impl *impl;
public:
    RefMonitor();
    virtual ~RefMonitor();

    void start(double period=10.0);
    void stop();
    bool running() const;

    void current();
protected:
    virtual void show(const RefSnapshot& snap, bool complete=false);
};

} // namespace epics

extern "C" {
#endif /* __cplusplus */

char* epicsRefSnapshotCurrent();

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif // REFTRACK_H