|
1
|
1 #include "foobar2000-sdk-pch.h"
|
|
|
2 #include "console_manager.h"
|
|
|
3 #include "console.h"
|
|
|
4 #include "metadb_handle.h"
|
|
|
5 #include "event_logger.h"
|
|
|
6
|
|
|
7 void console::info(const char * p_message) {print(p_message);}
|
|
|
8 void console::error(const char * p_message) {complain("Error", p_message);}
|
|
|
9 void console::warning(const char * p_message) {complain("Warning", p_message);}
|
|
|
10
|
|
|
11 void console::info_location(const playable_location & src) {print_location(src);}
|
|
|
12 void console::info_location(const metadb_handle_ptr & src) {print_location(src);}
|
|
|
13
|
|
|
14 void console::print_location(const metadb_handle_ptr & src)
|
|
|
15 {
|
|
|
16 print_location(src->get_location());
|
|
|
17 }
|
|
|
18
|
|
|
19 void console::print_location(const playable_location & src)
|
|
|
20 {
|
|
|
21 FB2K_console_formatter() << src;
|
|
|
22 }
|
|
|
23
|
|
|
24 void console::complain(const char * what, const char * msg) {
|
|
|
25 FB2K_console_formatter() << what << ": " << msg;
|
|
|
26 }
|
|
|
27 void console::complain(const char * what, std::exception const & e) {
|
|
|
28 complain(what, e.what());
|
|
|
29 }
|
|
|
30
|
|
|
31 void console::print(const char* p_message)
|
|
|
32 {
|
|
|
33 if (core_api::are_services_available()) {
|
|
|
34 for (auto p : console_receiver::enumerate()) {
|
|
|
35 p->print(p_message, SIZE_MAX);
|
|
|
36 }
|
|
|
37 }
|
|
|
38 }
|
|
|
39
|
|
|
40 void console::printf(const char* p_format,...)
|
|
|
41 {
|
|
|
42 va_list list;
|
|
|
43 va_start(list,p_format);
|
|
|
44 printfv(p_format,list);
|
|
|
45 va_end(list);
|
|
|
46 }
|
|
|
47
|
|
|
48 void console::printfv(const char* p_format,va_list p_arglist)
|
|
|
49 {
|
|
|
50 pfc::string8_fastalloc temp;
|
|
|
51 uPrintfV(temp,p_format,p_arglist);
|
|
|
52 print(temp);
|
|
|
53 }
|
|
|
54
|
|
|
55
|
|
|
56
|
|
|
57 namespace {
|
|
|
58
|
|
|
59 class event_logger_recorder_impl : public event_logger_recorder {
|
|
|
60 public:
|
|
|
61 void playback( event_logger::ptr playTo ) {
|
|
|
62 for(auto i = m_entries.first(); i.is_valid(); ++i ) {
|
|
|
63 playTo->log_entry( i->line.get_ptr(), i->severity );
|
|
|
64 }
|
|
|
65 }
|
|
|
66
|
|
|
67 void log_entry( const char * line, unsigned severity ) {
|
|
|
68 auto rec = m_entries.insert_last();
|
|
|
69 rec->line = line;
|
|
|
70 rec->severity = severity;
|
|
|
71 }
|
|
|
72 private:
|
|
|
73
|
|
|
74 struct entry_t {
|
|
|
75 pfc::string_simple line;
|
|
|
76 unsigned severity;
|
|
|
77 };
|
|
|
78 pfc::chain_list_v2_t< entry_t > m_entries;
|
|
|
79 };
|
|
|
80
|
|
|
81 }
|
|
|
82
|
|
|
83 event_logger_recorder::ptr event_logger_recorder::create() {
|
|
|
84 return new service_impl_t<event_logger_recorder_impl>();
|
|
|
85 }
|
|
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
|
|
90 namespace console {
|
|
|
91 void addNotify(fb2k::console_notify* n) {
|
|
|
92 static_api_ptr_t<fb2k::console_manager>()->addNotify(n);
|
|
|
93 }
|
|
|
94 void removeNotify(fb2k::console_notify* n) {
|
|
|
95 static_api_ptr_t<fb2k::console_manager>()->removeNotify(n);
|
|
|
96 }
|
|
|
97 fb2k::arrayRef getLines() {
|
|
|
98 return static_api_ptr_t<fb2k::console_manager>()->getLines();
|
|
|
99 }
|
|
|
100 void clearBacklog() {
|
|
|
101 static_api_ptr_t<fb2k::console_manager>()->clearBacklog();
|
|
|
102 }
|
|
|
103
|
|
|
104 bool isVerbose() {
|
|
|
105 return static_api_ptr_t<fb2k::console_manager>()->isVerbose();
|
|
|
106 }
|
|
|
107 }
|