{
stringstream s;
- s << "Finished locally-encoded frame " << _frame << " length " << cio_tell (_cio);
+ s << "Finished locally-encoded frame " << _frame;
_log->log (s.str ());
}
{
stringstream s;
- s << "Finished remotely-encoded frame " << _frame << " length " << e->size();
+ s << "Finished remotely-encoded frame " << _frame;
_log->log (s.str ());
}
read_metadata ();
- _log = new Log (_state.file ("log"));
+ _log = new FileLog (_state.file ("log"));
}
/** Copy constructor */
using namespace std;
-/** @param f Filename to write log to */
-Log::Log (string f)
- : _file (f)
- , _level (VERBOSE)
+Log::Log ()
+ : _level (VERBOSE)
{
}
return;
}
- ofstream f (_file.c_str(), fstream::app);
-
time_t t;
time (&t);
string a = ctime (&t);
-
- f << a.substr (0, a.length() - 1) << ": " << m << "\n";
+
+ stringstream s;
+ s << a.substr (0, a.length() - 1) << ": " << m;
+ do_log (s.str ());
}
void
_level = l;
}
+
+/** @param file Filename to write log to */
+FileLog::FileLog (string file)
+ : _file (file)
+{
+
+}
+
+void
+FileLog::do_log (string m)
+{
+ ofstream f (_file.c_str(), fstream::app);
+ f << m << "\n";
+}
+
/** @class Log
* @brief A very simple logging class.
- *
- * This class simply accepts log messages and writes them to a file.
- * Its single nod to complexity is that it has a mutex to prevent
- * multi-thread logging from clashing.
*/
class Log
{
public:
- Log (std::string f);
+ Log ();
enum Level {
STANDARD = 0,
void set_level (Level l);
-private:
- /** mutex to prevent simultaneous writes to the file */
+protected:
+ /** mutex to protect the log */
boost::mutex _mutex;
- /** filename to write to */
- std::string _file;
+
+private:
+ virtual void do_log (std::string m) = 0;
+
/** level above which to ignore log messages */
Level _level;
};
+class FileLog : public Log
+{
+public:
+ FileLog (std::string file);
+
+private:
+ void do_log (std::string m);
+ /** filename to write to */
+ std::string _file;
+};
+
#endif
return s.str ();
}
-Server::Server ()
- : _log ("servomatic.log")
+Server::Server (Log* log)
+ : _log (log)
{
}
image->hash ("Image for encoding (as received by server)");
#endif
- DCPVideoFrame dcp_video_frame (image, out_size, padding, scaler, frame, frames_per_second, post_process, colour_lut_index, j2k_bandwidth, &_log);
+ DCPVideoFrame dcp_video_frame (image, out_size, padding, scaler, frame, frames_per_second, post_process, colour_lut_index, j2k_bandwidth, _log);
shared_ptr<EncodedData> encoded = dcp_video_frame.encode_locally ();
encoded->send (socket);
class Server
{
public:
- Server ();
+ Server (Log* log);
void run ();
std::list<boost::shared_ptr<boost::asio::ip::tcp::socket> > _queue;
boost::mutex _worker_mutex;
boost::condition _worker_condition;
- Log _log;
+ Log* _log;
};
main ()
{
Scaler::setup_scalers ();
- Server server;
+ FileLog log ("servomatic.log");
+ Server server (&log);
server.run ();
return 0;
}
#include "lib/util.h"
#include "lib/server.h"
+using namespace std;
using namespace boost;
enum {
ID_status = 1,
- ID_quit
+ ID_quit,
+ ID_timer
};
+class MemoryLog : public Log
+{
+public:
+
+ string get () const {
+ boost::mutex::scoped_lock (_mutex);
+ return _log;
+ }
+
+private:
+ void do_log (string m)
+ {
+ _log = m;
+ }
+
+ string _log;
+};
+
+static MemoryLog memory_log;
+
class StatusDialog : public wxDialog
{
public:
StatusDialog ()
- : wxDialog (0, wxID_ANY, _("DVD-o-matic encode server"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
+ : wxDialog (0, wxID_ANY, _("DVD-o-matic encode server"), wxDefaultPosition, wxSize (600, 40), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
+ , _timer (this, ID_timer)
{
- wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
- table->AddGrowableCol (1, 1);
+ _sizer = new wxFlexGridSizer (1, 6, 6);
+ _sizer->AddGrowableCol (0, 1);
- add_label_to_sizer (table, this, "Hello");
+ _text = new wxTextCtrl (this, wxID_ANY);
+ _sizer->Add (_text, 1, wxEXPAND);
- SetSizer (table);
- table->Layout ();
- table->SetSizeHints (this);
+ SetSizer (_sizer);
+ _sizer->Layout ();
+
+ Connect (ID_timer, wxEVT_TIMER, wxTimerEventHandler (StatusDialog::update));
+ _timer.Start (1000);
}
+
+private:
+ void update (wxTimerEvent &)
+ {
+ _text->ChangeValue (std_to_wx (memory_log.get ()));
+ _sizer->Layout ();
+ }
+
+ wxFlexGridSizer* _sizer;
+ wxTextCtrl* _text;
+ wxTimer _timer;
};
class TaskBarIcon : public wxTaskBarIcon
void main_thread ()
{
- Server server;
+ Server server (&memory_log);
server.run ();
}
if (i >= 0) {
_servers->DeleteItem (i);
}
+
+ vector<ServerDescription*> o = Config::instance()->servers ();
+ o.erase (o.begin() + i);
+ Config::instance()->set_servers (o);
}
void