logo

Wallaroo

C++ Dependency Injection

Wallaroo Wiring Files

Wallaroo can load the description of your software from a configuration file, in XML or JSON format. You can use the file to specify the following:

However, you can use more than one configuration file, or you can decide to specify only a part of your application with the configuration file.

Loading a wiring file

Once you have a Catalog object in your application, you can fill it by using the classes XmlConfiguration or JsonConfiguration.

To load a xml file:

Catalog catalog;
...
XmlConfiguration file( "wiring.xml" );
file.Fill( catalog );
...
catalog.CheckWiring(); // throws a WiringError exception if any collaborator is missing

To load a json file:

Catalog catalog;
...
JsonConfiguration file( "wiring.json" );
file.Fill( catalog );
...
catalog.CheckWiring(); // throws a WiringError exception if any collaborator is missing

If there are classes defined in shared libraries, you should load them by using the code:

// create file as XmlConfiguration or JsonConfiguration class
XmlConfiguration file( "myFile.xml" );
// or JsonConfiguration file( "myFile.json" );
...
file.LoadPlugins(); // load the shared libraries specified in configuration file

XML Wiring file syntax

The XML file is composed by three sections:

<wallaroo>

  <plugins>
    ...
  </plugins>

  <parts>
    ...
  </parts>

  <wiring>
    ...
  </wiring>

</wallaroo>

Shared Libraries Section

If you want to load classes implemented in shared libraries you must write a section plugins where you specify every shared library to load:

<plugins>
  <shared>shared_lib_1</shared>
  <shared>shared_lib_2</shared>
</plugins>

Please note that the library name does not include the file extension: wallaroo add the os specific extension (.dll on windows, .so on linux).

Parts Section

For each object you want to be created, you must write a section part, where you specify the instance name (the id you will use to refer to this object) and the class of the object:

<part>

  <name>object_name</name>
  <class>class_name</class>

  <attribute> <!-- optional -->
    <name>attribute1_name</name>
    <value>attribute1_value</value>
  </attribute>
  <attribute> <!-- optional -->
    <name>attribute2_name</name>
    <value>attribute2_value</value>
  </attribute>
  ...

  <parameter1> <!-- optional -->
    <type>string</type>
    <value>parameter_value</value>
  </parameter1>
  <parameter2> <!-- optional -->
    <type>int</type>
    <value>3</value>
  </parameter2>

</part>

The parameter type currently supported are:

Wiring Section

For each relation between the instances you created, you must write a section wire, where you specify the two object you want to link (source and destination) and the name of the collaborator in the source object:

<wire>
  <source>source_object</source>
  <dest>dest_object</dest>
  <collaborator>plut_in_source_object</collaborator>
</wire>

Example

This is an example of a XML wiring file:

<wallaroo>

  <plugins>
    <shared>car</shared>
    <shared>engine</shared>
  </plugins>

  <parts>

    <part>
      <name>ferrari_f430</name>
      <class>Car</class>
      <parameter1>
        <type>string</type>
        <value>red</value>
      </parameter1>
    </part>

    <part>
      <name>maserati_granturismo</name>
      <class>Car</class>
      <parameter1>
        <type>string</type>
        <value>black</value>
      </parameter1>
    </part>

    <part>
      <name>m139p</name>
      <class>Engine</class>
    </part>

    <part>
      <name>f136e</name>
      <class>Engine</class>
    </part>

  </parts>

  <wiring>

    <wire>
      <source>ferrari_f430</source>
      <dest>f136e</dest>
      <collaborator>mainEngine</collaborator>
    </wire>

    <wire>
      <source>maserati_granturismo</source>
      <dest>m139p</dest>
      <collaborator>mainEngine</collaborator>
    </wire>

  </wiring>

</wallaroo>

XML schema

Here you can find the XML Schema of wallaroo xml wiring files.

JSON Wiring file syntax

The syntax of JSON file is equivalent to the XML one.

Follows an example of a JSON wiring file:

{
  "wallaroo":
  {

    "plugins":
    { 
      "shared": "car",
      "shared": "engine"
    },

    "parts":
    [
      {
        "name": "ferrari_f430",
        "class": "Car",
        "parameter1":
        {
          "type": "string",
          "value": "red"
        }
      },

      {
        "name": "maserati_granturismo",
        "class": "Car",
        "parameter1":
        {
          "type": "string",
          "value": "black"
        }
      },

      {
        "name": "m139p",
        "class": "Engine"
      },

      {
        "name": "f136e",
        "class": "Engine"
      }

    ],

    "wiring":
    [

      {
        "source": "ferrari_f430",
        "dest": "f136e",
        "collaborator": "mainEngine"
      },

      {
        "source": "maserati_granturismo",
        "dest": "m139p",
        "collaborator": "mainEngine"
      }

    ]
  }
}