Remove a data listener and error listener
ppsService.removeWatch(fd, datalistener, errorlistener);
| Argument | Type | Description |
|---|---|---|
| fd | Integer | The file descriptor with read permission returned by ppsService.open(). Required. |
| datalistener | Function | The data listener callback previously passed through ppsService.watch(). Required. |
| errorlistener | Function |
The error listener callback previously passed through ppsService.watch(). Required. See errorListener() for details. |
The ppsService.removeWatch() method removes the specified data listener and error listener. Other existing listeners will continue to work as expected. A call to this method has no effect if the specified listener was never added through a ppsService.watch() call.
None.
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);
}
// remove watch
if (fd_r > 1)
ppsService.removeWatch(fd_r, dataHandler, errorHandler);