Parcourir la source

coded some more basictypes...

Leon Urbas il y a 11 ans
Parent
commit
3b19bddd09
4 fichiers modifiés avec 205 ajouts et 163 suppressions
  1. 3 2
      Makefile.am
  2. 1 1
      configure.ac
  3. 2 14
      tool/main.c
  4. 199 146
      tool/opcua_basictypes.c

+ 3 - 2
Makefile.am

@@ -6,9 +6,10 @@ AM_CFLAGS = -O2
 endif
 
 if HAVE_CHECK
-    SUBS=src . tests .
+    SUBS=src tool . tests .
+
 else 
-    SUBS=src .
+    SUBS=src tool .
 endif
 
 SUBDIRS = $(SUBS) examples/src	

+ 1 - 1
configure.ac

@@ -46,6 +46,6 @@ AM_COND_IF([DEBUG],
 AC_LIBTOOL_WIN32_DLL
 AC_PROG_LIBTOOL
 AC_CONFIG_MACRO_DIR([m4])
-AC_CONFIG_FILES(Makefile src/Makefile tests/Makefile examples/src/Makefile)
+AC_CONFIG_FILES(Makefile src/Makefile tool/Makefile tests/Makefile examples/src/Makefile)
 AC_OUTPUT
 

+ 2 - 14
tool/main.c

@@ -8,25 +8,13 @@
 
 #include "opcua.h"
 
-#define UA_NO_ERROR ((Int32) 0)
-
-Int32 decodeInt32(char const * buf, Int32* pos, Int32* dst) {
-	Int32 t1 = (Int32) (((SByte) (buf[*pos]) & 0xFF));
-	Int32 t2 = (Int32) (((SByte) (buf[*pos + 1]) & 0xFF) << 8);
-	Int32 t3 = (Int32) (((SByte) (buf[*pos + 2]) & 0xFF) << 16);
-	Int32 t4 = (Int32) (((SByte) (buf[*pos + 3]) & 0xFF) << 24);
-	*pos += sizeof(Int32);
-	*dst = t1 + t2 + t3 + t4;
-	return UA_NO_ERROR;
-}
-
 typedef union Integer {
 	Int32 i;
 	SByte b[4];
 } Integer;
 
 int main() {
-	Integer a = { UA_IdType_Guid };
+	Integer a = { 0x11 };
 	Integer b;
 	int pos = 0;
 
@@ -35,7 +23,7 @@ int main() {
 
 	printf("%d, {%d,%d,%d,%d}\n", a.i, a.b[0], a.b[1], a.b[2], a.b[3]);
 
-	decodeInt32((char *) &a.b[0], &pos, &(b.i));
+	UA_Int32_decode((char *) &a.b[0], &pos, &(b.i));
 	printf("%d, {%d,%d,%d,%d}\n", b.i, b.b[0], b.b[1], b.b[2], b.b[3]);
 
 	return 0;

+ 199 - 146
tool/opcua_basictypes.c

@@ -7,42 +7,181 @@
 #include "opcua.h"
 #include <memory.h>
 
+Int32 UA_calcSize(void* const data, UInt32 type) {
+	return (UA_namespace_zero[type].calcSize)(data);
+}
+
+Int32 UA_Array_calcSize(Int32 nElements, Int32 type, void const ** data) {
+	int length = sizeof(UA_Int32);
+	int i;
+
+	if (nElements > 0) {
+		for(i=0; i<nElements;i++,data++) {
+			length += UA_calcSize(data,type);
+		}
+	}
+	return length;
+}
+
 Int32 UA_Boolean_calcSize(UA_Boolean const * ptr) { return sizeof(UA_Boolean); }
 Int32 UA_Boolean_encode(UA_Boolean const * src, Int32* pos, char * dst) {
 	UA_Boolean tmpBool = ((*src > 0) ? UA_TRUE : UA_FALSE);
-	memcpy(&(dst[*pos]), &tmpBool, sizeof(UA_Boolean));
-	*pos += sizeof(UA_Boolean);
+	memcpy(&(dst[(*pos)++]), &tmpBool, sizeof(UA_Boolean));
 	return UA_SUCCESS;
 }
 Int32 UA_Boolean_decode(char const * src, Int32* pos, UA_Boolean * dst) {
-	*dst = ((UA_Boolean) (src[*pos]) > 0) ? UA_TRUE : UA_FALSE;
-	*pos += sizeof(UA_Boolean);
+	*dst = ((UA_Boolean) (src[(*pos)++]) > 0) ? UA_TRUE : UA_FALSE;
 	return UA_SUCCESS;
 }
+Int32 UA_Boolean_delete(UA_Boolean* p) { return UA_memfree(p); };
+Int32 UA_Boolean_deleteMembers(UA_Boolean* p) { return UA_SUCCESS; };
 
 Int32 UA_Byte_calcSize(UA_Byte const * ptr) { return sizeof(UA_Byte); }
 Int32 UA_Byte_encode(UA_Byte const * src, Int32* pos, char * dst) {
-	*dst = src[*pos];
-	*pos += sizeof(UA_Byte);
-	return 1;
+	*dst = src[(*pos)++];
+	return UA_SUCCESS;
 }
 Int32 UA_Byte_decode(char const * src, Int32* pos, UA_Byte * dst) {
-	memcpy(&(dst[*pos]), src, sizeof(UA_Byte));
-	*pos += sizeof(UA_Byte);
-	return 1;
+	memcpy(&(dst[(*pos)++]), src, sizeof(UA_Byte));
+	return UA_SUCCESS;
 }
+Int32 UA_Byte_delete(UA_Byte* p) { return UA_memfree(p); };
+Int32 UA_Byte_deleteMembers(UA_Byte* p) { return UA_SUCCESS; };
 
 Int32 UA_SByte_calcSize(UA_SByte const * ptr) { return sizeof(UA_SByte); }
 Int32 UA_SByte_encode(UA_SByte const * src, Int32* pos, char * dst) {
-	dst[*pos] = *src;
-	*pos += sizeof(UA_SByte);
-	return 1;
+	dst[(*pos)++] = *src;
+	return UA_SUCCESS;
 }
 Int32 UA_SByte_decode(char const * src, Int32* pos, UA_SByte * dst) {
-	*dst = src[*pos];
-	*pos += sizeof(UA_SByte);
+	*dst = src[(*pos)++];
 	return 1;
 }
+Int32 UA_SByte_delete(UA_SByte* p) { return UA_memfree(p); };
+Int32 UA_SByte_deleteMembers(UA_SByte* p) { return UA_SUCCESS; };
+
+Int32 UA_UInt16_calcSize(UA_UInt16* p) { return sizeof(UA_UInt16); }
+Int32 UA_UInt16_encode(UA_UInt16 const *src, Int32* pos, char * dst) {
+	memcpy(&(dst[*pos]), src, sizeof(UA_UInt16));
+	*pos += sizeof(UA_UInt16);
+	return UA_SUCCESS;
+}
+Int32 UA_UInt16_decode(char const * src, Int32* pos, UA_UInt16* dst) {
+	Byte t1 = src[(*pos)++];
+	UInt16 t2 = (UInt16) (src[(*pos)++] << 8);
+	*dst = t1 + t2;
+	return UA_SUCCESS;
+}
+Int32 UA_UInt16_delete(UA_UInt16* p) { return UA_memfree(p); };
+Int32 UA_UInt16_deleteMembers(UA_UInt16* p) { return UA_SUCCESS; };
+
+Int32 UA_Int16_calcSize(UA_Int16* p) { return sizeof(UA_Int16); }
+Int32 UA_Int16_encode(UA_Int16 const* src, Int32* pos, char* dst) {
+	memcpy(&(dst[*pos]), src, sizeof(UA_Int16));
+	*pos += sizeof(UA_Int16);
+	return UA_SUCCESS;
+}
+Int32 UA_Int16_decode(char const * src, Int32* pos, UA_Int16 *dst) {
+	Int16 t1 = (Int16) (((SByte) (src[(*pos)++]) & 0xFF));
+	Int16 t2 = (Int16) (((SByte) (src[(*pos)++]) & 0xFF) << 8);
+	*dst = t1 + t2;
+	return UA_SUCCESS;
+}
+Int32 UA_Int16_delete(UA_Int16* p) { return UA_memfree(p); };
+Int32 UA_Int16_deleteMembers(UA_Int16* p) { return UA_SUCCESS; };
+
+Int32 decodeInt32(char const * buf, Int32 *pos, Int32 *dst) {
+	Int32 t1 = (Int32) (((SByte) (buf[*pos]) & 0xFF));
+	Int32 t2 = (Int32) (((SByte) (buf[*pos + 1]) & 0xFF) << 8);
+	Int32 t3 = (Int32) (((SByte) (buf[*pos + 2]) & 0xFF) << 16);
+	Int32 t4 = (Int32) (((SByte) (buf[*pos + 3]) & 0xFF) << 24);
+	*pos += sizeof(Int32);
+	*dst = t1 + t2 + t3 + t4;
+	return UA_SUCCESS;
+}
+void encodeInt32(Int32 value, Int32 *pos, char *dstBuf) {
+	memcpy(&(dstBuf[*pos]), &value, sizeof(Int32));
+	*pos = (*pos) + sizeof(Int32);
+}
+
+Int32 decodeUInt32(char const * buf, Int32 *pos, UInt32 *dst) {
+	Byte t1 = buf[*pos];
+	UInt32 t2 = (UInt32) buf[*pos + 1] << 8;
+	UInt32 t3 = (UInt32) buf[*pos + 2] << 16;
+	UInt32 t4 = (UInt32) buf[*pos + 3] << 24;
+	*pos += sizeof(UInt32);
+	*dst = t1 + t2 + t3 + t4;
+	return UA_NO_ERROR;
+}
+
+void encodeUInt32(UInt32 value, Int32 *pos, char *dstBuf) {
+	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt32));
+	*pos += 4;
+}
+
+Int32 decodeInt64(char const * buf, Int32 *pos, Int64 *dst) {
+
+	SByte t1 = buf[*pos];
+	Int64 t2 = (Int64) buf[*pos + 1] << 8;
+	Int64 t3 = (Int64) buf[*pos + 2] << 16;
+	Int64 t4 = (Int64) buf[*pos + 3] << 24;
+	Int64 t5 = (Int64) buf[*pos + 4] << 32;
+	Int64 t6 = (Int64) buf[*pos + 5] << 40;
+	Int64 t7 = (Int64) buf[*pos + 6] << 48;
+	Int64 t8 = (Int64) buf[*pos + 7] << 56;
+	*pos += 8;
+	*dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
+	return UA_NO_ERROR;
+}
+void encodeInt64(Int64 value, Int32 *pos, char *dstBuf) {
+	memcpy(&(dstBuf[*pos]), &value, sizeof(Int64));
+	*pos = (*pos) + sizeof(Int64);
+}
+
+Int32 decodeUInt64(char const * buf, Int32 *pos, UInt64 *dst) {
+
+	Byte t1 = buf[*pos];
+	UInt64 t2 = (UInt64) buf[*pos + 1] << 8;
+	UInt64 t3 = (UInt64) buf[*pos + 2] << 16;
+	UInt64 t4 = (UInt64) buf[*pos + 3] << 24;
+	UInt64 t5 = (UInt64) buf[*pos + 4] << 32;
+	UInt64 t6 = (UInt64) buf[*pos + 5] << 40;
+	UInt64 t7 = (UInt64) buf[*pos + 6] << 48;
+	UInt64 t8 = (UInt64) buf[*pos + 7] << 56;
+	*pos += 8;
+	*dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
+	return UA_NO_ERROR;
+}
+void encodeUInt64(UInt64 value, Int32 *pos, char *dstBuf) {
+	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt64));
+	*pos = (*pos) + sizeof(UInt64);
+}
+
+Int32 decodeFloat(char const * buf, Int32 *pos, Float *dst) {
+	Float tmpFloat;
+	memcpy(&tmpFloat, &(buf[*pos]), sizeof(Float));
+	*pos += sizeof(Float);
+	*dst = tmpFloat;
+	return UA_NO_ERROR;
+}
+Int32 encodeFloat(Float value, Int32 *pos, char *dstBuf) {
+	memcpy(&(dstBuf[*pos]), &value, sizeof(Float));
+	*pos += sizeof(Float);
+	return UA_NO_ERROR;
+}
+
+Int32 decodeDouble(char const * buf, Int32 *pos, Double *dst) {
+	Double tmpDouble;
+	tmpDouble = (Double) (buf[*pos]);
+	*pos += sizeof(Double);
+	*dst = tmpDouble;
+	return UA_NO_ERROR;
+}
+Int32 encodeDouble(Double value, Int32 *pos, char *dstBuf) {
+	memcpy(&(dstBuf[*pos]), &value, sizeof(Double));
+	*pos *= sizeof(Double);
+	return UA_NO_ERROR;
+}
 
 Int32 UA_String_calcSize(UA_String const * string) {
 	if (string->length > 0) {
@@ -51,9 +190,19 @@ Int32 UA_String_calcSize(UA_String const * string) {
 		return sizeof(UA_Int32);
 	}
 }
+// TODO: UA_String_encode
+// TODO: UA_String_decode
+Int32 UA_String_delete(UA_String* p) { return UA_memfree(p); };
+Int32 UA_String_deleteMembers(UA_String* p) { return UA_Byte_delete(p->data); };
+
+// TODO: can we really handle UA_String and UA_ByteString the same way?
 Int32 UA_ByteString_calcSize(UA_ByteString const * string) {
 	return UA_String_calcSize((UA_String*) string);
 }
+// TODO: UA_ByteString_encode
+// TODO: UA_ByteString_decode
+Int32 UA_ByteString_delete(UA_ByteString* p) { return UA_String_delete((UA_String*) p); };
+Int32 UA_ByteString_deleteMembers(UA_ByteString* p) { return UA_String_deleteMembers((UA_String*) p); };
 
 Int32 UA_Guid_calcSize(UA_Guid const * guid) {
 	return 	sizeof(guid->Data1)
@@ -61,6 +210,11 @@ Int32 UA_Guid_calcSize(UA_Guid const * guid) {
 			+ sizeof(guid->Data3)
 			+ UA_ByteString_calcSize(&(guid->Data4));
 }
+// TODO: UA_Guid_encode
+// TODO: UA_Guid_decode
+Int32 UA_Guid_delete(UA_Guid* p) { return UA_memfree(p); };
+Int32 UA_Guid_deleteMembers(UA_Guid* p) { return UA_ByteString_delete(p->Data4); };
+
 Int32 UA_LocalizedText_calcSize(UA_LocalizedText const * localizedText) {
 	Int32 length = 0;
 
@@ -74,22 +228,17 @@ Int32 UA_LocalizedText_calcSize(UA_LocalizedText const * localizedText) {
 
 	return length;
 }
+// TODO: UA_LocalizedText_encode
+// TODO: UA_LocalizedText_decode
+Int32 UA_LocalizedText_delete(UA_LocalizedText* p) { return UA_memfree(p); };
+Int32 UA_LocalizedText_deleteMembers(UA_LocalizedText* p) {
+	return UA_SUCCESS
+// TODO: both locale and text are yet neither pointers nor allocated
+//		|| UA_ByteString_delete(p->locale)
+//		|| UA_ByteString_delete(p->text)
+	;
+};
 
-Int32 UA_calcSize(void* const data, UInt32 type) {
-	return (UA_namespace_zero[type].calcSize)(data);
-}
-
-Int32 UA_Array_calcSize(Int32 nElements, Int32 type, void const ** data) {
-	int length = sizeof(UA_Int32);
-	int i;
-
-	if (nElements > 0) {
-		for(i=0; i<nElements;i++,data++) {
-			length += UA_calcSize(data,type);
-		}
-	}
-	return length;
-}
 
 Int32 UA_NodeId_calcSize(UA_NodeId const *nodeId) {
 	Int32 length = 0;
@@ -117,6 +266,10 @@ Int32 UA_NodeId_calcSize(UA_NodeId const *nodeId) {
 	}
 	return length;
 }
+// TODO: UA_NodeID_encode
+// TODO: UA_NodeID_decode
+// TODO: UA_NodeID_delete
+// TODO: UA_NodeID_deleteMembers
 
 Int32 UA_ExpandedNodeId_calcSize(UA_ExpandedNodeId *nodeId) {
 	Int32 length = sizeof(UA_Byte);
@@ -132,6 +285,10 @@ Int32 UA_ExpandedNodeId_calcSize(UA_ExpandedNodeId *nodeId) {
 	}
 	return length;
 }
+// TODO: UA_ExpandedNodeID_encode
+// TODO: UA_ExpandedNodeID_decode
+// TODO: UA_ExpandedNodeID_delete
+// TODO: UA_ExpandedNodeID_deleteMembers
 
 Int32 UA_ExtensionObject_calcSize(UA_ExtensionObject *extensionObject) {
 	Int32 length = 0;
@@ -151,6 +308,10 @@ Int32 UA_ExtensionObject_calcSize(UA_ExtensionObject *extensionObject) {
 	}
 	return length;
 }
+// TODO: UA_ExtensionObject_encode
+// TODO: UA_ExtensionObject_decode
+// TODO: UA_ExtensionObject_delete
+// TODO: UA_ExtensionObject_deleteMembers
 
 Int32 UA_DataValue_calcSize(UA_DataValue *dataValue) {
 	Int32 length = 0;
@@ -177,6 +338,10 @@ Int32 UA_DataValue_calcSize(UA_DataValue *dataValue) {
 	}
 	return length;
 }
+// TODO: UA_DataValue_encode
+// TODO: UA_DataValue_decode
+// TODO: UA_DataValue_delete
+// TODO: UA_DataValue_deleteMembers
 
 
 Int32 UA_DiagnosticInfo_calcSize(UA_DiagnosticInfo *diagnosticInfo) {
@@ -215,125 +380,13 @@ Int32 UA_DiagnosticInfo_calcSize(UA_DiagnosticInfo *diagnosticInfo) {
 	}
 	return length;
 }
+// TODO: UA_DiagnosticInfo_encode
+// TODO: UA_DiagnosticInfo_decode
+// TODO: UA_DiagnosticInfo_delete
+// TODO: UA_DiagnosticInfo_deleteMembers
 
 
 
-Int32 decodeUInt16(char const * buf, Int32 *pos, UInt16 *dst) {
-	Byte t1 = buf[*pos];
-	UInt16 t2 = (UInt16) (buf[*pos + 1] << 8);
-	*pos += 2;
-	*dst = t1 + t2;
-	return UA_NO_ERROR;
-}
-void encodeUInt16(UInt16 value, Int32 *pos, char* dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt16));
-	*pos = (*pos) + sizeof(UInt16);
-}
-
-Int32 decodeInt16(char const * buf, Int32 *pos, Int16 *dst) {
-	Int16 t1 = (Int16) (((SByte) (buf[*pos]) & 0xFF));
-	Int16 t2 = (Int16) (((SByte) (buf[*pos + 1]) & 0xFF) << 8);
-	*pos += 2;
-	*dst = t1 + t2;
-	return UA_NO_ERROR;
-}
-void encodeInt16(Int16 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(Int16));
-	*pos = (*pos) + sizeof(Int16);
-}
-
-Int32 decodeInt32(char const * buf, Int32 *pos, Int32 *dst) {
-	Int32 t1 = (Int32) (((SByte) (buf[*pos]) & 0xFF));
-	Int32 t2 = (Int32) (((SByte) (buf[*pos + 1]) & 0xFF) << 8);
-	Int32 t3 = (Int32) (((SByte) (buf[*pos + 2]) & 0xFF) << 16);
-	Int32 t4 = (Int32) (((SByte) (buf[*pos + 3]) & 0xFF) << 24);
-	*pos += sizeof(Int32);
-	*dst = t1 + t2 + t3 + t4;
-	return UA_NO_ERROR;
-}
-void encodeInt32(Int32 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(Int32));
-	*pos = (*pos) + sizeof(Int32);
-}
-
-Int32 decodeUInt32(char const * buf, Int32 *pos, UInt32 *dst) {
-	Byte t1 = buf[*pos];
-	UInt32 t2 = (UInt32) buf[*pos + 1] << 8;
-	UInt32 t3 = (UInt32) buf[*pos + 2] << 16;
-	UInt32 t4 = (UInt32) buf[*pos + 3] << 24;
-	*pos += sizeof(UInt32);
-	*dst = t1 + t2 + t3 + t4;
-	return UA_NO_ERROR;
-}
-
-void encodeUInt32(UInt32 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt32));
-	*pos += 4;
-}
-
-Int32 decodeInt64(char const * buf, Int32 *pos, Int64 *dst) {
-
-	SByte t1 = buf[*pos];
-	Int64 t2 = (Int64) buf[*pos + 1] << 8;
-	Int64 t3 = (Int64) buf[*pos + 2] << 16;
-	Int64 t4 = (Int64) buf[*pos + 3] << 24;
-	Int64 t5 = (Int64) buf[*pos + 4] << 32;
-	Int64 t6 = (Int64) buf[*pos + 5] << 40;
-	Int64 t7 = (Int64) buf[*pos + 6] << 48;
-	Int64 t8 = (Int64) buf[*pos + 7] << 56;
-	*pos += 8;
-	*dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
-	return UA_NO_ERROR;
-}
-void encodeInt64(Int64 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(Int64));
-	*pos = (*pos) + sizeof(Int64);
-}
-
-Int32 decodeUInt64(char const * buf, Int32 *pos, UInt64 *dst) {
-
-	Byte t1 = buf[*pos];
-	UInt64 t2 = (UInt64) buf[*pos + 1] << 8;
-	UInt64 t3 = (UInt64) buf[*pos + 2] << 16;
-	UInt64 t4 = (UInt64) buf[*pos + 3] << 24;
-	UInt64 t5 = (UInt64) buf[*pos + 4] << 32;
-	UInt64 t6 = (UInt64) buf[*pos + 5] << 40;
-	UInt64 t7 = (UInt64) buf[*pos + 6] << 48;
-	UInt64 t8 = (UInt64) buf[*pos + 7] << 56;
-	*pos += 8;
-	*dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
-	return UA_NO_ERROR;
-}
-void encodeUInt64(UInt64 value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt64));
-	*pos = (*pos) + sizeof(UInt64);
-}
-
-Int32 decodeFloat(char const * buf, Int32 *pos, Float *dst) {
-	Float tmpFloat;
-	memcpy(&tmpFloat, &(buf[*pos]), sizeof(Float));
-	*pos += sizeof(Float);
-	*dst = tmpFloat;
-	return UA_NO_ERROR;
-}
-Int32 encodeFloat(Float value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(Float));
-	*pos += sizeof(Float);
-	return UA_NO_ERROR;
-}
-
-Int32 decodeDouble(char const * buf, Int32 *pos, Double *dst) {
-	Double tmpDouble;
-	tmpDouble = (Double) (buf[*pos]);
-	*pos += sizeof(Double);
-	*dst = tmpDouble;
-	return UA_NO_ERROR;
-}
-Int32 encodeDouble(Double value, Int32 *pos, char *dstBuf) {
-	memcpy(&(dstBuf[*pos]), &value, sizeof(Double));
-	*pos *= sizeof(Double);
-	return UA_NO_ERROR;
-}
 
 Int32 decodeUAString(char const * buf, Int32 *pos, UA_String * dstUAString) {