[gnome-dvb-daemon] Converted Factory to a GObject class.
- From: Sebastian Polsterl <sebp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-dvb-daemon] Converted Factory to a GObject class.
- Date: Thu, 29 Sep 2011 20:29:17 +0000 (UTC)
commit 5b7c2b86ddaf7cf613571fbab04be427ed18b3fb
Author: Sebastian PÃlsterl <sebp k-d-w org>
Date: Thu Sep 29 22:04:21 2011 +0200
Converted Factory to a GObject class.
Static fields can only be initialized with constants in compact classes.
Using a GObject class, the mutexes are initialized once the first Factory instance is created.
See also https://bugzilla.gnome.org/show_bug.cgi?id=636509
src/ChannelList.vala | 6 ++--
src/DeviceGroup.vala | 8 +++---
src/EPGScanner.vala | 2 +-
src/Factory.vala | 59 +++++++++++++++++++------------------------------
src/Main.vala | 6 ++--
src/Manager.vala | 20 ++++++++--------
src/Recorder.vala | 10 ++++----
src/Schedule.vala | 2 +-
src/rtsp/Server.vala | 2 +-
9 files changed, 51 insertions(+), 64 deletions(-)
---
diff --git a/src/ChannelList.vala b/src/ChannelList.vala
index 1787c5e..63ed691 100644
--- a/src/ChannelList.vala
+++ b/src/ChannelList.vala
@@ -270,7 +270,7 @@ namespace DVB {
public bool GetChannelsOfGroup (int channel_group_id,
out uint[] channel_ids) throws DBusError
{
- ConfigStore config = Factory.get_config_store ();
+ ConfigStore config = new Factory().get_config_store ();
Gee.List<uint> channels;
try {
channels = config.get_channels_of_group (this.GroupId,
@@ -297,7 +297,7 @@ namespace DVB {
public bool AddChannelToGroup (uint channel_id, int channel_group_id)
throws DBusError
{
- ConfigStore config = Factory.get_config_store ();
+ ConfigStore config = new Factory().get_config_store ();
Channel? chan = this.get_channel (channel_id);
if (chan == null)
return false;
@@ -320,7 +320,7 @@ namespace DVB {
public bool RemoveChannelFromGroup (uint channel_id,
int channel_group_id) throws DBusError
{
- ConfigStore config = Factory.get_config_store ();
+ ConfigStore config = new Factory().get_config_store ();
Channel? chan = this.get_channel (channel_id);
if (chan == null)
return false;
diff --git a/src/DeviceGroup.vala b/src/DeviceGroup.vala
index 0fdcb62..154f1ca 100644
--- a/src/DeviceGroup.vala
+++ b/src/DeviceGroup.vala
@@ -260,7 +260,7 @@ namespace DVB {
if (this.add (device)) {
try {
- Factory.get_config_store ().add_device_to_group (device,
+ new Factory().get_config_store ().add_device_to_group (device,
this);
} catch (SqlError e) {
log.error ("%s", e.message);
@@ -316,7 +316,7 @@ namespace DVB {
this.stop_epg_scanner ();
try {
- Factory.get_config_store ().remove_device_from_group (
+ new Factory().get_config_store ().remove_device_from_group (
dev, this);
} catch (SqlError e) {
log.error ("%s", e.message);
@@ -351,7 +351,7 @@ namespace DVB {
public bool SetName (string name) throws DBusError {
this.Name = name;
try {
- ConfigStore config = Factory.get_config_store();
+ ConfigStore config = new Factory().get_config_store();
config.update_from_group (this);
} catch (SqlError e) {
log.error ("%s", e.message);
@@ -440,7 +440,7 @@ namespace DVB {
public bool SetRecordingsDirectory (string location) throws DBusError {
this.RecordingsDirectory = File.new_for_path (location);
try {
- ConfigStore config = Factory.get_config_store();
+ ConfigStore config = new Factory().get_config_store();
config.update_from_group (this);
} catch (SqlError e) {
log.error ("%s", e.message);
diff --git a/src/EPGScanner.vala b/src/EPGScanner.vala
index 6148410..aa90915 100644
--- a/src/EPGScanner.vala
+++ b/src/EPGScanner.vala
@@ -63,7 +63,7 @@ namespace DVB {
this.DeviceGroup = device;
// check if interval is unset
if (CHECK_EIT_INTERVAL == -1) {
- Settings settings = Factory.get_settings ();
+ Settings settings = new Factory().get_settings ();
CHECK_EIT_INTERVAL = settings.get_epg_scan_interval ();
}
}
diff --git a/src/Factory.vala b/src/Factory.vala
index eec87a0..fbac509 100644
--- a/src/Factory.vala
+++ b/src/Factory.vala
@@ -24,20 +24,16 @@ using DVB.Logging;
namespace DVB {
- [Compact]
- public class Factory {
+ public class Factory : GLib.Object {
private static Logger log = LogManager.getLogManager().getDefaultLogger();
private static SqliteConfigTimersStore store;
- private static StaticRecMutex store_mutex = StaticRecMutex ();
private static SqliteEPGStore epgstore;
- private static StaticRecMutex epgstore_mutex = StaticRecMutex ();
private static DVB.Settings settings;
- private static StaticRecMutex settings_mutex = StaticRecMutex ();
-
- public static TimersStore get_timers_store () {
- store_mutex.lock ();
+
+ public TimersStore get_timers_store () {
+ lock(store) {
if (store == null) {
store = new SqliteConfigTimersStore ();
try {
@@ -47,12 +43,12 @@ namespace DVB {
store = null;
}
}
- store_mutex.unlock ();
+ }
return store;
}
-
- public static ConfigStore get_config_store () {
- store_mutex.lock ();
+
+ public ConfigStore get_config_store () {
+ lock(store) {
if (store == null) {
store = new SqliteConfigTimersStore ();
try {
@@ -62,12 +58,12 @@ namespace DVB {
store = null;
}
}
- store_mutex.unlock ();
+ }
return store;
}
-
- public static EPGStore get_epg_store () {
- epgstore_mutex.lock ();
+
+ public EPGStore get_epg_store () {
+ lock (epgstore) {
if (epgstore == null) {
epgstore = new SqliteEPGStore ();
try {
@@ -77,35 +73,26 @@ namespace DVB {
epgstore = null;
}
}
- epgstore_mutex.unlock ();
+ }
return epgstore;
}
-
- public static DVB.Settings get_settings () {
- settings_mutex.lock ();
+
+ public DVB.Settings get_settings () {
+ lock(settings) {
if (settings == null) {
settings = new DVB.Settings ();
settings.load ();
}
- settings_mutex.unlock ();
+ }
return settings;
}
-
- public static void shutdown () {
- store_mutex.lock ();
- store = null;
- store_mutex.unlock ();
-
- epgstore_mutex.lock ();
- epgstore = null;
- epgstore_mutex.unlock ();
-
- settings_mutex.lock ();
+
+ public void shutdown () {
+ lock(settings) {
if (settings != null) settings.save ();
- settings = null;
- settings_mutex.unlock ();
+ }
}
-
+
}
-
+
}
diff --git a/src/Main.vala b/src/Main.vala
index 37767aa..518af31 100644
--- a/src/Main.vala
+++ b/src/Main.vala
@@ -72,7 +72,7 @@ namespace Main {
DVB.RTSPServer.shutdown ();
DVB.Manager.shutdown ();
- DVB.Factory.shutdown ();
+ new DVB.Factory().shutdown ();
DVB.RecordingsStore.shutdown ();
DVB.Logging.LogManager.getLogManager().cleanup ();
@@ -115,7 +115,7 @@ namespace Main {
}
private static void restore_device_groups () {
- DVB.database.ConfigStore config_store = DVB.Factory.get_config_store ();
+ DVB.database.ConfigStore config_store = new DVB.Factory().get_config_store ();
Gee.List<DVB.DeviceGroup> device_groups;
try {
@@ -137,7 +137,7 @@ namespace Main {
}
private static void restore_fake_devices (uint max_group_id) {
- DVB.Settings settings = DVB.Factory.get_settings ();
+ DVB.Settings settings = new DVB.Factory().get_settings ();
Gee.List<DVB.Device> devices = settings.get_fake_devices ();
if (devices.size > 0) {
DVB.Device ref_dev = devices.get (0);
diff --git a/src/Manager.vala b/src/Manager.vala
index 888621d..9fedc11 100644
--- a/src/Manager.vala
+++ b/src/Manager.vala
@@ -289,7 +289,7 @@ namespace DVB {
* @returns: ID and name of each channel group
*/
public ChannelGroupInfo[] GetChannelGroups () throws DBusError {
- ConfigStore config = Factory.get_config_store ();
+ ConfigStore config = new Factory().get_config_store ();
Gee.List<ChannelGroup> groups;
try {
groups = config.get_channel_groups ();
@@ -312,7 +312,7 @@ namespace DVB {
* @returns: TRUE on success
*/
public bool AddChannelGroup (string name, out int channel_group_id) throws DBusError {
- ConfigStore config = Factory.get_config_store ();
+ ConfigStore config = new Factory().get_config_store ();
bool ret;
try {
ret = config.add_channel_group (name, out channel_group_id);
@@ -328,7 +328,7 @@ namespace DVB {
* @returns: TRUE on success
*/
public bool RemoveChannelGroup (int channel_group_id) throws DBusError {
- ConfigStore config = Factory.get_config_store ();
+ ConfigStore config = new Factory().get_config_store ();
bool ret;
try {
ret = config.remove_channel_group (channel_group_id);
@@ -401,7 +401,7 @@ namespace DVB {
}
if (store) {
try {
- Factory.get_config_store ().add_device_group (devgroup);
+ new Factory().get_config_store ().add_device_group (devgroup);
} catch (SqlError e) {
log.error ("%s", e.message);
return false;
@@ -436,7 +436,7 @@ namespace DVB {
public void restore_timers (DeviceGroup device_group) {
log.info ("Restoring timers of device group %u", device_group.Id);
- TimersStore timers_store = Factory.get_timers_store ();
+ TimersStore timers_store = new Factory().get_timers_store ();
Gee.List<Timer> timers;
try {
@@ -567,12 +567,12 @@ namespace DVB {
devgroup.destroy ();
try {
- Factory.get_config_store ().remove_device_group (
+ new Factory().get_config_store ().remove_device_group (
devgroup);
- Factory.get_epg_store ().remove_events_of_group (
+ new Factory().get_epg_store ().remove_events_of_group (
devgroup.Id
);
- Factory.get_timers_store ().remove_all_timers_from_device_group (
+ new Factory().get_timers_store ().remove_all_timers_from_device_group (
devgroup.Id
);
this.group_removed (group_id);
@@ -584,7 +584,7 @@ namespace DVB {
}
private void create_device_group_by_id (uint group_id) {
- ConfigStore config_store = Factory.get_config_store ();
+ ConfigStore config_store = new Factory().get_config_store ();
Gee.List<DeviceGroup> groups;
try {
@@ -613,7 +613,7 @@ namespace DVB {
uint group_id;
bool found = false;
- ConfigStore config_store = Factory.get_config_store ();
+ ConfigStore config_store = new Factory().get_config_store ();
try {
found = config_store.get_parent_group (adapter,
frontend, out group_id);
diff --git a/src/Recorder.vala b/src/Recorder.vala
index 8073ade..047f607 100644
--- a/src/Recorder.vala
+++ b/src/Recorder.vala
@@ -122,7 +122,7 @@ namespace DVB {
return false;
}
- Settings settings = Factory.get_settings ();
+ Settings settings = new Factory().get_settings ();
int start_margin = -1 * settings.get_timers_margin_start ();
uint end_margin = (uint)(2 * settings.get_timers_margin_end ());
@@ -167,7 +167,7 @@ namespace DVB {
if (!has_conflict) {
this.timers.set (new_timer.Id, new_timer);
try {
- Factory.get_timers_store ().add_timer_to_device_group (new_timer,
+ new Factory().get_timers_store ().add_timer_to_device_group (new_timer,
this.DeviceGroup);
} catch (SqlError e) {
log.error ("%s", e.message);
@@ -199,7 +199,7 @@ namespace DVB {
*/
public bool AddTimerForEPGEvent (uint event_id, uint channel_sid,
out uint32 timer_id) throws DBusError {
- EPGStore epgstore = Factory.get_epg_store ();
+ EPGStore epgstore = new Factory().get_epg_store ();
Event? event = null;
try {
event = epgstore.get_event (event_id, channel_sid, this.DeviceGroup.Id);
@@ -241,7 +241,7 @@ namespace DVB {
}
this.timers.unset (timer_id);
try {
- Factory.get_timers_store ().remove_timer_from_device_group (
+ new Factory().get_timers_store ().remove_timer_from_device_group (
timer_id, this.DeviceGroup);
} catch (SqlError e) {
log.error ("%s", e.message);
@@ -535,7 +535,7 @@ namespace DVB {
public OverlapType HasTimerForEvent (uint event_id, uint channel_sid)
throws DBusError
{
- EPGStore epgstore = Factory.get_epg_store ();
+ EPGStore epgstore = new Factory().get_epg_store ();
Event? event = null;
try {
event = epgstore.get_event (event_id, channel_sid,
diff --git a/src/Schedule.vala b/src/Schedule.vala
index 652625a..9828a26 100644
--- a/src/Schedule.vala
+++ b/src/Schedule.vala
@@ -44,7 +44,7 @@ namespace DVB {
construct {
this.events = new EventStorage ();
- this.epgstore = Factory.get_epg_store ();
+ this.epgstore = new Factory().get_epg_store ();
}
public async void restore () {
diff --git a/src/rtsp/Server.vala b/src/rtsp/Server.vala
index 9dc3cf1..6b3c497 100644
--- a/src/rtsp/Server.vala
+++ b/src/rtsp/Server.vala
@@ -27,7 +27,7 @@ namespace DVB.RTSPServer {
private static uint timeout_id;
public static string get_address () {
- DVB.Settings settings = DVB.Factory.get_settings ();
+ DVB.Settings settings = new DVB.Factory().get_settings ();
string iface = settings.get_streaming_interface ();
string? address = null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]