AGX Dynamics  2.35.0.1
LoggerSubscriber.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agx/Notify.h>
20 #include <deque>
21 
22 namespace agx {
23 
34  {
35  public:
36 
37  // agx::Notify::NOTIFY_DEBUG | agx::Notify::NOTIFY_INFO | agx::Notify::NOTIFY_WARNING | agx::Notify::NOTIFY_ERROR;
38  static int ALL_LEVELS;
39 
40 
47 
53  std::string pop(int levelMask = ALL_LEVELS);
54 
61  size_t pop(agx::StringVector& outMessages, int levelMask = ALL_LEVELS);
62 
67  bool empty(int levelMask = ALL_LEVELS) const;
68 
73  void clear(int levelMask = ALL_LEVELS);
74 
79  void setEnable(bool flag);
80 
84  bool getEnable() const;
85 
86 
87  typedef std::pair<int, agx::String> Message;
97  bool getMessages(MessageVector& messages, bool clearMessages, int levelMask = ALL_LEVELS);
98 
99  protected:
100 
104  void message(const agx::String& msg, int notifyLevel);
105 
107  virtual ~LoggerSubscriber();
108 
110  {
111  public:
114 
115  protected:
117 
118  void message(const agx::String& msg, int notifyLevel) override;
119  };
120 
121  friend class LogCallback;
122 
123  private:
124  typedef std::deque<Message> MessageQueue;
125  MessageQueue m_messageQueue;
126 
127  agx::ref_ptr<LogCallback> m_callback;
128 
129  int m_levelMask;
130  bool m_enabled;
131  mutable agx::ReentrantMutex m_mutex;
132  };
133 }
#define AGXPHYSICS_EXPORT
void message(const agx::String &msg, int notifyLevel) override
Virtual method called whenever there is a message ready.
LogCallback(LoggerSubscriber *subscriber)
Class for polling messages from the LOGGER system in a Subscriber pattern.
void setEnable(bool flag)
Enable/disable the capturing of messages.
LoggerSubscriber(int levelMask=agx::Notify::NOTIFY_INFO|agx::Notify::NOTIFY_WARNING|agx::Notify::NOTIFY_ERROR)
Constructor for a logger mailbox.
bool getEnable() const
std::pair< int, agx::String > Message
void clear(int levelMask=ALL_LEVELS)
Remove all messages.
bool getMessages(MessageVector &messages, bool clearMessages, int levelMask=ALL_LEVELS)
Get a copy of all messages matching the specified notify level levelMask in the message queue.
agx::Vector< Message > MessageVector
void message(const agx::String &msg, int notifyLevel)
Callback that will be called when a new message is present.
std::string pop(int levelMask=ALL_LEVELS)
Get all available messages and then remove them.
bool empty(int levelMask=ALL_LEVELS) const
virtual ~LoggerSubscriber()
Destructor.
size_t pop(agx::StringVector &outMessages, int levelMask=ALL_LEVELS)
Get all available messages and then remove them.
Callback class, derive from this and Register to the notify singleton to get callbacks.
Definition: Notify.h:49
@ NOTIFY_WARNING
WARNING level.
Definition: Notify.h:68
@ NOTIFY_INFO
INFO level.
Definition: Notify.h:67
@ NOTIFY_ERROR
ERROR (highest) level.
Definition: Notify.h:69
Base class providing referencing counted objects.
Definition: Referenced.h:114
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
std::recursive_mutex ReentrantMutex
Definition: Object.h:49