Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Configuration

Marvin Frick edited this page May 28, 2013 · 1 revision

Configuration of an Application

It is possible to set parameters in a configuration file, and read them in a processor. Parameters can be integers, strings, boolean values, or floats. Valid assignments are:

  my_int_value=1
  my_string_value=HelloWorld
  my_boolean_value=true
  my_float_value=3.14

When processing such a configuration file, Shawn passes these values to the Simulation Environment which in turn acts as a lookup table. Hence, the key my_string_value contains the value HelloWorld. It can be accessed by the methods

  required_string_param( "KEY" );
  optional_string_param( "KEY", DEFAULT_VALUE );

When using the method prefixed with the string required_, and the key is not found, an exception is thrown with a corresponding error message. Generally, the simulation is directly aborted. Alternatively, when using the optional one, a default value can be given that is used if the key is not found within the configuration file.

To get access to the parameters from inside a processor, one must get a reference to the SimulationEnvironment. It can be accessed from the SimulationController which in turn is part of the World. The World is available via the owner() of a processor (which in turn is a Node). Hence, change your implementation as follows. Add a new member of type int to the class SimpleAppProcessor.

   private:
      int send_round_;

Then, adapt the boot() and work() method.

   void
   SimpleAppProcessor::
   boot( void )
      throw()
   {
      const shawn::SimulationEnvironment& se =
                     owner().world().simulation_controller().environment();
      send_round_ = se.optional_int_param( "send_round", 0 );
   }
   // ----------------------------------------------------------------------
   [...]
   // ----------------------------------------------------------------------
   void
   SimpleAppProcessor::
   work( void )
      throw()
   {
      // send message only in the first simulation round
      if ( simulation_round() == send_round_ )
      { 
         send( new SimpleAppMessage );
      }
   }

At last, the used configuration file may contain the new parameter. If the parameter is not set, the default value is used which was set to 0 in boot().

  prepare_world edge_model=simple comm_model=disk_graph range=2
  rect_world width=10 height=10 count=100 processors=simple_app
  send_round=8
  simulation max_iterations=10
  connectivity

When booting (method boot() is called when simulation starts; that is, after simulation task simulation is called), the SimpleAppProcessor reads the parameter send_round and writes it to send_round_. If not set, the value is set to the default of 0.

Then, in the work() method of the processor the parameter is checked. If the actual simulation round is equal to the value in the configuration file (or the default value, if not given), a message is sent out. The result is shown in Figure XXX.

ext_shawn03.png

The messages are sent in simulation round 8, and delivered in round 9, as configured with the parameter send_round_. However, there is one hint left before going on with data extraction from simulation. Note that Shawn related initializations like reading configuration parameters can not be done from the constructor, but only within methods boot(), work(), or process_message(). Within the constructor, there is no connection to the simulation controller available. A processor is created, and then assigned to the node which in turn provides access to the simulation controller. Thus, 'do not' try to access owner() in the constructor of a processor.