Since window is singleton anyway, get rid of window* parameters
[lsnes.git] / avsnoop.cpp
blob75a080a3831a8426ba42fcd172fd66c65931a70e
1 #include "avsnoop.hpp"
2 #include "misc.hpp"
3 #include "window.hpp"
5 namespace
7 std::list<av_snooper*>* snoopers;
8 std::list<av_snooper::dump_notification*> notifiers;
9 std::string s_gamename;
10 std::string s_rerecords;
11 double s_gametime;
12 std::list<std::pair<std::string, std::string>> s_authors;
13 bool gameinfo_set;
16 av_snooper::av_snooper() throw(std::bad_alloc)
18 if(!snoopers)
19 snoopers = new std::list<av_snooper*>();
20 snoopers->push_back(this);
21 for(auto i = notifiers.begin(); i != notifiers.end(); i++)
22 (*i)->dump_starting();
25 av_snooper::~av_snooper() throw()
27 if(!snoopers)
28 return;
29 for(auto i = snoopers->begin(); i != snoopers->end(); i++)
30 if(*i == this) {
31 snoopers->erase(i);
32 break;
34 for(auto i = notifiers.begin(); i != notifiers.end(); i++)
35 (*i)->dump_ending();
38 void av_snooper::frame(struct lcscreen& _frame, uint32_t fps_n, uint32_t fps_d, bool dummy) throw(std::bad_alloc)
40 if(!snoopers)
41 return;
42 for(auto i = snoopers->begin(); i != snoopers->end(); i++)
43 try {
44 (*i)->frame(_frame, fps_n, fps_d);
45 } catch(std::bad_alloc& e) {
46 throw;
47 } catch(std::exception& e) {
48 try {
49 window::out() << "Error dumping frame: " << e.what() << std::endl;
50 } catch(...) {
55 void av_snooper::sample(short l, short r, bool dummy) throw(std::bad_alloc)
57 if(!snoopers)
58 return;
59 for(auto i = snoopers->begin(); i != snoopers->end(); i++)
60 try {
61 (*i)->sample(l, r);
62 } catch(std::bad_alloc& e) {
63 throw;
64 } catch(std::exception& e) {
65 try {
66 window::out() << "Error dumping sample: " << e.what() << std::endl;
67 } catch(...) {
72 void av_snooper::end(bool dummy) throw(std::bad_alloc)
74 if(!snoopers)
75 return;
76 for(auto i = snoopers->begin(); i != snoopers->end(); i++)
77 try {
78 (*i)->end();
79 } catch(std::bad_alloc& e) {
80 throw;
81 } catch(std::exception& e) {
82 try {
83 window::out() << "Error ending dump: " << e.what() << std::endl;
84 } catch(...) {
89 void av_snooper::gameinfo(const std::string& gamename, const std::list<std::pair<std::string, std::string>>&
90 authors, double gametime, const std::string& rerecords, bool dummy) throw(std::bad_alloc)
92 if(!snoopers)
93 return;
94 s_gamename = gamename;
95 s_authors = authors;
96 s_gametime = gametime;
97 s_rerecords = rerecords;
98 gameinfo_set = true;
99 for(auto i = snoopers->begin(); i != snoopers->end(); i++)
100 (*i)->send_gameinfo();
103 void av_snooper::send_gameinfo() throw()
105 if(gameinfo_set)
106 try {
107 gameinfo(s_gamename, s_authors, s_gametime, s_rerecords);
108 } catch(...) {
112 bool av_snooper::dump_in_progress() throw()
114 return (snoopers && !snoopers->empty());
117 av_snooper::dump_notification::~dump_notification() throw()
121 void av_snooper::dump_notification::dump_starting() throw()
125 void av_snooper::dump_notification::dump_ending() throw()
129 void av_snooper::add_dump_notifier(av_snooper::dump_notification& notifier) throw(std::bad_alloc)
131 notifiers.push_back(&notifier);
134 void av_snooper::remove_dump_notifier(av_snooper::dump_notification& notifier) throw()
136 for(auto i = notifiers.begin(); i != notifiers.end(); i++)
137 if(*i == &notifier) {
138 notifiers.erase(i);
139 return;