diff options
Diffstat (limited to 'config.vala')
-rw-r--r-- | config.vala | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/config.vala b/config.vala new file mode 100644 index 0000000..4b28296 --- /dev/null +++ b/config.vala @@ -0,0 +1,114 @@ +/* Copyright 2012, Sebastian Reichel <sre@ring0.de> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +public class Config : KeyFile { + public Config() throws Error { + if(!load_from_file("microcopter.cfg", KeyFileFlags.NONE)) { + throw new FileError.FAILED("Could not load configuration file");; + } + } + + public MotorController get_motor_controller() throws Error { + string name = get_string("config", "motorcontroller"); + string path = Path.build_path("/", Environment.get_variable("PWD"), "actuators", "motor", "%s.so".printf(name)); + + var plugin = new PluginLoader<MotorController>(path); + if(!plugin.load()) + throw new KeyFileError.INVALID_VALUE("Could not load Plugin"); + + var result = plugin.new_object(); + result.init(this); + + return result; + } + + public Gyroscope get_gyroscope() throws Error { + string name = get_string("config", "gyroscope"); + string path = Path.build_path("/", Environment.get_variable("PWD"), "sensors", "gyroscope", "%s.so".printf(name)); + var plugin = new PluginLoader<Gyroscope>(path); + if(!plugin.load()) + throw new KeyFileError.INVALID_VALUE("Could not load Plugin"); + + var result = plugin.new_object(); + result.init(this); + + return result; + } + + public Barometer get_barometer() throws Error { + string name = get_string("config", "barometer"); + string path = Path.build_path("/", Environment.get_variable("PWD"), "sensors", "barometer", "%s.so".printf(name)); + var plugin = new PluginLoader<Barometer>(path); + if(!plugin.load()) + throw new KeyFileError.INVALID_VALUE("Could not load Plugin"); + + var result = plugin.new_object(); + result.init(this); + + return result; + } + + public Accelerometer get_accelerometer() throws Error { + string name = get_string("config", "accelerometer"); + string path = Path.build_path("/", Environment.get_variable("PWD"), "sensors", "accelerometer", "%s.so".printf(name)); + var plugin = new PluginLoader<Accelerometer>(path); + if(!plugin.load()) + throw new KeyFileError.INVALID_VALUE("Could not load Plugin"); + + var result = plugin.new_object(); + result.init(this); + + return result; + } + + public Compass get_compass() throws Error { + string name = get_string("config", "compass"); + string path = Path.build_path("/", Environment.get_variable("PWD"), "sensors", "compass", "%s.so".printf(name)); + var plugin = new PluginLoader<Compass>(path); + if(!plugin.load()) + throw new KeyFileError.INVALID_VALUE("Could not load Plugin"); + + var result = plugin.new_object(); + result.init(this); + + return result; + } + + public CopterModel get_model() throws Error { + string name = get_string("config", "model"); + string path = Path.build_path("/", Environment.get_variable("PWD"), "ctrl", "models", "%s.so".printf(name)); + var plugin = new PluginLoader<CopterModel>(path); + if(!plugin.load()) + throw new KeyFileError.INVALID_VALUE("Could not load Plugin"); + + var result = plugin.new_object(); + result.init(this); + + return result; + } + + public Receiver get_receiver() throws Error { + string name = get_string("config", "receiver"); + string path = Path.build_path("/", Environment.get_variable("PWD"), "receiver", "%s.so".printf(name)); + var plugin = new PluginLoader<Receiver>(path); + if(!plugin.load()) + throw new KeyFileError.INVALID_VALUE("Could not load Plugin"); + + var result = plugin.new_object(); + result.init(this); + + return result; + } +} |