1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/dss/dss_internal.h"
int opal_dss_copy(void **dest, void *src, opal_data_type_t type)
{
opal_dss_type_info_t *info;
/* check for error */
if (NULL == dest) {
return OPAL_ERR_BAD_PARAM;
}
if (NULL == src && (OPAL_NULL != type && OPAL_STRING != type)) {
return OPAL_ERR_BAD_PARAM;
}
/* Lookup the copy function for this type and call it */
if (NULL == (info = (opal_dss_type_info_t*)opal_pointer_array_get_item(&opal_dss_types, type))) {
return OPAL_ERR_UNKNOWN_DATA_TYPE;
}
return info->odti_copy_fn(dest, src, type);
}
/*
* STANDARD COPY FUNCTION - WORKS FOR EVERYTHING NON-STRUCTURED
*/
int opal_dss_std_copy(void **dest, void *src, opal_data_type_t type)
{
size_t datasize;
uint8_t *val = NULL;
switch(type) {
case OPAL_BOOL:
datasize = sizeof(bool);
break;
case OPAL_INT:
case OPAL_UINT:
datasize = sizeof(int);
break;
case OPAL_SIZE:
datasize = sizeof(size_t);
break;
case OPAL_PID:
datasize = sizeof(pid_t);
break;
case OPAL_BYTE:
case OPAL_INT8:
case OPAL_UINT8:
datasize = 1;
break;
case OPAL_INT16:
case OPAL_UINT16:
datasize = 2;
break;
case OPAL_INT32:
case OPAL_UINT32:
datasize = 4;
break;
case OPAL_INT64:
case OPAL_UINT64:
datasize = 8;
break;
case OPAL_DATA_TYPE:
datasize = sizeof(opal_data_type_t);
break;
default:
return OPAL_ERR_UNKNOWN_DATA_TYPE;
}
val = (uint8_t*)malloc(datasize);
if (NULL == val) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
memcpy(val, src, datasize);
*dest = val;
return OPAL_SUCCESS;
}
/* COPY FUNCTIONS FOR NON-STANDARD SYSTEM TYPES */
/*
* NULL
*/
int opal_dss_copy_null(char **dest, char *src, opal_data_type_t type)
{
char *val;
*dest = (char*)malloc(sizeof(char*));
if (NULL == *dest) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
val = *dest; /* save the address of the value */
/* set the dest to null */
*val = 0x00;
return OPAL_SUCCESS;
}
/*
* STRING
*/
int opal_dss_copy_string(char **dest, char *src, opal_data_type_t type)
{
if (NULL == src) { /* got zero-length string/NULL pointer - store NULL */
*dest = NULL;
} else {
*dest = strdup(src);
}
return OPAL_SUCCESS;
}
/* COPY FUNCTIONS FOR GENERIC OPAL TYPES */
/*
* OPAL_DATA_VALUE
*/
int opal_dss_copy_data_value(opal_dss_value_t **dest, opal_dss_value_t *src,
opal_data_type_t type)
{
int rc;
/* create the new object */
*dest = OBJ_NEW(opal_dss_value_t);
if (NULL == *dest) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
(*dest)->type = src->type;
/* copy the payload with its associated copy function */
if (OPAL_SUCCESS != (rc = opal_dss.copy(&((*dest)->data), src->data, src->type))) {
OBJ_RELEASE(*dest);
return rc;
}
return OPAL_SUCCESS;
}
/*
* OPAL_BYTE_OBJECT
*/
int opal_dss_copy_byte_object(opal_byte_object_t **dest, opal_byte_object_t *src,
opal_data_type_t type)
{
/* allocate space for the new object */
*dest = (opal_byte_object_t*)malloc(sizeof(opal_byte_object_t));
if (NULL == *dest) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
(*dest)->size = src->size;
/* allocate the required space for the bytes */
(*dest)->bytes = (uint8_t*)malloc(src->size);
if (NULL == (*dest)->bytes) {
OBJ_RELEASE(*dest);
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* copy the data across */
memcpy((*dest)->bytes, src->bytes, src->size);
return OPAL_SUCCESS;
}
/* OPAL_PSTAT */
int opal_dss_copy_pstat(opal_pstats_t **dest, opal_pstats_t *src,
opal_data_type_t type)
{
opal_pstats_t *p;
/* create the new object */
*dest = OBJ_NEW(opal_pstats_t);
if (NULL == *dest) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
p = *dest;
/* copy the individual fields */
memcpy(p->node, src->node, sizeof(src->node));
p->rank = src->rank;
p->pid = src->pid;
memcpy(p->cmd, src->cmd, sizeof(src->node));
p->state = src->state;
p->time = src->time;
p->priority = src->priority;
p->num_threads = src->num_threads;
p->vsize = src->vsize;
p->rss = src->rss;
p->peak_vsize = src->peak_vsize;
p->shared_size = src->shared_size;
p->processor = src->processor;
return OPAL_SUCCESS;
}
|