summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2007-11-30 16:59:16 +0000
committerSteve Huston <shuston@riverace.com>2007-11-30 16:59:16 +0000
commitf52f64baf7bdb8753e101a9f94f1224c38c20d81 (patch)
tree68825cb20264e8f3c3a3ba117d06afd5ced67e10
parent45616b51611ae92fa7edab71910217f7e5987b49 (diff)
downloadATCD-f52f64baf7bdb8753e101a9f94f1224c38c20d81.tar.gz
ChangeLogTag:Fri Nov 30 16:58:00 UTC 2007 Steve Huston <shuston@riverace.com>
-rw-r--r--ACE/ChangeLog23
-rw-r--r--ACE/NEWS7
-rw-r--r--ACE/ace/CDR_Stream.cpp69
-rw-r--r--ACE/ace/CDR_Stream.h72
-rw-r--r--ACE/tests/CDR_Test.cpp102
5 files changed, 231 insertions, 42 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog
index 8513bbbe113..4404701fb7d 100644
--- a/ACE/ChangeLog
+++ b/ACE/ChangeLog
@@ -1,3 +1,23 @@
+Fri Nov 30 16:58:00 UTC 2007 Steve Huston <shuston@riverace.com>
+
+ * ace/CDR_Stream.{h cpp}:
+ Added replace (ACE_CDR::Short, char *), analogous to the existing
+ replace (ACE_CDR::Long, char *); replaces a previous place in the
+ stream with a short.
+ To make the replace() methods more convenient and easier to use
+ correctly, added the following methods:
+ char* write_long_placeholder (void);
+ char* write_short_placeholder (void);
+ These methods align the stream's write pointer properly then write
+ a 0-valued placeholder in the stream. The pointer to the placeholder
+ is returned; that pointer can later be passed to replace().
+
+ * tests/CDR_Test.cpp: Added tests for placeholder and replace ops.
+
+ Thank you to Howard Finer for contributing these additions.
+
+ * NEWS: Added note about these additions.
+
Fri Nov 30 11:50:00 UTC 2007 Simon Massey <sma@prismtech.com>
* bin/tao_other_tests.lst:
@@ -6,7 +26,8 @@ Fri Nov 30 11:50:00 UTC 2007 Simon Massey <sma@prismtech.com>
Thu Nov 29 19:49:23 UTC 2007 Douglas C. Schmidt <schmidt@dre.vanderbilt.edu>
* tests/Process_Manager_Test.cpp: Changed ACE_MT_SYNCH to ACE_SYNCH so
- this works on single-threaded builds. Thanks to Johnny for reporting this.
+ this works on single-threaded builds. Thanks to Johnny for
+ reporting this.
Thu Nov 29 18:10:27 UTC 2007 J.T. Conklin <jtc@acorntoolworks.com>
diff --git a/ACE/NEWS b/ACE/NEWS
index a826f57fb30..ccedb28adea 100644
--- a/ACE/NEWS
+++ b/ACE/NEWS
@@ -33,6 +33,13 @@ USER VISIBLE CHANGES BETWEEN ACE-5.6.1 and ACE-5.6.2
. Removed deprecated (un)subscribe methods from ACE_SOCK_Dgram_Mcast
+. Added an additional replace() method to ACE_OuptutCDR for replacing a
+ ACE_CDR::Short value. Also added write_long_placeholder() and
+ write_short_placeholder() to properly align the stream's write pointer,
+ write a placeholder value and return the placeholder's pointer. The pointer
+ can later be used in a call to replace() to replace the placeholder with a
+ different value.
+
USER VISIBLE CHANGES BETWEEN ACE-5.6 and ACE-5.6.1
====================================================
diff --git a/ACE/ace/CDR_Stream.cpp b/ACE/ace/CDR_Stream.cpp
index a9e1fa4f6cf..00af2b70940 100644
--- a/ACE/ace/CDR_Stream.cpp
+++ b/ACE/ace/CDR_Stream.cpp
@@ -651,6 +651,46 @@ ACE_OutputCDR::write_array (const void *x,
ACE_CDR::Boolean
+ACE_OutputCDR::write_boolean_array (const ACE_CDR::Boolean* x,
+ ACE_CDR::ULong length)
+{
+ // It is hard to optimize this, the spec requires that on the wire
+ // booleans be represented as a byte with value 0 or 1, but in
+ // memory it is possible (though very unlikely) that a boolean has
+ // a non-zero value (different from 1).
+ // We resort to a simple loop.
+ ACE_CDR::Boolean const * const end = x + length;
+
+ for (ACE_CDR::Boolean const * i = x;
+ i != end && this->good_bit ();
+ ++i)
+ (void) this->write_boolean (*i);
+
+ return this->good_bit ();
+}
+
+
+char *
+ACE_OutputCDR::write_long_placeholder (void)
+{
+ this->align_write_ptr (ACE_CDR::LONG_SIZE);
+ char *pos = this->current_->wr_ptr ();
+ this->write_long (0);
+ return pos;
+}
+
+
+char *
+ACE_OutputCDR::write_short_placeholder (void)
+{
+ this->align_write_ptr (ACE_CDR::SHORT_SIZE);
+ char *pos = this->current_->wr_ptr();
+ this->write_short (0);
+ return pos;
+}
+
+
+ACE_CDR::Boolean
ACE_OutputCDR::replace (ACE_CDR::Long x, char* loc)
{
if (this->find (loc) == 0)
@@ -674,22 +714,25 @@ ACE_OutputCDR::replace (ACE_CDR::Long x, char* loc)
ACE_CDR::Boolean
-ACE_OutputCDR::write_boolean_array (const ACE_CDR::Boolean* x,
- ACE_CDR::ULong length)
+ACE_OutputCDR::replace (ACE_CDR::Short x, char* loc)
{
- // It is hard to optimize this, the spec requires that on the wire
- // booleans be represented as a byte with value 0 or 1, but in
- // memory it is possible (though very unlikely) that a boolean has
- // a non-zero value (different from 1).
- // We resort to a simple loop.
- ACE_CDR::Boolean const * const end = x + length;
+ if (this->find (loc) == 0)
+ return false;
- for (ACE_CDR::Boolean const * i = x;
- i != end && this->good_bit ();
- ++i)
- (void) this->write_boolean (*i);
+#if !defined (ACE_ENABLE_SWAP_ON_WRITE)
+ *reinterpret_cast<ACE_CDR::Short*> (loc) = x;
+#else
+ if (!this->do_byte_swap_)
+ {
+ *reinterpret_cast<ACE_CDR::Short *> (loc) = x;
+ }
+ else
+ {
+ ACE_CDR::swap_2 (reinterpret_cast<const char*> (&x), loc);
+ }
+#endif /* ACE_ENABLE_SWAP_ON_WRITE */
- return this->good_bit ();
+ return true;
}
diff --git a/ACE/ace/CDR_Stream.h b/ACE/ace/CDR_Stream.h
index 6588664f36f..58ddea442ed 100644
--- a/ACE/ace/CDR_Stream.h
+++ b/ACE/ace/CDR_Stream.h
@@ -233,32 +233,6 @@ public:
ACE_CDR::Boolean write_double (const ACE_CDR::Double &x);
ACE_CDR::Boolean write_longdouble (const ACE_CDR::LongDouble &x);
- /**
- * Writes a ACE_CDR::Long value into a specific location. This is commonly
- * used to update a prior location in the stream which was previously
- * written as a ACE_CDR::Long placeholder. There is no alignment required
- * since the alignment is done before writing the long type placeholder.
- * Treatment of @a x with repect to byte swapping is the same as for when
- * any ACE_CDR::Long value is inserted.
- *
- * @param x The Long value to insert into the specified location.
- * @param loc The location at which to insert @a x. @a loc must be a valid
- * position within the stream's current set of message blocks.
- *
- * @note An example use for this feature is:
- * @code
- ACE_OutputCDR strm;
- ... // insert values...
- strm.align_write_ptr (ACE_CDR::LONG_SIZE);
- char *pos = strm.current ().wr_ptr ();
- strm.write_long (0); // Placeholder value
- ... // insert more values
- ACE_CDR::Long real_val; // Somehow assign the "correct" value
- strm.replace (real_val, pos); // Replace earlier placeholder
- @endcode
- */
- ACE_CDR::Boolean replace (ACE_CDR::Long x, char* loc);
-
/// For string we offer methods that accept a precomputed length.
ACE_CDR::Boolean write_string (const ACE_CDR::Char *x);
ACE_CDR::Boolean write_string (ACE_CDR::ULong len,
@@ -306,6 +280,52 @@ public:
//@}
/**
+ * @{ @name Placeholder/replace operations
+ * Facilitates writing a placeholder into a CDR stream to be replaced
+ * later with a different value.
+ *
+ * @note An example use for this facility is:
+ * @code
+ ACE_OutputCDR strm;
+ ... // insert values...
+ char *pos = strm.write_long_placeholder ();
+ ... // insert more values
+ ACE_CDR::Long real_val; // Somehow assign the "correct" value
+ strm.replace (real_val, pos); // Replace earlier placeholder
+ @endcode
+ */
+
+ /**
+ * Write a placeholder into the stream. The placeholder's pointer
+ * is returned so it may later be passed as the @a loc argument to
+ * replace ().
+ * These methods align the stream's write pointer properly prior to
+ * writing the placeholder.
+ */
+ char* write_long_placeholder (void);
+ char* write_short_placeholder (void);
+
+ /**
+ * Writes a new value into a specific location. This is commonly
+ * used to update a prior "placeholder" location in the stream.
+ * The specified location is assumed to have proper CDR alignment for the
+ * type to insert. This requirement is satisfied by using one of the
+ * placeholder-writing methods to align the stream for the anticipated
+ * value and obtain the correct location.
+ * Treatment of @a x with repect to byte swapping is the same as for when
+ * any value is inserted.
+ *
+ * @param x The value to insert into the specified location.
+ * @param loc The location at which to insert @a x. @a loc must be a valid
+ * position within the stream's current set of message blocks.
+ *
+ * @sa write_long_placeholder(), write_short_placeholder ()
+ */
+ ACE_CDR::Boolean replace (ACE_CDR::Long x, char* loc);
+ ACE_CDR::Boolean replace (ACE_CDR::Short x, char* loc);
+ //@}
+
+ /**
* Return 0 on failure and 1 on success.
*/
//@{ @name Append contents of own CDR stream to another
diff --git a/ACE/tests/CDR_Test.cpp b/ACE/tests/CDR_Test.cpp
index b4f2c206f72..49bfde79de3 100644
--- a/ACE/tests/CDR_Test.cpp
+++ b/ACE/tests/CDR_Test.cpp
@@ -44,9 +44,13 @@ struct CDR_Test_Types
const ACE_CDR::Char *str;
const ACE_CDR::WChar *wstr;
ACE_CDR::Double d;
+ ACE_CDR::Short reps;
+ ACE_CDR::Long repl;
int test_put (ACE_OutputCDR& cdr);
int test_get (ACE_InputCDR& cdr) const;
+ int test_put_placeholder (ACE_OutputCDR& cdr);
+ int test_get_placeholder (ACE_InputCDR& cdr) const;
enum
{
@@ -62,7 +66,9 @@ CDR_Test_Types::CDR_Test_Types (void)
l (4),
str ("abc"),
wstr (0),
- d (8)
+ d (8),
+ reps (-123),
+ repl (-65800L)
{
for (int i = 0;
i < CDR_Test_Types::ARRAY_SIZE;
@@ -440,6 +446,72 @@ CDR_Test_Types::test_get (ACE_InputCDR &cdr) const
}
int
+CDR_Test_Types::test_put_placeholder (ACE_OutputCDR &cdr)
+{
+ // Write a placeholder then a bunch of other stuff, then replace.
+ char *pos = cdr.write_long_placeholder ();
+ if (test_put (cdr) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("test_put (long placeholder) failed\n")),
+ 1);
+ if (!cdr.replace (this->repl, pos))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("replace(long) failed\n")),
+ 1);
+
+ pos = cdr.write_short_placeholder ();
+ if (test_put (cdr) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("test_put (short placeholder) failed\n")),
+ 1);
+ if (!cdr.replace (this->reps, pos))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("replace(short) failed\n")),
+ 1);
+
+ return 0;
+}
+
+int
+CDR_Test_Types::test_get_placeholder (ACE_InputCDR &cdr) const
+{
+ ACE_CDR::Short xs;
+ ACE_CDR::Long xl;
+
+ if (cdr.read_long (xl) == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("read_long failed\n")),
+ 1);
+ if (xl != this->repl)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("replaced long differs\n")),
+ 1);
+
+ // The bunch of stuff written after the placeholder by test_put_placeholder
+ // should still be valid; check that it is.
+ if (test_get (cdr) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("test_get (long) failed\n")),
+ 1);
+
+ if (cdr.read_short (xs) == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("read_short failed\n")), 1);
+ if (xs != this->reps)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("replaced short differs\n")),
+ 1);
+
+ if (test_get (cdr) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("test_get (short) failed\n")),
+ 1);
+
+ return 0;
+}
+
+
+int
run_main (int argc, ACE_TCHAR *argv[])
{
ACE_START_TEST (ACE_TEXT ("CDR_Test"));
@@ -597,7 +669,33 @@ run_main (int argc, ACE_TCHAR *argv[])
return 1;
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Consolidation - no errors\n\n")));
+ ACE_TEXT ("Consolidation - no errors\n\n")
+ ACE_TEXT ("Testing placeholder/replace\n\n")));
+
+ output.reset();
+ if (test_types.test_put_placeholder (output) != 0)
+ return 1;
+
+ input = ACE_InputCDR(output);
+ if (debug > 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Output CDR: \n")));
+ ACE_HEX_DUMP ((LM_DEBUG,
+ input.rd_ptr(),
+ 64));
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Input CDR: \n")));
+ ACE_HEX_DUMP ((LM_DEBUG,
+ input.rd_ptr(),
+ 64));
+ }
+
+ if (test_types.test_get_placeholder (input) != 0)
+ return 1;
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Placeholder/Replace - no errors\n\n")));
ACE_END_TEST;
return 0;