Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Info API #443

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions parsec/include/parsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "parsec/datatype.h"
#include "parsec/scheduling.h"
#include "parsec/utils/debug.h"
#include "parsec/utils/info.h"

#include "parsec/interfaces/interface.h"
#include "parsec/interfaces/dtd/insert_function.h"
Expand Down
34 changes: 34 additions & 0 deletions parsec/utils/info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "parsec_config.h"
#include "parsec.h"
#include "parsec/utils/info.h"
#include "parsec/class/hashtable.h"
#include "parsec/class/parsec_object.h"

PARSEC_OBJ_CLASS_INSTANCE(parsec_info_t, parsec_hashtable_t, NULL, NULL);

int parsec_info_set(parsec_info_t *info, const char *key, char *value) {
return PARSEC_NOT_IMPLEMENTED;
}

int parsec_info_get(parsec_info_t *info, const char *key, char **value) {
return PARSEC_NOT_IMPLEMENTED;
}

int parsec_info_clear(parsec_info_t *info) {
/* must clear in-place as multiple refs ot the info may be held */
return PARSEC_NOT_IMPLEMENTED;
}

int parsec_context_get_info(parsec_context_t *ctx, parsec_info_t **info) {
if(NULL == ctx->info) {
ctx->info = PARSEC_OBJ_NEW(parsec_info_t);
}
return ctx->info;
}

int parsec_taskpool_get_info(parsec_taskpool_t *tp, parsec_info_t **info) {
if(NULL == tp->info) {
tp->info = PARSEC_OBJ_NEW(parsec_info_t);
}
return tp->info;
}
168 changes: 168 additions & 0 deletions parsec/utils/info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* Copyright (c) 2022 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/

/**
* @file
*
* Generic routines for "info" handling. This is a sinple key-value store that
* is independent from the main MCA param key-value store. Helpful for creating
* info strings without affecting MCA params.
*/

#ifndef PARSEC_INFO_H
#define PARSEC_INFO_H

#include "parsec/parsec_config.h"

#ifdef PARSEC_HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef PARSEC_HAVE_STDBOOL_H
#include <stdbool.h>
#endif

BEGIN_C_DECLS


typedef char* parsec_info_key_t;
typedef char* parsec_info_value_t;


struct parsec_info_value_s {
char val[PARSEC_INFO_VALUE_LEN];
} parsec_info_value_t;


struct parsec_info_s {
parsec_hashtable_t super;
} parsec_info_t;

PARSEC_OBJ_CLASS(parsec_info_t);

} parsec_info_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo.


#define PARSEC_INFO_VALUE_NULL NULL


/**
* Set the key-value pair in the target info object.
*
* @param info Pointer to the target info object. Must not be
* NULL.
* @param key String for the key, max length PARSEC_INFO_KEY_LEN.
* @param value String for the value to attache to the key, max
* length PARSEC_INFO_VALUE_LEN.
*
* @retval PARSEC_SUCCESS On success
* @retval PARSEC_ERROR On failure, values lower than PARSEC_ERROR may
* elaborate on the particular error type.
*
* This function associates a string value to the string key in the
* key-value store info. The value string is copied to the internal
* storage of the key-value store. To reiterate, there is no need to
* keep a copy of the value.
*
* If the key is already set to a value, the previous value is
* overwritten for te key. In particular, if the value is
* PARSEC_INFO_VALUE_NULL, the previous key-value pair is removed
* from the info.
*/
parsec_info_set(parsec_info_t *info, const char *key, const char *value);

/**
* Get the value associated with the key in the target info object.
*
* @param info Pointer to the target info object. Must not be
* NULL.
* @param key String for the key, max length PARSEC_INFO_KEY_LEN.
* @param value Pointer to the string of the value to retrieve;
*
* @retval PARSEC_SUCCESS On success
* @retval PARSEC_ERROR On failure, values lower than PARSEC_ERROR may
* elaborate on the particular error type.
*
* This function obtains the string value associated with the string
* key in the key-value store info. A pointer to the internal value
* string is returned. To reiterate, the value is shared with the
* internal storage of the info object and must not be freed.
*
* If the key is not set to a value, the value is set to
* PARSEC_INFO_VALUE_NULL.
*/
parsec_info_get(parsec_info_t *info, const char *key, char **value);

/**
* Clear all key-values from the target info object.
*
* @param info Pointer to the target info object. Must not be
* NULL.
*
* @retval PARSEC_SUCCESS On success
* @retcal PARSEC_ERROR On failure, values lower than PARSEC_ERROR may
* elaborate on the particular error type.
*
* This function clears all previously set key-values from the target
* key-value store object; that is, it is equivalent to calling
* parsec_info_set with the value PARSEC_INFO_VALUE_NULL, for any key
* previously set on the info.
*/
parsec_info_clear(parserc_info_t *info);

/**
* Obtain the info object associated with the givent context
*
* @param ctx The context to query
* @param info Pointer to the info object associated with the context
*
* @retval PARSEC_SUCCESS On success
* @retval PARSEC_ERROR On failure
*
* The returned info object may be empty (that is, it has no values
* associated with any keys), but is always returns a reference to a
* valid info object.
*
* Key-values added, modified, or removed to/from the info object will
* be implicitly applied to the context, that is, behavior for calls
* using that context may be altered accordingly to the set key-values.
*
* The returned info is a reference to the info object internally held
* by the context. The Info object should never be freed, and it ceases
* to be a valid reference when the concext has been freed.
*/
parsec_context_get_info(parsec_context_t *ctx, parsec_info_t **info);

/**
* Obtain the info object associated with the givent taskpool
*
* @param tp The taskpool to query
* @param info Pointer to the info object associated with the context
*
* @retval PARSEC_SUCCESS On success
* @retval PARSEC_ERROR On failure
*
* The returned info object may be empty (that is, it has no values
* associated with any keys), but is always returns a reference to a
* valid info object.
*
* Key-values added, modified, or removed to/from the info object will
* be implicitly applied to the taskpool, that is, behavior for calls
* using that taskpool may be altered accordingly to the set key-values.
*
* The returned info is a reference to the info object internally held
* by the taskpool. The Info object should never be freed, and it ceases
* to be a valid reference when the taskpool has been freed.
*/
parsec_taskpool_get_info(parsec_taskpool_t *tp, parsec_info_t **info);

END_C_DECLS

#endif /* PARSEC_INFO_H */