IBM Streams 4.3.0

Creating C++ primitive operators

You can create a C++ primitive operator in Streams Studio.

Before you begin

Tip: Streams Studio provides cheat sheets to guide you through the tasks of creating C++ primitive operators. You can use the cheat sheets as an alternative to following the steps outlined in this task. To open the cheat sheets in Streams Studio:
  1. From the main menu, click Help > Cheat Sheets.
  2. In the Cheat Sheet Selection window, expand IBM Streams.
  3. Select one of the C++ primitive operator cheat sheets and click OK. The cheat sheet opens in the Cheat Sheets view.

About this task

The following are the high-level steps for creating C++ operators:
  1. Define the C++ operator templates in the *.cgt files.
  2. (Optional) If your C++ operators use external shared libraries, implement the shared libraries in the SPL Project/impl directory to bundle the artifacts with the SPL project.
  3. (Optional) Create a makefile to build the shared libraries.
  4. (Optional) Specify the shared libraries in the operator model.
  5. Define attributes for the operators in the model operator.
  6. Create a Main composite to test your C++ operator.

Procedure

To create and implement C++ primitive operators, complete the following steps:

  1. Set up an SPL project and C++ project by following the instructions in Setting up for C++ operator development.
  2. In the Project Explorer view, right-click an SPL project, and then click New > C++ Primitive Operator.
  3. In the New C++ Primitive Operator window, select the SPL project in which you want to create the primitive operator. By default, this field already contains the current selection from the Project Explorer view. To choose another project, click Browse.
  4. From the Namespace list, specify the namespace in which to create the primitive operator, or select an existing namespace from the list. If the namespace does not exist, it is created.
  5. In the Name field, enter the name for the operator.
  6. Leave the Generic Operator option selected if you want to create a generic C++ operator.
  7. Click Finish to create the C++ operator in the specified project and namespace.
  8. To work with the operator templates:
    1. In the Project Explorer view, right-click the primitive operator.
    2. Click Open Template > CPP Template or Header Template. The operator template opens for the selected operator.
  9. If your C++ operator references external shared libraries, implement the shared libraries in the C++ project that you created.
    1. In the C++ project, add *.cpp files for the shared libraries in the src folder.
    2. In the C++ project, add *.hpp files for the shared libraries in the include folder.
  10. Create a makefile to build the shared libraries:
    1. In the SPL Project/impl folder, create a makefile that to build the shared libraries.
    2. The makefile must point the binaries (*.o) to the SPL Project/bin folder.
    3. The makefile must point the shared libraries (*.so) to the SPL Project/lib folder.
  11. Define the operator's attributes in its operator model. To make this C++ operator available in your SPL project, you must implement the C++ operator model. Double-click the C++ operator to open the Operator Model editor and complete the following steps:
    1. Create a Library element under Operator/C++/Context/Libraries.
    2. Open the Properties view of the Library element to see its attributes.
    3. In the Properties view, expand the Managed Library section and specify the following values:
      • Include Path: ../../impl/include
      • Lib: <Name of your shared library>
      • Lib Path: ../../impl/lib
    4. Configure the remaining attributes for the operator in the Operator Model editor. For details about working with the Operator Model editor, see Editing with the Operator model editor (<operator-name>.xml).
  12. Test the C++ operator by creating a Main composite that invokes the C++ operator in its graph clause. To create Main composites, see Creating SPL source files and Main composites.

Results

With this set up, all your source code is in the SPL project. The C++ project provides the tools to build and develop of the C++ shared libraries. The SPL project provides the tools for the development of SPL toolkit elements. If auto-build is not configured for the C++ project, you can do the following build sequence manually to build the shared libraries and the SPL applications:
  1. To build the shared library, in the Project Explorer view, right-click the C++ Project and click Build Project. The shared libraries are rebuilt and placed in the SPL Project/impl/lib folder.
  2. To build the SPL project, in the Project Explorer view, right-click the SPL project and click Build Active Configurations. The SPL applications in the SPL Project are rebuilt.