Split log.{cc,h}.
authorCarl Hetherington <cth@carlh.net>
Wed, 26 Aug 2015 18:45:37 +0000 (19:45 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 26 Aug 2015 18:45:37 +0000 (19:45 +0100)
13 files changed:
src/lib/file_log.cc [new file with mode: 0644]
src/lib/file_log.h [new file with mode: 0644]
src/lib/film.cc
src/lib/log.cc
src/lib/log.h
src/lib/null_log.h [new file with mode: 0644]
src/lib/wscript
src/tools/dcpomatic_server_cli.cc
src/tools/server_test.cc
test/client_server_test.cc
test/ffmpeg_decoder_seek_test.cc
test/ffmpeg_decoder_sequential_test.cc
test/file_log_test.cc

diff --git a/src/lib/file_log.cc b/src/lib/file_log.cc
new file mode 100644 (file)
index 0000000..599211d
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "file_log.h"
+#include "cross.h"
+#include <cstdio>
+
+using std::cout;
+using std::string;
+using std::max;
+
+/** @param file Filename to write log to */
+FileLog::FileLog (boost::filesystem::path file)
+       : _file (file)
+{
+
+}
+
+void
+FileLog::do_log (string m)
+{
+       FILE* f = fopen_boost (_file, "a");
+       if (!f) {
+               cout << "(could not log to " << _file.string() << "): " << m << "\n";
+               return;
+       }
+
+       fprintf (f, "%s\n", m.c_str ());
+       fclose (f);
+}
+
+string
+FileLog::head_and_tail (int amount) const
+{
+       boost::mutex::scoped_lock lm (_mutex);
+
+       uintmax_t head_amount = amount;
+       uintmax_t tail_amount = amount;
+       uintmax_t size = boost::filesystem::file_size (_file);
+
+       if (size < (head_amount + tail_amount)) {
+               head_amount = size;
+               tail_amount = 0;
+       }
+
+       FILE* f = fopen_boost (_file, "r");
+       if (!f) {
+               return "";
+       }
+
+       string out;
+
+       char* buffer = new char[max(head_amount, tail_amount) + 1];
+
+       int N = fread (buffer, 1, head_amount, f);
+       buffer[N] = '\0';
+       out += string (buffer);
+
+       if (tail_amount > 0) {
+               out +=  "\n .\n .\n .\n";
+
+               fseek (f, - tail_amount - 1, SEEK_END);
+
+               N = fread (buffer, 1, tail_amount, f);
+               buffer[N] = '\0';
+               out += string (buffer) + "\n";
+       }
+
+       delete[] buffer;
+       fclose (f);
+
+       return out;
+}
diff --git a/src/lib/file_log.h b/src/lib/file_log.h
new file mode 100644 (file)
index 0000000..1051ad1
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "log.h"
+
+class FileLog : public Log
+{
+public:
+       FileLog (boost::filesystem::path file);
+
+       std::string head_and_tail (int amount = 1024) const;
+
+private:
+       void do_log (std::string m);
+       /** filename to write to */
+       boost::filesystem::path _file;
+};
index ea11cf0bd2b15247da968a626ec5fd06f54e394a..685fc76588981c4b43aeabf12eb2c8b601d26e6e 100644 (file)
@@ -28,7 +28,8 @@
 #include "job_manager.h"
 #include "transcode_job.h"
 #include "upload_job.h"
-#include "log.h"
+#include "null_log.h"
+#include "file_log.h"
 #include "exceptions.h"
 #include "examine_content_job.h"
 #include "config.h"
index ac3277c4e618a1e04f7049492e6299424b79b1ee..2e5cc54e180aaeb8009123121f964d4db5fedcab 100644 (file)
@@ -120,66 +120,3 @@ Log::set_types (int t)
        boost::mutex::scoped_lock lm (_mutex);
        _types = t;
 }
-
-/** @param file Filename to write log to */
-FileLog::FileLog (boost::filesystem::path file)
-       : _file (file)
-{
-
-}
-
-void
-FileLog::do_log (string m)
-{
-       FILE* f = fopen_boost (_file, "a");
-       if (!f) {
-               cout << "(could not log to " << _file.string() << "): " << m << "\n";
-               return;
-       }
-
-       fprintf (f, "%s\n", m.c_str ());
-       fclose (f);
-}
-
-string
-FileLog::head_and_tail (int amount) const
-{
-       boost::mutex::scoped_lock lm (_mutex);
-
-       uintmax_t head_amount = amount;
-       uintmax_t tail_amount = amount;
-       uintmax_t size = boost::filesystem::file_size (_file);
-
-       if (size < (head_amount + tail_amount)) {
-               head_amount = size;
-               tail_amount = 0;
-       }
-
-       FILE* f = fopen_boost (_file, "r");
-       if (!f) {
-               return "";
-       }
-
-       string out;
-
-       char* buffer = new char[max(head_amount, tail_amount) + 1];
-
-       int N = fread (buffer, 1, head_amount, f);
-       buffer[N] = '\0';
-       out += string (buffer);
-
-       if (tail_amount > 0) {
-               out +=  "\n .\n .\n .\n";
-
-               fseek (f, - tail_amount - 1, SEEK_END);
-
-               N = fread (buffer, 1, tail_amount, f);
-               buffer[N] = '\0';
-               out += string (buffer) + "\n";
-       }
-
-       delete[] buffer;
-       fclose (f);
-
-       return out;
-}
index 73a1aa582935a17939f606d4935be0c6881d763e..3efed667bd003e9eb1f2a15bd05696201b0c821b 100644 (file)
@@ -68,28 +68,4 @@ private:
        boost::signals2::scoped_connection _config_connection;
 };
 
