2 Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "analytics.h"
22 #include "exceptions.h"
23 #include <dcp/raw_convert.h>
24 #include <libcxml/cxml.h>
25 #include <libxml++/libxml++.h>
26 #include <boost/filesystem.hpp>
27 #include <boost/algorithm/string.hpp>
30 using dcp::raw_convert;
31 using boost::algorithm::trim;
33 Analytics* Analytics::_instance;
34 int const Analytics::_current_version = 1;
36 Analytics::Analytics ()
37 : _successful_dcp_encodes (0)
43 Analytics::successful_dcp_encode ()
45 ++_successful_dcp_encodes;
50 Analytics::write () const
53 xmlpp::Element* root = doc.create_root_node ("Analytics");
55 root->add_child("Version")->add_child_text(raw_convert<string>(_current_version));
56 root->add_child("SuccessfulDCPEncodes")->add_child_text(raw_convert<string>(_successful_dcp_encodes));
59 doc.write_to_file_formatted(path("analytics.xml").string());
60 } catch (xmlpp::exception& e) {
63 throw FileError (s, path("analytics.xml"));
71 cxml::Document f ("Analytics");
72 f.read_file (path("analytics.xml"));
73 _successful_dcp_encodes = f.number_child<int>("SuccessfulDCPEncodes");
79 Analytics::instance ()
82 _instance = new Analytics();