1 /* -*- C -*-
2 *
3 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2006 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2007-2011 Cisco Systems, Inc. All rights reserved.
14 * Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
15 * Copyright (c) 2014-2017 Intel, Inc. All rights reserved.
16 * $COPYRIGHT$
17 *
18 * Additional copyrights may follow
19 *
20 * $HEADER$
21 */
22 /**
23 * @file
24 *
25 * Buffer management types.
26 */
27
28 #ifndef PMIX_MCA_BFROP_TYPES_H_
29 #define PMIX_MCA_BFROP_TYPES_H_
30
31 #include <src/include/pmix_config.h>
32
33
34 #include "src/class/pmix_object.h"
35 #include "src/class/pmix_pointer_array.h"
36 #include "src/class/pmix_list.h"
37 #include <pmix_common.h>
38
39 BEGIN_C_DECLS
40
41 /* define the results values for comparisons so we can change them in only one place */
42 typedef enum {
43 PMIX_EQUAL = 0,
44 PMIX_VALUE1_GREATER,
45 PMIX_VALUE2_GREATER
46 } pmix_value_cmp_t;
47
48 /**
49 * buffer type
50 */
51 typedef uint8_t pmix_bfrop_buffer_type_t;
52 #define PMIX_BFROP_BUFFER_UNDEF 0x00
53 #define PMIX_BFROP_BUFFER_NON_DESC 0x01
54 #define PMIX_BFROP_BUFFER_FULLY_DESC 0x02
55
56 #define PMIX_BFROP_BUFFER_TYPE_HTON(h)
57 #define PMIX_BFROP_BUFFER_TYPE_NTOH(h)
58
59 /* internally used object for transferring data
60 * to/from the server and for storing in the
61 * hash tables */
62 typedef struct {
63 pmix_list_item_t super;
64 char *key;
65 pmix_value_t *value;
66 } pmix_kval_t;
67 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_kval_t);
68
69
70 /**
71 * Structure for holding a buffer */
72 typedef struct {
73 /** First member must be the object's parent */
74 pmix_object_t parent;
75 /** type of buffer */
76 pmix_bfrop_buffer_type_t type;
77 /** Start of my memory */
78 char *base_ptr;
79 /** Where the next data will be packed to (within the allocated
80 memory starting at base_ptr) */
81 char *pack_ptr;
82 /** Where the next data will be unpacked from (within the
83 allocated memory starting as base_ptr) */
84 char *unpack_ptr;
85
86 /** Number of bytes allocated (starting at base_ptr) */
87 size_t bytes_allocated;
88 /** Number of bytes used by the buffer (i.e., amount of data --
89 including overhead -- packed in the buffer) */
90 size_t bytes_used;
91 } pmix_buffer_t;
92 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_buffer_t);
93
94 /* Convenience macro for loading a data blob into a pmix_buffer_t
95 *
96 * p - the pmix_peer_t of the process that provided the blob. This
97 * is needed so we can set the buffer type for later unpacking
98 *
99 * b - pointer to pmix_buffer_t
100 *
101 * d - pointer to the data blob
102 *
103 * s - number of bytes in the blob
104 *
105 * NOTE: the macro does NOT copy the data, but simply assigns
106 * its address to the buffer. Accordingly, the macro will
107 * set the provided data blob pointer to NULL and the size
108 * to zero.
109 */
110 #define PMIX_LOAD_BUFFER(p, b, d, s) \
111 do { \
112 (b)->type = (p)->nptr->compat.type; \
113 (b)->base_ptr = (char*)(d); \
114 (b)->bytes_used = (s); \
115 (b)->bytes_allocated = (s); \
116 (b)->pack_ptr = ((char*)(b)->base_ptr) + (s); \
117 (b)->unpack_ptr = (b)->base_ptr; \
118 (d) = NULL; \
119 (s) = 0; \
120 } while (0)
121
122 /* Convenience macro for extracting a pmix_buffer_t's payload
123 * as a data blob
124 *
125 * b - pointer to the pmix_buffer_t
126 *
127 * d - char* pointer to the data blob
128 *
129 * s - number of bytes in the blob
130 *
131 * NOTE: the macro does NOT copy the data, but simply assigns
132 * the address of the buffer's payload to the provided pointer.
133 * Accordingly, the macro will set all pmix_buffer_t internal
134 * tracking pointers to NULL and all counters to zero */
135 #define PMIX_UNLOAD_BUFFER(b, d, s) \
136 do { \
137 (d) = (char*)(b)->unpack_ptr; \
138 (s) = (b)->bytes_used; \
139 (b)->base_ptr = NULL; \
140 (b)->bytes_used = 0; \
141 (b)->bytes_allocated = 0; \
142 (b)->pack_ptr = NULL; \
143 (b)->unpack_ptr = NULL; \
144 } while (0)
145
146 /* Convenience macro to check for empty buffer without
147 * exposing the internals */
148 #define PMIX_BUFFER_IS_EMPTY(b) \
149 (0 == (b)->bytes_used)
150
151 END_C_DECLS
152
153 #endif /* PMIX_BFROP_TYPES_H */