12 #ifndef HPP_SERVICE_BODY_MANAGED_REPLY_HPP_
13 #define HPP_SERVICE_BODY_MANAGED_REPLY_HPP_
18 #include <dds/core/macros.hpp>
20 #include "osapi/osapi_heap.h"
21 #include "routingservice/routingservice_log.h"
22 #include "routingservice/routingservice_remote_config.h"
24 #include <rtiboost/assert.hpp>
25 #include <dds/core/Value.hpp>
26 #include <dds/core/types.hpp>
27 #include <rti/service/ServiceException.hpp>
28 #include <rti/service/DynamicBuffer.hpp>
30 namespace rti {
namespace service {
namespace admin {
32 class BodyManagedReply
36 typedef RTI_Service_Admin_CommandReply reply_type;
39 : string_body_(default_property()), octet_body_(default_property())
41 initialize_native_reply();
44 BodyManagedReply(
const DynamicBufferProperty &property)
45 : string_body_(property), octet_body_(property)
47 initialize_native_reply();
53 reply_.string_body = NULL;
54 if (!DDS_OctetSeq_has_ownership(&reply_.octet_body)) {
55 DDS_OctetSeq_unloan(&reply_.octet_body);
58 RTI_Service_Admin_CommandReply_finalize_ex(
63 void release_string_body(
char *&buffer, int32_t& length)
65 string_body_.release(buffer, length);
66 consolidate_string_body();
69 void own_string_body(
char *buffer, int32_t length)
71 string_body_.own(buffer, length);
72 consolidate_string_body();
77 return reply_.string_body;
80 DDS_OctetSeq& octet_body()
82 return reply_.octet_body;
85 char* string_body(int32_t length)
87 string_body_.ensure_length(length + 1);
88 consolidate_string_body();
92 DDS_OctetSeq& octet_body(int32_t length)
94 octet_body_.ensure_length(length + 1);
95 consolidate_octet_body();
99 void retcode(RTI_Service_Admin_CommandReplyRetcode retcode)
101 reply_.retcode = retcode;
104 void native_retcode(int32_t native_retcode)
106 reply_.native_retcode = native_retcode;
111 string_body_.trim_to_size();
112 *string_body_.buffer() =
'\0';
113 octet_body_.trim_to_size();
114 DDS_OctetSeq_set_length(&reply_.octet_body, 0);
115 retcode(RTI_SERVICE_COMMAND_REPLY_OK);
118 const reply_type& reply()
const
123 static DynamicBufferProperty default_property()
125 return DynamicBufferProperty(32 * 1024,
false);
129 void consolidate_string_body()
131 reply_.string_body = string_body_.buffer();
134 void consolidate_octet_body()
137 if (!DDS_OctetSeq_has_ownership(&reply_.octet_body)) {
138 DDS_OctetSeq_unloan(&reply_.octet_body);
140 DDS_OctetSeq_loan_contiguous(
142 (DDS_Octet *) octet_body_.buffer(),
144 octet_body_.length());
147 void initialize_native_reply()
149 RTIOsapiMemory_zero(&reply_,
sizeof(reply_type));
150 if (!RTI_Service_Admin_CommandReply_initialize_ex(
154 RTI_THROW_SERVICE_EXCEPTION(
155 &RTI_LOG_INIT_FAILURE_s,
158 RTIBOOST_ASSERT(reply_.string_body == NULL);
159 RTIBOOST_ASSERT(DDS_OctetSeq_get_length(&reply_.octet_body) == 0);
160 consolidate_string_body();
161 consolidate_octet_body();
166 DynamicBuffer string_body_;
167 DynamicBuffer octet_body_;