Example #1
0
/**
 * Create a context.
 *
 * Creates and returns a new `dpl_ctx_t` object, or NULL on error.
 *
 * Possible errors include memory allocation failure, failure to find
 * the profile, and failure to parse the profile.  @note If this function
 * fails there is no way for the caller to discover what went wrong.
 *
 * The droplet directory is used as the base directory for finding several
 * important files, notably the profile file.  It is the first non-NULL pathname of:
 * @arg the parameter @a droplet_dir, or
 * @arg the environmental variable `DPLDIR`, or
 * @arg `"~/.droplet/"`.
 *
 * A profile file is read to set up options for the context.  The profile
 * file is named `<name>.profile` where `<name>` is the profile's name,
 * and is located in the droplet directory.  The profile's name is the
 * first non-NULL name of:
 * @arg the @a profile_name parameter, or
 * @arg the environment variable `DPLPROFILE`, or
 * @arg `"default"`.
 *
 * Thus, if both parameters are passed `NULL` the profile will be read
 * from the file `~/.droplet/default.profile`.
 *
 * See @ref profile "Profile File" for details of the profile file format.
 *
 * @param droplet_dir pathname of directory containing Droplet state, or `NULL`
 * @param profile_name name of the profile to use, or `NULL`
 * @return a new context, or NULL on error
 */
dpl_ctx_t *
dpl_ctx_new(const char *droplet_dir,
            const char *profile_name)
{
  dpl_ctx_t *ctx;
  int ret;

  ctx = dpl_ctx_alloc();
  if (NULL == ctx)
    {
      DPL_LOG(NULL, DPL_ERROR, "No memory for droplet context creation.");
      return NULL;
    }

  ret = dpl_profile_load(ctx, droplet_dir, profile_name);
  if (DPL_SUCCESS != ret)
    {
      dpl_ctx_free(ctx);
      return NULL;
    }

  dpl_ctx_post_load(ctx);

  return ctx;
}
Example #2
0
/**
 * Create a context.
 *
 * Creates and returns a new `dpl_ctx_t` object, or NULL on error.
 *
 * Possible errors include memory allocation failure, failure to find
 * the profile, and failure to parse the profile.  @note If this function
 * fails there is no way for the caller to discover what went wrong.
 *
 * The droplet directory is used as the base directory for finding several
 * important files, notably the profile file.  It is the first non-NULL pathname of:
 * @arg the parameter @a droplet_dir, or
 * @arg the environmental variable `DPLDIR`, or
 * @arg `"~/.droplet/"`.
 *
 * A profile file is read to set up options for the context.  The profile
 * file is named `<name>.profile` where `<name>` is the profile's name,
 * and is located in the droplet directory.  The profile's name is the
 * first non-NULL name of:
 * @arg the @a profile_name parameter, or
 * @arg the environment variable `DPLPROFILE`, or
 * @arg `"default"`.
 *
 * Thus, if both parameters are passed `NULL` the profile will be read
 * from the file `~/.droplet/default.profile`.
 *
 * See @ref profile "Profile File" for details of the profile file format.
 *
 * @param droplet_dir pathname of directory containing Droplet state, or `NULL`
 * @param profile_name name of the profile to use, or `NULL`
 * @return a new context, or NULL on error
 */
dpl_ctx_t *
dpl_ctx_new(const char *droplet_dir,
            const char *profile_name)
{
  dpl_ctx_t *ctx;
  int ret;

  ctx = dpl_ctx_alloc();
  if (NULL == ctx)
    return NULL;

  ret = dpl_profile_load(ctx, droplet_dir, profile_name);
  if (DPL_SUCCESS != ret)
    {
      dpl_ctx_free(ctx);
      return NULL;
    }

  dpl_ctx_post_load(ctx);

  return ctx;
}
Example #3
0
dpl_ctx_t *
dpl_ctx_new(char *droplet_dir,
            char *profile_name)
{
  dpl_ctx_t *ctx;
  int ret;

  ctx = malloc(sizeof (*ctx));
  if (NULL == ctx)
    return NULL;

  memset(ctx, 0, sizeof (*ctx));

  pthread_mutex_init(&ctx->lock, NULL);

  ret = dpl_profile_load(ctx, droplet_dir, profile_name);
  if (DPL_SUCCESS != ret)
    {
      dpl_ctx_free(ctx);
      return NULL;
    }

  return ctx;
}