# EXAMPLES

- Summary
- PingPong
- Tutorial
- HelloWorld
- WaitSet
- Listener
- ContentFilteredTopic
- QueryCondition
- Lifecycle
- Durability
- Ownership
- BuiltInTopics
- NetworkPartitions
- RoundTrip
- Throughput

## HelloWorld

- Running of examples in Standalone Mode
- Running of examples in CORBA Cohabitation Mode

### 1) Description

The basic HelloWorld example is used to illustrate the necessary steps to setup DCPS entities.

This example also shows the deployment architecture choices available for OpenSplice. OpenSplice can be deployed as multiple processes interfacing directly with shared memory, or can be deployed with all OpenSplice services and applications in a single process utilizing dynamic heap memory. Please refer to the OpenSplice_DeploymentGuide.pdf document for more detailed discussion of these deployment strategies.

### 2) Design

It consists of 4 units :

- CheckStatus : provides return status checking
- DDSEntityManager : implements a class providing operations to setup DCPS entities (creation, deletion)
- HelloWorldPublisher : implements the publisher's main (uses DDSEntityManager)
- HelloWorldSubscriber : implements the subscriber's main (uses DDSEntityManager)

### 3) Scenario

The publisher sends a single HelloWorld sample. The sample contains 2 fields :

- a userID field (long type)
- a message field (string type).

When it receives the sample, the subscriber displays the userID field and the message field.

## Running of examples in Standalone Mode

- Running examples in Posix
- Running examples in Visual Studio

### Running the examples in a Posix environment

#### Environment Setup

Let's call OpenSplice_install_dir the OpenSplice installation directory.

The OpenSplice environment variables must be set in order for the examples to build/run correctly. To do this, open a terminal and source the "OpenSplice_install_dir/release.com" script supplied with the distribution.

- C/C++ Examples
- Java examples
- ISO C++ 2 examples

#### C and C++ Executables

Building the examples is described on the Summary page

Two executables and a library are generated in the standalone folder when the example is built:

For C++

- sacpp_helloworld_pub
- sacpp_helloworld_sub
- libsacpp_helloworld_types.so

For C

- sac_helloworld_pub
- sac_helloworld_sub
- libsac_helloworld_types.so

#### Java executables

Building the examples is described on the Summary page

Three jars are generated in the java/standalone or java5 folder when the example is built:

For Java

- saj_helloworld_sub.jar
- saj_helloworld_pub.jar
- saj_helloworld_types.jar

For Java5

- saj5_helloworld_sub.jar
- java5_HelloWorld_pub.jar

#### ISO C++ 2 Executables

Building the examples is described on the Summary page

Two executables are generated in the isocpp2 directory when the example is built:

- publisher
- subscriber

#### Running the example

Ensure that the environment for OpenSplice is set up correctly as described above for each new terminal used.

It is recommended that you run the subscriber and publisher in separate terminals to avoid mixing the output

Running in single process (heap memory) configuration : the application starts OpenSplice middleware

- OpenSplice is deployed in this mode by default.
- The OpenSplice daemon should not be started manually. Instead the OpenSplice middleware and optional services are implicitly started by the single process applications as required
- Open 2 terminals. Set up the environment and go to the example directory as described above

Running in multiple process shared memory configuration

To enable deployment in this mode, an OpenSplice configuration file must be selected that has shared memory support e.g. one of the ospl_shmem xml configuration files found in the OpenSplice_install_dir/etc/config directory.

- Open 2 terminals. In each terminal:
- Setup the environment and go to the example directory as described above
- Set the required configuraton file e.g. OSPL_URI=file://$OSPL_HOME/etc/config/ospl_shmem_ddsi.xml
- Start the OpenSplice daemon. You can do this by typing ospl start

Starting the subscriber and publisher

- In the first terminal start the subscriber by running either
  - sac_helloworld_sub for C
  - sacpp_helloworld_sub for C++
  - java -jar saj_helloworld_sub.jar for Java
  - java -jar sub/saj5_helloworld_sub.jar for Java5
  - subscriber for ISO C++ 2
