ppsService.watch()

Monitor changes that publishers make to a PPS object file

Signature

ppsService.watch(fd, datalistener, errorlistener);

Arguments

Argument Type Description
fd Integer A file descriptor with read permission, returned by ppsService.open(). Required.
datalistener Function The callback function that gets called to receive PPS data in JSON object format. Required. See dataListener() for details.
errorlistener Function The callback function that gets called if an error occurs. Required. See errorListener() for details.

Description

The ppsService.watch() method monitors all activities on the specified file descriptor and provides PPS data to the specified datalistener() callback function.

If you call ppsService.watch() on the same file descriptor multiple times with different data listeners, all listeners get invoked on each change to the PPS object.

Returns

True on success, false otherwise.

Examples

var PATH = '/pps/person';

var errorHandler = function(fd, errorID, errorMessage) {
   // handle the error
   console.log('FD: %d, Error ID: %d, Message: %s.', fd, errorID, errorMessage);
}

// open for write, create the file if it does not exist.
var fd_wrt = ppsService.open(PATH, ppsService.FLAG_WRONLY | ppsService.FLAG_CREAT | 
                                   ppsService.FLAG_TRUNC, ppsService.MODE_IRWXU | 
                                   ppsService.MODE_IRWXG | ppsService.MODE_IRWXO, 
                                   errorHandler);
if (fd_wrt < 1) {
   console.log('Open for write failed.');
}

// open for watch
var fd_r = ppsService.open(PATH, ppsService.FLAG_RDONLY, 0, errorHandler);
if (fd_r < 1) {
   console.log('Open for watch failed.');
}

var dataHandler = function(fd, data) {
   console.log('FD: PPSData: %s.', fd, JSON.stringify(data));
}

// watch PPS data
if (fd_r > 1 && !ppsService.watch(fd_r, dataHandler, errorHandler)) {
   console.log('Read PPS data failed, FD: %d.', fd_r);
}