<commit_before>"use strict";

var Utils = require('./utils');

var ServiceInterface = require('./service_interface');

var ServiceObject = module.exports = function(service, objectPath) {
	var self = this;

	self.service = service;
	self.path = objectPath;
	self.interfaces = {};
	self.introspection = null;

	// Initializing introspectable interface
	self.introspectableInterface = self.createInterface('org.freedesktop.DBus.Introspectable');
	self.introspectableInterface.addMethod('Introspect', { out: Utils.Define(String, 'data') }, function(callback) {
		self.updateIntrospection();
		callback(self.introspection);
	});
	self.introspectableInterface.update();

	// Initializing property interface
	self.propertyInterface = self.createInterface('org.freedesktop.DBus.Properties');
	self.propertyInterface.addMethod('Get', {
		in: [
			Utils.Define(String, 'interface_name'),
			Utils.Define(String, 'property_name')
		],
		out: Utils.Define('Auto', 'value')
	}, function(interfaceName, propName, callback) {
		var iface = self['interfaces'][interfaceName];
		if (!iface) {
			callback('Doesn\'t support such property');
			return;
		}

		if (!iface.getProperty(propName, callback))
			callback('Doesn\'t support such property');
	});

	self.propertyInterface.addMethod('Set', {
		in: [
			Utils.Define(String, 'interface_name'),
			Utils.Define(String, 'property_name'),
			Utils.Define('auto', 'value')
		]
	}, function(interfaceName, propName, value, callback) {
		var iface = self['interfaces'][interfaceName];
		if (!iface) {
			callback('Doesn\'t support such property');
			return;
		}

		if (!iface.setProperty(propName, value, callback))
			callback('Doesn\'t support such property');
	});

	self.propertyInterface.addMethod('GetAll', {
		in: [
			Utils.Define(String, 'interface_name')
		],
		out: Utils.Define(Object, 'properties')
	}, function(interfaceName, callback) {
		var iface = self['interfaces'][interfaceName];
		if (!iface) {
			callback('Doesn\'t have any properties');
			return;
		}

		iface.getProperties(function(props) {
			callback(props);
		});
	});
	
	self.propertyInterface.addSignal('PropertiesChanged', {
		types: [Utils.Define(String, 'interface_name'), Utils.Define(Object, 'changed_properties'), Utils.Define(Array, 'invalidated_properties')]
	});
	
	self.propertyInterface.update();
};

ServiceObject.prototype.createInterface = function(interfaceName) {
	var self = this;

	if (!self.interfaces[interfaceName])
		self.interfaces[interfaceName] = new ServiceInterface(self, interfaceName);

	self.interfaces[interfaceName].update();

	return self.interfaces[interfaceName];
};

ServiceObject.prototype.updateIntrospection = function() {
	var self = this;

	var introspection = [
		'<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"',
		'"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">',
		'<node name="' + self.path + '">'
	];

	for (var interfaceName in self.interfaces) {
		var iface = self.interfaces[interfaceName];
		introspection.push(iface.introspection);
	}

	introspection.push('</node>');

	self.introspection = introspection.join('\n');
};<commit_msg>Allow child paths to be introspectable<commit_after>"use strict";

var Utils = require('./utils');

var ServiceInterface = require('./service_interface');

var ServiceObject = module.exports = function(service, objectPath) {
	var self = this;

	self.service = service;
	self.path = objectPath;
	self.interfaces = {};
	self.introspection = null;

	// Initializing introspectable interface
	self.introspectableInterface = self.createInterface('org.freedesktop.DBus.Introspectable');
	self.introspectableInterface.addMethod('Introspect', { out: Utils.Define(String, 'data') }, function(callback) {
		self.updateIntrospection();
		callback(self.introspection);
	});
	self.introspectableInterface.update();

	// Initializing property interface
	self.propertyInterface = self.createInterface('org.freedesktop.DBus.Properties');
	self.propertyInterface.addMethod('Get', {
		in: [
			Utils.Define(String, 'interface_name'),
			Utils.Define(String, 'property_name')
		],
		out: Utils.Define('Auto', 'value')
	}, function(interfaceName, propName, callback) {
		var iface = self['interfaces'][interfaceName];
		if (!iface) {
			callback('Doesn\'t support such property');
			return;
		}

		if (!iface.getProperty(propName, callback))
			callback('Doesn\'t support such property');
	});

	self.propertyInterface.addMethod('Set', {
		in: [
			Utils.Define(String, 'interface_name'),
			Utils.Define(String, 'property_name'),
			Utils.Define('auto', 'value')
		]
	}, function(interfaceName, propName, value, callback) {
		var iface = self['interfaces'][interfaceName];
		if (!iface) {
			callback('Doesn\'t support such property');
			return;
		}

		if (!iface.setProperty(propName, value, callback))
			callback('Doesn\'t support such property');
	});

	self.propertyInterface.addMethod('GetAll', {
		in: [
			Utils.Define(String, 'interface_name')
		],
		out: Utils.Define(Object, 'properties')
	}, function(interfaceName, callback) {
		var iface = self['interfaces'][interfaceName];
		if (!iface) {
			callback('Doesn\'t have any properties');
			return;
		}

		iface.getProperties(function(props) {
			callback(props);
		});
	});
	
	self.propertyInterface.addSignal('PropertiesChanged', {
		types: [Utils.Define(String, 'interface_name'), Utils.Define(Object, 'changed_properties'), Utils.Define(Array, 'invalidated_properties')]
	});
	
	self.propertyInterface.update();
};

ServiceObject.prototype.createInterface = function(interfaceName) {
	var self = this;

	if (!self.interfaces[interfaceName])
		self.interfaces[interfaceName] = new ServiceInterface(self, interfaceName);

	self.interfaces[interfaceName].update();

	return self.interfaces[interfaceName];
};

ServiceObject.prototype.updateIntrospection = function() {
	var self = this;
	var i;

	var introspection = [
		'<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"',
		'"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">',
		'<node name="' + self.path + '">'
	];

	for (var interfaceName in self.interfaces) {
		var iface = self.interfaces[interfaceName];
		introspection.push(iface.introspection);
	}

	var childNodes = self.buildChildNodes();

	for (i = 0; i < childNodes.length; i++) {
		introspection.push('<node name="' + childNodes[i] + '"/>');
	}
	introspection.push('</node>');

	self.introspection = introspection.join('\n');
};

ServiceObject.prototype.buildChildNodes = function() {
	var self = this;

	function unique(arr) {
		var t = {};
		var i;
		for (i = 0; i < arr.length; i++) {
			t[arr[i]] = true;
		}

		return Object.keys(t);
	}

	var prefix = self.path + '/';
	var allKeys = Object.keys(self.service.objects);
	var childKeys = allKeys.filter(function(key) {
		return key.substr(0, prefix.length) == prefix
		    && key.length > prefix.length;
	});
	var unprefixedChildKeys = childKeys.map(function(key) {
		return key.substr(prefix.length);
	});
	var childNodes = unprefixedChildKeys.map(function(key) {
		return key.split('/')[0];
	});
	var uniqueChildNodes = unique(childNodes);

	return uniqueChildNodes;
};
{'fraction_non_alphanumeric': 0.15858416945373466, 'fraction_numerical': 0.0016722408026755853, 'mean_word_length': 5.015926236378877, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '196916', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2283, 'n_words': 420}