Core Examples

Attention: Make sure that following three preconditions are fulfilled:

  • The Naming-Service of SMARTSOFT/ACE is ready and running:
    • cd $SMART_ROOT_ACE; ./startSmartSoftNamingService
  • The LD_LIBRARY_PATH environment-variable is set correctly. (see installation instructions)
  • The svc.conf file is accessible.

The sourcecode for the examples below, can be viewed online at doxygen or downloaded at sourceforge.

First example

Demonstrates:

  • query communication pattern (QueryClient, QueryServer, Communication Objects)

WHAT DOES THE FIRST EXAMPLE ?

  • Component1 provides a server reporting the current time and also a server which returns the sum of the received values.
  • Component2 is a multithreaded client.

This example illustrates the organization of the communication patterns including the file structure etc. A component provides several services which can be accessed by a client component. By looking at the component description file you get further information on which services a component requires and which one it provides. Look at the Makefile to see how libraries of communication objects needed by a component are linked.

Components:

run:

    # cd $SMART_ROOT_ACE
    # xterm -e bin/exampleComponent01 &
    # xterm -e bin/exampleComponent02 &

Second example

Demonstrates:

  • push newest communication pattern (PushNewestClient, PushNewestServer)
  • thread management

WHAT DOES THE SECOND EXAMPLE ?

  • Component10 pushes the current time to every subscribed client every 2 seconds
  • Component11 subscribes / unsubscribes and illustrates the blocking call which waits for the next new data

Components:

run:

    # cd $SMART_ROOT_ACE
    # xterm -e bin/exampleComponent10 &
    # xterm -e bin/exampleComponent11 &

Third Example

Demonstrates:

  • query communication pattern
  • state management pattern
  • thread management

WHAT DOES THE THIRD EXAMPLE ?

  • Component20 consists of several user threads which run only if the appropriate states are set. One of the threads requests the current time from Component22 which however delays every answer by 10 seconds. This is used to demonstrate how a blocking query can be canceled by enforcing the neutral state.
  • Component21 is the master of Component20 and demonstrates how states can be set.
  • Component22 provides the already mentioned time service

Notice the behavior of the state pattern:

  • you can see the state changes and how the different threads are activated / deactivated
  • when setting the "neutral" state, this is delayed until all threads release their locks
  • when enforcing the "neutral" state by "deactivated", the pending query to receive the time is aborted with state SMART_CANCELLED

Components:

run:

    # cd $SMART_ROOT_ACE
    # xterm -e bin/exampleComponent20 &
    # xterm -e bin/exampleComponent21 &
    # xterm -e bin/exampleComponent22 &

Fifth Example

Demonstrates:

  • event communication pattern
  • thread management

WHAT DOES THE FIFTH EXAMPLE ?

One component provides a cyclic counter in the interval 0 ... 49. The first event fires as soon as the counter is greater than the parameter given by the event activation. If the event fires, it returns the current counter value. This event is used in single and continuous mode. The second event checks whether the current counter value is in the specified interval. It reports only state changes and is therefore used in continuous mode. The second event gives an example of a state based event. The parameter object contains a state which allows to report the current state with the next test of the event condition.

Components:

run:

    # cd $SMART_ROOT_ACE
    # xterm -e bin/exampleComponent40 &
    # xterm -e bin/exampleComponent41 &

Sixth Example

Demonstrates:

  • send communication pattern

WHAT DOES THE SIXTH EXAMPLE ?

One component simply sends several messages from several threads. The content of the messages is printed by the server component. One component contains time triggered send commands to demonstrate how to register objects at the time service.

Components:

run:

    # cd $SMART_ROOT
    # xterm -e bin/smartExampleComponent50 &
    # xterm -e bin/smartExampleComponent51 &
    

Eighth Example

Demonstrates:

  • push timed pattern

WHAT DOES THE EIGHTH EXAMPLE ?

One component regularly provides (every second) the current time based on a pushTimed-service. The other component subscribes for an update every second time so it gets an update every 2 seconds.

Components:

run:

    # cd $SMART_ROOT_ACE
    # xterm -e bin/exampleComponent70 &
    # xterm -e bin/exampleComponent71 &

Ninth Example

Demonstrates:

  • wiring pattern for dynamic wiring of component connections
  • query communication pattern (QueryClient, QueryServer, Communication Objects)
  • thread management
  • handling of slow and/or blocking queries

WHAT DOES THE NINTH EXAMPLE ?

Two components provide exactly the same services which are dynamically connected by a client. When to connect which server is configured from another component. Rewiring is done without taking into account the internal state of the client component. This example is a modified version of the first example.

Components:

run:

    # cd $SMART_ROOT_ACE
    # xterm -e bin/exampleComponent101 &
    # xterm -e bin/exampleComponent102 &
    # xterm -e bin/exampleComponent103 &
    # xterm -e bin/exampleComponent104 &

Eleventh Example

Demonstrates:

  • push newest communication pattern
  • automatic reconnect
  • usage of ACE_CDR basic-data-types
  • usage of a ManagedTask
  • shutdown procedure with STRG+C aborting

WHAT DOES THE ELEVENTH EXAMPLE ?

The ShutdownServer publishes data periodically using a PushNewest service. The data consists of various data types that demonstrate the usage of basic-data-types in a communication object. Various ShutdownClients can be started and stopped (by pushing STRG+C buttons) without to interfere other ShutdownClients. Even the ShutdownServer can be restarted without crashing the ShutdownClients. In the later case the performing ShutdownClients should reconnect as soon as the ShutdownServer is ready and running again.

Components:

run:

    # cd $SMART_ROOT_ACE
    # xterm -e bin/exampleShutdownServer &
    # xterm -e bin/exampleShutdownClient &
    # xterm -e bin/exampleShutdownClient &