summaryrefslogtreecommitdiff
path: root/src/librygel-ruih
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2014-10-19 10:24:15 +0200
committerJens Georg <mail@jensge.org>2014-11-08 13:20:55 +0100
commitf4f1ba6a658469bfb5cc6ba080116afc1976a71e (patch)
tree2ce161fb2352363b93b7c02486d6260200d030a5 /src/librygel-ruih
parent1ee43f693ca8581fa382085111a504f52972cf7f (diff)
downloadrygel-f4f1ba6a658469bfb5cc6ba080116afc1976a71e.tar.gz
ruih: Remove locking
get_compatible_uis () and set_ui_list () can never be called from different threads. It is not possible to modify the UI list while querying it. Signed-off-by: Jens Georg <mail@jensge.org>
Diffstat (limited to 'src/librygel-ruih')
-rw-r--r--src/librygel-ruih/rygel-ruih-servicemanager.vala243
1 files changed, 119 insertions, 124 deletions
diff --git a/src/librygel-ruih/rygel-ruih-servicemanager.vala b/src/librygel-ruih/rygel-ruih-servicemanager.vala
index d4777fd1..6b85b1ad 100644
--- a/src/librygel-ruih/rygel-ruih-servicemanager.vala
+++ b/src/librygel-ruih/rygel-ruih-servicemanager.vala
@@ -48,7 +48,6 @@ public class Rygel.RuihServiceManager : Object
private static string POST_RESULT = "</" + UILIST + ">\n";
private ArrayList<UIElem> ui_list;
- private Object object = null;
private static RuihServiceManager instance = null;
@@ -106,155 +105,151 @@ public class Rygel.RuihServiceManager : Object
}
public void set_ui_list (string ui_list_file_path) throws RuihServiceError {
- lock (object) {
- this.ui_list = new ArrayList<UIElem> ();
- // Empty internal data
- if (ui_list_file_path == null) {
- return;
- }
+ this.ui_list = new ArrayList<UIElem> ();
+ // Empty internal data
+ if (ui_list_file_path == null) {
+ return;
+ }
- Xml.Doc* doc = Parser.parse_file (ui_list_file_path);
- if (doc == null) {
- throw new RuihServiceError.OPERATION_REJECTED
- ("Unable to parse UI list file: " + ui_list_file_path);
- }
+ Xml.Doc* doc = Parser.parse_file (ui_list_file_path);
+ if (doc == null) {
+ throw new RuihServiceError.OPERATION_REJECTED
+ ("Unable to parse UI list file: " + ui_list_file_path);
+ }
- Xml.Node* ui_list_node = doc->get_root_element ();
- if (ui_list_node != null &&
- ui_list_node->name == UILIST)
+ Xml.Node* ui_list_node = doc->get_root_element ();
+ if (ui_list_node != null &&
+ ui_list_node->name == UILIST)
+ {
+ for (Xml.Node* child_node = ui_list_node->children;
+ child_node != null; child_node = child_node->next)
{
- for (Xml.Node* child_node = ui_list_node->children;
- child_node != null; child_node = child_node->next)
+ if (child_node->name == UI)
{
- if (child_node->name == UI)
- {
- this.ui_list.add (new UIElem (child_node));
- }
+ this.ui_list.add (new UIElem (child_node));
}
}
- delete doc;
}
+ delete doc;
}
public string get_compatible_uis (string deviceProfile, string filter)
- throws RuihServiceError {
- lock (object) {
- ArrayList<FilterEntry> filter_entries = new ArrayList<FilterEntry> ();
- Xml.Node* device_profile_node = null;
- Xml.Doc* doc = null;
- // Parse if there is device info
-
- if (deviceProfile != null && deviceProfile.length > 0) {
- doc = Parser.parse_memory (deviceProfile,
- deviceProfile.length);
- if (doc == null) {
- throw new RuihServiceError.OPERATION_REJECTED
- ("Unable to parse device profile data: " + deviceProfile);
- }
- device_profile_node = doc->get_root_element ();
+ throws RuihServiceError {
+ ArrayList<FilterEntry> filter_entries = new ArrayList<FilterEntry> ();
+ Xml.Node* device_profile_node = null;
+ Xml.Doc* doc = null;
+ // Parse if there is device info
+
+ if (deviceProfile != null && deviceProfile.length > 0) {
+ doc = Parser.parse_memory (deviceProfile,
+ deviceProfile.length);
+ if (doc == null) {
+ throw new RuihServiceError.OPERATION_REJECTED
+ ("Unable to parse device profile data: " + deviceProfile);
}
+ device_profile_node = doc->get_root_element ();
+ }
- // If inputDeviceProfile and filter are empty
- // just display all HTML5 UI elements.
- // This is a change from the UPNP-defined behavior
- if (device_profile_node == null && filter == "") {
- filter_entries.add (new FilterEntry (SHORT_NAME, "*HTML5*"));
- }
+ // If inputDeviceProfile and filter are empty
+ // just display all HTML5 UI elements.
+ // This is a change from the UPNP-defined behavior
+ if (device_profile_node == null && filter == "") {
+ filter_entries.add (new FilterEntry (SHORT_NAME, "*HTML5*"));
+ }
- // Parse device info to create protocols
- if (device_profile_node != null) {
- if (device_profile_node->name == DEVICEPROFILE) {
- for (Xml.Node* child_node = device_profile_node->children;
- child_node != null; child_node = child_node->next) {
- if (child_node->type == Xml.ElementType.TEXT_NODE) {
- // ignore text nodes
- continue;
- }
- if (child_node->name == PROTOCOL) {
- // Get shortName attribute
- for (Xml.Attr* prop = child_node->properties; prop != null;
- prop = prop->next) {
- if (prop->name == SHORT_NAME &&
- prop->children->content != null) {
- filter_entries.add (new FilterEntry (SHORT_NAME,
- prop->children->content));
- }
+ // Parse device info to create protocols
+ if (device_profile_node != null) {
+ if (device_profile_node->name == DEVICEPROFILE) {
+ for (Xml.Node* child_node = device_profile_node->children;
+ child_node != null; child_node = child_node->next) {
+ if (child_node->type == Xml.ElementType.TEXT_NODE) {
+ // ignore text nodes
+ continue;
+ }
+ if (child_node->name == PROTOCOL) {
+ // Get shortName attribute
+ for (Xml.Attr* prop = child_node->properties; prop != null;
+ prop = prop->next) {
+ if (prop->name == SHORT_NAME &&
+ prop->children->content != null) {
+ filter_entries.add (new FilterEntry (SHORT_NAME,
+ prop->children->content));
}
}
- if (child_node->name == PROTOCOL_INFO &&
- child_node->content != null) {
- filter_entries.add (new FilterEntry (PROTOCOL_INFO,
- child_node->content));
- }
- }// for
- }// if
- delete doc;
- } // outer if
-
- if (filter.length > 0) {
- var filter_wildcard = (filter == "*" || filter == "\"*\"");
-
- // Only enable wildcard if deviceprofile is not available
- if (device_profile_node == null && filter_wildcard) {
- // Wildcard filter entry
- filter_entries.add (new WildCardFilterEntry ());
- } else if (!filter_wildcard) {
- // Check if the input UIFilter is in the right format.
- if ((filter.get_char (0) != '"') ||
- ((filter.get_char (filter.length - 1) != '"')
- && (filter.get_char (filter.length - 1) != ','))
- || (!(filter.contains (",")) && filter.contains (";"))) {
- throw new RuihServiceError.INVALID_FILTER
- ("Invalid filter: " + filter);
}
+ if (child_node->name == PROTOCOL_INFO &&
+ child_node->content != null) {
+ filter_entries.add (new FilterEntry (PROTOCOL_INFO,
+ child_node->content));
+ }
+ }// for
+ }// if
+ delete doc;
+ } // outer if
+
+ if (filter.length > 0) {
+ var filter_wildcard = (filter == "*" || filter == "\"*\"");
+
+ // Only enable wildcard if deviceprofile is not available
+ if (device_profile_node == null && filter_wildcard) {
+ // Wildcard filter entry
+ filter_entries.add (new WildCardFilterEntry ());
+ } else if (!filter_wildcard) {
+ // Check if the input UIFilter is in the right format.
+ if ((filter.get_char (0) != '"') ||
+ ((filter.get_char (filter.length - 1) != '"')
+ && (filter.get_char (filter.length - 1) != ','))
+ || (!(filter.contains (",")) && filter.contains (";"))) {
+ throw new RuihServiceError.INVALID_FILTER
+ ("Invalid filter: " + filter);
+ }
- string[] entries = filter.split (",");
- foreach (unowned string str in entries) {
- // separator with no content, ignore
- if (str.length == 0) {
- continue;
- }
- string value = null;
- // string off quotes
- var name_value = str.split ("=");
- if (name_value != null &&
- name_value.length == 2 &&
- name_value[1] != null &&
- name_value[1].length > 2) {
- if (name_value[1].get_char (0) == '"' &&
- name_value[1].get_char
- (name_value[1].length - 1) == '"') {
- value = name_value[1].substring
- (1, name_value[1].length - 1);
- filter_entries.add (new FilterEntry
- (name_value[0], value));
- }
+ string[] entries = filter.split (",");
+ foreach (unowned string str in entries) {
+ // separator with no content, ignore
+ if (str.length == 0) {
+ continue;
+ }
+ string value = null;
+ // string off quotes
+ var name_value = str.split ("=");
+ if (name_value != null &&
+ name_value.length == 2 &&
+ name_value[1] != null &&
+ name_value[1].length > 2) {
+ if (name_value[1].get_char (0) == '"' &&
+ name_value[1].get_char
+ (name_value[1].length - 1) == '"') {
+ value = name_value[1].substring
+ (1, name_value[1].length - 1);
+ filter_entries.add (new FilterEntry
+ (name_value[0], value));
}
}
}
}
+ }
- // Generate result XML with or without protocols
- StringBuilder result = new StringBuilder (PRE_RESULT);
-
- if (this.ui_list != null && this.ui_list.size > 0) {
- var result_content = new StringBuilder ();
+ // Generate result XML with or without protocols
+ StringBuilder result = new StringBuilder (PRE_RESULT);
- foreach (UIElem i in this.ui_list) {
- UIElem ui = (UIElem)i;
- result_content.append (ui.to_ui_listing (filter_entries));
- }
+ if (this.ui_list != null && this.ui_list.size > 0) {
+ var result_content = new StringBuilder ();
- // Return empty string if there is no matching UI for a filter
- if (result_content.str == "") {
- return "";
- }
+ foreach (UIElem i in this.ui_list) {
+ UIElem ui = (UIElem)i;
+ result_content.append (ui.to_ui_listing (filter_entries));
+ }
- result.append (result_content.str);
+ // Return empty string if there is no matching UI for a filter
+ if (result_content.str == "") {
+ return "";
}
- result.append (POST_RESULT);
- return result.str;
+ result.append (result_content.str);
}
- }
+ result.append (POST_RESULT);
+
+ return result.str;
+}
} // RygelServiceManager class