## Adding Ethos to my Application

As a developer, you might be wondering what Ethos does for you. Ethos provides the scaffolding around supporting plugins within your application. This includes the details like cracking open shared libraries to extract the plugins, hosting various virtual machines for higher-level language support, and reusable widgets to manage plugins in your GTK+ application during runtime. However, if you are writing an application that does not have a user interface, ethos can also be used without a UI and therefore only require libglib2.0 and libgobject2.0.

It only takes a couple of lines of code to setup Ethos during runtime. Lets look at an example in Vala for the succinctness of code.

    using GLib;
    using Gtk;
    using Ethos;

    static void main (string[] args) {
    	Gtk.init (ref args);

    	var manager = new Ethos.Manager ();
    	manager.set_app_name ("Foo");
    	manager.set_plugin_dirs (new string[] { "./plugins" });
    	manager.initialized += _ => { stdout.printf ("Ethos initialized\n"); };
    	manager.initialize ();

    	Gtk.main ();
    }

This prepares the basic EthosManager instance that can locate and load plugins. When "manager.initialize()" is called, the EthosManager will lookup all the plugins within the plugin directories. By default, EthosManager will enable all plugins. This behaviour can be changed by inheriting from EthosManager and overridding the "load_plugin" slot in the classes vtable.

Many applications will have a GTK+ user interface and want to present a way to control plugins during runtime to the user. There is a reusable GTK+ widget that is bundled with Ethos called EthosUIManagerWidget. It is ideal for embedding within a preferences dialog. Lets take a quick look at what that might look like.

    using GLib;
    using Gtk;
    using Ethos;
    using Ethos.UI;

    ...
    	void setup_plugins_page () {
    		var widget = new Ethos.UI.ManagerWidget ();
    		widget.set_manager (this.manager);
    		this.plugins_page.add (widget);
    		widget.show ();
    	}
    ...

This will create the EthosUIManagerWidget and prepare it to observe the EthosManager for runtime changes.