axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sam...@apache.org
Subject svn commit: r345805 - in /webservices/axis2/trunk/c: include/axis2_ctx.h modules/core/context/src/Makefile.am modules/core/context/src/ctx.c
Date Mon, 21 Nov 2005 01:54:47 GMT
Author: samisa
Date: Sun Nov 20 17:54:39 2005
New Revision: 345805

URL: http://svn.apache.org/viewcvs?rev=345805&view=rev
Log:
C version of AbsractContext added. Compiles but needs testing.

Added:
    webservices/axis2/trunk/c/include/axis2_ctx.h
    webservices/axis2/trunk/c/modules/core/context/src/ctx.c
Modified:
    webservices/axis2/trunk/c/modules/core/context/src/Makefile.am

Added: webservices/axis2/trunk/c/include/axis2_ctx.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_ctx.h?rev=345805&view=auto
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_ctx.h (added)
+++ webservices/axis2/trunk/c/include/axis2_ctx.h Sun Nov 20 17:54:39 2005
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+#ifndef AXIS2_CTX_H
+#define AXIS2_CTX_H
+
+
+/**
+  * @file axis2_ctx.h
+  * @brief axis2 Message Context interface
+  */
+
+#include <axis2_defines.h>
+#include <axis2_hash.h>
+#include <axis2_env.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/** @defgroup axis2_ctx Message Context 
+ * @ingroup axis2_core_context
+ * @{
+ */
+    
+typedef struct axis2_ctx_ops axis2_ctx_ops_t;
+typedef struct axis2_ctx axis2_ctx_t; 
+
+    
+/** 
+ * @brief Message Context operations struct
+ * Encapsulator struct for operations of axis2_ctx
+ */  
+struct axis2_ctx_ops
+{
+    /**
+     * Stores a key value pair depending on the persistent flag.
+     *
+     * @param key
+     * @param value
+     * @param persistent
+     */
+    axis2_status_t (AXIS2_CALL *set_property)(struct axis2_ctx *ctx, axis2_env_t **env, axis2_char_t
*key, axis2_status_t *value, axis2_bool_t persistent);
+    
+    /**
+     * @param key
+     * @param persistent
+     * @return
+     */
+    axis2_char_t* (AXIS2_CALL *get_property)(struct axis2_ctx *ctx, axis2_env_t **env, axis2_char_t
*key, axis2_bool_t persistent);
+    
+    axis2_hash_t* (AXIS2_CALL *get_non_persistent_map)(struct axis2_ctx *ctx, axis2_env_t
**env);
+    
+    axis2_hash_t* (AXIS2_CALL *get_persistent_map)(struct axis2_ctx *ctx, axis2_env_t **env);
+
+    /** 
+     * Deallocate memory
+     * @return status code
+     */
+    axis2_status_t (AXIS2_CALL *free)(axis2_ctx_t *ctx,
+                                        axis2_env_t **env); 
+};
+
+/** 
+ * @brief Message Context struct
+  *	Axis2 Message Context
+ */
+struct axis2_ctx
+{
+    axis2_ctx_ops_t *ops;    
+};
+
+AXIS2_DECLARE(axis2_ctx_t*) axis2_ctx_create (axis2_env_t **env);
+    
+/************************** Start of function macros **************************/
+
+#define AXIS2_CTX_SET_PROPERTY(ctx, env, key, value, persistent) ((ctx)->ops->set_property)(ctx,
env, key, value, persistent))
+#define AXIS2_CTX_GET_PROPERTY(ctx, env, key, persistent) ((ctx)->ops->get_property)(ctx,
env, key, persistent))
+#define AXIS2_CTX_GET_NON_PERSISTANT_MAP(ctx, env) ((ctx)->ops->get_non_persistent_map)(ctx,
env))
+#define AXIS2_CTX_GET_PERSISTANT_MAP(ctx, env) ((ctx)->ops->get_persistent_map)(ctx,
env))
+#define AXIS2_CTX_FREE(ctx, env) ((ctx)->ops->free (ctx, env))
+
+/************************** End of function macros ****************************/    
+
+/** @} */
+#ifdef __cplusplus
+}
+#endif
+
+#endif                          /* AXIS2_CTX_H */

