9#include "sparta/log/categories/CategoryManager.hpp"
10#include "sparta/utils/StringManager.hpp"
11#include "sparta/log/Destination.hpp"
12#include "sparta/log/Events.hpp"
13#include "sparta/simulation/TreeNodePrivateAttorney.hpp"
55 template <
typename DestT>
56 Tap(
TreeNode* node,
const std::string* pcategory, DestT& dest) :
81 template <
typename DestT>
82 Tap(
TreeNode* node,
const std::string& category, DestT& dest) :
102 template <
typename DestT>
103 Tap(
const std::string& category, DestT& dest) :
105 category_(
StringManager::getStringManager().internString(category))
136 typename std::remove_reference<
decltype(*this)>::type,
137 &std::remove_reference<
decltype(*this)>::type::send_>
138 (node_wptr_.lock().get(),
this, *category_,
false);
151 if(!node_wptr_.expired()){
152 auto shared = node_wptr_.lock();
155 typename std::remove_reference<
decltype(*this)>::type,
156 &std::remove_reference<
decltype(*this)>::type::send_>(shared.get(),
173 const std::string* getCategoryID()
const {
177 const std::string& getCategoryName()
const {
181 const Destination* getDestination()
const {
185 Destination* getDestination() {
214 return node_wptr_.expired();
238 (void)obs_pt_DO_NOT_USE;
249 const std::string*
const category_;
251 uint64_t num_msgs_ = 0;
262 const std::string& _category,
263 const std::string& _destination) :
264 loc_pattern_(_loc_pattern),
265 category_(_category),
274 std::string stringize()
const {
275 std::stringstream ss;
276 ss <<
"Tap location_pattern=\"" << loc_pattern_ <<
"\" (category=\"" << category_
277 <<
"\") -> file: \"" << dest_ <<
"\"";
282 void incrementUsageCount()
const { ++num_times_used_; }
285 uint32_t getUsageCount()
const {
return num_times_used_; }
288 const std::string &getLocation()
const {
return loc_pattern_; }
291 const std::string &getCategory()
const {
return category_; }
294 const std::string &getDestination()
const {
return dest_; }
297 bool hasBadPattern()
const {
return has_bad_pattern_; }
300 void setBadPattern(
bool bad)
const { has_bad_pattern_ = bad; }
305 std::string loc_pattern_;
308 std::string category_;
315 mutable uint32_t num_times_used_ = 0;
320 mutable bool has_bad_pattern_ =
false;
324 typedef std::vector<TapDescriptor> TapDescVec;
332 inline std::vector<const log::TapDescriptor*>
getUnusedTaps(
const log::TapDescVec& taps) {
333 std::vector<const log::TapDescriptor*> unused_taps;
335 if(td.getUsageCount() == 0){
336 unused_taps.push_back(&td);
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Basic Node framework in sparta device tree composite pattern.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Manages string internment for SPARTA. This allows strings to be compared by pointer once interned.
Node in a composite tree representing a sparta Tree item.
std::weak_ptr< TreeNode > WeakPtr
Weak pointer to a TreeNode. Acquire with getWeakPtr.
WeakPtr getWeakPtr()
Gets a weak pointer to this TreeNode. This weak pointer is guaranteed to expire when this TreeNode is...
static Destination * getDestination(DestT &arg)
Requests an existing Destination* from the manager and allocates a new one if it does not yet have a ...
Generic Logging destination stream interface which writes sparta::log::Message structures to some out...
void write(const sparta::log::Message &msg)
Logging Tap. Attach to a TreeNode to intercept logging messages from any NotificationSource nodes in ...
void reset(TreeNode *node)
Detach the tap from the current node (if any) and re-attach to a new node. Destination and category o...
Tap(TreeNode *node, const std::string *pcategory, DestT &dest)
Constructor.
virtual ~Tap()
Destructor.
Tap(TreeNode *node, const std::string &category, DestT &dest)
Constructor.
uint64_t getNumMessages() const
Gets the number of messages seen by this tap having the designated category.
TreeNode * getObservedNode() const
Gets the node at which this tap is observing.
void send_(const TreeNode &origin, const TreeNode &obs_pt_DO_NOT_USE, const Message &msg)
Actually send the notification.
void detach()
Detach the tap from a node without destructing. Node can later be reattached to the same or another n...
Tap & operator=(const Tap &)=delete
Disallow copy assignment.
Tap(const Tap &)=delete
Disallow copy construction.
Tap(const std::string &category, DestT &dest)
Non-observing Constructor.
bool isObservedNodeExpired() const
Checks if the node at which this tap is observing has been deleted (i.e. its weak reference has expir...
std::vector< const log::TapDescriptor * > getUnusedTaps(const log::TapDescVec &taps)
Finds all unused taps in the given tap descriptor vector.
Macros for handling exponential backoff.
Contains a logging message header and content.