[Previous] [Contents] [Next]

Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

pm_attach()

Obtain a handle to a power managed object

Synopsis:

#include <sys/pm.h>
#include <fcnl.h>

pm_hdl_t pm_attach(const char *name, int flags);

Arguments:

name
Name of the object within the power manager namespace.
flags
Specifies the access required to the object.

Library:

libpm

Description:

The pm_attach() obtains a handle allowing a client to manipulate a power managed object.

The flags argument specifies the required access:

O_RDONLY
The client isn't allowed to perform operations that modify the object.
O_RDWR
The client is allowed to perform operations that modify the object.

Returns:

An opaque handle that can be used to manipulate the object.

The pm_valid_hdl() function can be used to check if the handle is valid. If pm_attach() is unsuccessful, errno is set to indicate the error.

Errors:

ENOENT
name does not exist.
EACCES
Search permission is denied for a component within name.
EACCES
The permissions specified by flags are denied.
ENOTDIR
A component of name is not a directory.
EMFILE
Too many file descriptors are currently in use by the process.
ENFILE
Too many files are currently open in the system.

Examples:

#include <sys/pm.h>
#include <fcntl.h>
#include <stdlib.h>
int
main()
{
   pm_hdl_t        hdl;

   // attach to object with read-only access
   hdl = pm_attach("object", O_RDONLY);
   if (!pm_valid_hdl(hdl)) {
      perror("pm_attach");
      return EXIT_FAILURE;
   }
   
   if (pm_detach(hdl) == -1) {
      perror("pm_detach");
      return EXIT_FAILURE;
   }

   // attach to object with read-write access
   hdl = pm_attach("object", O_RDWR);
   if (!pm_valid_hdl(hdl)) {
      perror("pm_attach");
      return EXIT_FAILURE;
   }

   
   return EXIT_SUCCESS;
}

Classification:

Neutrino

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

pm_detach(), pm_create()


[Previous] [Contents] [Next]