Put a name into the namespace

To register our resource manager's path, we call resmgr_attach() like this:

/* attach our device name */
id = resmgr_attach(dpp,            /* dispatch handle        */
                   &resmgr_attr,   /* resource manager attrs */
                   "/dev/sample",  /* device name            */
                   _FTYPE_ANY,     /* open type              */
                   0,              /* flags                  */
                   &connect_funcs, /* connect routines       */
                   &io_funcs,      /* I/O routines           */
                   &attr);         /* handle                 */
if(id == -1) {
    fprintf(stderr, "%s: Unable to attach name.\n", argv[0]);
    return EXIT_FAILURE;
}

Before a resource manager can receive messages from other programs, it needs to inform the other programs (via the process manager) that it's the one responsible for a particular pathname prefix. This is done via pathname registration. When the name is registered, other processes can find and connect to this process using the registered name.

In this example, a serial port may be managed by a resource manager called devc-xxx, but the actual resource is registered as /dev/sample in the pathname space. Therefore, when a program requests serial port services, it opens the /dev/sample serial port.

We'll look at the parameters in turn, skipping the ones we've already discussed.

device name
Name associated with our device (i.e., /dev/sample).
open type
Specifies the constant value of _FTYPE_ANY. This tells the process manager that our resource manager will accept any type of open request; we're not limiting the kinds of connections we're going to be handling.

Some resource managers legitimately limit the types of open requests they handle. For instance, the POSIX message queue resource manager accepts only open messages of type _FTYPE_MQUEUE.

flags
Controls the process manager's pathname resolution behavior. By specifying a value of zero, we indicate that we'll accept only requests for the name /dev/sample.
Note: The bits that you use in this argument are the _RESMGR_FLAG_* flags (e.g., _RESMGR_FLAG_BEFORE) defined in <sys/resmgr.h>. We'll discuss some of these flags in this guide, but you can find a full list in the entry for resmgr_attach() in the QNX Neutrino C Library Reference.

There are some other flags whose names don't start with an underscore, but they're for the flags member of the resmgr_attr_t structure, which we'll look at in more detail in Setting resource manager attributes in the Fleshing Out the Skeleton chapter.

If you want to use the same dispatch handler for other types of notifications, you can also call message_attach(), pulse_attach(), and select_attach() at this point.