osaf/libs/core/include/ncsencdec_pub.h |  110 +++++++++++--------------
 osaf/libs/core/leap/hj_enc.c           |  144 ++++++++++++++++++++++++++++----
 2 files changed, 171 insertions(+), 83 deletions(-)


Services not using EDU ends repeating functionality that should be common.
This patch proposes a set of functions that makes it easy to removed use of EDU.
Functions for certain data types are missing but would be easy to add as needed.

diff --git a/osaf/libs/core/include/ncsencdec_pub.h 
b/osaf/libs/core/include/ncsencdec_pub.h
--- a/osaf/libs/core/include/ncsencdec_pub.h
+++ b/osaf/libs/core/include/ncsencdec_pub.h
@@ -1,6 +1,6 @@
 /*      -*- OpenSAF  -*-
  *
- * (C) Copyright 2008 The OpenSAF Foundation
+ * (C) Copyright 2008-2014 The OpenSAF Foundation
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -11,7 +11,7 @@
  * See the Copying file included with the OpenSAF distribution for full
  * licensing terms.
  *
- * Author(s): Emerson Network Power
+ * Author(s): Emerson Network Power, Ericsson
  *
  */
 
@@ -92,6 +92,8 @@
 
 #include "ncsgl_defs.h"
 #include "ncs_osprm.h"
+#include <saAis.h>
+#include <ncs_ubaid.h>
 #include "ncsusrbuf.h"
 #include "ncs_svd.h"
 
