ppsService.open()

Open a PPS object file for read, write, or both

Signature

ppsService.open(path, flags, mode, errorlistener);

Arguments

Argument Type Description
path String The pathname of a PPS object file to open. Required.

You can append any of the following pathname open options to the PPS object path:

OPTION_DELTA — Open in delta mode
OPTION_NATIVE — Open in native mode
OPTION_NOPERSIST — Open as nonpersistent object
OPTION_SERVER — Open as server object
OPTION_VERBOSE — Be verbose

For information on the native-mode option, see the Description, below. For information on all other pathname open options, see the Persistent Publish/Subscribe Developer's Guide.

flags Integer

Open the PPS object file, using the specified access modes. Required.

You can specify any of the following constants:

FLAG_RDONLY — Read only
FLAG_WRONLY — Write only
FLAG_RDWR — Read-write
FLAG_CREAT — Open with file create
FLAG_TRUNC — Open with truncation
    

You can also specify flags defined in the QNX system header file fcntl.h.

mode Integer

Use the specified owner, group, other access permissions for the newly created PPS object file. Required.

Specify a mode in this argument only if you specify FLAG_CREAT in the flags argument; otherwise, pass 0.

You can specify any of the following constants:

Owner
    MODE_IRWXU — Read, write, execute/search
    MODE_IRUSR — Read
    MODE_IWUSR — Write
    MODE_IXUSR — Execute/search
    

Group
    MODE_IRWXG — Read, write, execute/search
    MODE_IRGRP — Read
    MODE_IWGRP — Write
    MODE_IXGRP — Execute/search
    

Other
    MODE_IRWXO — Read, write, execute/search
    MODE_IROTH — Read
    MODE_IWOTH — Write
    MODE_IXOTH — Execute/search
    

You can also specify any permissions defined the QNX OS header file fcntl.h.

errorlistener Function The callback function that gets called if an error occurs. Required. See errorListener() for details.

Description

The ppsService.open() method is a JavaScript wrapper of the QNX native open() function. It has the same usage as open(), except for its extra errorlistener argument. See open() in the QNX Neutrino RTOS Library Reference for more information, including details of the various access modes.

The JavaScript PPS API has an exclusive “native” pathname open option. When you append this option to the PPS path (i.e. pps_path?native or pps_path?ppsService.OPTION_NATIVE), the PPS data received by calling ppsService.read() or ppsService.watch() on the file descriptor will be in PPS native format. See dataListener() for signature information.

See the QNX Persistent Publish/Subscribe Developer's Guide for more information on pathname open options.

Returns

On success, a positive number that represents the file descriptor; otherwise, 0 or a negative number.

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_wr = ppsService.open(PATH, ppsService.FLAG_WRONLY | ppsService.FLAG_CREAT, 
                                  ppsService.MODE_IRWXU | ppsService.MODE_IRWXG | 
                                  ppsService.MODE_IRWXO, errorHandler);
if (fd_wr < 1) {
   console.log('Open for write failed.');
}

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

// open for read in delta mode
var fd_r_delta = ppsService.open(PATH + '?delta', ppsService.FLAG_RDONLY, 0, errorHandler);
if (fd_r_delta < 1) {
   console.log('Open for read in delta mode failed.');
}

// open for read in raw data format
var fd_r_raw = ppsService.open(PATH + '?native', ppsService.FLAG_RDONLY, 0, errorHandler);
if (fd_r_raw < 1) {
   console.log('Open for read in raw data format failed.');
}

// open for read and write
var fd_rw = ppsService.open(PATH, ppsService.FLAG_RDWR, 0, errorHandler);
if (fd_rw < 1) {
   console.log('Open for read and write failed.');
}