1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
13 * $COPYRIGHT$
14 *
15 * Additional copyrights may follow
16 *
17 * $HEADER$
18 */
19
20 #include "opal_config.h"
21
22 #include "opal/dss/dss_internal.h"
23
opal_dss_register(opal_dss_pack_fn_t pack_fn,opal_dss_unpack_fn_t unpack_fn,opal_dss_copy_fn_t copy_fn,opal_dss_compare_fn_t compare_fn,opal_dss_print_fn_t print_fn,bool structured,const char * name,opal_data_type_t * type)24 int opal_dss_register(opal_dss_pack_fn_t pack_fn,
25 opal_dss_unpack_fn_t unpack_fn,
26 opal_dss_copy_fn_t copy_fn,
27 opal_dss_compare_fn_t compare_fn,
28 opal_dss_print_fn_t print_fn,
29 bool structured,
30 const char *name, opal_data_type_t *type)
31 {
32 opal_dss_type_info_t *info, *ptr;
33 int32_t i;
34
35 /* Check for bozo cases */
36
37 if (NULL == pack_fn || NULL == unpack_fn || NULL == copy_fn || NULL == compare_fn ||
38 NULL == print_fn || NULL == name || NULL == type) {
39 return OPAL_ERR_BAD_PARAM;
40 }
41
42 /* check if this entry already exists - if so, error - we do NOT allow multiple type registrations */
43 for (i=0; i < opal_pointer_array_get_size(&opal_dss_types); i++) {
44 ptr = opal_pointer_array_get_item(&opal_dss_types, i);
45 if (NULL != ptr) {
46 /* check if the name exists */
47 if (0 == strcmp(ptr->odti_name, name)) {
48 return OPAL_ERR_DATA_TYPE_REDEF;
49 }
50 /* check if the specified type exists */
51 if (*type > 0 && ptr->odti_type == *type) {
52 return OPAL_ERR_DATA_TYPE_REDEF;
53 }
54 }
55 }
56
57 /* if type is given (i.e., *type > 0), then just use it.
58 * otherwise, it is an error
59 */
60 if (0 >= *type) {
61 return OPAL_ERR_BAD_PARAM;
62 }
63
64 /* Add a new entry to the table */
65 info = (opal_dss_type_info_t*) OBJ_NEW(opal_dss_type_info_t);
66 if (NULL == info) {
67 return OPAL_ERR_OUT_OF_RESOURCE;
68 }
69 info->odti_type = *type;
70 info->odti_name = strdup(name);
71 info->odti_pack_fn = pack_fn;
72 info->odti_unpack_fn = unpack_fn;
73 info->odti_copy_fn = copy_fn;
74 info->odti_compare_fn = compare_fn;
75 info->odti_print_fn = print_fn;
76 info->odti_structured = structured;
77
78 return opal_pointer_array_set_item(&opal_dss_types, *type, info);
79 }
80