/*
 * Monitor a directory.
 *
 * Returns a Fam::Request object, which is used to identify the monitor
 * associated with events.
 *
 * Raises a Fam::Error exception if the directory could not be
 * monitored.
 *
 * Aliases:
 *   Fam::Connection#monitor_dir
 *   Fam::Connection#directory
 *   Fam::Connection#dir
 *
 * Examples:
 *   req = fam.monitor_directory '/tmp'
 *
 */
static VALUE fam_conn_dir(VALUE self, VALUE dir)
{
  FAMConnection *conn;
  FAMRequest *req = NULL;
  int err;

  Data_Get_Struct(self, FAMConnection, conn);
  req = ALLOC(FAMRequest);
  err = FAMMonitorDirectory(conn, RSTRING(dir)->ptr, req, NULL);

  if (err == -1) {
    xfree(req);
    rb_raise(eError, "Couldn't monitor directory \"%s\": %s",
             RSTRING(dir)->ptr ? RSTRING(dir)->ptr : "NULL", fam_error());
  }

  return wrap_req(req);
}