Harlequin RIP SDK

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

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

Data Structures

struct  keyboard_ack_t
 Data returned from keyboard_event() to relay_keyboard_string() in a ZeroMQ message between the main UI and keyboard_worker threads. More...
 
struct  RELAY_KEYBOARD_CTXT
 Structure used by relay_keyboard_string(). It is anonymously passed through keyboard_loop(). More...
 

Typedefs

typedef struct keyboard_ack_t keyboard_ack_t
 Data returned from keyboard_event() to relay_keyboard_string() in a ZeroMQ message between the main UI and keyboard_worker threads.
 

Functions

static void prompt (void)
 
void keyboard_loop (RELAY_KEYBOARD_CTXT *kbd_ctxt)
 Keyboard commands from stdin are monitored and passed to the test tool reactor via relay_keyboard_string. The test tool reactor will direct the command to process_keyboard_cmd(). More...
 
HqBool relay_keyboard_string (char *str, RELAY_KEYBOARD_CTXT *kbd_ctxt, int *waitms)
 Relays keyboard strings between the keyboard_worker and main UI threads by sending a messages over a ZeroMQ socket to keyboard_event(). More...
 
void keyboard_worker (zsock_t *keyboard_pipe, void *arg)
 Keyboard strokes from stdin are monitored and passed to the test tool reactor via a ZeroMQ message over keyboard_pipe. The test tool reactor will direct the message to keyboard_event(). More...
 
int keyboard_event (zloop_t *loop, zsock_t *socket, void *arg)
 Receives the ZeroMQ messages from relay_keyboard_string() via the test tool reactor, then calls process_keyboard_cmd() to process the message. Then sends a reply message in the reverse direction. 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 keyboard_worker and UI threads of the test tool.

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

  1. There are two threads dealing with the keyboard, the main UI and the keyboard_worker threads. The messaging between these threads is via ZeroMQ messages.
  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.

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

Function Documentation

◆ keyboard_event()

int keyboard_event ( zloop_t *  loop,
zsock_t *  socket,
void *  arg 
)

Receives the ZeroMQ messages from relay_keyboard_string() via the test tool reactor, then calls process_keyboard_cmd() to process the message. Then sends a reply message in the reverse direction.

This function runs in the main UI thread.

Parameters
loopUnused.
[in]socketThe ZeroMQ socket which the message is received from.
[in]argContains the libripfarm interface context. Created in testtool_reactor().
Return values
0Normal value. The test tool reactor continues processing keyboard events, even when some errors are encountered.
-1Abort the test tool reactor. Normally this should only happen if an exit message was passed from the keyboard.

◆ keyboard_loop()

void keyboard_loop ( RELAY_KEYBOARD_CTXT kbd_ctxt)

Keyboard commands from stdin are monitored and passed to the test tool reactor via relay_keyboard_string. The test tool reactor will direct the command to process_keyboard_cmd().

This function runs in the keyboard_worker thread.

Parameters
[in]kbd_ctxtAnonymous context for passing to relay_keyboard_string().

◆ keyboard_worker()

void keyboard_worker ( zsock_t *  keyboard_pipe,
void *  arg 
)

Keyboard strokes from stdin are monitored and passed to the test tool reactor via a ZeroMQ message over keyboard_pipe. The test tool reactor will direct the message to keyboard_event().

This function runs in the keyboard_worker thread.

Parameters
[in]keyboard_pipeZeroMQ socket to use for comms in relay_keyboard_string().
argUnused.

◆ prompt()

static void prompt ( void  )
static

Print out a prompt on the monitor. This function runs in the keyboard_worker thread.

◆ relay_keyboard_string()

HqBool relay_keyboard_string ( char *  str,
RELAY_KEYBOARD_CTXT kbd_ctxt,
int *  waitms 
)

Relays keyboard strings between the keyboard_worker and main UI threads by sending a messages over a ZeroMQ socket to keyboard_event().

Waits for a reply from keyboard_event() which contains a keyboard_ack_t struct.

This function runs in the keyboard_worker thread.

Parameters
[in]strThe keyboard string.
[in]kbd_ctxtThe context from keyboard_worker() passed anonymously via keyboard_loop().
[out]waitmsNormally 0. It is the value, in ms, of the delay that keyboard_loop() should wait before accepting the next command.
Return values
TRUENormal return value.
FALSEIFF the response from keyboard_event() is to exit the test tool.