Преглед на файлове

keep the namespace simple for merging xml2ns0

Julius Pfrommer преди 10 години
родител
ревизия
e15423defd
променени са 5 файла, в които са добавени 23 реда и са изтрити 139 реда
  1. 0 1
      src/Makefile.am
  2. 4 14
      src/ua_namespace.c
  3. 18 36
      src/ua_namespace.h
  4. 0 86
      src/ua_namespace_transactions.c
  5. 1 2
      tools/indent.sh

+ 0 - 1
src/Makefile.am

@@ -11,7 +11,6 @@ libopen62541_la_SOURCES = opcua.c \
 						  ua_transport_binary.c \
 						  ua_transport_binary_secure.c \
 						  ua_namespace.c \
-						  ua_namespace_transactions.c \
 						  ua_services_attribute.c \
 						  ua_services_session.c \
 						  ua_services_discovery.c \

+ 4 - 14
src/ua_namespace.c

@@ -6,23 +6,15 @@
 /* Internal (not exported) functionality */
 /*****************************************/
 
-typedef struct Namespace_Entry {
+struct Namespace_Entry {
 	UA_UInt64 status;	/* 2 bits status | 14 bits checkout count | 48 bits timestamp */
 	const UA_Node *node;	/* Nodes are immutable. It is not recommended to change nodes in place */
-} Namespace_Entry;
+};
 
 struct Namespace_Entry_Lock {
 	Namespace_Entry *entry;
 };
 
-struct Namespace {
-	UA_UInt32 namespaceId;
-	Namespace_Entry *entries;
-	UA_UInt32 size;
-	UA_UInt32 count;
-	UA_UInt32 sizePrimeIndex;	/* Current size, as an index into the table of primes.  */
-};
-
 /* The tombstone (entry.node == 0x01) indicates that an entry was deleted at the position in the
    hash-map. This is information is used to decide whether the entire table shall be rehashed so
    that entries are found faster. */
@@ -39,8 +31,7 @@ struct prime_ent {
 	hash_t shift;
 };
 
