HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_UniversalLogSource.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_UniversalLogSource.h ( FS Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_UniversalLogSource__
13 #define __UT_UniversalLogSource__
14 
15 #include "UT_API.h"
16 #include "UT_Array.h"
17 #include "UT_Function.h"
18 #include "UT_Lock.h"
19 #include "UT_StringHolder.h"
20 #include "UT_UniversalLogEntry.h"
21 
22 class UT_StringArray;
25 
28 
29 /// Use this macro to register a log source class so it can be created by
30 /// and attached to a log sink object.
31 #define UT_REGISTERUNIVERSALLOGSOURCE(source_class) \
32  static UT_UniversalLogSourceRegistration theReg##source_class( \
33  source_class::staticName(), \
34  [] () { return new source_class(); })
35 
36 /// This class performs the registration of a log source class. It also holds
37 /// the static map of instantiated source objects.
39 {
40 public:
42  const UT_StringHolder &source_name,
44 
45  static bool connect(const UT_StringHolder &source_name,
46  UT_UniversalLogSink *sink);
47  static bool disconnect(const UT_StringHolder &source_name,
48  UT_UniversalLogSink *sink);
49 
50  static void getSourceNames(UT_StringArray &source_names);
51  static bool isSourceName(const UT_StringRef &source_name);
52  static UT_UniversalLogSource *getSource(const UT_StringRef &source_name);
53 };
54 
55 /// This class represents a logging data source. Each source is a singleton
56 /// created by the registration code the first time a sink asks to connect
57 /// to it. The Source is destroyed when the last sink disconnects from it.
58 /// The source's connection to its sinks is maintained by the base class, so
59 /// source subclasses simply need to call sendToSinks when they have a log
60 /// entry to broadcast.
62 {
63 public:
64  /// Sends a message to our associated log sinks.
65  void sendToSinks(const UT_UniversalLogEntry &entry);
66 
67 protected:
69  virtual ~UT_UniversalLogSource();
70 
72  UT_UniversalLogSource &operator=(const UT_UniversalLogSource &) = delete;
73 
76 
78 };
79 
80 #endif
int getSource() override
#define UT_API
Definition: UT_API.h:14
UT_Function< UT_UniversalLogSource *()> UT_UniversalLogSourceCreator
std::function< T > UT_Function
Definition: UT_Function.h:37
UT_Array< UT_UniversalLogSink * > mySinks
Simple object to hold the data associated with a single log entry event.