/*
 *
 * 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.
 *
 */


// This file automatically generated by:
//   Apache Etch 1.1.0-incubating (LOCAL-0) / c 1.1.0-incubating (LOCAL-0)
//   Fri Aug 28 15:58:20 CEST 2009
// This file is automatically created and should not be edited!

#include "helloworld_server.h"
#include "etch_objecttypes.h"
#include "etch_general.h"
#include "etch_url.h"  

unsigned short CLASSID_HELLOWORLD_SERVER_BASE;
	
	
int destroy_helloworld_server_via_base(void*);

static int helloworld_server_id_farm;

/* - - - - - - - - - - - - - -  
 * constructors
 * - - - - - - - - - - - - - -  
 */
/**
 * new_helloworld_server_base()
 * @param implobj not interpreted
 * @param psi a helloworld service interface. if supplied, caller retains,
 * otherwise a service interface is instantiated and owned here. 
 */
i_helloworld_server* new_helloworld_server_base(void* implobj, i_helloworld* psi)
{
    i_helloworld_server* ips = (i_helloworld_server*) new_object (sizeof(i_helloworld_server), 
        ETCHTYPEB_EXESERVERBASE, get_dynamic_classid_unique(&CLASSID_HELLOWORLD_SERVER_BASE));

    /* the server impl is destroyed via this base object. the virtual destructor we assign
     * here will call the impl object's virtual destructor, which will directly call a 
     * non-virtual destructor for the base object. 
     */

    ((etch_object*)ips)->destroy = destroy_helloworld_server_via_base;
    
    ips->thisx   = implobj; /* null passed thru from client main */
    
    if (psi)
        ips->ihelloworld = psi;
    else
    {   ips->ihelloworld = new_helloworld_service_interface();
        ips->is_service_interface_owned = TRUE;
    }

    ips->say_hello = ips->ihelloworld->say_hello;

    ips->user = ips->ihelloworld->user;

    ips->iobjsession = new_default_objsession_interface (ips);
    ips->_session_control = ips->iobjsession->_session_control; 
    ips->_session_notify  = ips->iobjsession->_session_notify; 
    ips->_session_query   = ips->iobjsession->_session_query; 

    ips->server_id = ++helloworld_server_id_farm;

    return ips;
}

/**
 * new_helloworld_remote_server_base()  
 * constructor for server base when host is a remote server.
 * the server base destructor in this case destroys only itself.   
 * @param psi a helloworld service interface, if supplied, caller retains.
 * may be null.
 */
i_helloworld_server* new_helloworld_remote_server_base (void* implobj, i_helloworld* psi)
{
    i_helloworld_server* ips = new_helloworld_server_base (implobj, psi);
    ((etch_object*)ips)->destroy = destroy_helloworld_server_base;
    return ips;
}

/**
 * destroy_helloworld_server_base()
 * i_helloworld_server destructor.
 */
int destroy_helloworld_server_base (void* data)
{

    i_helloworld_server* ips = (i_helloworld_server*)data;
    if (NULL == ips) return -1;

    if (!is_etchobj_static_content(ips))
    {    
        if (ips->is_service_interface_owned){
            //ETCHOBJ_DESTROY(ips->ihelloworld);
			if(ips->ihelloworld){
				etch_object_destroy(ips->ihelloworld);
			}
			ips->ihelloworld = NULL;
			
		}

        etch_free(ips->iobjsession);
    }
            
    return destroy_objectex((etch_object*)ips);
}


/**
 * destroy_helloworld_server_via_base()
 * destructor for helloworld_server_impl via i_helloworld_server.
 */
int destroy_helloworld_server_via_base (void* data)
{
    i_helloworld_server* ips = (i_helloworld_server*)data;
    if (NULL == ips) return -1;  

    if (!is_etchobj_static_content(ips))
    {    
        /* serverimpl dtor will call base dtor (destroy_helloworld_server_base) */
        etch_object* serverimpl = (etch_object*) ips->thisx;
        ETCH_ASSERT(is_etch_serverimpl(serverimpl));
        //ETCHOBJ_DESTROY(serverimpl);
		if(serverimpl){
			etch_object_destroy(serverimpl);
		}
		serverimpl = NULL;
    }

    return 0;
}