-static
-struct prime_ent const prime_tab[] = {
+static struct prime_ent const prime_tab[] = {
 	{7, 0x24924925, 0x9999999b, 2},
 	{13, 0x3b13b13c, 0x745d1747, 3},
 	{31, 0x08421085, 0x1a7b9612, 4},
@@ -282,8 +273,7 @@ static inline UA_Int32 find_entry(const Namespace * ns, const UA_NodeId * nodeid
    hash table must already exist. Remember also that the place of the table entries is changed. If
    memory allocation failures are allowed, this function will return zero, indicating that the
    table could not be expanded. If all goes well, it will return a non-zero value. */
-static
-UA_Int32 expand(Namespace * ns) {
+static UA_Int32 expand(Namespace * ns) {
 	Namespace_Entry *nentries;
 	int32_t nsize;
 	UA_UInt32 nindex;

+ 18 - 36
src/ua_namespace.h

@@ -11,19 +11,26 @@
 #include <pthread.h>
 #endif
 
-struct Namespace;
-typedef struct Namespace Namespace;
-
+/** @brief Namespace entries point to an UA_Node. But the actual data structure
+	is opaque outside of ua_namespace.c */
+struct Namespace_Entry;
+typedef struct Namespace_Entry Namespace_Entry;
+
+/** @brief Namespace datastructure. It mainly serves as a hashmap to UA_Nodes. */
+typedef struct Namespace {
+	UA_UInt32 namespaceId;
+	Namespace_Entry *entries;
+	UA_UInt32 size;
+	UA_UInt32 count;
+	UA_UInt32 sizePrimeIndex;	/* Current size, as an index into the table of primes.  */
+} Namespace;
+
+/** Namespace locks indicate that a thread currently operates on an entry. */
 struct Namespace_Entry_Lock;
 typedef struct Namespace_Entry_Lock Namespace_Entry_Lock;
-void Namespace_Entry_Lock_release(Namespace_Entry_Lock * lock);
-
-struct Namespace_Transaction;
-typedef struct Namespace_Transaction Namespace_Transaction;
 
-/*************/
-/* Namespace */
-/*************/
+/** @brief Release a lock on a namespace entry. */
+void Namespace_Entry_Lock_release(Namespace_Entry_Lock * lock);
 
 /** @brief Create a new namespace */
 UA_Int32 Namespace_new(Namespace ** result, UA_UInt32 size, UA_UInt32 namespaceId);
@@ -57,35 +64,10 @@ UA_Int32 Namespace_contains(const Namespace * ns, const UA_NodeId * nodeid);
 UA_Int32 Namespace_get(Namespace const *ns, const UA_NodeId * nodeid, UA_Node const **result,
 					   Namespace_Entry_Lock ** lock);
 
+/** @brief A function that can be evaluated on all entries in a namespace via Namespace_iterate */
 typedef void (*Namespace_nodeVisitor) (UA_Node const *node);
 
 /** @brief Iterate over all nodes in a namespace */
 UA_Int32 Namespace_iterate(const Namespace * ns, Namespace_nodeVisitor visitor);
 
-/****************/
-/* Transactions */
-/****************/
-
-/** @brief Create a transaction that operates on a single namespace */
-UA_Int32 Namespace_Transaction_new(Namespace * ns, Namespace_Transaction ** result);
-
-/** @brief Insert a new node into the namespace as part of a transaction */
-UA_Int32 Namespace_Transaction_enqueueInsert(Namespace_Transaction * t, const UA_Node * node);
-
-/** @brief Insert a new node or replace an existing node as part of a transaction */
-UA_Int32 Namespace_Transaction_enqueueInsertOrReplace(Namespace_Transaction * t, const UA_Node * node);
-
-/** @brief Find an unused (numeric) NodeId in the namespace and insert the node as
-	part of a transaction */
-UA_Int32 Namespace_Transaction_enqueueInsertUnique(Namespace_Transaction * t, UA_Node * node);
-
-/** @brief Remove a node from the namespace as part of a transaction */
-UA_Int32 Namespace_Transaction_enqueueRemove(Namespace_Transaction * t, const UA_NodeId * nodeid);
-
-/** @brief Executes a transaction and returns the status */
-UA_Int32 Namespace_Transaction_commit(Namespace_Transaction * t);
-
-/** @brief Frees the transaction and deletes all the member objects */
-UA_Int32 Namespace_Transaction_delete(Namespace_Transaction * t);
-
 #endif /* __NAMESPACE_H */

+ 0 - 86
src/ua_namespace_transactions.c

@@ -1,86 +0,0 @@
-#include "ua_namespace.h"
-#include "ua_list.h"
-
-/**************************/
-/* Internal Functionality */
-/**************************/
-
-enum NAMESPACE_TRANSACTION_ACTIONTYPE_enum {
-	NAMESPACE_TRANSACTION_ACTIONTYPE_INSERT = 0x00,
-	NAMESPACE_TRANSACTION_ACTIONTYPE_INSERTREPLACE = 0x01,
-	NAMESPACE_TRANSACTION_ACTIONTYPE_INSERTUNIQUE = 0x02,
-	NAMESPACE_TRANSACTION_ACTIONTYPE_REMOVE = 0x03,
-};
-
-typedef struct Namespace_Transaction_Action {
-	UA_SLIST_ENTRY(Namespace_Transaction_Action) next;	// next entry in the list
-	union {
-		UA_Node *insert;
-		const UA_NodeId *remove;
-	} obj;
-	UA_Byte action;	// from NAMESPACE_TRANSACTION_ACTIONTYPE_enum
-} Namespace_Transaction_Action;
-
-struct Namespace_Transaction {
-	UA_SLIST_HEAD(Namespace_Transaction_Actions, Namespace_Transaction_Action) actions;
-	Namespace *ns;
-};
-
-/**********************/
-/* Exported Functions */
-/**********************/
-
-UA_Int32 Namespace_Transaction_new(Namespace * ns, Namespace_Transaction ** result) {
-	Namespace_Transaction *new_ts;
-	if(UA_alloc((void **)&new_ts, sizeof(Namespace_Transaction)) != UA_SUCCESS)
-		return UA_ERROR;
-
-	new_ts->ns = ns;
-	UA_SLIST_INIT(&new_ts->actions);
-	*result = new_ts;
-	return UA_SUCCESS;
-}
-
-UA_Int32 Namespace_Transaction_enqueueInsert(Namespace_Transaction * t, const UA_Node * node) {
-	Namespace_Transaction_Action *new_action;
-	UA_alloc((void **)&new_action, sizeof(Namespace_Transaction_Action));
-	new_action->obj.insert = (UA_Node *)node;
-	new_action->action = NAMESPACE_TRANSACTION_ACTIONTYPE_INSERT;
-	UA_SLIST_INSERT_HEAD(&t->actions, new_action, next);
-	return UA_SUCCESS;
-}
-
-UA_Int32 Namespace_Transaction_enqueueInsertOrReplace(Namespace_Transaction * t, const UA_Node * node) {
-	Namespace_Transaction_Action *new_action;
-	UA_alloc((void **)&new_action, sizeof(Namespace_Transaction_Action));
-	new_action->obj.insert = (UA_Node *)node;
-	new_action->action = NAMESPACE_TRANSACTION_ACTIONTYPE_INSERTREPLACE;
-	UA_SLIST_INSERT_HEAD(&t->actions, new_action, next);
-	return UA_SUCCESS;
-}
-
-UA_Int32 Namespace_Transaction_enqueueInsertUnique(Namespace_Transaction * t, UA_Node * node) {
-	Namespace_Transaction_Action *new_action;
-	UA_alloc((void **)&new_action, sizeof(Namespace_Transaction_Action));
-	new_action->obj.insert = node;
-	new_action->action = NAMESPACE_TRANSACTION_ACTIONTYPE_INSERTUNIQUE;
-	UA_SLIST_INSERT_HEAD(&t->actions, new_action, next);
-	return UA_SUCCESS;
-}
-
-UA_Int32 Namespace_Transaction_enqueueRemove(Namespace_Transaction * t, const UA_NodeId * nodeid) {
-	Namespace_Transaction_Action *new_action;
-	UA_alloc((void **)&new_action, sizeof(Namespace_Transaction_Action));
-	new_action->obj.remove = nodeid;
-	new_action->action = NAMESPACE_TRANSACTION_ACTIONTYPE_REMOVE;
-	UA_SLIST_INSERT_HEAD(&t->actions, new_action, next);
-	return UA_SUCCESS;
-}
-
-UA_Int32 Namespace_Transaction_commit(Namespace_Transaction * t) {
-	return UA_ERROR; // TODO not yet implemented
-}
-
-UA_Int32 Namespace_Transaction_delete(Namespace_Transaction * t) {
-	return UA_SUCCESS; // TODO
-}

+ 1 - 2
tools/indent.sh

@@ -12,7 +12,7 @@ fi
 # E.g. when indenting to the opening braces of an argument list.
 
 indent \
---line-length160 \
+--line-length120 \
 --comment-line-length100 \
 --indent-level4 \
 --use-tabs \
@@ -43,7 +43,6 @@ indent \
 --declaration-comment-column0 \
 --format-all-comments \
 --line-comments-indentation0 \
---blank-lines-before-block-comments \
 --space-special-semicolon \
 $@