Modified: webservices/axis2/trunk/c/modules/core/context/src/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/context/src/Makefile.am?rev=345805&r1=345804&r2=345805&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/context/src/Makefile.am (original)
+++ webservices/axis2/trunk/c/modules/core/context/src/Makefile.am Sun Nov 20 17:54:39 2005
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libaxis2_context.la
 AM_CPPFLAGS = $(CPPFLAGS)
-libaxis2_context_la_SOURCES = msg_ctx.c
+libaxis2_context_la_SOURCES = ctx.c msg_ctx.c
 
 libaxis2_context_la_LIBADD = $(LDFLAGS)
 INCLUDES = -I${CUTEST_HOME}/include \

Added: webservices/axis2/trunk/c/modules/core/context/src/ctx.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/context/src/ctx.c?rev=345805&view=auto
==============================================================================
--- webservices/axis2/trunk/c/modules/core/context/src/ctx.c (added)
+++ webservices/axis2/trunk/c/modules/core/context/src/ctx.c Sun Nov 20 17:54:39 2005
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+#include <axis2_ctx.h>
+#include <axis2.h>
+#include <axis2_hash.h>
+
+typedef struct axis2_ctx_impl
+{
+    /** context base struct */
+    axis2_ctx_t ctx;
+    /** non persistent map */
+    axis2_hash_t *non_persistent_map;
+    /** persistent map */
+    axis2_hash_t *persistent_map;
+    /*axis2_ctx_t *parent; This will be not required as the responsibility of 
+    knwong the parent is  deligated to impl structs */
+} axis2_ctx_impl_t;
+
+/** Interface to implementation conversion macro */
+#define AXIS2_INTF_TO_IMPL(ctx) ((axis2_ctx_impl_t *)ctx)
+
+axis2_char_t* AXIS2_CALL axis2_ctx_get_property(struct axis2_ctx *ctx, axis2_env_t **env,
axis2_char_t *key, axis2_bool_t persistent);
+axis2_hash_t* AXIS2_CALL axis2_ctx_get_non_persistent_map(struct axis2_ctx *ctx, axis2_env_t
**env);
+axis2_hash_t* AXIS2_CALL axis2_ctx_get_persistent_map(struct axis2_ctx *ctx, axis2_env_t
**env);
+axis2_status_t AXIS2_CALL axis2_ctx_free (struct axis2_ctx *ctx, 
+                                   axis2_env_t **env);
+
+axis2_ctx_t* AXIS2_CALL axis2_ctx_create(axis2_env_t **env) 
+{
+    axis2_ctx_impl_t *ctx_impl = NULL;
+    
+    AXIS2_ENV_CHECK(env, NULL);
+    
+    ctx_impl = AXIS2_MALLOC( (*env)->allocator, sizeof(axis2_ctx_impl_t) );
+    if (!ctx_impl)
+    { 
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;        
+    }
+
+    ctx_impl->persistent_map = NULL;
+	ctx_impl->non_persistent_map = NULL;
+    
+    ctx_impl->persistent_map = axis2_hash_make(env);
+    if (!(ctx_impl->persistent_map))
+    {
+        axis2_ctx_free(&(ctx_impl->ctx), env);
+        return NULL;
+    }
+    
+	ctx_impl->non_persistent_map = axis2_hash_make(env);
+    if (!(ctx_impl->non_persistent_map))
+    {
+        axis2_ctx_free(&(ctx_impl->ctx), env);
+        return NULL;
+    }
+	
+    /* initialize operations */
+    ctx_impl->ctx.ops = NULL;
+    ctx_impl->ctx.ops  = AXIS2_MALLOC( (*env)->allocator, sizeof(axis2_ctx_ops_t) );
+    if (!ctx_impl->ctx.ops)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        axis2_ctx_free(&(ctx_impl->ctx), env);
+        return NULL;        
+    }
+
+    ctx_impl->ctx.ops->free = axis2_ctx_free;
+
+    return &(ctx_impl->ctx);
+}
+
+axis2_status_t AXIS2_CALL axis2_ctx_set_property(struct axis2_ctx *ctx, axis2_env_t **env,
axis2_char_t *key, axis2_status_t *value, axis2_bool_t persistent) 
+{
+    axis2_ctx_impl_t *ctx_impl = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(ctx, env, AXIS2_FAILURE);
+    
+    ctx_impl = AXIS2_INTF_TO_IMPL(ctx);
+
+    if (persistent) 
+    {
+        axis2_hash_set(ctx_impl->persistent_map, key, AXIS2_HASH_KEY_STRING, value);
+    } 
+    else 
+    {
+        axis2_hash_set(ctx_impl->non_persistent_map, key, AXIS2_HASH_KEY_STRING, value);
+    }
+    return AXIS2_SUCCESS;
+}
+
+axis2_char_t* AXIS2_CALL axis2_ctx_get_property(struct axis2_ctx *ctx, axis2_env_t **env,
axis2_char_t *key, axis2_bool_t persistent) 
+{
+    axis2_ctx_impl_t *ctx_impl = NULL;
+    axis2_char_t *ret = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(ctx, env, NULL);
+    
+    ctx_impl = AXIS2_INTF_TO_IMPL(ctx);
+    
+    if (persistent) 
+    {
+        ret = axis2_hash_get(ctx_impl->persistent_map, key, AXIS2_HASH_KEY_STRING);
+    }
+    
+    if (!ret) 
+    {
+        ret = axis2_hash_get(ctx_impl->non_persistent_map, key, AXIS2_HASH_KEY_STRING);
+    }
+    /** it is the responsibility of the caller to lookup parent if key is not found here

+        Note that in C implementation it is the responsibility of the deriving struct to

+        handle the parent as we do not have the inheritance facility. Im case of 
+        context it is not worth trying to mimic inheritance. */
+    
+    return ret;
+}
+
+axis2_hash_t* AXIS2_CALL axis2_ctx_get_non_persistent_map(struct axis2_ctx *ctx, axis2_env_t
**env) 
+{
+    AXIS2_FUNC_PARAM_CHECK(ctx, env, NULL);
+    return AXIS2_INTF_TO_IMPL(ctx)->non_persistent_map;
+}
+
+axis2_hash_t* AXIS2_CALL axis2_ctx_get_persistent_map(struct axis2_ctx *ctx, axis2_env_t
**env) 
+{
+    AXIS2_FUNC_PARAM_CHECK(ctx, env, NULL);
+    return AXIS2_INTF_TO_IMPL(ctx)->persistent_map;
+}
+
+axis2_status_t AXIS2_CALL axis2_ctx_free (struct axis2_ctx *ctx, 
+                                   axis2_env_t **env)
+{
+    axis2_ctx_impl_t *ctx_impl = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(ctx, env, AXIS2_FAILURE);
+    
+    ctx_impl = AXIS2_INTF_TO_IMPL(ctx);
+    
+    if (ctx_impl->ctx.ops)
+    {
+        AXIS2_FREE((*env)->allocator, ctx_impl->ctx.ops);
+        ctx_impl->ctx.ops = NULL;
+    }
+    
+    if (ctx_impl->non_persistent_map)
+    {
+        axis2_hash_free(ctx_impl->non_persistent_map, env);
+        ctx_impl->non_persistent_map = NULL;
+    }    
+    
+    if (ctx_impl->persistent_map)
+    {
+        axis2_hash_free(ctx_impl->persistent_map, env);
+        ctx_impl->persistent_map = NULL;
+    }    
+    
+    AXIS2_FREE((*env)->allocator, ctx_impl);
+    ctx_impl = NULL;
+    
+    return AXIS2_SUCCESS;
+}



Mime
View raw message