Client/Server C Application (vxWorks/Windows Host)

Introduction

Now that you've gotten comfortable with creating a database in the How to Create a Schema section, lets build an application that will allow you to read and write to a database.

We recommend getting familiar with some of the concepts and tools that you will be using in this tutorial. We will be covering: interacting with the Transaction File Server (TFS), inserting a row with the function call rdm_dbInsertRow(), and reading rows with the function call rdm_cursorReadRow(). You may also find it useful to read about the DOCROOT as well.

  • The TFS is responsible for safely storing and retrieving objects. It is like a key/value store, but very fast and transactionally safe. The TFS owns and is co-located with the database files.
  • In this example rdm_dbInsertRow() will be used to insert a new row into two of our tables: AUTHOR and BOOK.
  • rdm_cursorReadRow() reads all columns from a row specified by the RDM_CURSOR and places the contents inside of the designated buffer.
  • The DOCROOT is a directory which is designated for holding databases available to a Transaction File Server (TFS). The concept is similar to a web server document root for storing web pages

Prerequisites:

Steps: 

  1. Change directories into C:\Raima\RDM\14.1\target\vxworks7-x86_64_core
  2. The target directory (vxworks7-x86_core) may be different depending on the package you have installed. Change in to the corresponding directory for the package you have installed. For example: vxworks7-x86_32_core or vxworks7-armv7)

  3. Start the Wind River environment shell:
  4. $> C:\WindRiver\wrenv -p vxworks-7
  5. In the wrenv shell, execute the setup of the vxWorks Source Build (VSB) for the target you will be using:
  6. $> sh setup.sh --vsb

    This setup script may take a while. It only needs to be done once as it will install the new VSB in your Wind River installation.

  7. Start the Wind River Workbench 4 tool.
  8. This rest of this example will be using the target directory above as the Workbench workspace. You may use any workspace location.

  9. Right click inside of the Project Explorer tab and click Create New Project
  10. Under the VxWorks7 folder, choose VxWorks Downloadable Kernel Module Project (DKM)
  11. Name the project bookStore and press Next
  12. In the Project dropdown menu, choose vsb_x86_64_core(prebuilt) and press Finish
  13. Again, the name of source build project to use will be the one with name corresponding to the package you have installed. See Step 1 above.

  14. Outside the Workbench IDE, copy the bookStore_client.c and bookStore.sdl file created in the How to Create an Embedded C Application session into the bookStore directory in the workspace.
  15. In the Terminal Window, enter the following commands to create the bookStore schema header we will need to include in the bookStore application:
$> cd bookStore
$> rdm-compile --c-structs bookStore.sdl

    The file created by rdm-compile will be: bookStore_structs.h.

  1. In the Workbench environment, refresh the screen and you will see the newly added files (delete the dkm.c file automatically added by the creation of the DKM project).
  2. Make the following modifications to the bookStore_client.c file.
    • Change name of main function to bookStore_main
    • int bookStore_main(int argc, const char* const* argv)
      
    • Add the following line at end of the file:
    • RDM_STARTUP_EXAMPLE(bookStore)
    • In the rdm_dbOpen function call on line 155, change localhost to be the IP address of the machine where you will be running the rdm-tfs command.
    • rc = rdm_dbOpen(db, "tfs-tcp://localhost:21553/bookStore", RDM_OPEN_SHARED);
  3. Right click on your project folder and click on Properties
  4. Navigate to the Paths tab
  5. Click the Add button to the right of the screen and add the include folder from Raima
    C:/Raima/RDM/14.1/include
  6. Next, navigate to the Libraries tab and click Add
  7. Choose the Add library search path (-L) radio button option and find the path
    C:/Raima/RDM/14.1/target/vxwors7-x86_64_core/lib
  8. The lib directory will be in the target name directory. (See Step 1).

  9. Remaining under the Libraries tab, click Add and choose the Add library file (-l) radio button
  10. Type in rdmtfs and press OK
  11. Repeat step 18 and 19 replacing rdmtfs with the following libraries:
  12. rdmrdm
    rdmddl
    rdmtransport
    rdmtx
    rdmhttp
    rdmbase
    rdmpsp

    Not all of the above libraries may be needed for your application. For each of the Raima RDM function calls used, you will need to consult the reference manual to see which library must be added. Also, you will need to add dependent libraries to this list as well. The dependencies are documented in the RDM Libraries section.

  13. The bookStore project is ready to be built!
  14. Before running the above program on the target machine, the remote TFS will need to be launched. From the command line on the machine hosting the database, navigate to the directory where your database bookStore.rdm is stored and run the command rdm-tfs.
  15. The bookStore program is ready to be launched!

Conclusion

Your program should be fully functional at this point. You set up a Remote TFS which is used when you are interacting with a database through server processes, and you wrote and read rows from the database by interacting with the TFS.

Next, you might want to add some more functionality by deleting a row with rdm_cursorDeleteRow() or update a row with rdm_cursorUpdateRow(). Some other concepts to look over might be:

The full source file can be found here: bookStore_main.c Example TFS Remote Program