Hi all,

Adding a macro to check the environment null condition  in the axis2_environment.h will be useful in writing code , This macro would be like AXIS2_ENV_CHECK(env,error_return) , which will check the env passed and create a default environment if the environment is null and then set error codes to it and return the error_return value passed to the macro.

so in writing a function it will be used as

axis2_om_node_get_parent(axis2_om_node_t *om_node,axis2_env_t **env)
{
       AXIS2_ENV_CHECK(env,NULL);
      ......................
}
if env is null the function will simply return null with the correct  error status set in the default environment created so that user can get the error message


Regards ..
nandika



On 11/3/05, Damitha Kumarage <[EMAIL PROTECTED]> wrote:
Samisa Abeysinghe wrote:

> Damitha Kumarage wrote:
>
>> Hi all,
>>
>> I have done some changes to axis2_enviroment_t. Please read and give
>> your
>> comments.
>>
>> Currently we are facing following problems with the environment
>>
>>   1.  Currently some functions return axis2_status_t (status code)
>> and some other return types.
>>        We need a conventions as to which functions return status
>> codes and which return types
>>        Following convention is adapted
>>        * Functions which are getters , creaters, makers should always
>> return what they are supposed to give and create
>>        * All the other functions should return the status
>> code.(AXIS2_SUCCESS or error_number other wise
>
>
> All other functions return a status code (AXIS2_SUCCESS, AXIS2_FAILURE
> or AXIS2_CRTICAL_FAILURE)
> AXIS2_CRTICAL_FAILURE is returned when an unrecoverable error like env
> NULL happens.
>
>>
>>    2. In case of returning types we again face the problem of return
>> NULL. Returning NULL from a function
>>        could happen in two instances.
>>            1 error situation
>>            2 as a flag (for example to indicate that a iteration is
>> over)
>>              When the person who call the application receives null
>> he should know whether NULL indicate a flag or error.
>>         To facilitate that inside the function, if error situation
>>                 env->error_number is set
>>                env->status_code is set to AXIS2_FAILURE
>>                and return NULL
>>          if NULL is returned as flag set env->status_code to
>> AXIS2_SUCCESS
>
>
> This, when a user calls a function that returns a pointer, to get to
> know if the operation is successfull, he/she must check
> if (env->status_code == AXIS2_SUCCESS) before using the return value
>
>>
>>    3. if env passed to a function is null, application  does not
>> handle it  and crash.
>>        solution:
>>                We need to handle two cases.
>>                if function return status code then
>>
>>                            return AXIS2_ERROR_ENVIRONMENT_IS_NULL;
>
>
> It shoud return AXIS2_CRTICAL_FAILURE staus code.
> Also, should create a temp environment as in the case of returning a
> pointer. This way we will have consistancy in dealing with env related
> errors.
>
>>                              else if function return type
>
>
> is a pointer
>
>>                We make the environment as an out parameter so that if
>> the environment
>>                 received in a function is null then a default
>> environment is created and set
>>
>>                     env->error_number = AXIS2_ERROR_ENVIRONMENT_IS_NULL;
>>                     env->status_code = AXIS2_FAILURE
>
>
> env->status_code = AXIS2_CRTICAL_FAILURE ;
>
>>                         Then we return NULL from the application.
>> Note that although we created a
>>                default environment structure it is not used to
>> proceed the application normally.
>>                it is just used to handle the error situation (that
>> env is null)
>>
>>                 Then the user who call the application should handle
>> it as following
>>                            axis2_env_t *env;
>>                            /* Suppose user did properly initialized
>> env here */
>>                           ........................
>>                           .........................
>>                            /* But here he  mistakenly make env to n
>> ull */
>>                            env = NULL;
>>                            /*Now he call an axis2 mock function called
>>                             * test_function
>>                             */
>>                            char *msg = test_function(&env);
>>                            int status =
>> axis2_environment_check_status(env);
>>                            if(AXIS2_SUCCESS == status)
>>                                     /* Proceed normally */
>>                            else if(AXIS2_FAILURE == status)
>
>
>                           else
>
>>                                    char* msg =
>> env->get_error_message(env->error_number);
>>
>>
>>  4.  Currenly environment can be created as following
>>         axis2_environment_create (allocator,  error, stream, log);
>>         if user use this as following
>>          axis2_environment_create (allocator, NULL, NULL, NULL);
>>          then  default error, stream and log are creatd and used
>> through out the Axis2.
>>          This behaviour is changed now. Axis2 need allocator error
>> and stream for its
>>          correct functionlity. but log may be null. But still Axis2
>> should not create the
>>          default error and stream. if allocator, stream or error is
>> null, axis2 should
>>         set status_code to AXIS2_FAILURE and set some error_number.
>>                 So now  user of axis2 can use two create functions
>>          axis2_environment_create (allocator, error, stream)
>>          axis2_environment_create_with_log(allocator, error, stream,
>> log)
>
I'll further added
                 axis2_environment_create (allocator)
       which is not supposed to be used by Axis2 users. This is used
only to create the default environment


>>
>>         if log is set env->enable_log = AXIS2_TRUE is set. Axis 2
>> will check this
>>         flag when writing log.
>
>
> This is cool.
>
> Samisa...
>
>>
>> cheers
>> damitha
>>
>>
>
>
>
>


Reply via email to