@@ -102,84 +104,68 @@ extern "C" {
 /*
  * NCS_ENC encode functions
  */
-       USRBUF *ncs_encode_n_octets(USRBUF *, uint8_t *, unsigned int);
-       USRBUF *ncs_encode_uns8(USRBUF *u, uint8_t val8);
-       USRBUF *ncs_encode_uns16(USRBUF *u, uint16_t val16);
-       USRBUF *ncs_encode_uns32(USRBUF *u, uint32_t val32);
-       USRBUF *ncs_encode_uns64(USRBUF *u, uint64_t val64);
-       USRBUF *ncs_prepend_n_octets(USRBUF *pbuf, uint8_t *os, unsigned int);
-       USRBUF *ncs_prepend_uns16(USRBUF *u, uint16_t);
-       USRBUF *ncs_prepend_uns32(USRBUF *u, uint32_t);
-       USRBUF *ncs_prepend_uns64(USRBUF *u, uint64_t);
-       USRBUF *ncs_encode_float(USRBUF *u, float obj_val);
+USRBUF *ncs_encode_n_octets(USRBUF *, uint8_t *, unsigned int);
+USRBUF *ncs_encode_uns8(USRBUF *u, uint8_t val8);
+USRBUF *ncs_encode_uns16(USRBUF *u, uint16_t val16);
+USRBUF *ncs_encode_uns32(USRBUF *u, uint32_t val32);
+USRBUF *ncs_encode_uns64(USRBUF *u, uint64_t val64);
+USRBUF *ncs_prepend_n_octets(USRBUF *pbuf, uint8_t *os, unsigned int);
+USRBUF *ncs_prepend_uns16(USRBUF *u, uint16_t);
+USRBUF *ncs_prepend_uns32(USRBUF *u, uint32_t);
+USRBUF *ncs_prepend_uns64(USRBUF *u, uint64_t);
+USRBUF *ncs_encode_float(USRBUF *u, float obj_val);
 
-       uint64_t ncs_encode_64bit(uint8_t **stream, uint64_t);
-       uint32_t ncs_encode_32bit(uint8_t **stream, uint32_t);
-       uint32_t ncs_encode_24bit(uint8_t **stream, uint32_t);
-       uint32_t ncs_encode_16bit(uint8_t **stream, uint32_t);
-       uint32_t ncs_encode_8bit(uint8_t **stream, uint32_t);
-       uint32_t ncs_encode_key(uint8_t **stream, NCS_KEY *key);
-
-       uint32_t ncs_encode_octets(uint8_t **stream, uint8_t *val, uint32_t 
count);
+uint64_t ncs_encode_64bit(uint8_t **stream, uint64_t);
+uint32_t ncs_encode_32bit(uint8_t **stream, uint32_t);
+uint32_t ncs_encode_24bit(uint8_t **stream, uint32_t);
+uint32_t ncs_encode_16bit(uint8_t **stream, uint32_t);
+uint32_t ncs_encode_8bit(uint8_t **stream, uint32_t);
+uint32_t ncs_encode_key(uint8_t **stream, NCS_KEY *key);
+uint32_t ncs_encode_octets(uint8_t **stream, uint8_t *val, uint32_t count);
 
 /*
  * NCS_DEC decode functions
  */
-       USRBUF *ncs_decode_n_octets(USRBUF *, uint8_t *, uint32_t);
+USRBUF *ncs_decode_n_octets(USRBUF *, uint8_t *, uint32_t);
 
-       USRBUF *ncs_skip_n_octets(USRBUF *, uint32_t);
-       uint8_t *ncs_flatten_n_octets(USRBUF *u, uint8_t *os, uint32_t count);
+USRBUF *ncs_skip_n_octets(USRBUF *, uint32_t);
+uint8_t *ncs_flatten_n_octets(USRBUF *u, uint8_t *os, uint32_t count);
 
-       uint32_t ncs_decode_short(uint8_t **stream);
-       uint32_t ncs_decode_24bit(uint8_t **stream);
-       uint32_t ncs_decode_32bit(uint8_t **stream);
-       uint16_t ncs_decode_16bit(uint8_t **stream);
-       uint64_t ncs_decode_64bit(uint8_t **stream);
-       uint8_t ncs_decode_8bit(uint8_t **stream);
-       uint32_t ncs_decode_key(uint8_t **stream, NCS_KEY *key);
+uint32_t ncs_decode_short(uint8_t **stream);
+uint32_t ncs_decode_24bit(uint8_t **stream);
+uint32_t ncs_decode_32bit(uint8_t **stream);
+uint16_t ncs_decode_16bit(uint8_t **stream);
+uint64_t ncs_decode_64bit(uint8_t **stream);
+uint8_t ncs_decode_8bit(uint8_t **stream);
+uint32_t ncs_decode_key(uint8_t **stream, NCS_KEY *key);
+float ncs_decode_float(uint8_t **stream);
 
-       float ncs_decode_float(uint8_t **stream);
-
-/*****************************************************************************
- * STRUCTURE NAME:     USRFRAME
- *
- * DESCRIPTION:        This structure is an alternative to the userbuf
- *                     for passing data across the sysf_ip interface.
- * NOTES:
- * Header goes from *bufp to *(bufp+header_len-1)
- * data goes from *(bufp+header_len) to *(bufp+len-1)
- *
- * This used to be located in ncs_ip.h.  The USRFRAME is used outside of
- * sysf_ip and hence, must be located outside of ncs_ip.h
- *
- ****************************************************************************/
-       typedef struct {
-               unsigned int header_len;        /* header length */
-               unsigned int len;       /* length of entire frame including 
header */
-               char *bufp;     /* ptr to a (flat) buffer containing the frame 
*/
-       } USRFRAME;
+/***** new style (2014) encoding/decoding functions follows ******/
+void osaf_encode_uint8(NCS_UBAID *ub, uint8_t value);
+void osaf_decode_uint8(NCS_UBAID *ub, uint8_t *to);
+void osaf_encode_uint16(NCS_UBAID *ub, uint16_t value);
+void osaf_decode_uint16(NCS_UBAID *ub, uint16_t *to);
+void osaf_encode_uint32(NCS_UBAID *ub, uint32_t value);
+void osaf_decode_uint32(NCS_UBAID *ub, uint32_t *to);
+void osaf_decode_int(NCS_UBAID *ub, int *to);
+void osaf_encode_uint64(NCS_UBAID *ub, uint64_t value);
+void osaf_decode_uint64(NCS_UBAID *ub, uint64_t *to);
+void osaf_encode_sanamet(NCS_UBAID *ub, const SaNameT *name);
+void osaf_decode_sanamet(NCS_UBAID *ub, SaNameT *name);
+void osaf_encode_satimet(NCS_UBAID *ub, SaTimeT time);
+void osaf_decode_satimet(NCS_UBAID *ub, SaTimeT *time);
+void osaf_encode_bool(NCS_UBAID *ub, bool value);
+void osaf_decode_bool(NCS_UBAID *ub, bool *to);
 
 /* encode float */
-#if defined(__NCSINC_PSOS__)
 #define m_NCS_ENCODE_FLOAT(f, enc) {\
           *((uint32_t *)(enc)) = htonl(*((uint32_t *)&(f))); \
          }
