Using notification groups

Once you have created a notification group and associated file descriptors with it, you can use this group to learn about changes to any of the objects associated with it.

Whenever data is available for reading on any of the group's file descriptors, reads to the notification object's file descriptor return the string passed in the ?notify=group:value pathname option.

For example, with PPS mounted at /pps, you could write something like the following:

char noid[16], buf[128];
int notify_fd, fd1, fd2;

notify_fd = open("/pps/.notify", O_RDONLY);
read(notify_fd, &noid[0], sizeof(noid));

sprintf(buf, "/pps/fish?notify=%s:water", noid);
fd1 = open(buf, O_RDONLY);
sprintf(buf, "/pps/dir/birds?notify=%s:air", noid);
fd2 = open(buf, O_RDONLY);

while(read(notify_fd, &buf, sizeof(buf) > 0) {
    printf("Notify %s\n", buf);
}

The data printed from the “while” loop in the example above would look something like the following:

Notify 243:water
Notify 243:water
Notify 243:air
Notify 243:water
Notify 243:air
Note: When reading from an object that is bound to a notification group, a subscriber should do multiple reads for each change indicated. There may be more than one change on an item, but there's no guarantee that every change will be indicated on the notification group's file descriptor.

Notification of closed file descriptors for objects

If a file descriptor for an object that is part of a notification group is closed, the string passed with the change notification is prefixed by a minus (“-”) sign. For example:

-243:air