You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@axis.apache.org by Susantha Kumara <su...@opensource.lk> on 2004/02/10 08:13:26 UTC

Replacing some WSDL2Ws generated code with C macros

Hi all,

It is possible for Axis to define set of macros to be used within the
WSDL2WS tool generated code. Advantage of this is

1. These macros can be changed in the Axis code base without effecting the
already existing web services and client applications.
2. Hence a user (web service or client application developer) will not have
to re-generate code when some Axis APIs change. Only thing is that he has to
compile code again.

Disadvantages

1. Some of the code generated will contain set of macros and may not be
understandable by itself (this is ok I think).
2. We cannot go into the macro definitions while debugging (most popular
debugging tools does not show expanded macros).

See following example.

Example :

The class loader file generated by the WSDL2WS tool now is,

#ifdef WIN32
#define STORAGE_CLASS_INFO __declspec(dllexport)
#else
#define STORAGE_CLASS_INFO
#endif

#include <malloc.h>
#include "InteropTestPortTypeWrapper.h"

static BasicHandlerFunctions InteropTestPortTypeWrapper_functions =
{
	InteropTestPortTypeWrapper_Invoke,
	InteropTestPortTypeWrapper_OnFault,
	InteropTestPortTypeWrapper_Init,
	InteropTestPortTypeWrapper_Fini,
	InteropTestPortTypeWrapper_GetType,
	InteropTestPortTypeWrapper_GetBindingStyle
};

STORAGE_CLASS_INFO
int GetClassInstance(BasicHandler **inst)
{
	*inst = malloc(sizeof(BasicHandler));
	(*inst)->_object = 0;	// instantiate and provide the context object if
needed
	(*inst)->_functions = &InteropTestPortTypeWrapper_functions;
	return (*inst)->_functions->Init((*inst)->_object);
}

STORAGE_CLASS_INFO
int DestroyInstance(BasicHandler *inst)
{
	if (inst)
	{
		inst->_functions->Fini(inst->_object);
		//destroy the context object set to inst->_object if any here
		free(inst);
		return AXIS_SUCCESS;
	}
	return AXIS_FAIL;
}

When we introduce macros, there will be only 3 line of code in the generated
file

#include <malloc.h>
#include "InteropTestPortTypeWrapper.h"
AXIS_SERVICE_LOADER_MACRO( InteropTestPortTypeWrapper )


And the macro AXIS_SERVICE_LOADER_MACRO is defined in an include file like,

#define AXIS_SERVICE_LOADER_MACRO(WCName) static \
BasicHandlerFunctions WCName##_functions = { \
	##WCName##_Invoke, \
	##WCName##_OnFault, \
	##WCName##_Init, \
	##WCName##_Fini, \
	##WCName##_GetType, \
	##WCName##_GetBindingStyle \
}; \
STORAGE_CLASS_INFO \
int GetClassInstance(BasicHandler **inst) \
{ \
	*inst = malloc(sizeof(BasicHandler)); \
	(*inst)->_object = 0; \
	(*inst)->_functions = &##WCName##_functions; \
	return (*inst)->_functions->Init((*inst)->_object); \
} \
STORAGE_CLASS_INFO  \
int DestroyInstance(BasicHandler *inst) \
{ \
	if (inst) \
	{ \
		inst->_functions->Fini(inst->_object); \
		free(inst); \
		return AXIS_SUCCESS; \
	} \
	return AXIS_FAIL; \
}

There are lot of such places in generated code where we can introduce this
kind of macros. Specially when we expect to use long typenames and namepaces
etc.

What do you think about this idea. If there are no objections we expect to
proceed in few days.

Thanks,

Susantha.