-#else
-#define m_NCS_ENCODE_FLOAT(f, enc) {\
-          *((uint32_t *)(enc)) = htonl(*((uint32_t *)&(f))); \
-         }
-#endif
 
 /* decode float */
-#if defined(__NCSINC_PSOS__)
 #define m_NCS_DECODE_FLOAT(n, dec) {\
           *((uint32_t *) (dec)) = (n); \
          }
-#else
-#define m_NCS_DECODE_FLOAT(n, dec) {\
-          *((uint32_t *) (dec)) = (n); \
-         }
-#endif
 
 #ifdef  __cplusplus
 }
diff --git a/osaf/libs/core/leap/hj_enc.c b/osaf/libs/core/leap/hj_enc.c
--- a/osaf/libs/core/leap/hj_enc.c
+++ b/osaf/libs/core/leap/hj_enc.c
@@ -1,6 +1,6 @@
 /*      -*- OpenSAF  -*-
  *
- * (C) Copyright 2008 The OpenSAF Foundation
+ * (C) Copyright 2008-2014 The OpenSAF Foundation
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -11,7 +11,7 @@
  * See the Copying file included with the OpenSAF distribution for full
  * licensing terms.
  *
- * Author(s): Emerson Network Power
+ * Author(s): Emerson Network Power, Ericsson
  *
  */
 
@@ -39,25 +39,6 @@
 
 ..............................................................................
 
-  FUNCTIONS INCLUDED in this module:
-
-The following set does buffer chaining management
-  ncs_encode_n_octets....Encode "n" octets in the control frame
-  ncs_encode_uint16_t   ....Encode short
-  ncs_encode_uint32_t   ....Encode long
-  ncs_encode_uint64_t   ....Encode long long
-  ncs_prepend_n_octets...Encode "n" octets encapsulating given frame
-  ncs_prepend_uint16_t   ...Encode 16 bit unsigned encapsulating given frame
-  ncs_prepend_uint32_t   ...Encode 32 bit unsigned encapsulating given frame
-  ncs_prepend_uint64_t   ...Encode 64 bit unsigned encapsulating given frame
-
-The following set does NOT do buffer chaining management
-  ncs_encode_64bit   ....Encode 64 bits of a 64 bit value
-  ncs_encode_32bit   ....Encode 32 bits of a 32 bit value
-  ncs_encode_24bit   ....Encode 24 least significant octets of a 32 bit value
-  ncs_encode_16bit   ....Encode 16 least significant octets of a 32 bit value
-  ncs_encode_8bit    ....Encode  8 least significant octets of a 32 bit value
-  ncs_encode_octets  ....Encode "n" octets encapsulating given frame
 
 *******************************************************************************
 */
@@ -310,3 +291,124 @@ uint32_t ncs_encode_octets(uint8_t **str
                *(*stream)++ = *val++;
        return count;
 }