- In the second terminal start the publisher by running either
  - sac_helloworld_pub for C
  - sacpp_helloworld_pub for C++
  - java -jar saj_helloworld_pub.jar for Java
  - java -jar pub/java5_HelloWorld_pub.jar for Java5
  - publisher for ISO C++ 2

### Running C/C++/C#/Java examples on Windows

#### Environment Setup

Let's call OpenSplice_install_dir the OpenSplice installation directory.

The OpenSplice environment variables must be set in order for the examples to run correctly. To do this open an OpenSplice Command Prompt which will set up the environment variables for OpenSplice automatically. The OpenSplice Command Prompt can be selected from the start menu. Alternatively, open a windows Command Prompt and execute the "OpenSplice_install_dir\release.bat" batch script supplied with the distribution.

- C/C++/C# Examples
- Java examples
- ISO C++ 2 examples

#### C/C++/C# Executables

Building the examples is described on the Summary page

Two executables are generated in the standalone directory when the example is built:

For C

- sac_helloworld_sub.exe
- sac_helloworld_pub.exe

For C++

- sacpp_helloworld_sub.exe
- sacpp_helloworld_pub.exe

For C#

- sacs_helloworld_sub.exe
- sacs_helloworld_pub.exe

#### Java Executables

Building the examples is described on the Summary page

Three jars are generated in the java/standalone or java5 folder when the example is built:

For Java

- saj_helloworld_sub.jar
- saj_helloworld_pub.jar
- saj_helloworld_types.jar

For Java5

- saj5_helloworld_sub.jar
- java5_HelloWorld_pub.jar

#### ISO C++ 2 Executables

Building the examples is described on the Summary page

Two executables are generated in the isocpp2 directory when the example is built:

- publisher.exe
- subscriber.exe

#### Running the C/C++/C#/ISO C++ 2/Java Examples

Ensure that the environment for OpenSplice is set up correctly as described above for each new command prompt used.

The following steps describe how to run the examples:

Running in single process (heap memory) configuration : the application starts OpenSplice middleware

- OpenSplice is deployed in this mode by default.
- The OpenSplice daemon should not be started manually. Instead the OpenSplice middleware and optional services are implicitly started by the single process applications as required
- Open 2 OpenSplice Command Prompts and go to the example directory as described above

Running in multiple process shared memory configuration

To enable deployment in this mode, an OpenSplice configuration file must be selected that has shared memory support e.g. one of the ospl_shmem xml configuration files found in the OpenSplice_install_dir\etc\config directory.

- Open 2 OpenSplice Command Prompts. In each window:
- Go to the example directory as described above
- Set the required configuration file e.g. set OSPL_URI=file://%OSPL_HOME%\etc\config\ospl_shmem_ddsi.xml
- Start the OpenSplice daemon. You can do this by typing ospl start

Starting the subscriber and publisher

- In the first terminal start the subscriber by running either
  - sac_helloworld_sub for C
  - sacpp_helloworld_sub for C++
  - sacs_helloworld_sub for C#
  - java -jar saj_helloworld_sub.jar for Java
  - java -jar sub/saj5_helloworld_sub.jar for Java5
  - subscriber for ISO C++ 2
- In the second terminal start the publisher by running either
  - sac_helloworld_pub for C
  - sacpp_helloworld_pub for C++
  - sacs_helloworld_pub for C#
  - java -jar saj_helloworld_pub.jar for Java
  - java -jar pub/java5_HelloWorld_pub.jar for Java5
  - publisher for ISO C++ 2

## Running in CORBA Cohabitation Mode

Doing the substitution and additional set ups described below, everything previously said for Standalone Mode can be applied to CORBA Cohabitation Mode.

#### Environment Set up

Besides OpenSplice environment variables, we need to set

- C/C++

- The TAO environment variable TAO_ROOT to point to the Tao installation directory.

- Java

- The JacORB environment variable JACORB_HOME to point to the JacORB installation directory.

#### Substitution

- standalone is replaced by corba
- the Java command is java -Djava.endorsed.dirs=$JACORB_HOME/lib/endorsed -classpath $OSPL_HOME/jar/dcpssaj.jar:classes