Harlequin RIP SDK

Implements the RIP Farm Test Tool as an example usage of the RIP Farm. More...

#include <stdio.h>
#include "czmq.h"
#include "std.h"
#include "ripfarmtesttool.h"

Data Structures

struct  FARM_REPLY_CTXT
 Structure used by relay_message_callback(). It is anonymously passed to rf_iface_start() and returned in callbacks from the libripfarm interface. More...
 

Macros

#define FARM_REPLY_PIPE   "inproc://farm_reply_pipe"
 Name of internal push-pull ZeroMQ pipe for sending messages between relay_message_callback() and farm_reply_handler().
 

Functions

HqBool relay_message_callback (FARM_REPLY_CTXT *farm_reply_ctxt, RF_FARM_REPLY *farm_reply)
 Relay a message received from the farm to farm_reply_handler() in the main UI thread via a ZeroMQ pipe. More...
 
static int farm_reply_handler (zloop_t *loop, zsock_t *socket, void *arg)
 Receives ZeroMQ messages from relay_message_callback() via the test tool reactor, then sends the message to process_farm_reply() for processing. More...
 
void destroy_farm_reply_ctxt (FARM_REPLY_CTXT **p_farm_reply_ctxt)
 Free resources allocated by create_farm_reply_ctxt(). More...
 
FARM_REPLY_CTXTcreate_farm_reply_ctxt (void)
 Create a context that is used for ZeroMQ messaging from the DFE Interface thread to farm_reply_handler(). The context is passed back by the libripfarm interface as a handle in message_callback(). More...
 
HqBool testtool_reactor (struct RF_IFACE_CTXT *iface_ctxt)
 Runs the test tool reactor which monitors ZeroMQ messages from both keyboard_worker() and message_callback(). More...
 

Detailed Description

Implements the RIP Farm Test Tool as an example usage of the RIP Farm.

This file implements the inter-thread messaging between the DFE Interface and UI threads. The reactor must also handle the inter-thread messaging related to the keyboard commands.

Refer to the design notes and data flow diagrams in ripfarmtesttool.c.

  1. There are two threads in the RIPFarmTestTool, the main UI, and the keyboard_worker threads, in addition to the DFE Interface thread. This file implements the signalling between the three threads via ZeroMQ messages. Other signalling methods could be used to replace ZeroMQ for this purpose.
  2. Keyboard input. A dedicated thread runs keyboard_worker() which simply runs the keyboard_loop() for the UI to implement. A separate thread is used because it is otherwise difficult to monitor both keyboard input and ZeroMQ messages in the same thread, at least on Windows.

    Lines of text are passed from relay_keyboard_string() to keyboard_event(), running in keyboard_worker and main UI threads respectively, using a ZeroMQ socket and the test tool reactor.

    The exit and waitms data items are passed in the reverse direction over the same ZeroMQ socket.

  3. RIP farm reply messages. The data is passed from relay_message_callback() to farm_reply_handler(), running in the DFE Interface and main UI threads respectively, using a ZeroMQ socket and the test tool reactor.
  4. The test tool reactor. This runs in the main UI thread, and receives events from both the keyboard input and the message_callback() function. The appropriate handler is called in each case. The reactor is a ZeroMQ poller.
  5. It is expected that the contents of the functions in this file will be completely replaced in customer applications using a inter-thread comms and a reactor that fit with a framework library used by that application.

Copyright (C) 2023 Global Graphics Software Ltd. All rights reserved. Global Graphics Software Ltd. Confidential Information.

Function Documentation

◆ create_farm_reply_ctxt()

FARM_REPLY_CTXT* create_farm_reply_ctxt ( void  )

Create a context that is used for ZeroMQ messaging from the DFE Interface thread to farm_reply_handler(). The context is passed back by the libripfarm interface as a handle in message_callback().

This function runs in the main UI thread.

Returns
The context used in relay_message_callback().

◆ destroy_farm_reply_ctxt()

void destroy_farm_reply_ctxt ( FARM_REPLY_CTXT **  p_farm_reply_ctxt)

Free resources allocated by create_farm_reply_ctxt().

Safe against a NULL value of p_farm_reply_ctxt, which is always set to NULL on exit.

This function runs in the main UI thread.

Parameters
p_farm_reply_ctxtThe pointer to the context returned by create_farm_reply_ctxt().

◆ farm_reply_handler()

static int farm_reply_handler ( zloop_t *  loop,
zsock_t *  socket,
void *  arg 
)
static

Receives ZeroMQ messages from relay_message_callback() via the test tool reactor, then sends the message to process_farm_reply() for processing.

This function runs in the main UI thread.

Parameters
loopUnused.
[in]socketThe ZeroMQ socket which the message is received from.
[in]argUnused.
Return values
0Normal value.
-1Abort the test tool reactor. This should not normally happen even in many error conditions.

◆ relay_message_callback()

HqBool relay_message_callback ( FARM_REPLY_CTXT farm_reply_ctxt,
RF_FARM_REPLY farm_reply 
)

Relay a message received from the farm to farm_reply_handler() in the main UI thread via a ZeroMQ pipe.

This function runs in the DFE Interface thread.

Parameters
[in]farm_reply_ctxtContains the ZeroMQ socket for comms with farm_reply_handler().
[in]farm_replyA message sent by the rip farm.
Return values
TRUENormal value.
FALSEcatastrophic error in sending the message. Results in

◆ testtool_reactor()

HqBool testtool_reactor ( struct RF_IFACE_CTXT iface_ctxt)

Runs the test tool reactor which monitors ZeroMQ messages from both keyboard_worker() and message_callback().

Simple commands are input via the keyboard and the responses from the farm are displayed on the monitor.

This function runs in the main UI thread.

Parameters
[in]iface_ctxtThe libripfarm interface context for use in keyboard_event().