2005-03-14 23:57:21 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-23 07:32:36 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2005-03-14 23:57:21 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2005-03-14 23:57:21 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DPS Buffer Operations
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "orte_config.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2005-04-11 09:00:26 +04:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2005-03-14 23:57:21 +03:00
|
|
|
#include <netinet/in.h>
|
2005-04-11 09:00:26 +04:00
|
|
|
#endif
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
#include "orte/mca/ns/base/base.h"
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
#include "orte/dss/dss_internal.h"
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
int orte_dss_unload(orte_buffer_t *buffer, void **payload,
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t *bytes_used)
|
2005-03-14 23:57:21 +03:00
|
|
|
{
|
2006-12-07 02:19:06 +03:00
|
|
|
char *hdr_dst = NULL;
|
|
|
|
orte_dss_buffer_type_t type;
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/* check that buffer is not null */
|
|
|
|
if (!buffer) {
|
|
|
|
return ORTE_ERR_BAD_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* were we given someplace to point to the payload */
|
|
|
|
if (NULL == payload) {
|
|
|
|
return ORTE_ERR_BAD_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* anything in the buffer - if not, nothing to do */
|
2005-05-01 04:53:00 +04:00
|
|
|
if (NULL == buffer->base_ptr || 0 == buffer->bytes_used) {
|
2005-03-14 23:57:21 +03:00
|
|
|
*payload = NULL;
|
2005-05-01 04:53:00 +04:00
|
|
|
*bytes_used = 0;
|
2005-03-14 23:57:21 +03:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
2006-12-07 02:19:06 +03:00
|
|
|
|
|
|
|
/* add room for our description of the buffer -- currently just the type */
|
|
|
|
if (NULL == (hdr_dst = orte_dss_buffer_extend(buffer,
|
|
|
|
sizeof(orte_dss_buffer_type_t)))) {
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the header (at the end, so perhaps it's a footer? */
|
|
|
|
type = buffer->type;
|
|
|
|
ORTE_DSS_BUFFER_TYPE_HTON(type);
|
|
|
|
memcpy(hdr_dst, &type, sizeof(orte_dss_buffer_type_t));
|
|
|
|
buffer->bytes_used += sizeof(orte_dss_buffer_type_t);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-05-01 04:53:00 +04:00
|
|
|
/* okay, we have something to provide - pass it back */
|
2005-03-14 23:57:21 +03:00
|
|
|
*payload = buffer->base_ptr;
|
2006-10-20 06:25:50 +04:00
|
|
|
*bytes_used = (orte_std_cntr_t)buffer->bytes_used;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
/* dereference everything in buffer */
|
|
|
|
buffer->base_ptr = NULL;
|
2005-05-01 04:53:00 +04:00
|
|
|
buffer->pack_ptr = buffer->unpack_ptr = NULL;
|
|
|
|
buffer->bytes_allocated = buffer->bytes_used = buffer->bytes_avail = 0;
|
|
|
|
|
|
|
|
/* All done */
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-08-15 22:25:35 +04:00
|
|
|
return ORTE_SUCCESS;
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
int orte_dss_load(orte_buffer_t *buffer, void *payload,
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t bytes_used)
|
2005-03-14 23:57:21 +03:00
|
|
|
{
|
2006-12-07 02:19:06 +03:00
|
|
|
char *hdr_ptr;
|
|
|
|
orte_dss_buffer_type_t type;
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/* check to see if the buffer has been initialized */
|
|
|
|
if (NULL == buffer) {
|
|
|
|
return ORTE_ERR_BAD_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check that the payload is there */
|
2005-05-11 18:19:48 +04:00
|
|
|
if (NULL == payload) {
|
2005-03-14 23:57:21 +03:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if buffer already has payload - free it if so */
|
|
|
|
if (NULL != buffer->base_ptr) {
|
|
|
|
free(buffer->base_ptr);
|
|
|
|
}
|
2006-12-07 02:19:06 +03:00
|
|
|
|
|
|
|
/* get our header */
|
|
|
|
hdr_ptr = (char*) payload + bytes_used - sizeof(orte_dss_buffer_type_t);
|
|
|
|
memcpy(&type, hdr_ptr, sizeof(orte_dss_buffer_type_t));
|
|
|
|
ORTE_DSS_BUFFER_TYPE_NTOH(type);
|
|
|
|
buffer->type = type;
|
|
|
|
bytes_used -= sizeof(orte_dss_buffer_type_t);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
/* populate the buffer */
|
2006-08-23 07:32:36 +04:00
|
|
|
buffer->base_ptr = (char*)payload;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-05-01 04:53:00 +04:00
|
|
|
/* set pack/unpack pointers */
|
|
|
|
buffer->pack_ptr = ((char*)buffer->base_ptr) + bytes_used;
|
|
|
|
buffer->unpack_ptr = buffer->base_ptr;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-05-01 04:53:00 +04:00
|
|
|
/* set counts for size and space */
|
|
|
|
buffer->bytes_allocated = buffer->bytes_used = bytes_used;
|
|
|
|
buffer->bytes_avail = 0;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-05-01 04:53:00 +04:00
|
|
|
/* All done */
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|