-class FileLog : public Log
-{
-public:
-       FileLog (boost::filesystem::path file);
-
-       std::string head_and_tail (int amount = 1024) const;
-
-private:
-       void do_log (std::string m);
-       /** filename to write to */
-       boost::filesystem::path _file;
-};
-
-class NullLog : public Log
-{
-public:
-       std::string head_and_tail (int) const {
-               return "";
-       }
-
-private:
-       void do_log (std::string) {}
-};
-
 #endif
diff --git a/src/lib/null_log.h b/src/lib/null_log.h
new file mode 100644 (file)
index 0000000..304c5ec
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "log.h"
+
+class NullLog : public Log
+{
+public:
+       std::string head_and_tail (int) const {
+               return "";
+       }
+
+private:
+       void do_log (std::string) {}
+};
index 9cd8c47a22fe349688d104f39bfc677144ac8501..e79f11f771e478aa23ae0c057fe00d682b4de677 100644 (file)
@@ -55,6 +55,7 @@ sources = """
           examine_content_job.cc
           exceptions.cc
           file_group.cc
+          file_log.cc
           filter_graph.cc
           ffmpeg.cc
           ffmpeg_audio_stream.cc
index 237673179a87074e35d3697e2a8dabcdb639f010..81c553ef7c3094aa57761f3f289ee27132bdd749 100644 (file)
 
 */
 
-#include "lib/server.h"
-#include <iostream>
-#include <stdexcept>
-#include <cstring>
-#include <vector>
-#include <unistd.h>
-#include <errno.h>
-#include <getopt.h>
-#include <boost/array.hpp>
-#include <boost/asio.hpp>
-#include <boost/algorithm/string.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/condition.hpp>
 #include "lib/config.h"
 #include "lib/dcp_video.h"
 #include "lib/exceptions.h"
 #include "lib/util.h"
 #include "lib/config.h"
 #include "lib/image.h"
-#include "lib/log.h"
+#include "lib/file_log.h"
+#include "lib/null_log.h"
 #include "lib/version.h"
+#include "lib/server.h"
+#include <boost/array.hpp>
+#include <boost/asio.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
+#include <unistd.h>
+#include <errno.h>
+#include <getopt.h>
+#include <iostream>
+#include <stdexcept>
+#include <cstring>
+#include <vector>
 
 using std::cerr;
 using std::string;
index 201761ed5e927a81a2db5276438f1c5a736a1868..9e9a01694f43bc76e82e74546019c67e28c41896 100644 (file)
@@ -25,7 +25,7 @@
 #include "lib/dcp_video.h"
 #include "lib/decoder.h"
 #include "lib/exceptions.h"
-#include "lib/log.h"
+#include "lib/file_log.h"
 #include "lib/video_decoder.h"
 #include "lib/player.h"
 #include "lib/player_video.h"
index 89a8e82cc2a6c3463069ef2ec594003fbef521e2..22c0f7ea882833ca690984313eb606a9de52621d 100644 (file)
@@ -33,7 +33,7 @@
 #include "lib/raw_image_proxy.h"
 #include "lib/data.h"
 #include "lib/server_description.h"
-#include "lib/log.h"
+#include "lib/file_log.h"
 #include <boost/test/unit_test.hpp>
 #include <boost/thread.hpp>
 
@@ -216,4 +216,3 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv)
 
        delete server;
 }
-
index c81b7389c418dcc95a932445a23a849177a9530a..39536f1abfd4537fd3f323cc9ce99ba1c3e6a9c2 100644 (file)
  *  it probably should.
  */
 
-#include <vector>
-#include <boost/test/unit_test.hpp>
-#include <boost/filesystem.hpp>
 #include "lib/ffmpeg_content.h"
 #include "lib/ffmpeg_decoder.h"
-#include "lib/log.h"
+#include "lib/null_log.h"
 #include "lib/film.h"
 #include "test.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/filesystem.hpp>
+#include <vector>
 
 using std::cerr;
 using std::vector;
@@ -91,4 +91,3 @@ BOOST_AUTO_TEST_CASE (ffmpeg_decoder_seek_test)
 
        test ("prophet_clip.mkv", frames);
 }
-
index 601dd1c59db7b4137f121d4e0507561d1a8d3b9d..ce799bb24dc5c1175bf20497415ab3b965f3cff9 100644 (file)
  *  (dropped frames being checked by assert() in VideoDecoder).  Also that the decoder picks up frame rates correctly.
  */
 
-#include <boost/test/unit_test.hpp>
-#include <boost/filesystem.hpp>
 #include "lib/ffmpeg_content.h"
 #include "lib/ffmpeg_decoder.h"
-#include "lib/log.h"
+#include "lib/null_log.h"
 #include "lib/film.h"
 #include "test.h"
+#include <boost/filesystem.hpp>
+#include <boost/test/unit_test.hpp>
 
 using std::cout;
 using std::cerr;
@@ -78,4 +78,3 @@ BOOST_AUTO_TEST_CASE (ffmpeg_decoder_sequential_test)
        */
        test ("prophet_clip.mkv", 23.976, 12);
 }
-
index a587b87efa25c5e495f0436743ce8d93034cf2e3..29205e40033e27d76753819475354e16c4e3e630 100644 (file)
@@ -17,8 +17,8 @@
 
 */
 
+#include "lib/file_log.h"
 #include <boost/test/unit_test.hpp>
-#include "lib/log.h"
 
 using std::cout;