From 8a08b9dce9cfc161494ddb07a1c979c7796780ff Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Fri, 15 Jun 2012 22:56:00 +0200 Subject: restructure code it is now loading its components from plugins --- config.vala | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 config.vala (limited to 'config.vala') 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 + * + * 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(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(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(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(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(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(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(path); + if(!plugin.load()) + throw new KeyFileError.INVALID_VALUE("Could not load Plugin"); + + var result = plugin.new_object(); + result.init(this); + + return result; + } +} -- cgit v1.2.3