ScummVM API documentation
debug_manager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // AGS logging system is built with idea that the engine components should not
25 // be bothered with specifying particular output method. Instead they use
26 // generic logging interface, and the actual message printing is done by one
27 // or more registered handlers.
28 // Firstly this makes logging functions independent of running platform or
29 // back-end, secondly it grants end-users ability to configure output according
30 // to their preference.
31 //
32 // To make the logging work we need to register two sets of "entities":
33 // debug groups and output targets.
34 // Debug group is an arbitrary object with a name that describes message
35 // sender.
36 // Output target defines printing handler and a set of verbosity rules
37 // one per each known group.
38 //
39 // When the message is sent, it is tagged with one of the existing group IDs
40 // and a message type (debug info, warning, error). This message is sent onto
41 // each of the registered output targets, which do checks to find out whether
42 // the message is permitted to be sent further to the printing handler, or not.
43 //
44 //=============================================================================
45 
46 #ifndef AGS_SHARED_DEBUGGING_DEBUG_MANAGER_H
47 #define AGS_SHARED_DEBUGGING_DEBUG_MANAGER_H
48 
49 #include "common/std/memory.h"
50 #include "common/std/map.h"
51 #include "ags/shared/debugging/out.h"
52 #include "ags/shared/debugging/output_handler.h"
53 #include "ags/shared/util/string.h"
54 #include "ags/shared/util/string_types.h"
55 
56 namespace AGS3 {
57 namespace AGS {
58 namespace Shared {
59 
60 // DebugGroup is a message sender definition, identified by DebugGroupID
61 // and providing OutputName that could be used when printing its messages.
62 // OutputName may or may not be same as DebugGroupID.SID.
63 struct DebugGroup {
64  DebugGroupID UID;
65  String OutputName;
66 
67  DebugGroup() {
68  }
69  DebugGroup(DebugGroupID id, String out_name) : UID(id), OutputName(out_name) {
70  }
71 };
72 
73 // DebugOutput is a slot for IOutputHandler with its own group filter
74 class DebugOutput {
75 public:
76  DebugOutput(const String &id, IOutputHandler *handler, MessageType def_verbosity = kDbgMsg_All, bool enabled = true);
77 
78  String GetID() const;
79  IOutputHandler *GetHandler() const;
80 
81  bool IsEnabled() const;
82  void SetEnabled(bool enable);
83  // Setup group filter: either allow or disallow a group with the given ID
84  void SetGroupFilter(DebugGroupID id, MessageType verbosity);
85  // Assign same verbosity level to all known groups
86  void SetAllGroupFilters(MessageType verbosity);
87  // Clear all group filters; this efficiently disables everything
88  void ClearGroupFilters();
89  // Try to resolve group filter unknown IDs
90  void ResolveGroupID(DebugGroupID id);
91  // Test if given group id is permitted
92  bool TestGroup(DebugGroupID id, MessageType mt) const;
93 
94 private:
95  String _id;
96  IOutputHandler *_handler;
97  bool _enabled;
98  MessageType _defaultVerbosity;
99  // Set of permitted groups' numeric IDs
100  std::vector<MessageType> _groupFilter;
101  // Set of unresolved groups, which numeric IDs are not yet known
103  GroupNameToMTMap _unresolvedGroups;
104 };
105 
107 
108 
110  friend class DebugOutput;
111 
112 public:
113  DebugManager();
114 
115  // Gets full group ID for any partial one; if the group is not registered returns unset ID
116  DebugGroup GetGroup(DebugGroupID id);
117  // Gets output control interface for the given ID
118  PDebugOutput GetOutput(const String &id);
119  // Registers debugging group with the given string ID; numeric ID
120  // will be assigned internally. Returns full ID pair.
121  // If the group with such string id already exists, returns existing ID.
122  DebugGroup RegisterGroup(const String &id, const String &out_name);
123  // Registers output delegate for passing debug messages to;
124  // if the output with such id already exists, replaces the old one
125  PDebugOutput RegisterOutput(const String &id, IOutputHandler *handler, MessageType def_verbosity = kDbgMsg_All, bool enabled = true);
126  // Unregisters all groups and all targets
127  void UnregisterAll();
128  // Unregisters debugging group with the given ID
129  void UnregisterGroup(DebugGroupID id);
130  // Unregisters output delegate with the given ID
131  void UnregisterOutput(const String &id);
132 
133  // Output message of given group and message type
134  void Print(DebugGroupID group_id, MessageType mt, const String &text);
135  // Send message directly to the output with given id; the message
136  // must pass the output's message filter though
137  void SendMessage(const String &out_id, const DebugMessage &msg);
138 
139 private:
140  // OutputSlot struct wraps over output target and adds a flag which indicates
141  // that this target is temporarily disabled (for internal use only)
142  struct OutputSlot {
143  PDebugOutput Target;
144  bool Suppressed;
145 
146  OutputSlot() : Suppressed(false) {
147  }
148  };
149 
153 
154  void RegisterGroup(const DebugGroup &id);
155  void SendMessage(OutputSlot &out, const DebugMessage &msg);
156 
157  uint32_t _firstFreeGroupID;
158  uint32_t _lastGroupID;
159  GroupVector _groups;
160  GroupByStringMap _groupByStrLookup;
161  OutMap _outputs;
162 };
163 
164 } // namespace Shared
165 } // namespace AGS
166 } // namespace AGS3
167 
168 #endif
Definition: achievements_tables.h:27
Definition: debug_manager.h:109
Definition: out.h:130
Definition: debug_manager.h:63
Definition: output_handler.h:39
Definition: string.h:62
Definition: debug_manager.h:74
Definition: ptr.h:159
Definition: output_handler.h:55
Definition: ags.h:40