You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by fi...@apache.org on 2011/07/21 16:52:03 UTC
svn commit: r1149205 - in
/incubator/etch/branches/singlestack/binding-c/runtime/c:
include/etch_inet_who.h include/etch_object.h include/etch_objecttypes.h
src/main/CMakeLists.txt src/main/common/etch_inet_who.c
Author: fitzner
Date: Thu Jul 21 14:52:01 2011
New Revision: 1149205
URL: http://svn.apache.org/viewvc?rev=1149205&view=rev
Log:
ETCH-157 binding-c: add inet_who object
Implementation of inet_who object, which is needed for the C UDP implementation
Patch from Aleksandar Kanchev <ka...@itestra.com>
Added:
incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_inet_who.h
incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/common/etch_inet_who.c
Modified:
incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_object.h
incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_objecttypes.h
incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/CMakeLists.txt
Added: incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_inet_who.h
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_inet_who.h?rev=1149205&view=auto
==============================================================================
--- incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_inet_who.h (added)
+++ incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_inet_who.h Thu Jul 21 14:52:01 2011
@@ -0,0 +1,46 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * etch_inet_who.h
+ * subclass of etch_who holding an inet address.
+ */
+
+#ifndef ETCHINETWHO_H
+#define ETCHINETWHO_H
+
+#include "apr_network_io.h"
+#include "etch_object.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct etch_inet_who {
+ etch_object object;
+} etch_inet_who;
+
+etch_inet_who* new_inet_who (apr_sockaddr_t*);
+
+apr_sockaddr_t* inet_who_sockaddr (etch_inet_who*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* #ifndef ETCHINETWHO_H */
Modified: incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_object.h
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_object.h?rev=1149205&r1=1149204&r2=1149205&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_object.h (original)
+++ incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_object.h Thu Jul 21 14:52:01 2011
@@ -509,6 +509,10 @@ typedef union
#define is_etch_connection(cx) (cx && (*(unsigned*)cx) == ETCH_CONX_SIG)
+#define is_etch_inet_who(x) (x \
+ && ((etch_object*)x)->obj_type == ETCHTYPEB_INET_WHO \
+ && ((etch_object*)x)->class_id == CLASSID_INET_WHO)
+
/**
* macros to interpret state of the object byteflag is_static
*/
Modified: incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_objecttypes.h
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_objecttypes.h?rev=1149205&r1=1149204&r2=1149205&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_objecttypes.h (original)
+++ incubator/etch/branches/singlestack/binding-c/runtime/c/include/etch_objecttypes.h Thu Jul 21 14:52:01 2011
@@ -147,6 +147,7 @@ typedef enum objtype_b
ETCHTYPEB_CLIENTSTUB = 0x71,
ETCHTYPEB_SERVERSTUB = 0x72,
ETCHTYPEB_FACTORYPARAMS = 0x73,
+ ETCHTYPEB_INET_WHO = ETCHTYPEB_WHO,
ETCHTYPEB_EODMARK = 0x7f,
@@ -323,6 +324,8 @@ typedef enum etch_classid
CLASSID_QUERY_WAITUP = 0x113,
CLASSID_QUERY_WAITDOWN = 0x114,
+ CLASSID_INET_WHO = 0x120,
+
CLASSID_DYNAMIC_START = 0x400,
} etch_classid;
Modified: incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/CMakeLists.txt?rev=1149205&r1=1149204&r2=1149205&view=diff
==============================================================================
--- incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/CMakeLists.txt (original)
+++ incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/CMakeLists.txt Thu Jul 21 14:52:01 2011
@@ -34,6 +34,7 @@ add_library (etch-c STATIC
common/etch_general.c
common/etch_hash.c
common/etch_hashfunc.c
+ common/etch_inet_who.c
common/etch_linked_list.c
common/etch_log.c
common/etch_map.c
Added: incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/common/etch_inet_who.c
URL: http://svn.apache.org/viewvc/incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/common/etch_inet_who.c?rev=1149205&view=auto
==============================================================================
--- incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/common/etch_inet_who.c (added)
+++ incubator/etch/branches/singlestack/binding-c/runtime/c/src/main/common/etch_inet_who.c Thu Jul 21 14:52:01 2011
@@ -0,0 +1,159 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * etch_inet_who.c
+ * inet who object
+ */
+
+#include "etch_inet_who.h"
+#include "etch_log.h"
+#include "etch_objecttypes.h"
+
+static const char* LOG_CATEGORY = "etch_inet_who";
+
+
+etch_inet_who* new_inet_who_init(apr_sockaddr_t*);
+
+/**
+ * new_inet_who()
+ * constructor for etch_inet_who
+ * the value factory is a reference, the type is a copy to be passed through
+ */
+etch_inet_who* new_inet_who (apr_sockaddr_t* sockaddr)
+{
+ etch_inet_who* newinetwho = NULL;
+
+ if (!sockaddr)
+ return NULL;
+
+ newinetwho = new_inet_who_init(sockaddr);
+ if (!newinetwho)
+ return NULL;
+
+ ETCH_LOG(LOG_CATEGORY, ETCH_LOG_XDEBUG, "creating inet who %x\n", newinetwho);
+ return newinetwho;
+}
+
+/**
+ * clone_inet_who()
+ * create clone for etch_inet_who
+ */
+void* clone_inet_who(void* data)
+{
+ etch_inet_who* inetwho = (etch_inet_who*)data;
+ etch_who* who = (etch_who*)(inetwho->object.parent);
+ etch_inet_who* newinetwho = new_inet_who_init((apr_sockaddr_t*)(who->value));
+
+ ETCH_LOG(LOG_CATEGORY, ETCH_LOG_XDEBUG, "cloning inet who %x to %x\n", inetwho, newinetwho);
+ return newinetwho;
+}
+
+/**
+ * destroy_inet_who()
+ * destructor for etch_inet_who
+ */
+int destroy_inet_who (void* data)
+{
+ etch_inet_who* inetwho = (etch_inet_who*)data;
+
+ if (!is_etchobj_static_content(inetwho))
+ {
+ etch_who* who = (etch_who*)inetwho->object.parent;
+
+ ETCH_LOG(LOG_CATEGORY, ETCH_LOG_XDEBUG, "destroying inet who %x\n", inetwho);
+ etch_free(who->value);
+ who->value = NULL;
+ }
+
+ return destroy_objectex((etch_object*)inetwho);
+}
+
+/**
+ * etch_inet_who defgethashkey
+ * default hashkey computation for an etch_inet_who object
+ */
+uint32 defgethashkey_inet_who(void* data)
+{
+ etch_inet_who* inetwho = (etch_inet_who*)data;
+ apr_sockaddr_t* hashitem = inet_who_sockaddr(inetwho); /* uses the socket address as hash source */
+
+ ETCH_ASSERT(hashitem != NULL);
+
+ if(inetwho->object.hashkey == 0)
+ inetwho->object.hashkey = etchhash((char*)hashitem, sizeof(*hashitem), 0);
+
+ return inetwho->object.hashkey;
+}
+
+/**
+ * new_message_init()
+ * common initialization on etch_message construction.
+ */
+etch_inet_who* new_inet_who_init(apr_sockaddr_t* sockaddr)
+{
+ etch_inet_who* newinetwho = NULL;
+ etch_object* parent = NULL;
+ apr_sockaddr_t* newsockaddr = NULL;
+
+ if (!sockaddr)
+ goto _error;
+
+ newsockaddr = (apr_sockaddr_t*)etch_malloc(sizeof(apr_sockaddr_t), 0);
+ if (!newsockaddr)
+ goto _error;
+ *newsockaddr = *sockaddr;
+ newsockaddr->pool = 0;
+
+ parent = (etch_object*)new_who(newsockaddr);
+ if (!parent)
+ goto _error;
+
+ newinetwho = (etch_inet_who*) new_object(sizeof(etch_inet_who),
+ ETCHTYPEB_INET_WHO, CLASSID_INET_WHO);
+ if (!newinetwho)
+ goto _error;
+
+ newinetwho->object.parent = parent;
+ newinetwho->object.clone = clone_inet_who;
+ newinetwho->object.destroy = destroy_inet_who;
+ newinetwho->object.get_hashkey = defgethashkey_inet_who;
+
+ return newinetwho;
+
+_error:
+ if (parent)
+ etch_object_destroy(parent);
+ if (newsockaddr)
+ etch_free(newsockaddr);
+
+ return NULL;
+}
+
+
+/**
+ * inet_who_sockaddr()
+ * return sockaddr.
+ * @return a reference to the who sockaddr, caller does not own it.
+ */
+apr_sockaddr_t* inet_who_sockaddr (etch_inet_who* inetwho)
+{
+ etch_who* who = (etch_who*)inetwho->object.parent;
+
+ return (apr_sockaddr_t*)who->value;
+}