[gnome-dvb-daemon] Use new logging facility
- From: Sebastian Polsterl <sebp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-dvb-daemon] Use new logging facility
- Date: Tue, 19 Apr 2011 21:23:06 +0000 (UTC)
commit d50e9516b5ee90ae00f772a0a736a90739239489
Author: Sebastian Pölsterl <sebp k-d-w org>
Date: Tue Apr 19 23:08:16 2011 +0200
Use new logging facility
Removed trailing whitespaces
Makefile.am | 1 +
src/ChannelFactory.vala | 197 +++++++-------
src/ChannelList.vala | 9 +-
src/Device.vala | 10 +-
src/DeviceGroup.vala | 127 +++++----
src/EPGScanner.vala | 23 +-
src/Factory.vala | 9 +-
src/Logging.vala | 326 ++++++++++++++++++++++
src/Main.vala | 79 ++++--
src/Manager.vala | 164 ++++++------
src/Recorder.vala | 51 ++--
src/Recording.vala | 7 +-
src/RecordingsStore.vala | 9 +-
src/ScannedItem.vala | 5 +-
src/Scanner.vala | 55 ++--
src/Schedule.vala | 35 ++-
src/Settings.vala | 19 +-
src/Utils.vala | 26 +-
src/database/sqlite/SqliteConfigTimersStore.vala | 121 ++++----
src/database/sqlite/SqliteDatabase.vala | 15 +-
src/io/ChannelListReader.vala | 5 +-
src/io/RecordingReader.vala | 21 +-
src/io/RecordingWriter.vala | 7 +-
src/rtsp/MediaFactory.vala | 31 ++-
src/rtsp/Server.vala | 9 +-
src/rygel/Services2.vala | 10 +-
vapi/cutils.vapi | 3 -
27 files changed, 895 insertions(+), 479 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 941b262..39cec73 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -48,6 +48,7 @@ gnome_dvb_daemon_SOURCES = \
src/Event.vala \
src/EventStorage.vala \
src/Factory.vala \
+ src/Logging.vala \
src/Main.vala \
src/Manager.vala \
src/MpegTsEnums.vala \
diff --git a/src/ChannelFactory.vala b/src/ChannelFactory.vala
index 941f095..997afcc 100644
--- a/src/ChannelFactory.vala
+++ b/src/ChannelFactory.vala
@@ -19,6 +19,7 @@
using GLib;
using Gee;
using Gst;
+using DVB.Logging;
namespace DVB {
@@ -26,7 +27,7 @@ namespace DVB {
/**
* This class handles watching channels one physical device.
- *
+ *
* It's possible to watch multiple channels at the same time
* if they are all on the same transport stream.
*
@@ -34,7 +35,9 @@ namespace DVB {
* and forward EPG data to #EPGScanner.
*/
public class PlayerThread : GLib.Object {
-
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
private class ChannelElements {
public uint sid;
public ArrayList<Gst.Element> sinks;
@@ -43,11 +46,11 @@ namespace DVB {
public ForcedStopNotify notify_func;
}
- /**
+ /**
* Emitted when we came across EIT table
*/
public signal void eit_structure (Gst.Structure structure);
-
+
// List of channels that are currently in use
public HashSet<Channel> active_channels {get; construct;}
// The device in use
@@ -67,19 +70,19 @@ namespace DVB {
return val;
}
}
-
+
private Element? pipeline;
private HashMap<uint, ChannelElements> elements_map;
private EPGScanner? epgscanner;
private Element? dvbbasebin;
private bool destroyed;
-
+
construct {
this.elements_map = new HashMap<uint, ChannelElements> ();
this.active_channels = new HashSet<Channel> ();
this.destroyed = false;
}
-
+
/**
* @device: The device to use
* @epgscanner: #EPGScanner to forward EIT to
@@ -88,17 +91,17 @@ namespace DVB {
base (device: device);
this.epgscanner = epgscanner;
}
-
+
public Gst.Element? get_pipeline () {
return this.pipeline;
}
-
+
public Gst.Element? get_dvbbasebin () {
return this.dvbbasebin;
}
-
+
/**
- * @returns: GstBin containing queue and @sink_element
+ * @returns: GstBin containing queue and @sink_element
*
* Start watching @channel and link it with @sink_element
*/
@@ -112,47 +115,47 @@ namespace DVB {
lock (this.pipeline) {
if (this.pipeline == null) {
// New channel and new pipeline
- debug ("Creating new pipeline");
+ log.debug ("Creating new pipeline");
// Setup new pipeline
this.pipeline = new Pipeline ("recording");
-
+
Gst.Bus bus = this.pipeline.get_bus();
bus.add_signal_watch();
bus.message.connect (this.bus_watch_func);
-
+
this.dvbbasebin = ElementFactory.make ("dvbbasebin", null);
if (this.dvbbasebin == null) {
- critical ("Could not create dvbbasebin element");
+ log.error ("Could not create dvbbasebin element");
return null;
}
this.dvbbasebin.pad_added.connect (this.on_dvbbasebin_pad_added);
-
+
channel.setup_dvb_source (this.dvbbasebin);
-
+
this.dvbbasebin.set ("program-numbers", channel_sid_str);
this.dvbbasebin.set ("adapter", this.device.Adapter);
this.dvbbasebin.set ("frontend", this.device.Frontend);
-
- // don't use add_many because of problems with ownership transfer
+
+ // don't use add_many because of problems with ownership transfer
((Bin) this.pipeline).add (this.dvbbasebin);
-
+
tee = ElementFactory.make ("tee", null);
this.add_element (tee);
-
+
bin = this.add_sink_bin (sink_element);
if (!tee.link (bin)) {
- critical ("Could not link tee and bin");
+ log.error ("Could not link tee and bin");
return null;
}
-
+
create_channel = true;
-
+
} else {
// Use current pipeline and add new sink
- debug ("Reusing existing pipeline");
+ log.debug ("Reusing existing pipeline");
if (this.dvbbasebin == null) {
- critical ("No dvbbasebin element");
+ log.error ("No dvbbasebin element");
return null;
}
@@ -160,25 +163,25 @@ namespace DVB {
if (!this.active_channels.contains (channel)) {
// existing pipeline and new channel
-
+
tee = ElementFactory.make ("tee", null);
this.add_element (tee);
-
+
bin = this.add_sink_bin (sink_element);
if (!tee.link (bin)) {
- critical ("Could not link tee and bin");
+ log.error ("Could not link tee and bin");
return null;
}
string programs;
dvbbasebin.get ("program-numbers", out programs);
-
+
string new_programs = "%s:%s".printf (programs,
channel_sid_str);
- debug ("Changing program-numbers from %s to %s", programs,
+ log.debug ("Changing program-numbers from %s to %s", programs,
new_programs);
this.dvbbasebin.set ("program-numbers", new_programs);
-
+
create_channel = true;
} else { // existing pipeline and existing channel
@@ -188,11 +191,11 @@ namespace DVB {
tee = c_element.tee;
- bin = this.add_sink_bin (sink_element);
+ bin = this.add_sink_bin (sink_element);
- debug ("Linking %s with %s", tee.get_name (), bin.get_name ());
+ log.debug ("Linking %s with %s", tee.get_name (), bin.get_name ());
if (!tee.link (bin)) {
- critical ("Could not link tee and bin");
+ log.error ("Could not link tee and bin");
return null;
}
@@ -201,7 +204,7 @@ namespace DVB {
create_channel = false;
}
}
-
+
if (create_channel) {
ChannelElements celems = new ChannelElements ();
celems.sid = channel_sid;
@@ -216,33 +219,33 @@ namespace DVB {
}
this.active_channels.add (channel);
}
-
+
return bin;
}
}
-
+
private Gst.Element add_sink_bin (Gst.Element sink_element) {
Element queue = ElementFactory.make ("queue", null);
queue.set ("max-size-buffers", 0);
-
+
Gst.Element bin = new Gst.Bin (null);
((Gst.Bin)bin).add_many (queue, sink_element);
if (!queue.link (sink_element)) {
- critical ("Could not link elements %s and %s", queue.get_name (),
+ log.error ("Could not link elements %s and %s", queue.get_name (),
sink_element.get_name ());
}
-
+
var pad = queue.get_static_pad ("sink");
var ghost = new Gst.GhostPad ("sink", pad);
ghost.set_active (true);
bin.add_pad (ghost);
/* src pad is ghosted by gst-rtsp-server */
-
+
this.add_element (bin);
return bin;
}
-
+
private static int find_element (void* av, void *bv) {
Gst.Element a = (Gst.Element)av;
Gst.Element b = (Gst.Element)bv;
@@ -258,7 +261,7 @@ namespace DVB {
public Gst.Element? get_sink_bin (uint sid, Gst.Element sink) {
Gst.Element? result = null;
- debug ("Searching for sink %s (%p) of channel %u", sink.get_name (), sink, sid);
+ log.debug ("Searching for sink %s (%p) of channel %u", sink.get_name (), sink, sid);
lock (this.elements_map) {
ChannelElements? celems = this.elements_map.get (sid);
if (celems != null) {
@@ -275,12 +278,12 @@ namespace DVB {
}
}
if (result == null)
- debug ("Found NO sink");
+ log.debug ("Found NO sink");
else
- debug ("Found sink");
+ log.debug ("Found sink");
return result;
}
-
+
/**
* Stop watching @channel
*/
@@ -288,7 +291,7 @@ namespace DVB {
uint channel_sid = channel.Sid;
if (!this.active_channels.contains (channel)) {
- critical ("Could not find channel with SID %u", channel_sid);
+ log.error ("Could not find channel with SID %u", channel_sid);
return false;
}
@@ -307,10 +310,10 @@ namespace DVB {
lock (this.pipeline) {
// Check if that's the only channel in use
if (this.active_channels.size > 1) {
-
+
if (stop_channel) {
string channel_sid_string = channel_sid.to_string ();
-
+
string programs;
dvbbasebin.get ("program-numbers", out programs);
string[] programs_arr = programs.split (":");
@@ -327,7 +330,7 @@ namespace DVB {
new_programs.append (":" + new_programs_list.get (i));
}
- debug ("Changing program-numbers from %s to %s", programs,
+ log.debug ("Changing program-numbers from %s to %s", programs,
new_programs.str);
this.pipeline.set_state (State.PAUSED);
@@ -340,9 +343,9 @@ namespace DVB {
this.remove_sink_bin (channel_sid, sink);
- if (stop_channel) {
+ if (stop_channel) {
/* No one watches the channel anymore */
- debug ("Removing tee %s from pipeline",
+ log.debug ("Removing tee %s from pipeline",
celements.tee.get_name ());
celements.tee.set_state (State.NULL);
((Bin)this.pipeline).remove (celements.tee);
@@ -373,21 +376,21 @@ namespace DVB {
private bool set_playing_or_destroy () {
Gst.StateChangeReturn ret = this.pipeline.set_state (State.PLAYING);
if (ret == Gst.StateChangeReturn.FAILURE) {
- critical ("Failed setting pipeline to playing");
+ log.error ("Failed setting pipeline to playing");
this.destroy ();
return false;
}
return true;
}
-
+
private void remove_sink_bin (uint channel_sid, Gst.Element sink) {
- debug ("Removing sink bin of sink %s (%p) of channel %u",
+ log.debug ("Removing sink bin of sink %s (%p) of channel %u",
sink.get_name (), sink, channel_sid);
-
+
Gst.Element? sink_bin = this.get_sink_bin (channel_sid, sink);
if (sink_bin == null) {
- critical ("Could not find sink bin for channel %u and sink %s (%p)",
+ log.error ("Could not find sink bin for channel %u and sink %s (%p)",
channel_sid, sink.get_name (), sink);
return;
}
@@ -395,21 +398,21 @@ namespace DVB {
lock (this.elements_map) {
ChannelElements celems = this.elements_map.get (channel_sid);
- debug ("Setting state of queue and sink %s (%p) to NULL",
+ log.debug ("Setting state of queue and sink %s (%p) to NULL",
sink.get_name (), sink);
celems.tee.unlink (sink_bin);
sink_bin.set_state (State.NULL);
-
+
if (!celems.sinks.remove (sink_bin)) {
- critical ("Could not find sink bin %s (%p)",
+ log.error ("Could not find sink bin %s (%p)",
sink_bin.get_name (), sink_bin);
}
}
- debug ("Removing queue and sink from pipeline");
+ log.debug ("Removing queue and sink from pipeline");
((Bin)this.pipeline).remove (sink_bin);
}
-
+
/**
* Stop pipeline and clean up everything else
*/
@@ -431,7 +434,7 @@ namespace DVB {
lock (this.pipeline) {
if (this.pipeline != null) {
- debug ("Stopping pipeline");
+ log.debug ("Stopping pipeline");
Gst.Bus bus = this.pipeline.get_bus ();
bus.remove_signal_watch ();
this.pipeline.set_state (State.NULL);
@@ -448,51 +451,51 @@ namespace DVB {
private bool add_element (owned Gst.Element elem) {
string elem_name = elem.get_name ();
if (!((Bin) this.pipeline).add (elem)) {
- critical ("Could not add element %s", elem_name);
+ log.error ("Could not add element %s", elem_name);
return false;
}
- debug ("Element %s (%p) added to pipeline", elem_name, elem);
+ log.debug ("Element %s (%p) added to pipeline", elem_name, elem);
return true;
}
-
+
/**
* Link program_%d pad with tee
*/
private void on_dvbbasebin_pad_added (Gst.Element elem, Gst.Pad pad) {
string pad_name = pad.get_name();
- debug ("Pad %s added", pad_name);
-
+ log.debug ("Pad %s added", pad_name);
+
if (!pad_name.has_prefix ("program_"))
return;
-
+
uint sid;
pad_name.scanf("program_%u", out sid);
-
- debug ("SID is '%u'", sid);
+
+ log.debug ("SID is '%u'", sid);
// Check if we're interested in the pad
lock (this.elements_map) {
if (this.elements_map.has_key (sid)) {
Element? sink = this.elements_map.get (sid).tee;
if (sink == null) {
- critical ("Could not find sink for SID %u", sid);
+ log.error ("Could not find sink for SID %u", sid);
return;
}
-
- debug ("Linking elements %s and %s", elem.get_name(), sink.get_name ());
+
+ log.debug ("Linking elements %s and %s", elem.get_name(), sink.get_name ());
Pad sinkpad = sink.get_static_pad ("sink");
-
+
PadLinkReturn rc = pad.link (sinkpad);
if (rc != PadLinkReturn.OK) {
- critical ("Could not link pads %s and %s", pad.get_name (),
+ log.error ("Could not link pads %s and %s", pad.get_name (),
sinkpad.get_name ());
} else {
- debug ("Src pad %s linked with sink pad %s",
+ log.debug ("Src pad %s linked with sink pad %s",
pad.get_name (), sinkpad.get_name ());
}
}
}
}
-
+
/**
* Forward EIT structure
*/
@@ -511,7 +514,7 @@ namespace DVB {
warning ("%s", structure.to_string ());
break;
case Gst.MessageType.ERROR:
- critical ("%s", structure.to_string ());
+ log.error ("%s", structure.to_string ());
break;
default:
break;
@@ -523,18 +526,20 @@ namespace DVB {
* This class handles watching channels for a single #DeviceGroup
*/
public class ChannelFactory : GLib.Object {
-
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
// The device group the factory belongs to
public unowned DeviceGroup device_group {get; construct;}
-
+
// List of players that are currently in use
private HashSet<PlayerThread> active_players;
-
+
public ChannelFactory (DeviceGroup devgroup) {
base (device_group: devgroup);
this.active_players = new HashSet<PlayerThread> ();
}
-
+
/**
* Stop all currently active players
*/
@@ -560,8 +565,8 @@ namespace DVB {
*/
public PlayerThread? watch_channel (Channel channel, owned Gst.Element sink_element,
bool force=false, ForcedStopNotify? notify_func = null) {
- debug ("Watching channel %s (%u)", channel.Name, channel.Sid);
-
+ log.debug ("Watching channel %s (%u)", channel.Name, channel.Sid);
+
bool create_new = true;
PlayerThread? player = null;
DVB.Device? free_device = null;
@@ -576,8 +581,8 @@ namespace DVB {
}
}
}
-
- debug ("Creating new PlayerThread: %s", create_new.to_string ());
+
+ log.debug ("Creating new PlayerThread: %s", create_new.to_string ());
if (create_new) {
// Stop epgscanner before starting recording
this.device_group.stop_epg_scanner ();
@@ -591,14 +596,14 @@ namespace DVB {
active_player.destroy (true);
break;
} else {
- critical ("No active players that are not forced");
+ log.error ("No active players that are not forced");
}
}
}
free_device = this.device_group.get_next_free_device ();
}
if (free_device == null) {
- message ("All devices are busy");
+ log.info ("All devices are busy");
return null;
}
@@ -612,14 +617,14 @@ namespace DVB {
return player;
}
-
+
/**
* @returns: TRUE on success
*
* Stop watching @channel
*/
public bool stop_channel (Channel channel, Gst.Element sink) {
- debug ("Stopping channel %s (%u)", channel.Name, channel.Sid);
+ log.debug ("Stopping channel %s (%u)", channel.Name, channel.Sid);
bool success = false;
PlayerThread? player = null;
@@ -631,10 +636,10 @@ namespace DVB {
break;
}
}
-
+
if (success && player.active_channels.size == 0)
this.active_players.remove (player);
-
+
if (this.active_players.size == 0) {
// Start EPG scanner again
this.device_group.start_epg_scanner ();
@@ -643,14 +648,14 @@ namespace DVB {
return success;
}
-
+
/**
* @returns: a new #PlayerThread instance for @device
*/
public virtual PlayerThread create_player (Device device) {
return new PlayerThread (device, this.device_group.epgscanner);
}
-
+
}
}
diff --git a/src/ChannelList.vala b/src/ChannelList.vala
index abbf1bb..e523643 100644
--- a/src/ChannelList.vala
+++ b/src/ChannelList.vala
@@ -21,10 +21,13 @@ using GLib;
using Gee;
using DVB.database;
using DVB.database.sqlite;
+using DVB.Logging;
namespace DVB {
public class ChannelList : GLib.Object, Iterable<Channel>, IDBusChannelList {
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
public File? channels_file {get; construct;}
public uint GroupId {get; set;}
@@ -273,7 +276,7 @@ namespace DVB {
channels = config.get_channels_of_group (this.GroupId,
channel_group_id);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return false;
}
@@ -302,7 +305,7 @@ namespace DVB {
try {
ret = config.add_channel_to_group (chan, channel_group_id);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
ret = false;
}
return ret;
@@ -325,7 +328,7 @@ namespace DVB {
try {
ret = config.remove_channel_from_group (chan, channel_group_id);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
ret = false;
}
return ret;
diff --git a/src/Device.vala b/src/Device.vala
index af7e7b6..aeb999b 100644
--- a/src/Device.vala
+++ b/src/Device.vala
@@ -19,6 +19,8 @@
using GLib;
using Gst;
+using DVB.Logging;
+
namespace DVB {
public errordomain DeviceError {
@@ -33,6 +35,8 @@ namespace DVB {
}
public class Device : GLib.Object {
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
private static const int PRIME = 31;
@@ -103,7 +107,7 @@ namespace DVB {
public bool is_busy () {
Element dvbsrc = ElementFactory.make ("dvbsrc", "text_dvbsrc");
if (dvbsrc == null) {
- critical ("Could not create dvbsrc element");
+ log.error ("Could not create dvbsrc element");
return true;
}
dvbsrc.set ("adapter", this.Adapter);
@@ -125,7 +129,7 @@ namespace DVB {
string debug_text;
msg.parse_error (out gerror, out debug_text);
- debug ("Error tuning: %s; %s", gerror.message, debug_text);
+ log.debug ("Error tuning: %s; %s", gerror.message, debug_text);
busy_val = true;
}
@@ -139,7 +143,7 @@ namespace DVB {
private bool setAdapterTypeAndName (uint adapter, uint frontend) {
Element dvbsrc = ElementFactory.make ("dvbsrc", "test_dvbsrc");
if (dvbsrc == null) {
- critical ("Could not create dvbsrc element");
+ log.error ("Could not create dvbsrc element");
return false;
}
dvbsrc.set ("adapter", adapter);
diff --git a/src/DeviceGroup.vala b/src/DeviceGroup.vala
index 01dddd6..0fdcb62 100644
--- a/src/DeviceGroup.vala
+++ b/src/DeviceGroup.vala
@@ -20,6 +20,7 @@
using GLib;
using Gee;
using DVB.database;
+using DVB.Logging;
namespace DVB {
@@ -28,7 +29,9 @@ namespace DVB {
* (list of channels, recordings dir)
*/
public class DeviceGroup : GLib.Object, IDBusDeviceGroup, Iterable<Device> {
-
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
public int size {
get { return this.devices.size; }
}
@@ -56,21 +59,21 @@ namespace DVB {
get { return this._channelfactory; }
}
public string Name {get; set;}
-
+
// All settings are copied from this one
public Device reference_device {
get;
construct set;
}
-
+
private Set<Device> devices;
private Recorder _recorder;
private EPGScanner? _epgscanner;
private ChannelFactory _channelfactory;
-
- // Containss object paths to Schedule
+
+ // Containss object paths to Schedule
private HashSet<string> schedules;
-
+
construct {
this.devices = new HashSet<Device> (Device.hash, Device.equal);
this.schedules = new HashSet<string> (GLib.str_hash,
@@ -79,7 +82,7 @@ namespace DVB {
this._channelfactory = new ChannelFactory (this);
this._recorder = new Recorder (this);
}
-
+
/**
* @id: ID of group
* @reference_device: All devices of this group will inherit
@@ -101,7 +104,7 @@ namespace DVB {
}
public void destroy () {
- debug ("Destroying group %u", this.Id);
+ log.debug ("Destroying group %u", this.Id);
this.stop_epg_scanner ();
this._recorder.stop ();
this._channelfactory.destroy ();
@@ -120,7 +123,7 @@ namespace DVB {
if (this._epgscanner != null)
this._epgscanner.stop ();
}
-
+
/**
* @adapter: Number of the device's adapter
* @frontend: Number of the device's frontend
@@ -133,7 +136,7 @@ namespace DVB {
Device new_dev = Device.new_with_type (adapter, frontend);
this.add (new_dev);
}
-
+
/**
* Add device to group. The device's settings will be overridden
* with those of the reference device.
@@ -143,13 +146,13 @@ namespace DVB {
warning ("Cannot add device, because it is not of same type");
return false;
}
-
+
bool result;
lock (this.devices) {
// Set settings from reference device
device.Channels = this.reference_device.Channels;
device.RecordingsDirectory = this.reference_device.RecordingsDirectory;
-
+
result = this.devices.add (device);
}
return result;
@@ -162,7 +165,7 @@ namespace DVB {
}
return false;
}
-
+
public bool contains (Device device) {
bool result;
lock (this.devices) {
@@ -170,14 +173,14 @@ namespace DVB {
}
return result;
}
-
+
public bool remove (Device device) {
bool result;
lock (this.devices) {
result = this.devices.remove (device);
if (Device.equal (device, this.reference_device)) {
foreach (Device dev in this.devices) {
- debug ("Assigning new reference device");
+ log.debug ("Assigning new reference device");
this.reference_device = dev;
break;
}
@@ -193,7 +196,7 @@ namespace DVB {
}
return false;
}
-
+
/**
* Get first device that isn't busy.
* If all devices are busy NULL is returned.
@@ -208,10 +211,10 @@ namespace DVB {
}
}
}
-
+
return result;
}
-
+
/**
* @returns: Name of adapter type the group holds
* or an empty string when group with given id doesn't exist.
@@ -226,7 +229,7 @@ namespace DVB {
}
return type_str;
}
-
+
/**
* @adapter: Number of the device's adapter
* @frontend: Number of the device's frontend
@@ -241,18 +244,18 @@ namespace DVB {
// might see some errors if the device is
// currently in use
Device device = Device.new_with_type (adapter, frontend);
-
+
if (device == null) return false;
-
+
Manager manager = Manager.get_instance ();
if (manager.device_is_in_any_group (device)) {
- debug ("Device with adapter %u, frontend %u is" +
+ log.debug ("Device with adapter %u, frontend %u is" +
"already part of a group", adapter, frontend);
return false;
}
-
+
uint group_id = this.Id;
- debug ("Adding device with adapter %u, frontend %u to group %u",
+ log.debug ("Adding device with adapter %u, frontend %u to group %u",
adapter, frontend, group_id);
if (this.add (device)) {
@@ -260,32 +263,32 @@ namespace DVB {
Factory.get_config_store ().add_device_to_group (device,
this);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return false;
}
-
+
this.device_added (adapter, frontend);
-
+
return true;
}
-
+
return false;
}
-
+
/**
* @returns: Object path of the device's recorder
- *
+ *
* Returns the object path to the device's recorder.
*/
public ObjectPath GetRecorder () throws DBusError {
return new ObjectPath (
Constants.DBUS_RECORDER_PATH.printf (this.Id));
- }
-
+ }
+
protected bool register_recorder () {
- debug ("Creating new Recorder D-Bus service for group %u",
+ log.debug ("Creating new Recorder D-Bus service for group %u",
this.Id);
-
+
Recorder recorder = this.recorder;
string path = Constants.DBUS_RECORDER_PATH.printf (this.Id);
@@ -294,7 +297,7 @@ namespace DVB {
return true;
}
-
+
/**
* @adapter: Number of the device's adapter
* @frontend: Number of the device's frontend
@@ -305,7 +308,7 @@ namespace DVB {
*/
public bool RemoveDevice (uint adapter, uint frontend) throws DBusError {
Device dev = new Device (adapter, frontend);
-
+
if (this.contains (dev)) {
if (this.remove (dev)) {
// Stop epgscanner, because it might use the
@@ -316,7 +319,7 @@ namespace DVB {
Factory.get_config_store ().remove_device_from_group (
dev, this);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return false;
}
// Group has no devices anymore, delete it
@@ -326,21 +329,21 @@ namespace DVB {
}
this.device_removed (adapter, frontend);
-
+
return true;
}
}
-
+
return false;
}
-
+
/**
* @returns: Name of the device group
*/
public string GetName () throws DBusError {
return this.Name;
}
-
+
/**
* @name: Name of the group
* @returns: TRUE on success
@@ -351,12 +354,12 @@ namespace DVB {
ConfigStore config = Factory.get_config_store();
config.update_from_group (this);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return false;
}
return true;
}
-
+
/**
* @returns: Object path to the ChannelList service for this device
*/
@@ -364,27 +367,27 @@ namespace DVB {
return new ObjectPath (
Constants.DBUS_CHANNEL_LIST_PATH.printf (this.Id));
}
-
+
protected bool register_channel_list () {
- debug ("Creating new ChannelList D-Bus service for group %u",
+ log.debug ("Creating new ChannelList D-Bus service for group %u",
this.Id);
-
+
ChannelList channels = this.Channels;
string path = Constants.DBUS_CHANNEL_LIST_PATH.printf (this.Id);
Utils.dbus_register_object<IDBusChannelList> (Main.conn,
path, channels);
-
+
return true;
}
-
+
/**
* @returns: List of paths to the devices that are part of
* the group (e.g. /dev/dvb/adapter0/frontend0)
*/
public string[] GetMembers () throws DBusError {
string[] groupdevs = new string[this.size];
-
+
int i=0;
lock (this.devices) {
foreach (Device dev in this.devices) {
@@ -393,7 +396,7 @@ namespace DVB {
i++;
}
}
-
+
return groupdevs;
}
/**
@@ -404,21 +407,21 @@ namespace DVB {
public bool GetSchedule (uint channel_sid, out ObjectPath opath) throws DBusError {
if (this.Channels.contains (channel_sid)) {
string path = Constants.DBUS_SCHEDULE_PATH.printf (this.Id, channel_sid);
-
+
if (!this.schedules.contains (path)) {
Schedule schedule = this.Channels.get_channel (
channel_sid).Schedule;
-
+
Utils.dbus_register_object<IDBusSchedule> (Main.conn,
path, schedule);
-
+
this.schedules.add (path);
}
-
+
opath = new ObjectPath (path);
return true;
}
-
+
opath = new ObjectPath ("");
return false;
}
@@ -429,7 +432,7 @@ namespace DVB {
public string GetRecordingsDirectory () throws DBusError {
return this.RecordingsDirectory.get_path ();
}
-
+
/**
* @location: Location of the recordings directory
* @returns: TRUE on success
@@ -440,18 +443,18 @@ namespace DVB {
ConfigStore config = Factory.get_config_store();
config.update_from_group (this);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return false;
}
return true;
}
-
+
public Type element_type { get { return typeof (Device); } }
-
+
public Iterator<Device> iterator () {
return this.devices.iterator();
}
-
+
/**
* Set RecordingsDirectory property of all
* devices to the values of the reference device
@@ -465,7 +468,7 @@ namespace DVB {
}
}
}
-
+
}
-
+
}
diff --git a/src/EPGScanner.vala b/src/EPGScanner.vala
index 9522d24..ab8934d 100644
--- a/src/EPGScanner.vala
+++ b/src/EPGScanner.vala
@@ -19,10 +19,13 @@
using GLib;
using Gee;
+using DVB.Logging;
namespace DVB {
public class EPGScanner : GLib.Object {
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
// how long to wait after all channels have been scanned
// before the next iteration is started
@@ -69,7 +72,7 @@ namespace DVB {
* Stop collecting EPG data
*/
public void stop () {
- debug ("Stopping EPG scan for group %u (%d)", this.DeviceGroup.Id, this.stop_counter);
+ log.debug ("Stopping EPG scan for group %u (%d)", this.DeviceGroup.Id, this.stop_counter);
if (this.stop_counter == 0) {
this.remove_timeouts ();
@@ -131,13 +134,13 @@ namespace DVB {
* Start collection EPG data for all channels
*/
public bool start () {
- debug ("Starting EPG scan for group %u (%d)", this.DeviceGroup.Id, this.stop_counter);
+ log.debug ("Starting EPG scan for group %u (%d)", this.DeviceGroup.Id, this.stop_counter);
this.loop = new MainLoop (this.context, false);
try {
this.worker_thread = Thread.create<bool> (this.worker, true);
} catch (ThreadError e) {
- critical ("Could not create thread: %s", e.message);
+ log.error ("Could not create thread: %s", e.message);
return false;
}
@@ -157,7 +160,7 @@ namespace DVB {
this.pipeline = Gst.parse_launch (PIPELINE_TEMPLATE.printf (
device.Adapter, device.Frontend));
} catch (Error e) {
- critical ("Could not create pipeline: %s", e.message);
+ log.error ("Could not create pipeline: %s", e.message);
return false;
}
@@ -186,7 +189,7 @@ namespace DVB {
}
HashSet<Event> list = this.channel_events.get (sid);
- debug ("Adding %d events of channel %s (%u)",
+ log.debug ("Adding %d events of channel %s (%u)",
list.size, channel.Name, sid);
channel.Schedule.add_all (list);
}
@@ -194,7 +197,7 @@ namespace DVB {
}
if (this.channels.is_empty ()) {
- debug ("Finished EPG scan for group %u", this.DeviceGroup.Id);
+ log.debug ("Finished EPG scan for group %u", this.DeviceGroup.Id);
this.reset ();
// Time the next iteration
@@ -207,7 +210,7 @@ namespace DVB {
Channel channel = this.channels.pop_head ();
channel.Schedule.remove_expired_events ();
/*
- debug ("Scanning channel %s (%u left)",
+ log.debug ("Scanning channel %s (%u left)",
channel.Name, this.channels.get_length ());
*/
lock (this.pipeline) {
@@ -226,7 +229,7 @@ namespace DVB {
case Gst.MessageType.ELEMENT:
Gst.Structure structure = message.get_structure ();
if (structure.get_name() == "dvb-read-failure") {
- critical ("Could not read from DVB device");
+ log.error ("Could not read from DVB device");
this.stop ();
} else if (structure.get_name() == "eit") {
this.on_eit_structure (structure);
@@ -237,7 +240,7 @@ namespace DVB {
Error gerror;
string debug;
message.parse_error (out gerror, out debug);
- critical ("%s %s", gerror.message, debug);
+ log.error ("%s %s", gerror.message, debug);
this.stop ();
return false;
@@ -292,7 +295,7 @@ namespace DVB {
Gst.Value components = event.get_value ("components");
add_components (components, event_class);
*/
- //debug ("Adding new event: %s", event_class.to_string ());
+ //log.debug ("Adding new event: %s", event_class.to_string ());
uint sid = get_uint_val (structure, "service-id");
if (!this.channel_events.has_key (sid)) {
diff --git a/src/Factory.vala b/src/Factory.vala
index 0142270..eec87a0 100644
--- a/src/Factory.vala
+++ b/src/Factory.vala
@@ -20,12 +20,15 @@
using GLib;
using DVB.database;
using DVB.database.sqlite;
+using DVB.Logging;
namespace DVB {
[Compact]
public class Factory {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
private static SqliteConfigTimersStore store;
private static StaticRecMutex store_mutex = StaticRecMutex ();
private static SqliteEPGStore epgstore;
@@ -40,7 +43,7 @@ namespace DVB {
try {
store.open ();
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
store = null;
}
}
@@ -55,7 +58,7 @@ namespace DVB {
try {
store.open ();
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
store = null;
}
}
@@ -70,7 +73,7 @@ namespace DVB {
try {
epgstore.open ();
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
epgstore = null;
}
}
diff --git a/src/Logging.vala b/src/Logging.vala
new file mode 100644
index 0000000..d2a35e3
--- /dev/null
+++ b/src/Logging.vala
@@ -0,0 +1,326 @@
+/*
+ * Copyright (C) 2011 Sebastian Pölsterl
+ *
+ * This file is part of GNOME DVB Daemon.
+ *
+ * GNOME DVB Daemon 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME DVB Daemon 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 GNOME DVB Daemon. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using GLib;
+
+namespace DVB.Logging {
+
+public enum LogLevel {
+ LOG,
+ DEBUG,
+ INFO,
+ WARNING,
+ ERROR
+}
+
+public interface Formatter : GLib.Object {
+
+ public abstract string format (string logger_name, LogLevel level, string format);
+
+}
+
+public interface Handler : GLib.Object {
+
+ public abstract Formatter formatter {get; set;}
+ public abstract LogLevel threshold {get; set;}
+
+ public abstract void publish (string logger_name, LogLevel level, string format, va_list args);
+ public abstract void close ();
+
+}
+
+public class DefaultFormatter : GLib.Object, Formatter {
+
+ protected virtual string get_level_name (LogLevel level) {
+ string lvlstr = null;
+ switch (level) {
+ case LogLevel.LOG: lvlstr = "LOG"; break;
+ case LogLevel.DEBUG: lvlstr = "DEBUG"; break;
+ case LogLevel.INFO: lvlstr = "INFO"; break;
+ case LogLevel.WARNING: lvlstr = "WARNING"; break;
+ case LogLevel.ERROR: lvlstr = "ERROR"; break;
+ default: assert_not_reached ();
+ }
+ return lvlstr;
+ }
+
+ public virtual string format (string logger_name, LogLevel level, string format) {
+ string lvlstr = this.get_level_name (level);
+
+ string msg = "%-12s %-12s %s\n".printf (logger_name, lvlstr, format);
+ return msg;
+ }
+
+}
+
+public class ColorFormatter : DefaultFormatter {
+
+ static string[] colormap = new string[] {
+ "\033[37m", /* LOG */
+ "\033[36m", /* DEBUG */
+ "\033[32;01m", /* INFO */
+ "\033[33;01m", /* WARNING */
+ "\033[31;01m" /* ERROR */
+ };
+ static const string clear = "\033[00m";
+
+ protected override string get_level_name (LogLevel level) {
+ string lvlstr = base.get_level_name (level);
+ return "%s%s%s".printf (colormap[level], lvlstr, clear);
+ }
+
+ public override string format (string logger_name, LogLevel level, string format) {
+ string lvlstr = this.get_level_name (level);
+
+ string msg;
+ if (level < LogLevel.INFO)
+ msg = "%-12s %-20s %s\n".printf (logger_name, lvlstr, format);
+ else
+ msg = "%-12s %-23s %s\n".printf (logger_name, lvlstr, format);
+ return msg;
+ }
+
+}
+
+public class ConsoleHandler : GLib.Object, Handler {
+
+ public Formatter formatter {get; set; default = new DefaultFormatter ();}
+ public LogLevel threshold {get; set; default = LogLevel.LOG;}
+
+ public void publish (string logger_name, LogLevel level, string format, va_list args) {
+ if (level < threshold)
+ return;
+
+ string msg = formatter.format (logger_name, level, format);
+ if (level > LogLevel.INFO)
+ stderr.vprintf (msg, args);
+ else
+ stdout.vprintf (msg, args);
+ }
+
+ public void close () { }
+
+}
+
+public class FileHandler : GLib.Object, Handler {
+
+ public Formatter formatter {get; set; default = new DefaultFormatter ();}
+ public LogLevel threshold {get; set; default = LogLevel.LOG;}
+ public int limit {get; set; default = 0;}
+ public int count {get; set; default = 1;}
+ public string pattern {get; construct;}
+
+ private OutputStream os;
+ private int file_size;
+ private int file_index;
+
+ public FileHandler (string file_pattern) throws Error {
+ GLib.Object (pattern: file_pattern);
+
+ this.file_index = 0;
+ this.rotate ();
+ }
+
+ public void publish (string logger_name, LogLevel level, string format, va_list args) {
+ if (level < threshold)
+ return;
+
+ string msg = formatter.format (logger_name, level, format);
+ string txt = msg.vprintf (args);
+
+ try {
+ if (limit > 0) {
+ file_size += txt.length;
+ if (file_size > limit) {
+ this.rotate ();
+ }
+ }
+
+ os.write (txt.data);
+ } catch (Error e) {
+ stderr.printf ("Error in FileHandler.publish: %s\n", e.message);
+ }
+ }
+
+ public void close () {
+ try {
+ os.close ();
+ } catch (IOError e) {
+ stderr.printf ("Error in FileHandler.close: %s\n", e.message);
+ }
+ }
+
+ private void rotate () throws Error {
+ if (this.os != null)
+ this.close ();
+
+ File file = this.get_next_file ();
+
+ FileOutputStream fos;
+ if (file.query_exists (null)) {
+ fos = file.replace (null, false, FileCreateFlags.NONE, null);
+ } else {
+ fos = file.create (FileCreateFlags.NONE, null);
+ }
+ this.os = new BufferedOutputStream (fos);
+ this.file_size = 0;
+ }
+
+ private File get_next_file () {
+ if (this.file_index == this.count) {
+ this.file_index = 0;
+ }
+
+ string filename = this.pattern.printf (this.file_index++);
+ return File.new_for_path (filename);
+ }
+
+}
+
+public class Logger : GLib.Object {
+
+ public string name {get; set;}
+ private Gee.HashSet<Handler> handlers;
+
+ construct {
+ this.handlers = new Gee.HashSet<Handler> (GLib.direct_hash, GLib.direct_equal);
+ }
+
+ public void addHandler (Handler handler) {
+ lock (this.handlers) {
+ this.handlers.add (handler);
+ }
+ }
+
+ public void removeHandler (Handler handler) {
+ lock (this.handlers) {
+ this.handlers.remove (handler);
+ }
+ }
+
+ public Gee.HashSet<Handler> getHandlers () {
+ return this.handlers;
+ }
+
+ private inline void log_full (LogLevel level, string format, va_list args) {
+ lock (this.handlers) {
+ foreach (Handler handler in this.handlers) {
+ var l = args.copy (args);
+ handler.publish (this.name, level, format, l);
+ }
+ }
+ }
+
+ [Diagnostics]
+ [PrintfFormat]
+ public void log (string format, ...) {
+ var l = va_list ();
+ this.log_full (LogLevel.LOG, format, l);
+ }
+
+ [Diagnostics]
+ [PrintfFormat]
+ public void debug (string format, ...) {
+ var l = va_list ();
+ this.log_full (LogLevel.DEBUG, format, l);
+ }
+
+ [Diagnostics]
+ [PrintfFormat]
+ public void info (string format, ...) {
+ var l = va_list ();
+ this.log_full (LogLevel.INFO, format, l);
+ }
+
+ [Diagnostics]
+ [PrintfFormat]
+ public void warning (string format, ...) {
+ var l = va_list ();
+ this.log_full (LogLevel.WARNING, format, l);
+ }
+
+ [Diagnostics]
+ [PrintfFormat]
+ public void error (string format, ...) {
+ var l = va_list ();
+ this.log_full (LogLevel.ERROR, format, l);
+ }
+
+}
+
+public class LogManager : GLib.Object {
+
+ private static const string DEFAULT_NAME = "default";
+
+ private static LogManager instance;
+ private static StaticRecMutex instance_mutex = StaticRecMutex ();
+
+ private Gee.HashMap<string, Logger> loggers;
+
+ construct {
+ this.loggers = new Gee.HashMap<string, Logger> (GLib.str_hash,
+ GLib.str_equal, GLib.direct_equal);
+ }
+
+ public static unowned LogManager getLogManager () {
+ instance_mutex.lock ();
+ if (instance == null) {
+ instance = new LogManager ();
+ }
+ instance_mutex.unlock ();
+ return instance;
+ }
+
+ public Logger getDefaultLogger () {
+ return this.getLogger (DEFAULT_NAME);
+ }
+
+ public Logger getLogger (string name) {
+ Logger l;
+ lock (this.loggers) {
+ if (this.loggers.has_key (name)) {
+ l = this.loggers.get (name);
+ } else {
+ l = createLogger (name);
+ }
+ }
+ return l;
+ }
+
+ private Logger createLogger (string name) {
+ Logger l = new Logger ();
+ l.name = name;
+ this.loggers.set (name, l);
+ return l;
+ }
+
+ public void cleanup () {
+ lock (this.loggers) {
+ foreach (Logger logger in this.loggers.values) {
+ foreach (Handler handler in logger.getHandlers ()) {
+ handler.close ();
+ }
+ }
+ this.loggers.clear ();
+ }
+ }
+
+}
+
+}
diff --git a/src/Main.vala b/src/Main.vala
index ce9f1f2..034c075 100644
--- a/src/Main.vala
+++ b/src/Main.vala
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008,2009 Sebastian Pölsterl
+ * Copyright (C) 2008-2011 Sebastian Pölsterl
*
* This file is part of GNOME DVB Daemon.
*
@@ -28,6 +28,7 @@ namespace Main {
private static bool disable_epg_scanner;
private static bool disable_mediaserver;
private static MainLoop mainloop;
+ public static DVB.Logging.Logger log;
public static DBusConnection conn;
const OptionEntry[] options = {
@@ -59,7 +60,7 @@ namespace Main {
}
private static void start_recordings_store () {
- message ("Creating new RecordingsStore D-Bus service");
+ log.info ("Creating new RecordingsStore D-Bus service");
recstore = DVB.RecordingsStore.get_instance ();
DVB.Utils.dbus_register_object<DVB.IDBusRecordingsStore> (conn,
@@ -67,25 +68,20 @@ namespace Main {
}
private static void on_exit (int signum) {
- message ("Exiting");
-
+ log.info ("Exiting");
+
DVB.RTSPServer.shutdown ();
DVB.Manager.shutdown ();
DVB.Factory.shutdown ();
DVB.RecordingsStore.shutdown ();
-
+ DVB.Logging.LogManager.getLogManager().cleanup ();
+
recstore = null;
manager = null;
-
+
mainloop.quit ();
}
-
- private static void log_func (string? log_domain, LogLevelFlags log_levels,
- string message) {
- if (has_debug)
- cUtils.log_default_handler (log_domain, log_levels, message, null);
- }
-
+
public static bool get_disable_epg_scanner () {
return Main.disable_epg_scanner;
}
@@ -99,7 +95,7 @@ namespace Main {
ret = false;
else
ret = feature.check_version (major, minor, micro);
- debug ("Has %s >= %u.%u.%u: %s", name, major, minor, micro, ret.to_string ());
+ log.debug ("Has %s >= %u.%u.%u: %s", name, major, minor, micro, ret.to_string ());
return ret;
}
@@ -120,7 +116,7 @@ namespace Main {
private static void restore_device_groups () {
DVB.database.ConfigStore config_store = DVB.Factory.get_config_store ();
-
+
Gee.List<DVB.DeviceGroup> device_groups;
try {
device_groups = config_store.get_all_device_groups ();
@@ -129,23 +125,54 @@ namespace Main {
return;
}
- message ("Restoring %d device groups", device_groups.size);
+ log.info ("Restoring %d device groups", device_groups.size);
foreach (DVB.DeviceGroup device_group in device_groups) {
manager.restore_device_group_and_timers (device_group);
}
}
-
+
+ private static void configure_logging () {
+ DVB.Logging.LogManager manager = DVB.Logging.LogManager.getLogManager ();
+ log = manager.getDefaultLogger ();
+
+ File cache_dir = File.new_for_path (Environment.get_user_cache_dir ());
+ File our_cache = cache_dir.get_child ("gnome-dvb-daemon");
+ File log_file = our_cache.get_child ("debug%d.log");
+
+ try {
+ DVB.Logging.FileHandler fhandler = new DVB.Logging.FileHandler (
+ log_file.get_path ());
+ fhandler.limit = 1024 * 1024; /* 1 MB */
+ if (has_debug) {
+ fhandler.limit = fhandler.limit * 5;
+ } else {
+ fhandler.threshold = DVB.Logging.LogLevel.WARNING;
+ }
+
+ log.addHandler (fhandler);
+ } catch (Error e) {
+ stderr.printf ("*** Failed creating DVB.Logging.FileHandler: %s\n", e.message);
+ }
+
+ DVB.Logging.ConsoleHandler chandler = new DVB.Logging.ConsoleHandler();
+ chandler.formatter = new DVB.Logging.ColorFormatter ();
+ if (!has_debug) {
+ chandler.threshold = DVB.Logging.LogLevel.ERROR;
+ }
+ log.addHandler (chandler);
+ }
+
public static int main (string[] args) {
// set timezone to avoid that strftime stats /etc/localtime on every call
Environment.set_variable ("TZ", "/etc/localtime", false);
cUtils.Signal.connect (cUtils.Signal.SIGINT, on_exit);
cUtils.Signal.connect (cUtils.Signal.SIGTERM, on_exit);
-
+
OptionContext context = new OptionContext ("- record and watch TV shows using one or more DVB adapters");
context.add_main_entries (options, null);
context.add_group (Gst.init_get_option_group ());
-
+
try {
context.parse (ref args);
} catch (OptionError e) {
@@ -153,30 +180,28 @@ namespace Main {
stderr.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
return 1;
}
-
+
if (has_version) {
stdout.printf (Config.PACKAGE_NAME);
stdout.printf (" %s\n", Config.PACKAGE_VERSION);
return 0;
}
-
- Log.set_handler (null, LogLevelFlags.LEVEL_DEBUG |
- LogLevelFlags.FLAG_FATAL | LogLevelFlags.FLAG_RECURSION,
- log_func);
-
+
// Creating a GLib main loop with a default context
mainloop = new MainLoop (null, false);
// Initializing GStreamer
Gst.init (ref args);
+ configure_logging ();
+
if (!check_requirements ()) {
stderr.printf ("You don't have all of the necessary requirements to run %s.\n",
Config.PACKAGE_NAME);
stderr.printf ("Start the daemon with the --debug flag for more details.\n");
return -1;
}
-
+
start_manager ();
Idle.add (DVB.RTSPServer.start);
@@ -187,7 +212,7 @@ namespace Main {
// Start GLib mainloop
mainloop.run ();
-
+
return 0;
}
diff --git a/src/Manager.vala b/src/Manager.vala
index 9674136..0e5df51 100644
--- a/src/Manager.vala
+++ b/src/Manager.vala
@@ -20,30 +20,33 @@
using GLib;
using Gee;
using DVB.database;
+using DVB.Logging;
namespace DVB {
-
+
public class Manager : Object, IDBusManager {
-
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
public Gee.Collection<DeviceGroup> device_groups {
owned get {
return this.devices.values;
}
}
-
+
// Map object path to Scanner
private HashMap<string, Scanner> scanners;
-
+
// Maps device group id to Device
private HashMap<uint, DeviceGroup> devices;
-
+
private uint device_group_counter;
private GUdev.Client udev_client;
-
+
private static Manager instance;
private static StaticRecMutex instance_mutex = StaticRecMutex ();
private static const string[] UDEV_SUBSYSTEMS = {"dvb", null};
-
+
construct {
this.scanners = new HashMap<string, Scanner> (GLib.str_hash,
GLib.str_equal, GLib.direct_equal);
@@ -52,7 +55,7 @@ namespace DVB {
this.udev_client = new GUdev.Client (UDEV_SUBSYSTEMS);
this.udev_client.uevent.connect (this.on_udev_event);
}
-
+
public static unowned Manager get_instance () {
instance_mutex.lock ();
if (instance == null) {
@@ -61,33 +64,33 @@ namespace DVB {
instance_mutex.unlock ();
return instance;
}
-
+
public static void shutdown () {
instance_mutex.lock ();
Manager m = instance;
-
+
if (instance != null) {
m.udev_client = null;
lock (m.scanners) {
foreach (Scanner scanner in m.scanners.values) {
- debug ("Stopping scanner");
+ log.debug ("Stopping scanner");
scanner.do_destroy ();
}
m.scanners.clear ();
}
-
+
lock (m.devices) {
foreach (DeviceGroup devgrp in m.devices.values) {
devgrp.destroy ();
}
m.devices.clear ();
}
-
+
instance = null;
}
instance_mutex.unlock ();
}
-
+
/**
* @adapter: Number of the device's adapter
* @frontend: Number of the device's frontend
@@ -112,12 +115,12 @@ namespace DVB {
} else {
// Stop epgscanner for device if there's any
this.get_device_group_of_device (reg_dev).stop_epg_scanner ();
-
+
// Assign existing device
device = reg_dev;
}
- switch (device.Type) {
+ switch (device.Type) {
case AdapterType.DVB_C:
case AdapterType.DVB_S:
case AdapterType.DVB_T:
@@ -128,13 +131,13 @@ namespace DVB {
dbusiface = null;
break;
}
-
+
if (dbusiface == null) {
- critical ("Unknown adapter type");
+ log.error ("Unknown adapter type");
dbusiface = "";
return false;
}
-
+
lock (this.scanners) {
if (!this.scanners.has_key (path)) {
Scanner scanner = null;
@@ -142,35 +145,30 @@ namespace DVB {
case AdapterType.DVB_T:
scanner = new TerrestrialScanner (device);
break;
-
+
case AdapterType.DVB_S:
scanner = new SatelliteScanner (device);
break;
-
+
case AdapterType.DVB_C:
scanner = new CableScanner (device);
break;
}
- if (scanner == null) {
- critical ("Unknown adapter type");
- return false;
- }
-
Utils.dbus_register_object (Main.conn, path, (IDBusScanner)scanner);
scanner.destroyed.connect (this.on_scanner_destroyed);
-
+
this.scanners.set (path, scanner);
-
- debug ("Created new Scanner D-Bus service for adapter %u, frontend %u (%s)",
+
+ log.debug ("Created new Scanner D-Bus service for adapter %u, frontend %u (%s)",
adapter, frontend, dbusiface);
}
}
-
+
return true;
}
-
+
/**
* @group_id: A group ID
* @path: Device group's DBus path
@@ -191,7 +189,7 @@ namespace DVB {
}
return ret;
}
-
+
/**
* @returns: Device groups' DBus path
*/
@@ -207,7 +205,7 @@ namespace DVB {
}
return devs;
}
-
+
/**
* @adapter: Number of the device's adapter
* @frontend: Number of the device's frontend
@@ -224,34 +222,34 @@ namespace DVB {
public bool AddDeviceToNewGroup (uint adapter, uint frontend,
string channels_conf, string recordings_dir, string name)
throws DBusError
- {
+ {
File chan_file = File.new_for_path (channels_conf);
File rec_dir = File.new_for_path (recordings_dir);
-
+
Device device;
try {
device = Device.new_full (adapter, frontend, chan_file,
rec_dir, device_group_counter + 1);
} catch (DeviceError e) {
- critical ("Could not create device: %s", e.message);
+ log.error ("Could not create device: %s", e.message);
return false;
}
-
+
// Check if device is already assigned to other group
if (this.device_is_in_any_group (device)) return false;
-
+
device_group_counter++;
-
+
DeviceGroup devgroup = new DeviceGroup (device_group_counter, device);
devgroup.Name = name;
-
+
this.restore_device_group (devgroup);
-
+
this.group_added (device_group_counter);
-
+
return true;
}
-
+
/**
* @adapter: Adapter of device
* @frontend: Frontend of device
@@ -265,7 +263,7 @@ namespace DVB {
out string name) throws DBusError
{
Device? dev = this.get_registered_device (adapter, frontend);
-
+
if (dev == null) {
name = "";
return false;
@@ -274,14 +272,14 @@ namespace DVB {
return true;
}
}
-
+
/**
* @returns: the numner of configured device groups
*/
public int GetDeviceGroupSize () throws DBusError {
return this.devices.size;
}
-
+
/**
* @returns: ID and name of each channel group
*/
@@ -291,7 +289,7 @@ namespace DVB {
try {
groups = config.get_channel_groups ();
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return new ChannelGroupInfo[] {};
}
ChannelGroupInfo[] arr = new ChannelGroupInfo[groups.size];
@@ -314,7 +312,7 @@ namespace DVB {
try {
ret = config.add_channel_group (name, out channel_group_id);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
ret = false;
}
return ret;
@@ -330,7 +328,7 @@ namespace DVB {
try {
ret = config.remove_channel_group (channel_group_id);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
ret = false;
}
return ret;
@@ -341,7 +339,7 @@ namespace DVB {
* devices retrieved via udev
*/
public GLib.HashTable<string, string>[] GetDevices () throws DBusError {
- GLib.List<GUdev.Device> devices =
+ GLib.List<GUdev.Device> devices =
this.udev_client.query_by_subsystem ("dvb");
var devices_list = new GLib.List<HashTable<string, string>> ();
@@ -384,22 +382,22 @@ namespace DVB {
*/
public bool add_device_group (DeviceGroup devgroup) {
uint group_id = devgroup.Id;
- debug ("Adding device group %u with %d devices", group_id,
+ log.debug ("Adding device group %u with %d devices", group_id,
devgroup.size);
-
+
if (devgroup.Type == AdapterType.UNKNOWN) {
- warning ("Not adding device group %u of unknown type",
+ log.warning ("Not adding device group %u of unknown type",
devgroup.Id);
return false;
}
-
+
lock (this.devices) {
this.devices.set (group_id, devgroup);
}
try {
Factory.get_config_store ().add_device_group (devgroup);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return false;
}
devgroup.device_removed.connect (this.on_device_removed_from_group);
@@ -407,30 +405,30 @@ namespace DVB {
string path = Constants.DBUS_DEVICE_GROUP_PATH.printf (group_id);
Utils.dbus_register_object<IDBusDeviceGroup> (Main.conn,
path, devgroup);
-
+
if (group_id > device_group_counter)
device_group_counter = group_id;
devgroup.start_epg_scanner ();
-
+
return true;
}
public bool restore_device_group (DeviceGroup device_group) {
- debug ("Restoring group %u", device_group.Id);
+ log.debug ("Restoring group %u", device_group.Id);
- try {
+ try {
device_group.Channels.load (device_group.Type);
} catch (Error e) {
- critical ("Error reading channels from file: %s", e.message);
+ log.error ("Error reading channels from file: %s", e.message);
return false;
}
-
+
return this.add_device_group (device_group);
}
-
+
public void restore_timers (DeviceGroup device_group) {
- message ("Restoring timers of device group %u", device_group.Id);
+ log.info ("Restoring timers of device group %u", device_group.Id);
TimersStore timers_store = Factory.get_timers_store ();
Gee.List<Timer> timers;
@@ -438,7 +436,7 @@ namespace DVB {
timers = timers_store.get_all_timers_of_device_group (
device_group);
} catch (SqlError e) {
- critical ("Failed retrieving timers of group %u: %s",
+ log.error ("Failed retrieving timers of group %u: %s",
device_group.Id, e.message);
return;
}
@@ -452,7 +450,7 @@ namespace DVB {
try {
timers_store.remove_timer_from_device_group (t.Id, device_group);
} catch (SqlError e) {
- critical ("Failed removing timer: %s", e.message);
+ log.error ("Failed removing timer: %s", e.message);
}
}
}
@@ -467,7 +465,7 @@ namespace DVB {
this.restore_timers (device_group);
}
}
-
+
public DeviceGroup? get_device_group_if_exists (uint group_id) {
DeviceGroup? result = null;
lock (this.devices) {
@@ -476,7 +474,7 @@ namespace DVB {
}
return result;
}
-
+
public bool device_is_in_any_group (Device device) {
bool result = false;
lock (this.devices) {
@@ -490,26 +488,26 @@ namespace DVB {
}
return result;
}
-
+
private void on_scanner_destroyed (Scanner scanner) {
uint adapter = scanner.Device.Adapter;
uint frontend = scanner.Device.Frontend;
-
+
string path = Constants.DBUS_SCANNER_PATH.printf (adapter, frontend);
lock (this.scanners) {
this.scanners.unset (path);
}
-
- debug ("Destroying scanner for adapter %u, frontend %u (%s)", adapter,
+
+ log.debug ("Destroying scanner for adapter %u, frontend %u (%s)", adapter,
frontend, path);
-
+
// Start epgscanner for device again if there was one
DeviceGroup? devgroup = this.get_device_group_of_device (scanner.Device);
if (devgroup != null) {
devgroup.start_epg_scanner ();
}
}
-
+
private Device? get_registered_device (uint adapter, uint frontend) {
Device? result = null;
Device fake_device = new Device (adapter, frontend);
@@ -526,10 +524,10 @@ namespace DVB {
}
}
}
-
+
return result;
}
-
+
private DeviceGroup? get_device_group_of_device (Device device) {
DeviceGroup? result = null;
lock (this.devices) {
@@ -545,10 +543,10 @@ namespace DVB {
}
}
}
-
+
return result;
}
-
+
private void on_device_removed_from_group (IDBusDeviceGroup idevgroup,
uint adapter, uint frontend) {
DeviceGroup devgroup = (DeviceGroup)idevgroup;
@@ -560,7 +558,7 @@ namespace DVB {
}
if (success) {
devgroup.destroy ();
-
+
try {
Factory.get_config_store ().remove_device_group (
devgroup);
@@ -572,7 +570,7 @@ namespace DVB {
);
this.group_removed (group_id);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
}
}
@@ -585,11 +583,11 @@ namespace DVB {
try {
groups = config_store.get_all_device_groups ();
} catch (SqlError e) {
- critical ("Error restoring group %u: %s", group_id,
+ log.error ("Error restoring group %u: %s", group_id,
e.message);
return;
}
-
+
foreach (DeviceGroup group in groups) {
if (group.Id == group_id) {
this.restore_device_group_and_timers (group);
@@ -618,7 +616,7 @@ namespace DVB {
if (!found)
return;
- debug ("%s device %s, part of group %u", action, dev_file,
+ log.debug ("%s device %s, part of group %u", action, dev_file,
group_id);
DeviceGroup? group = this.get_device_group_if_exists (group_id);
@@ -650,7 +648,7 @@ namespace DVB {
group.start_epg_scanner ();
}
}
-
+
}
}
diff --git a/src/Recorder.vala b/src/Recorder.vala
index cd85372..ab6c310 100644
--- a/src/Recorder.vala
+++ b/src/Recorder.vala
@@ -20,6 +20,7 @@
using GLib;
using Gee;
using DVB.database;
+using DVB.Logging;
namespace DVB {
@@ -29,6 +30,8 @@ namespace DVB {
*/
public class Recorder : GLib.Object, IDBusRecorder, Iterable<Timer> {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
public unowned DVB.DeviceGroup DeviceGroup { get; construct; }
public uint count {
@@ -150,7 +153,7 @@ namespace DVB {
conflict_count++;
if (conflict_count >= this.DeviceGroup.size) {
- debug ("Timer is conflicting with another timer: %s",
+ log.debug ("Timer is conflicting with another timer: %s",
this.timers.get(key).to_string ());
has_conflict = true;
break;
@@ -164,12 +167,12 @@ namespace DVB {
Factory.get_timers_store ().add_timer_to_device_group (new_timer,
this.DeviceGroup);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
this.changed (new_timer.Id, ChangeType.ADDED);
if (this.timers.size == 1 && !this.have_check_timers_timeout) {
- debug ("Creating new check timers");
+ log.debug ("Creating new check timers");
this. check_timers_event_id = Timeout.add_seconds (
CHECK_TIMERS_INTERVAL, this.check_timers
);
@@ -198,10 +201,10 @@ namespace DVB {
try {
event = epgstore.get_event (event_id, channel_sid, this.DeviceGroup.Id);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
if (event == null) {
- debug ("Could not find event with id %u", event_id);
+ log.debug ("Could not find event with id %u", event_id);
timer_id = 0;
return false;
}
@@ -238,7 +241,7 @@ namespace DVB {
Factory.get_timers_store ().remove_timer_from_device_group (
timer_id, this.DeviceGroup);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
this.changed (timer_id, ChangeType.DELETED);
val = true;
@@ -531,10 +534,10 @@ namespace DVB {
event = epgstore.get_event (event_id, channel_sid,
this.DeviceGroup.Id);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
if (event == null) {
- debug ("Could not find event with id %u", event_id);
+ log.debug ("Could not find event with id %u", event_id);
return OverlapType.UNKNOWN;
}
@@ -574,7 +577,7 @@ namespace DVB {
protected Timer? create_timer (uint channel,
int start_year, int start_month, int start_day,
int start_hour, int start_minute, uint duration) {
- debug ("Creating new timer: channel: %u, start: %04d-%02d-%02d %02d:%02d, duration: %u",
+ log.debug ("Creating new timer: channel: %u, start: %04d-%02d-%02d %02d:%02d, duration: %u",
channel, start_year, start_month, start_day,
start_hour, start_minute, duration);
@@ -606,7 +609,7 @@ namespace DVB {
Gst.Element filesink = Gst.ElementFactory.make ("filesink", null);
if (filesink == null) {
- critical ("Could not create filesink element");
+ log.error ("Could not create filesink element");
return;
}
filesink.set ("location", location.get_path ());
@@ -616,11 +619,11 @@ namespace DVB {
PlayerThread? player = channel_factory.watch_channel (channel,
filesink, true);
if (player != null) {
- debug ("Setting pipeline to playing");
+ log.debug ("Setting pipeline to playing");
Gst.StateChangeReturn ret = player.get_pipeline().set_state (
Gst.State.PLAYING);
if (ret == Gst.StateChangeReturn.FAILURE) {
- critical ("Failed setting pipeline to playing");
+ log.error ("Failed setting pipeline to playing");
channel_factory.stop_channel (channel, filesink);
return;
}
@@ -641,7 +644,7 @@ namespace DVB {
* transfer informations */
Event? event = channel.Schedule.get_event (timer.EventID);
if (event != null) {
- debug ("Transfering event information from timer");
+ log.debug ("Transfering event information from timer");
recording.Name = event.name;
recording.Description = "%s\n%s".printf (
event.description,
@@ -671,7 +674,7 @@ namespace DVB {
rec.Length = Utils.difftime (Time.local (time_t ()),
rec.StartTime);
- debug ("Recording of channel %s stopped after %"
+ log.debug ("Recording of channel %s stopped after %"
+ int64.FORMAT +" seconds",
rec.ChannelName, rec.Length);
@@ -711,7 +714,7 @@ namespace DVB {
try {
Utils.mkdirs (dir);
} catch (Error e) {
- critical ("Could not create directory %s: %s",
+ log.error ("Could not create directory %s: %s",
dir.get_path (), e.message);
return null;
}
@@ -721,18 +724,18 @@ namespace DVB {
try {
info = dir.query_info (ATTRIBUTES, 0, null);
} catch (Error e) {
- critical ("Could not retrieve attributes: %s", e.message);
+ log.error ("Could not retrieve attributes: %s", e.message);
return null;
}
if (info.get_attribute_uint32 (FILE_ATTRIBUTE_STANDARD_TYPE)
!= FileType.DIRECTORY) {
- critical ("%s is not a directory", dir.get_path ());
+ log.error ("%s is not a directory", dir.get_path ());
return null;
}
if (!info.get_attribute_boolean (FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
- critical ("Cannot write to %s", dir.get_path ());
+ log.error ("Cannot write to %s", dir.get_path ());
return null;
}
@@ -745,7 +748,7 @@ namespace DVB {
}
private bool check_timers () {
- debug ("Checking timers");
+ log.debug ("Checking timers");
bool val;
SList<Timer> ended_recordings =
@@ -771,7 +774,7 @@ namespace DVB {
foreach (uint32 key in this.timers.keys) {
Timer timer = this.timers.get (key);
- debug ("Checking timer: %s", timer.to_string());
+ log.debug ("Checking timer: %s", timer.to_string());
// Check if we should start new recording and if we didn't
// start it before
@@ -779,7 +782,7 @@ namespace DVB {
&& !this.active_timers.contains (timer.Id)) {
this.start_recording (timer);
} else if (timer.has_expired()) {
- debug ("Removing expired timer: %s", timer.to_string());
+ log.debug ("Removing expired timer: %s", timer.to_string());
deleteable_items.prepend (key);
}
}
@@ -791,13 +794,13 @@ namespace DVB {
if (this.timers.size == 0 && this.active_timers.size == 0) {
// We don't have any timers and no recording is in progress
- debug ("No timers left and no recording in progress");
+ log.debug ("No timers left and no recording in progress");
this.have_check_timers_timeout = false;
this.check_timers_event_id = 0;
val = false;
} else {
// We still have timers
- debug ("%d timers and %d active recordings left",
+ log.debug ("%d timers and %d active recordings left",
this.timers.size,
this.active_timers.size);
val = true;
@@ -819,7 +822,7 @@ namespace DVB {
Event? event = sched.get_running_event ();
if (event != null) {
- debug ("Found running event for active recording");
+ log.debug ("Found running event for active recording");
rec.Name = event.name;
rec.Description = "%s\n%s".printf (event.description,
event.extended_description);
diff --git a/src/Recording.vala b/src/Recording.vala
index 043bf75..7865816 100644
--- a/src/Recording.vala
+++ b/src/Recording.vala
@@ -18,6 +18,7 @@
*/
using GLib;
+using DVB.Logging;
namespace DVB {
@@ -25,6 +26,8 @@ namespace DVB {
* This class represents a finished recording
*/
public class Recording : GLib.Object {
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
public uint32 Id {get; set;}
public uint ChannelSid {get; set;}
@@ -60,7 +63,7 @@ namespace DVB {
try {
writer.write ();
} catch (Error e) {
- critical ("Could not save recording: %s", e.message);
+ log.error ("Could not save recording: %s", e.message);
}
}
@@ -68,7 +71,7 @@ namespace DVB {
File file, File? other_file, FileMonitorEvent event) {
if (event == FileMonitorEvent.DELETED) {
string location = file.get_path ();
- debug ("%s has been deleted", location);
+ log.debug ("%s has been deleted", location);
monitor.cancel ();
diff --git a/src/RecordingsStore.vala b/src/RecordingsStore.vala
index d9b993e..2daf6a1 100644
--- a/src/RecordingsStore.vala
+++ b/src/RecordingsStore.vala
@@ -19,6 +19,7 @@
using GLib;
using Gee;
+using DVB.Logging;
namespace DVB {
@@ -26,6 +27,8 @@ namespace DVB {
* This class manages the recordings off all devices
*/
public class RecordingsStore : GLib.Object, IDBusRecordingsStore {
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
private HashMap<uint32, Recording> recordings;
private uint32 last_id;
@@ -67,7 +70,7 @@ namespace DVB {
uint32 id = rec.Id;
lock (this.recordings) {
if (this.recordings.has_key (id)) {
- critical ("Recording with id %u already available", id);
+ log.error ("Recording with id %u already available", id);
return false;
}
@@ -242,13 +245,13 @@ namespace DVB {
lock (this.recordings) {
if (!this.recordings.has_key (rec_id)) val = false;
else {
- debug ("Deleting recording %u", rec_id);
+ log.debug ("Deleting recording %u", rec_id);
var rec = this.recordings.get (rec_id);
try {
Utils.delete_dir_recursively (rec.Location.get_parent ());
val = true;
} catch (Error e) {
- critical ("Could not delete recording: %s", e.message);
+ log.error ("Could not delete recording: %s", e.message);
val = false;
}
this.remove (rec);
diff --git a/src/ScannedItem.vala b/src/ScannedItem.vala
index 3b980c4..f3bf561 100644
--- a/src/ScannedItem.vala
+++ b/src/ScannedItem.vala
@@ -18,6 +18,7 @@
*/
using GLib;
+using DVB.Logging;
namespace DVB {
@@ -27,6 +28,8 @@ namespace DVB {
*/
public class ScannedItem : GLib.Object {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
public uint Frequency {get; construct;}
private static const int PRIME = 31;
@@ -65,7 +68,7 @@ namespace DVB {
return (item1.Frequency == item2.Frequency);
} else {
- critical ("Don't comparing ScannedItem instances");
+ log.error ("Don't comparing ScannedItem instances");
return false;
}
}
diff --git a/src/Scanner.vala b/src/Scanner.vala
index 0638721..2eeed08 100644
--- a/src/Scanner.vala
+++ b/src/Scanner.vala
@@ -19,6 +19,7 @@
using GLib;
using Gee;
+using DVB.Logging;
namespace DVB {
@@ -27,6 +28,8 @@ namespace DVB {
*/
public abstract class Scanner : GLib.Object {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
/**
* Emitted when the Destroy () method is called
*/
@@ -157,7 +160,7 @@ namespace DVB {
try {
this.worker_thread = Thread.create<bool> (this.worker, true);
} catch (ThreadError e) {
- critical ("Could not create thread: %s", e.message);
+ log.error ("Could not create thread: %s", e.message);
return;
}
@@ -168,7 +171,7 @@ namespace DVB {
PIPELINE_TEMPLATE.printf (this.Device.Adapter,
this.Device.Frontend, BASE_PIDS));
} catch (Error e) {
- critical ("Could not create pipeline: %s", e.message);
+ log.error ("Could not create pipeline: %s", e.message);
return;
}
@@ -217,7 +220,7 @@ namespace DVB {
try {
writer.write (c);
} catch (Error e) {
- critical ("Could not write to file: %s", e.message);
+ log.error ("Could not write to file: %s", e.message);
success = false;
}
}
@@ -225,7 +228,7 @@ namespace DVB {
try {
writer.close ();
} catch (Error e) {
- critical ("Could not close file handle: %s", e.message);
+ log.error ("Could not close file handle: %s", e.message);
success = false;
}
@@ -252,7 +255,7 @@ namespace DVB {
try {
writer.write (c);
} catch (Error e) {
- critical ("Could not write to file: %s", e.message);
+ log.error ("Could not write to file: %s", e.message);
success = false;
}
}
@@ -260,7 +263,7 @@ namespace DVB {
try {
writer.close ();
} catch (Error e) {
- critical ("Could not close file handle: %s", e.message);
+ log.error ("Could not close file handle: %s", e.message);
success = false;
}
@@ -270,7 +273,7 @@ namespace DVB {
public bool AddScanningDataFromFile (string path) throws DBusError {
File datafile = File.new_for_path(path);
- debug ("Reading scanning data from %s", path);
+ log.debug ("Reading scanning data from %s", path);
if (!Utils.is_readable_file (datafile)) return false;
@@ -278,7 +281,7 @@ namespace DVB {
try {
reader = new DataInputStream (datafile.read (null));
} catch (Error e) {
- critical ("Could not open %s: %s", path, e.message);
+ log.error ("Could not open %s: %s", path, e.message);
return false;
}
@@ -294,14 +297,14 @@ namespace DVB {
this.add_scanning_data_from_string (line);
}
} catch (Error e) {
- critical ("Could not read %s: %s", path, e.message);
+ log.error ("Could not read %s: %s", path, e.message);
return false;
}
try {
reader.close (null);
} catch (Error e) {
- critical ("Could not close file handle: %s", e.message);
+ log.error ("Could not close file handle: %s", e.message);
return false;
}
@@ -323,7 +326,7 @@ namespace DVB {
bus_watch_source.destroy ();
this.bus_watch_id = 0;
}
- debug ("Disposing pipeline");
+ log.debug ("Disposing pipeline");
this.pipeline.set_state (Gst.State.NULL);
// Free pipeline
this.pipeline = null;
@@ -351,7 +354,7 @@ namespace DVB {
ScannedItem item = this.get_scanned_item (structure);
if (!this.scanned_frequencies.contains (item)) {
- debug ("Queueing new frequency %u", item.Frequency);
+ log.debug ("Queueing new frequency %u", item.Frequency);
this.frequencies.push_tail (structure);
this.scanned_frequencies.add (item);
}
@@ -364,7 +367,7 @@ namespace DVB {
protected bool start_scan () {
bool all_tables = (this.sdt_arrived && this.nit_arrived
&& this.pat_arrived && this.pmt_arrived);
- debug ("Received all tables: %s (pat: %s, sdt: %s, nit: %s, pmt: %s)",
+ log.debug ("Received all tables: %s (pat: %s, sdt: %s, nit: %s, pmt: %s)",
all_tables.to_string (), this.pat_arrived.to_string (),
this.sdt_arrived.to_string (), this.nit_arrived.to_string (),
this.pmt_arrived.to_string ());
@@ -386,7 +389,7 @@ namespace DVB {
// We don't have all the information for those channels
// remove them
lock (this.new_channels) {
- debug ("%u channels still have missing or invalid information",
+ log.debug ("%u channels still have missing or invalid information",
this.new_channels.size);
foreach (uint sid in this.new_channels) {
this.channels.remove (sid);
@@ -473,7 +476,7 @@ namespace DVB {
/* Avoid creating source multiple times */
if (this.start_scan_source == null ||
this.start_scan_source.is_destroyed ()) {
- debug ("Queueing start_scan");
+ log.debug ("Queueing start_scan");
this.start_scan_source = new IdleSource ();
this.start_scan_source.set_callback (this.start_scan);
this.start_scan_source.attach (this.context);
@@ -549,7 +552,7 @@ namespace DVB {
i++;
}
- debug ("Setting %d pids: %s", pid_set.size, new_pids.str);
+ log.debug ("Setting %d pids: %s", pid_set.size, new_pids.str);
// We want to parse the pmt as well
Gst.Element dvbsrc = ((Gst.Bin)this.pipeline).get_by_name ("dvbsrc");
dvbsrc.set ("pids", new_pids.str);
@@ -607,7 +610,7 @@ namespace DVB {
channel.Network = "";
}
- debug ("Found service 0x%x, %s, scrambled: %s", sid,
+ log.debug ("Found service 0x%x, %s, scrambled: %s", sid,
channel.Name, channel.Scrambled.to_string ());
}
@@ -630,7 +633,7 @@ namespace DVB {
structure.get_uint ("network-id", out nid);
name = "%u".printf (nid);
}
- debug ("Network name '%s'", name);
+ log.debug ("Network name '%s'", name);
Gst.Value transports = structure.get_value ("transports");
uint size = transports.list_get_size ();
@@ -649,7 +652,7 @@ namespace DVB {
weak Gst.Structure delivery =
delivery_val.get_structure ();
- debug ("Received TS 0x%x", tsid);
+ log.debug ("Received TS 0x%x", tsid);
uint freq;
delivery.get_uint ("frequency", out freq);
@@ -694,7 +697,7 @@ namespace DVB {
}
protected void on_pmt_structure (Gst.Structure structure) {
- debug ("Received PMT");
+ log.debug ("Received PMT");
uint program_number;
structure.get_uint ("program-number", out program_number);
@@ -726,7 +729,7 @@ namespace DVB {
case 0x01:
case 0x02:
case 0x1b: /* H.264 video stream */
- debug ("Found video PID 0x%x for channel 0x%x",
+ log.debug ("Found video PID 0x%x for channel 0x%x",
pid, program_number);
dvb_channel.VideoPID = pid;
break;
@@ -734,12 +737,12 @@ namespace DVB {
case 0x04:
case 0x0f:
case 0x11:
- debug ("Found audio PID 0x%x for channel 0x%x",
+ log.debug ("Found audio PID 0x%x for channel 0x%x",
pid, program_number);
dvb_channel.AudioPIDs.add (pid);
break;
default:
- debug ("Other stream type: 0x%02x", stream_type);
+ log.debug ("Other stream type: 0x%02x", stream_type);
break;
}
}
@@ -791,14 +794,14 @@ namespace DVB {
// because we didn't came across the sdt or pmt, yet
if (channel.is_valid ()) {
string type = (channel.is_radio ()) ? "Radio" : "TV";
- debug ("Channel added: %s", channel.to_string ());
+ log.debug ("Channel added: %s", channel.to_string ());
this.channel_added (channel.Frequency, sid,
channel.Name, channel.Network, type,
channel.Scrambled);
// Mark channel for deletion of this.new_channels
del_channels.add (sid);
} else {
- debug ("Channel 0x%x is not valid: %s", sid,
+ log.debug ("Channel 0x%x is not valid: %s", sid,
channel.to_string ());
this.pmt_arrived = false;
}
@@ -824,7 +827,7 @@ namespace DVB {
}
protected void add_new_channel (uint sid) {
- debug ("Adding new channel with SID 0x%x", sid);
+ log.debug ("Adding new channel with SID 0x%x", sid);
Channel new_channel = this.get_new_channel ();
new_channel.Sid = sid;
// add values from Gst.Structure to Channel
diff --git a/src/Schedule.vala b/src/Schedule.vala
index 55f3f5c..1c6950c 100644
--- a/src/Schedule.vala
+++ b/src/Schedule.vala
@@ -20,6 +20,7 @@
using GLib;
using Gee;
using DVB.database;
+using DVB.Logging;
namespace DVB {
@@ -28,6 +29,8 @@ namespace DVB {
*/
public class Schedule : GLib.Object, IDBusSchedule {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
private static const int MATCH_THRESHOLD = 100;
private static const double MIN_EVENT_OVERLAP = 0.5;
@@ -52,7 +55,7 @@ namespace DVB {
levents = this.epgstore.get_events (
this.channel.Sid, this.channel.GroupId);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return false;
}
@@ -73,12 +76,12 @@ namespace DVB {
this.epgstore.remove_events_older_than (event,
this.channel.Sid, this.channel.GroupId);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return false;
}
}
- debug ("Finished restoring EPG events for channel %u",
+ log.debug ("Finished restoring EPG events for channel %u",
this.channel.Sid);
return false;
}
@@ -102,7 +105,7 @@ namespace DVB {
}
}
- debug ("Removing expired events of channel %s (%u)",
+ log.debug ("Removing expired events of channel %s (%u)",
channel.Name, channel.Sid);
for (int i=0; i<=last_expired; i++) {
@@ -112,7 +115,7 @@ namespace DVB {
this.epgstore.remove_events_older_than (event,
this.channel.Sid, this.channel.GroupId);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
}
@@ -127,7 +130,7 @@ namespace DVB {
return this.epgstore.get_event (event_id,
this.channel.Sid, this.channel.GroupId);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
return null;
}
}
@@ -142,7 +145,7 @@ namespace DVB {
try {
this.store_event (event);
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
}
}
@@ -160,7 +163,7 @@ namespace DVB {
((database.sqlite.SqliteDatabase)this.epgstore).end_transaction ();
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
} finally {
mutex.unlock ();
}
@@ -386,7 +389,7 @@ namespace DVB {
next_event = next.id;
}
} else {
- debug ("No event with id %u", event_id);
+ log.debug ("No event with id %u", event_id);
}
}
@@ -404,7 +407,7 @@ namespace DVB {
ret = true;
}
} else {
- debug ("No event with id %u", event_id);
+ log.debug ("No event with id %u", event_id);
}
}
if (!ret) name = "";
@@ -424,7 +427,7 @@ namespace DVB {
ret = true;
}
} else {
- debug ("No event with id %u", event_id);
+ log.debug ("No event with id %u", event_id);
}
}
if (!ret) description = "";
@@ -444,7 +447,7 @@ namespace DVB {
ret = true;
}
} else {
- debug ("No event with id %u", event_id);
+ log.debug ("No event with id %u", event_id);
}
}
if (!ret) description = "";
@@ -464,7 +467,7 @@ namespace DVB {
ret = true;
}
} else {
- debug ("No event with id %u", event_id);
+ log.debug ("No event with id %u", event_id);
}
}
@@ -485,7 +488,7 @@ namespace DVB {
ret = true;
}
} else {
- debug ("No event with id %u", event_id);
+ log.debug ("No event with id %u", event_id);
start_time = new uint[] {};
}
}
@@ -525,7 +528,7 @@ namespace DVB {
ret = true;
}
} else {
- debug ("No event with id %u", event_id);
+ log.debug ("No event with id %u", event_id);
}
}
@@ -545,7 +548,7 @@ namespace DVB {
ret = true;
}
} else {
- debug ("No event with id %u", event_id);
+ log.debug ("No event with id %u", event_id);
}
}
diff --git a/src/Settings.vala b/src/Settings.vala
index f77e1be..4708a3c 100644
--- a/src/Settings.vala
+++ b/src/Settings.vala
@@ -18,10 +18,13 @@
*/
using GLib;
+using DVB.Logging;
namespace DVB {
public class Settings : GLib.Object {
+
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
private static const string TIMERS_SECTION = "timers";
private static const string MARGIN_START = "margin_start";
@@ -114,7 +117,7 @@ namespace DVB {
try {
stream = settings_file.create (0, null);
} catch (Error e) {
- critical ("Could not create file %s: %s",
+ log.error ("Could not create file %s: %s",
settings_file.get_path (), e.message);
return false;
}
@@ -122,7 +125,7 @@ namespace DVB {
try {
stream.write (DEFAULT_SETTINGS.data);
} catch (Error e) {
- critical ("Could not write to file %s: %s",
+ log.error ("Could not write to file %s: %s",
settings_file.get_path (), e.message);
success = false;
}
@@ -130,7 +133,7 @@ namespace DVB {
try {
stream.close (null);
} catch (Error e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
success = false;
}
}
@@ -139,10 +142,10 @@ namespace DVB {
try {
keyfile.load_from_file (settings_file.get_path (), 0);
} catch (KeyFileError e) {
- critical ("Could not load settings: %s", e.message);
+ log.error ("Could not load settings: %s", e.message);
success = false;
} catch (FileError e) {
- critical ("Could not load settings: %s", e.message);
+ log.error ("Could not load settings: %s", e.message);
success = false;
}
}
@@ -157,7 +160,7 @@ namespace DVB {
try {
stream = settings_file.replace (null, true, 0, null);
} catch (Error e) {
- critical ("Could not replace file %s: %s",
+ log.error ("Could not replace file %s: %s",
settings_file.get_path (), e.message);
return false;
}
@@ -169,7 +172,7 @@ namespace DVB {
try {
stream.write_all (data.data, null);
} catch (Error e) {
- critical ("Could not write to file %s: %s",
+ log.error ("Could not write to file %s: %s",
settings_file.get_path (), e.message);
return false;
}
@@ -178,7 +181,7 @@ namespace DVB {
try {
stream.close (null);
} catch (Error e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
return false;
diff --git a/src/Utils.vala b/src/Utils.vala
index 23da437..db0a90f 100644
--- a/src/Utils.vala
+++ b/src/Utils.vala
@@ -29,7 +29,7 @@ namespace DVB.Utils {
unowned EnumValue? eval = eclass.get_value (val);
if (eval == null) {
- critical ("Enum has no value %d", val);
+ Main.log.error ("Enum has no value %d", val);
return null;
} else {
return eval.value_nick;
@@ -41,7 +41,7 @@ namespace DVB.Utils {
unowned EnumValue? eval = enumclass.get_value_by_name (name);
if (eval == null) {
- critical ("Enum has no member named %s", name);
+ Main.log.error ("Enum has no member named %s", name);
return false;
} else {
evalue = eval.value;
@@ -54,7 +54,7 @@ namespace DVB.Utils {
unowned EnumValue? eval = enumclass.get_value (val);
if (eval == null) {
- critical ("Enum has no value %d", val);
+ Main.log.error ("Enum has no value %d", val);
return null;
} else {
return eval.value_name;
@@ -72,7 +72,7 @@ namespace DVB.Utils {
}
foreach (File dir in create_dirs) {
- debug ("Creating %s", dir.get_path ());
+ Main.log.debug ("Creating %s", dir.get_path ());
dir.make_directory (null);
}
}
@@ -82,7 +82,7 @@ namespace DVB.Utils {
try {
regex = new Regex ("[^-_\\.a-zA-Z0-9]", 0, 0);
} catch (RegexError e) {
- critical ("RegexError: %s", e.message);
+ Main.log.error ("RegexError: %s", e.message);
return text;
}
@@ -90,7 +90,7 @@ namespace DVB.Utils {
try {
new_text = regex.replace_literal (text, -1, 0, "_", 0);
} catch (RegexError e) {
- critical ("RegexError: %s", e.message);
+ Main.log.error ("RegexError: %s", e.message);
return text;
}
@@ -159,17 +159,17 @@ namespace DVB.Utils {
try {
info = file.query_info (READ_ATTRS, 0, null);
} catch (Error e) {
- critical ("Could not retrieve attributes: %s", e.message);
+ Main.log.error ("Could not retrieve attributes: %s", e.message);
return false;
}
if (info.get_file_type () != FileType.REGULAR) {
- critical ("%s is not a regular file", file.get_path ());
+ Main.log.error ("%s is not a regular file", file.get_path ());
return false;
}
if (!info.get_attribute_boolean (FILE_ATTRIBUTE_ACCESS_CAN_READ)) {
- critical ("Cannot read %s", file.get_path ());
+ Main.log.error ("Cannot read %s", file.get_path ());
return false;
}
@@ -194,13 +194,13 @@ namespace DVB.Utils {
break;
case FileType.REGULAR:
- debug ("Deleting file %s", child.get_path ());
+ Main.log.debug ("Deleting file %s", child.get_path ());
child.delete (null);
break;
}
}
- debug ("Deleting directory %s", dir.get_path ());
+ Main.log.debug ("Deleting directory %s", dir.get_path ());
dir.delete (null);
}
@@ -236,7 +236,7 @@ namespace DVB.Utils {
}
public static void dbus_own_name (string service_name, BusAcquiredCallback cb) {
- message ("Creating D-Bus service %s", service_name);
+ Main.log.info ("Creating D-Bus service %s", service_name);
Bus.own_name (BusType.SESSION, service_name, BusNameOwnerFlags.NONE,
cb,
() => {},
@@ -247,7 +247,7 @@ namespace DVB.Utils {
try {
conn.register_object (object_path, obj);
} catch (IOError e) {
- critical ("Could not register object '%s': %s", object_path, e.message);
+ Main.log.error ("Could not register object '%s': %s", object_path, e.message);
}
}
diff --git a/src/database/sqlite/SqliteConfigTimersStore.vala b/src/database/sqlite/SqliteConfigTimersStore.vala
index 58d475d..9880a99 100644
--- a/src/database/sqlite/SqliteConfigTimersStore.vala
+++ b/src/database/sqlite/SqliteConfigTimersStore.vala
@@ -20,11 +20,14 @@
using GLib;
using Gee;
using Sqlite;
+using DVB.Logging;
namespace DVB.database.sqlite {
public class SqliteConfigTimersStore : SqliteDatabase, ConfigStore, TimersStore {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
private static const int VERSION = 1;
private static const string CREATE_DEVICE_GROUPS =
@@ -35,14 +38,14 @@ namespace DVB.database.sqlite {
recordings_dir VARCHAR(255),
name VARCHAR(255),
PRIMARY KEY(group_id))""";
-
+
private static const string CREATE_DEVICES =
"""CREATE TABLE devices (
group_id INTEGER,
adapter INTEGER,
frontend INTEGER,
PRIMARY KEY(adapter, frontend))""";
-
+
private static const string CREATE_TIMERS =
"""CREATE TABLE timers (
timer_id INTEGER,
@@ -61,56 +64,56 @@ namespace DVB.database.sqlite {
"""CREATE TABLE channel_groups (
channel_group_id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(255))""";
-
+
private static const string CREATE_CHANNELS =
"""CREATE TABLE channels (
sid INTEGER,
group_id INTEGER,
channel_group_id INTEGER,
PRIMARY KEY(sid, group_id, channel_group_id))""";
-
+
private static const string SELECT_ALL_GROUPS =
"SELECT * FROM device_groups";
-
+
private static const string SELECT_DEVICES =
"SELECT * FROM devices WHERE group_id=?";
-
+
private static const string DELETE_GROUP =
"DELETE FROM device_groups WHERE group_id=?";
-
+
private static const string INSERT_GROUP =
"INSERT INTO device_groups VALUES (?, ?, ?, ?, ?)";
-
+
private static const string CONTAINS_GROUP =
"SELECT 1 FROM device_groups WHERE group_id=?";
-
+
private static const string UPDATE_GROUP =
"UPDATE device_groups SET adapter_type=?, channels_file=?, recordings_dir=?, name=? WHERE group_id=?";
-
+
private static const string DELETE_DEVICE =
"DELETE FROM devices WHERE adapter=? AND frontend=?";
-
+
private static const string DELETE_GROUP_DEVICES =
"DELETE FROM devices WHERE group_id=?";
-
+
private static const string INSERT_DEVICE =
"INSERT INTO devices VALUES (?, ?, ?)";
private static const string SELECT_GROUP_OF_DEVICE =
"SELECT group_id FROM devices WHERE adapter=? AND frontend=?";
-
+
private static const string SELECT_TIMERS =
"SELECT * FROM timers WHERE group_id=?";
-
+
private static const string DELETE_TIMER =
"DELETE FROM timers WHERE timer_id=?";
-
+
private static const string DELETE_GROUP_TIMERS =
"DELETE FROM timers WHERE group_id=?";
-
+
private static const string INSERT_TIMER =
"INSERT INTO timers VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
-
+
private static const string CONTAINS_TIMER =
"SELECT 1 FROM timers WHERE timer_id=?";
@@ -134,7 +137,7 @@ namespace DVB.database.sqlite {
private static const string SELECT_CHANNELS =
"SELECT sid FROM channels WHERE group_id=? AND channel_group_id=?";
-
+
private Statement select_devices_statement;
private Statement delete_group_statement;
private Statement insert_group_statement;
@@ -174,7 +177,7 @@ namespace DVB.database.sqlite {
this.exec_sql (CREATE_CHANNELS);
}
- public override void upgrade (int old_version, int new_version)
+ public override void upgrade (int old_version, int new_version)
throws SqlError
{
@@ -227,13 +230,13 @@ namespace DVB.database.sqlite {
public Gee.List<DeviceGroup> get_all_device_groups () throws SqlError {
Gee.List<DeviceGroup> groups = new ArrayList<DeviceGroup> ();
-
+
Statement statement;
if (this.db.prepare (SELECT_ALL_GROUPS, -1, out statement) != Sqlite.OK) {
this.throw_last_error ();
return groups;
}
-
+
while (statement.step () == Sqlite.ROW) {
int group_id = statement.column_int (0);
@@ -262,7 +265,7 @@ namespace DVB.database.sqlite {
ref_dev = Device.new_full (adapter, frontend,
channels_file, rec_dir, group_id);
} catch (DeviceError e) {
- critical ("Could not create device: %s", e.message);
+ log.error ("Could not create device: %s", e.message);
}
} else {
devs.add (Device.new_with_type (adapter, frontend));
@@ -272,7 +275,7 @@ namespace DVB.database.sqlite {
// No devices for this group
if (ref_dev == null) {
- debug ("Group %d has no devices", group_id);
+ log.debug ("Group %d has no devices", group_id);
continue;
}
@@ -280,19 +283,19 @@ namespace DVB.database.sqlite {
DeviceGroup group = new DeviceGroup ((uint)group_id, ref_dev,
!Main.get_disable_epg_scanner());
group.Name = statement.column_text (4);
-
+
for (int i=0; i<devs.size; i++)
group.add (devs.get (i));
-
+
groups.add (group);
}
-
+
return groups;
}
-
+
public bool add_device_group (DeviceGroup dev_group) throws SqlError {
if (this.contains_group (dev_group.Id)) return false;
-
+
string channels = dev_group.Channels.channels_file.get_path ();
string recdir = dev_group.RecordingsDirectory.get_path ();
@@ -304,14 +307,14 @@ namespace DVB.database.sqlite {
this.throw_last_error ();
return false;
}
-
+
this.begin_transaction ();
if (this.insert_group_statement.step () != Sqlite.DONE) {
this.throw_last_error_reset (this.insert_group_statement);
return false;
- }
+ }
this.insert_group_statement.reset ();
-
+
foreach (Device dev in dev_group)
this.add_device_to_group (dev, dev_group);
@@ -319,7 +322,7 @@ namespace DVB.database.sqlite {
return true;
}
-
+
public bool remove_device_group (DeviceGroup devgroup) throws SqlError {
if (this.delete_group_statement.bind_int (1, (int)devgroup.Id) != Sqlite.OK) {
this.throw_last_error ();
@@ -341,11 +344,11 @@ namespace DVB.database.sqlite {
if (this.delete_group_devices_statement.step () != Sqlite.DONE) {
this.throw_last_error_reset (this.delete_group_devices_statement);
return false;
- }
+ }
this.delete_group_devices_statement.reset ();
this.end_transaction ();
-
+
return true;
}
@@ -366,14 +369,14 @@ namespace DVB.database.sqlite {
return ret;
}
-
+
public bool contains_group (uint group_id) throws SqlError {
if (this.contains_group_statement.bind_int (1, (int)group_id) != Sqlite.OK)
{
this.throw_last_error ();
return false;
}
-
+
int c = 0;
while (this.contains_group_statement.step () == Sqlite.ROW) {
c = this.contains_group_statement.column_int (0);
@@ -382,7 +385,7 @@ namespace DVB.database.sqlite {
return (c > 0);
}
-
+
public bool add_device_to_group (Device dev, DeviceGroup devgroup)
throws SqlError
{
@@ -393,7 +396,7 @@ namespace DVB.database.sqlite {
this.throw_last_error ();
return false;
}
-
+
if (this.insert_device_statement.step () != Sqlite.DONE) {
this.throw_last_error_reset (this.insert_device_statement);
return false;
@@ -402,7 +405,7 @@ namespace DVB.database.sqlite {
return true;
}
-
+
public bool remove_device_from_group (Device dev, DeviceGroup devgroup)
throws SqlError
{
@@ -412,7 +415,7 @@ namespace DVB.database.sqlite {
this.throw_last_error ();
return false;
}
-
+
if (this.delete_device_statement.step () != Sqlite.DONE) {
this.throw_last_error_reset (this.delete_device_statement);
return false;
@@ -421,7 +424,7 @@ namespace DVB.database.sqlite {
return true;
}
-
+
public Gee.List<Timer> get_all_timers_of_device_group (DeviceGroup dev)
throws SqlError
{
@@ -431,11 +434,11 @@ namespace DVB.database.sqlite {
this.throw_last_error ();
return timers;
}
-
+
while (this.select_timers_statement.step () == Sqlite.ROW) {
uint tid, sid, duration, event_id;
int year, month, day, hour, minute;
-
+
tid = (uint)this.select_timers_statement.column_int (0);
sid = (uint)this.select_timers_statement.column_int (2);
year = this.select_timers_statement.column_int (3);
@@ -445,18 +448,18 @@ namespace DVB.database.sqlite {
minute = this.select_timers_statement.column_int (7);
duration = (uint)this.select_timers_statement.column_int (8);
event_id = (uint)this.select_timers_statement.column_int (9);
-
+
Channel channel = dev.Channels.get_channel (sid);
Timer timer = new Timer (tid, channel, year, month, day, hour,
minute, duration);
timer.EventID = event_id;
timers.add (timer);
- }
+ }
this.select_timers_statement.reset ();
return timers;
}
-
+
public bool add_timer_to_device_group (Timer timer, DeviceGroup dev)
throws SqlError
{
@@ -477,16 +480,16 @@ namespace DVB.database.sqlite {
this.throw_last_error ();
return false;
}
-
+
if (this.insert_timer_statement.step () != Sqlite.DONE) {
this.throw_last_error_reset (this.insert_timer_statement);
return false;
- }
+ }
this.insert_timer_statement.reset ();
return true;
}
-
+
public bool remove_timer_from_device_group (uint timer_id,
DeviceGroup dev) throws SqlError
{
@@ -495,7 +498,7 @@ namespace DVB.database.sqlite {
this.throw_last_error ();
return false;
}
-
+
if (this.delete_timer_statement.step () != Sqlite.DONE) {
this.throw_last_error_reset (this.delete_timer_statement);
return false;
@@ -504,16 +507,16 @@ namespace DVB.database.sqlite {
return true;
}
-
+
public bool remove_all_timers_from_device_group (uint group_id)
- throws SqlError
+ throws SqlError
{
if (this.delete_group_timers_statement.bind_int (1, (int)group_id) != Sqlite.OK)
{
this.throw_last_error ();
return false;
}
-
+
if (this.delete_group_timers_statement.step () != Sqlite.DONE) {
this.throw_last_error_reset (this.delete_group_timers_statement);
return false;
@@ -522,23 +525,23 @@ namespace DVB.database.sqlite {
return true;
}
-
+
public bool contains_timer (uint timer_id) throws SqlError {
if (this.contains_timer_statement.bind_int (1, (int)timer_id) != Sqlite.OK)
{
this.throw_last_error ();
return false;
}
-
+
int c = 0;
while (this.contains_timer_statement.step () == Sqlite.ROW) {
c = this.contains_timer_statement.column_int (0);
}
this.contains_timer_statement.reset ();
-
+
return (c > 0);
}
-
+
public bool update_from_group (DeviceGroup devgroup) throws SqlError {
if (this.update_group_statement.bind_int (1, (int)devgroup.Type) != Sqlite.OK
|| this.update_group_statement.bind_text (2, devgroup.Channels.channels_file.get_path ()) != Sqlite.OK
@@ -549,7 +552,7 @@ namespace DVB.database.sqlite {
this.throw_last_error ();
return false;
}
-
+
if (this.update_group_statement.step () != Sqlite.DONE) {
this.throw_last_error_reset (this.update_group_statement);
return false;
@@ -603,7 +606,7 @@ namespace DVB.database.sqlite {
return true;
}
-
+
public Gee.List<ChannelGroup> get_channel_groups ()
throws SqlError
{
diff --git a/src/database/sqlite/SqliteDatabase.vala b/src/database/sqlite/SqliteDatabase.vala
index ea72a87..78cd1cb 100644
--- a/src/database/sqlite/SqliteDatabase.vala
+++ b/src/database/sqlite/SqliteDatabase.vala
@@ -19,11 +19,14 @@
using GLib;
using Sqlite;
+using DVB.Logging;
namespace DVB.database.sqlite {
public abstract class SqliteDatabase : GLib.Object {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
public File database_file {get; construct;}
protected Database db;
@@ -48,7 +51,7 @@ namespace DVB.database.sqlite {
try {
Utils.mkdirs (dbfile_dir);
} catch (Error e) {
- critical ("Could not create directory: %s", e.message);
+ log.error ("Could not create directory: %s", e.message);
return;
}
}
@@ -60,10 +63,10 @@ namespace DVB.database.sqlite {
int version = this.get_version ();
if (create_tables) {
- debug ("Creating tables");
+ log.debug ("Creating tables");
this.create ();
} else if (this.new_version > version) {
- debug ("Updating tables");
+ log.debug ("Updating tables");
this.upgrade (version, this.new_version);
}
this.set_version (this.new_version);
@@ -79,7 +82,7 @@ namespace DVB.database.sqlite {
try {
this.exec_sql ("PRAGMA user_version = %d".printf (version));
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
}
@@ -87,7 +90,7 @@ namespace DVB.database.sqlite {
try {
this.exec_sql ("PRAGMA journal_mode = TRUNCATE");
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
}
@@ -99,7 +102,7 @@ namespace DVB.database.sqlite {
try {
version = this.simple_query_int ("PRAGMA user_version");
} catch (SqlError e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
}
return version;
}
diff --git a/src/io/ChannelListReader.vala b/src/io/ChannelListReader.vala
index 89cecad..a841338 100644
--- a/src/io/ChannelListReader.vala
+++ b/src/io/ChannelListReader.vala
@@ -18,11 +18,14 @@
*/
using GLib;
+using DVB.Logging;
namespace DVB.io {
public class ChannelListReader : GLib.Object {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
public ChannelList channels {get; construct;}
public AdapterType Type {get; construct;}
@@ -66,7 +69,7 @@ namespace DVB.io {
break;
default:
- critical ("Unknown adapter type");
+ log.error ("Unknown adapter type");
break;
}
diff --git a/src/io/RecordingReader.vala b/src/io/RecordingReader.vala
index bbb9a3c..7041dd7 100644
--- a/src/io/RecordingReader.vala
+++ b/src/io/RecordingReader.vala
@@ -18,11 +18,14 @@
*/
using GLib;
+using DVB.Logging;
namespace DVB.io {
public class RecordingReader : GLib.Object {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
public File directory {get; construct;}
public RecordingsStore store {get; construct;}
@@ -42,7 +45,7 @@ namespace DVB.io {
*/
public bool load_into () {
if (!this.directory.query_exists (null)) {
- debug ("Directory %s does not exist", this.directory.get_path ());
+ log.debug ("Directory %s does not exist", this.directory.get_path ());
return false;
}
@@ -54,17 +57,17 @@ namespace DVB.io {
try {
info = directory.query_info (ATTRS, 0, null);
} catch (Error e) {
- critical ("Could not retrieve attributes: %s", e.message);
+ log.error ("Could not retrieve attributes: %s", e.message);
return false;
}
if (info.get_file_type () != FileType.DIRECTORY) {
- critical ("%s is not a directory", directory.get_path ());
+ log.error ("%s is not a directory", directory.get_path ());
return false;
}
if (!info.get_attribute_boolean (FILE_ATTRIBUTE_ACCESS_CAN_READ)) {
- critical ("Cannot read %s", directory.get_path ());
+ log.error ("Cannot read %s", directory.get_path ());
return false;
}
@@ -80,7 +83,7 @@ namespace DVB.io {
files = recordingsbasedir.enumerate_children (
ATTRS, 0, null);
} catch (Error e) {
- critical ("Could not read directory: %s", e.message);
+ log.error ("Could not read directory: %s", e.message);
return false;
}
@@ -105,12 +108,12 @@ namespace DVB.io {
try {
rec = this.deserialize (child);
} catch (Error e) {
- critical (
+ log.error (
"Could not deserialize recording: %s",
e.message);
}
if (rec != null) {
- debug ("Restored recording from %s",
+ log.debug ("Restored recording from %s",
child.get_path ());
this.store.add_and_monitor (rec);
@@ -121,13 +124,13 @@ namespace DVB.io {
}
}
} catch (Error e) {
- critical ("%s", e.message);
+ log.error ("%s", e.message);
success = false;
} finally {
try {
files.close (null);
} catch (Error e) {
- critical ("Could not close file: %s", e.message);
+ log.error ("Could not close file: %s", e.message);
success = false;
}
}
diff --git a/src/io/RecordingWriter.vala b/src/io/RecordingWriter.vala
index e8e078b..9f53d3b 100644
--- a/src/io/RecordingWriter.vala
+++ b/src/io/RecordingWriter.vala
@@ -18,11 +18,14 @@
*/
using GLib;
+using DVB.Logging;
namespace DVB.io {
public class RecordingWriter : GLib.Object {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
public Recording rec {get; construct;}
public RecordingWriter (Recording rec) {
@@ -38,10 +41,10 @@ namespace DVB.io {
File recfile = parentdir.get_child ("info.rec");
- debug ("Saving recording to %s", recfile.get_path() );
+ log.debug ("Saving recording to %s", recfile.get_path() );
if (recfile.query_exists (null)) {
- debug ("Deleting old info.rec");
+ log.debug ("Deleting old info.rec");
recfile.delete (null);
}
diff --git a/src/rtsp/MediaFactory.vala b/src/rtsp/MediaFactory.vala
index 8777a93..dd94b0c 100644
--- a/src/rtsp/MediaFactory.vala
+++ b/src/rtsp/MediaFactory.vala
@@ -18,11 +18,14 @@
*/
using GLib;
+using DVB.Logging;
namespace DVB {
public class MediaFactory : Gst.RTSPMediaFactory {
+ private static Logger log = LogManager.getLogManager().getDefaultLogger();
+
construct {
this.set_shared (true);
}
@@ -30,7 +33,7 @@ namespace DVB {
public override Gst.RTSPMedia? @construct (Gst.RTSPUrl url) {
uint sidnr = 0;
uint grpnr = 0;
-
+
string[] path_elements = url.abspath.split ("/");
int i = 0;
string elem;
@@ -39,41 +42,41 @@ namespace DVB {
grpnr = (uint)int.parse (elem);
else if (i == 2)
sidnr = (uint)int.parse (elem);
-
+
i++;
}
-
+
Manager manager = Manager.get_instance();
-
- DeviceGroup? devgrp =
+
+ DeviceGroup? devgrp =
manager.get_device_group_if_exists (grpnr);
if (devgrp == null) {
warning ("Unknown group %u", grpnr);
return null;
}
-
+
Gst.Element payload = Gst.ElementFactory.make ("rtpmp2tpay",
"pay0");
if (payload == null) {
- critical ("Could not create rtpmp2tpay element");
- return null;
+ log.error ("Could not create rtpmp2tpay element");
+ return null;
}
payload.set ("pt", 96);
-
+
Channel? channel = devgrp.Channels.get_channel (sidnr);
if (channel == null) {
- critical ("No channel with SID %u", sidnr);
+ log.error ("No channel with SID %u", sidnr);
return null;
}
ChannelFactory channels_factory = devgrp.channel_factory;
-
+
PlayerThread? player = channels_factory.watch_channel (channel,
payload, false, DVB.RTSPServer.stop_streaming);
if (player == null) {
- debug ("Could not create player");
+ log.debug ("Could not create player");
return null;
}
- debug ("Retrieving sink bin with payloader");
+ log.debug ("Retrieving sink bin with payloader");
Gst.Element? bin = player.get_sink_bin (sidnr, payload);
// Construct media
@@ -81,7 +84,7 @@ namespace DVB {
media.element = bin;
// Set pipeline
media.pipeline = player.get_pipeline ();
-
+
this.collect_streams (url, media);
return media;
diff --git a/src/rtsp/Server.vala b/src/rtsp/Server.vala
index d5607c0..7cfc783 100644
--- a/src/rtsp/Server.vala
+++ b/src/rtsp/Server.vala
@@ -17,8 +17,12 @@
* along with GNOME DVB Daemon. If not, see <http://www.gnu.org/licenses/>.
*/
+using DVB.Logging;
+
namespace DVB.RTSPServer {
+ private static Logger log;
+
private static Gst.RTSPServer server;
private static uint timeout_id;
@@ -44,7 +48,8 @@ namespace DVB.RTSPServer {
}
public static bool start () {
- message ("Starting RTSP server");
+ log = LogManager.getLogManager().getDefaultLogger();
+ log.info ("Starting RTSP server");
server = new Gst.RTSPServer ();
server.set_media_mapping (new MediaMapping ());
server.set_address (get_address ());
@@ -59,7 +64,7 @@ namespace DVB.RTSPServer {
}
public static void stop_streaming (Channel channel) {
- debug ("Stop streaming channel %s", channel.Name);
+ log.debug ("Stop streaming channel %s", channel.Name);
var helper = new StopChannelHelper (channel.URL);
server.session_pool.filter (helper.session_filter_func);
diff --git a/src/rygel/Services2.vala b/src/rygel/Services2.vala
index e915ed8..afb79ae 100644
--- a/src/rygel/Services2.vala
+++ b/src/rygel/Services2.vala
@@ -18,9 +18,12 @@
*/
using GLib;
using Gee;
+using DVB.Logging;
namespace DVB.MediaServer2 {
-
+
+ private static Logger log;
+
private static const string SERVICE_NAME = "org.gnome.UPnP.MediaServer2.DVBDaemon";
private static const string ROOT_PATH = "/org/gnome/UPnP/MediaServer2/DVBDaemon";
@@ -56,7 +59,7 @@ namespace DVB.MediaServer2 {
}
private void create_service (DeviceGroup devgroup) {
- debug ("Creating container for device group %u", devgroup.Id);
+ log.debug ("Creating container for device group %u", devgroup.Id);
var devgroup_container = new ChannelsMediaContainer2 (
devgroup, this.path);
@@ -199,7 +202,7 @@ namespace DVB.MediaServer2 {
}
public void create_service (Channel channel) {
- debug ("Creating container for channel %u", channel.Sid);
+ log.debug ("Creating container for channel %u", channel.Sid);
var channel_item = new ChannelMediaItem2 (
channel, new ObjectPath (this.Path));
@@ -380,6 +383,7 @@ namespace DVB.MediaServer2 {
}
public static bool start_rygel_services () {
+ log = LogManager.getLogManager().getDefaultLogger();
Utils.dbus_own_name (SERVICE_NAME, on_bus_acquired);
return false;
}
diff --git a/vapi/cutils.vapi b/vapi/cutils.vapi
index 5529737..aedf182 100644
--- a/vapi/cutils.vapi
+++ b/vapi/cutils.vapi
@@ -26,9 +26,6 @@ namespace cUtils {
public static SignalHandler connect (int signum, SignalHandler handler);
}
- [CCode (cname = "g_log_default_handler", cheader_filename = "glib.h")]
- public static void log_default_handler (string? log_domain, GLib.LogLevelFlags log_levels, string message, void* data);
-
[CCode (cname = "gst_bus_add_watch_context", cheader_filename = "cstuff.h")]
public static uint gst_bus_add_watch_context (Gst.Bus bus, Gst.BusFunc func, GLib.MainContext context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]