+
+/***** new style (2014) encoding/decoding functions follows ******/
+
+static uint8_t *encode_reserve_space(NCS_UBAID *ub, int32_t count)
+{
+    uint8_t *p8 = ncs_enc_reserve_space(ub, count);
+    osafassert(p8);
+    return p8;
+}
+
+static uint8_t *decode_flatten_space(NCS_UBAID *uba, uint8_t *os, int32_t 
count)
+{
+       uint8_t *p8 = ncs_dec_flatten_space(uba, os, count);
+       osafassert(p8);
+       return p8;
+}
+
+void osaf_encode_uint8(NCS_UBAID *ub, uint8_t value)
+{
+       uint8_t *p8 = encode_reserve_space(ub, 1);
+       ncs_encode_8bit(&p8, value);
+       ncs_enc_claim_space(ub, 1);
+}
+
+void osaf_decode_uint8(NCS_UBAID *ub, uint8_t *to)
+{
+       uint8_t buf[1];
+
+       uint8_t *p8 = decode_flatten_space(ub, buf, 1);
+       *to = ncs_decode_8bit(&p8);
+       ncs_dec_skip_space(ub, 1);
+}
+
+void osaf_encode_uint16(NCS_UBAID *ub, uint16_t value)
+{
+       uint8_t *p8 = encode_reserve_space(ub, 2);
+       ncs_encode_16bit(&p8, value);
+       ncs_enc_claim_space(ub, 2);
+}
+
+void osaf_decode_uint16(NCS_UBAID *ub, uint16_t *to)
+{
+       uint8_t buf[2];
+
+       uint8_t *p8 = decode_flatten_space(ub, buf, 2);
+       *to = ncs_decode_16bit(&p8);
+       ncs_dec_skip_space(ub, 2);
+}
+
+void osaf_encode_uint32(NCS_UBAID *ub, uint32_t value)
+{
+       uint8_t *p8 = encode_reserve_space(ub, 4);
+       ncs_encode_32bit(&p8, value);
+       ncs_enc_claim_space(ub, 4);
+}
+
+void osaf_decode_uint32(NCS_UBAID *ub, uint32_t *to)
+{
+       uint8_t buf[4];
+
+       uint8_t *p8 = decode_flatten_space(ub, buf, 4);
+       *to = ncs_decode_32bit(&p8);
+       ncs_dec_skip_space(ub, 4);
+}
+
+void osaf_encode_uint64(NCS_UBAID *ub, uint64_t value)
+{
+       uint8_t *p8 = encode_reserve_space(ub, 8);
+       ncs_encode_64bit(&p8, value);
+       ncs_enc_claim_space(ub, 8);
+}
+
+void osaf_decode_uint64(NCS_UBAID *ub, uint64_t *to)
+{
+       uint8_t buf[8];
+
+       uint8_t *p8 = decode_flatten_space(ub, buf, 8);
+       *to = ncs_decode_64bit(&p8);
+       ncs_dec_skip_space(ub, 8);
+}
+
+void osaf_encode_sanamet(NCS_UBAID *ub, const SaNameT *name)
+{
+       int i;
+       osaf_encode_uint16(ub, name->length);
+       for (i = 0; i < SA_MAX_NAME_LENGTH; i++)
+               osaf_encode_uint8(ub, name->value[i]);
+}
+
+void osaf_decode_sanamet(NCS_UBAID *ub, SaNameT *name)
+{
+       int i;
+       osaf_decode_uint16(ub, &name->length);
+       for (i = 0; i < SA_MAX_NAME_LENGTH; i++)
+               osaf_decode_uint8(ub, &name->value[i]);
+}
+
+void osaf_encode_satimet(NCS_UBAID *ub, SaTimeT time)
+{
+       osaf_encode_uint64(ub, time);
+}
+
+void osaf_decode_satimet(NCS_UBAID *ub, SaTimeT *time)
+{
+       osaf_decode_uint64(ub, (uint64_t*)time);
+}
+
+void osaf_encode_bool(NCS_UBAID *ub, bool value)
+{
+       // for backwards compatibility reasons a bool is encoded as 4 bytes
+       uint32_t tmp = value;
+       osaf_encode_uint32(ub, tmp);
+}
+
+void osaf_decode_bool(NCS_UBAID *ub, bool *to)
+{
+       uint32_t value;
+       osaf_decode_uint32(ub, &value);
+       *to = (bool)value;
+}
+

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to