lsnes rr0-β15
[lsnes.git] / generic / avsnoop.cpp
blob1343a22f0b4fb9dd50f8eff103931205e9588603
1 #include "avsnoop.hpp"
2 #include "misc.hpp"
3 #include "globalwrap.hpp"
5 namespace
7 globalwrap<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 snoopers().push_back(this);
19 for(auto i = notifiers.begin(); i != notifiers.end(); i++)
20 (*i)->dump_starting();
23 av_snooper::~av_snooper() throw()
25 for(auto i = snoopers().begin(); i != snoopers().end(); i++)
26 if(*i == this) {
27 snoopers().erase(i);
28 break;
30 for(auto i = notifiers.begin(); i != notifiers.end(); i++)
31 (*i)->dump_ending();
34 void av_snooper::frame(struct lcscreen& _frame, uint32_t fps_n, uint32_t fps_d, bool dummy) throw(std::bad_alloc)
36 for(auto i = snoopers().begin(); i != snoopers().end(); i++)
37 try {
38 (*i)->frame(_frame, fps_n, fps_d);
39 } catch(std::bad_alloc& e) {
40 throw;
41 } catch(std::exception& e) {
42 try {
43 messages << "Error dumping frame: " << e.what() << std::endl;
44 } catch(...) {
49 void av_snooper::sample(short l, short r, bool dummy) throw(std::bad_alloc)
51 for(auto i = snoopers().begin(); i != snoopers().end(); i++)
52 try {
53 (*i)->sample(l, r);
54 } catch(std::bad_alloc& e) {
55 throw;
56 } catch(std::exception& e) {
57 try {
58 messages << "Error dumping sample: " << e.what() << std::endl;
59 } catch(...) {
64 void av_snooper::end(bool dummy) throw(std::bad_alloc)
66 for(auto i = snoopers().begin(); i != snoopers().end(); i++)
67 try {
68 (*i)->end();
69 } catch(std::bad_alloc& e) {
70 throw;
71 } catch(std::exception& e) {
72 try {
73 messages << "Error ending dump: " << e.what() << std::endl;
74 } catch(...) {
79 void av_snooper::gameinfo(const std::string& gamename, const std::list<std::pair<std::string, std::string>>&
80 authors, double gametime, const std::string& rerecords, bool dummy) throw(std::bad_alloc)
82 s_gamename = gamename;
83 s_authors = authors;
84 s_gametime = gametime;
85 s_rerecords = rerecords;
86 gameinfo_set = true;
87 for(auto i = snoopers().begin(); i != snoopers().end(); i++)
88 (*i)->send_gameinfo();
91 void av_snooper::send_gameinfo() throw()
93 if(gameinfo_set)
94 try {
95 gameinfo(s_gamename, s_authors, s_gametime, s_rerecords);
96 } catch(...) {
100 bool av_snooper::dump_in_progress() throw()
102 return !snoopers().empty();
105 av_snooper::dump_notification::~dump_notification() throw()
109 void av_snooper::dump_notification::dump_starting() throw()
113 void av_snooper::dump_notification::dump_ending() throw()
117 void av_snooper::add_dump_notifier(av_snooper::dump_notification& notifier) throw(std::bad_alloc)
119 notifiers.push_back(&notifier);
122 void av_snooper::remove_dump_notifier(av_snooper::dump_notification& notifier) throw()
124 for(auto i = notifiers.begin(); i != notifiers.end(); i++)
125 if(*i == &notifier) {
126 notifiers.erase(i);
127 return;