Custom C++ Simple Function Sample

The log.sbapp application demonstrates how to use a custom C++ simple function.

This topic describes how to load and run the sample. For detailed information about the sample, see the topic, Creating Custom C++ Functions, in the API Guide.

This Sample's Files

The sample has the following files:

  • A sample configuration file, sbd.sbconf, which tells StreamBase Server to load the custom simple function.

  • A sample application, log.sbapp, which uses the function.

  • DLL or .so library that contains the custom simple function.

  • Source code for the custom simple function, LogFunction.cpp.

  • Either Microsoft Visual Studio .NET solution and project files (Windows) or a Makefile (UNIX), which can be used to build all of the sample source code. (In the Visual Studio project files, the paths to the StreamBase include files and libraries are configured for the standard default installation directory. You may need to adjust these paths for your PC.)

Running the Custom C++ Simple Function Sample

Running custom-simple-function in StreamBase Studio

  1. In the Package Explorer, double-click to open the log.sbapp application. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. In the Application Output view, select the output stream.

  4. In the Manual Input view, select the input stream.

  5. Enter 1.

  6. Click Send Data, and observe 0.0 appears in the output stream.

  7. Enter 10.

  8. Click Send Data, and observe 2.302585092994046 appears in the output stream.

  9. Using the same send technique, send 50 and 100, and observe 3.912023005428146 and 4.605170185988092 appears respectively in the output stream.

  10. When done, press F9 or click the Stop Running Application button.

Running the custom-simple-function sample in Terminal Windows

This section describes how to run the sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.

  2. In window 1, launch a StreamBase Server instance on the sample application:

    sbd -f sbd.sbconf log.sbapp

    Alternatively, if running in a 64-bit environment:

    sbd -f sbd-x64.sbconf log.sbapp

  3. In window 2, run a dequeuer so that you can see the output that will be produced:

    sbc dequeue output

  4. In window 3, run an enqueuer:

    sbc enqueue input

  5. Type numbers into the enqueuer in window 3, one number per line. For example, if you enter the numbers 1, 10, 50, and 100, you should see the following output from the dequeuer in window 2:

    0
    2.30258509299405
    3.91202300542815
    4.60517018598809

  6. To see what happens when the function throws an exception, try enqueuing a negative number.

  7. In window 2, press Ctrl+C to close the enqueuer. Then run sbadmin shutdown to close the server.

Back to Top ^

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, click FileLoad StreamBase Sample.

  • Select this sample from the Extending StreamBase list.

  • Click OK.

StreamBase Studio creates a project for the sample.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_custom-simple-function

See Default Installation Directories for the default location of studio-workspace on your system.

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/custom-simple-function

See Default Installation Directories for the default location of studio-workspace on your system.