/*
 *
 * 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_remote.h"
#include "etch_url.h"  
#include "etch_objecttypes.h"
#include "etch_general.h"

unsigned short CLASSID_HELLOWORLD_REMOTE;

int destroy_helloworld_remote (void*);
#if(0)
etch_message* etchremote_new_message(helloworld_remote*, etch_type*);
int etchremote_send(helloworld_remote*, etch_message*);
int etchremote_begincall(helloworld_remote*, etch_message*, void**);
int etchremote_endcall  (helloworld_remote*, i_mailbox*, etch_type*, void**);
int etchremote_transport_control (helloworld_remote*, etch_event*, etch_int32*);
int etchremote_transport_notify  (helloworld_remote*, etch_event*);
etch_object* etchremote_transport_query (helloworld_remote*, etch_object*); 
int etchremote_start_waitup  (helloworld_remote*, const int);
int etchremote_stop_waitdown (helloworld_remote*, const int);
#endif


/* - - - - - - - - - - - - - -  
 * constructors
 * - - - - - - - - - - - - - -  
 */

/**
 * new_helloworld_remote
 * @param ids delivery service -- caller retains
 * @param vf helloworld value factory - caller retains 
 * @param ihelloworld optional helloworld service interface -- caller retains
 */
helloworld_remote* new_helloworld_remote (void* thisx, 
    i_delivery_service* ids, etch_value_factory* vf, i_helloworld* iservice)
{
    helloworld_remote* remote = (helloworld_remote*) new_object (sizeof(helloworld_remote), 
        ETCHTYPEB_REMOTE, get_dynamic_classid_unique(&CLASSID_HELLOWORLD_REMOTE));

    ((etch_object*)remote)->destroy = destroy_helloworld_remote;

    /* helloworld_remote instance data and methods */
    remote->dsvc = ids; 
    remote->vf   = vf;
    remote->start_waitup  = etchremote_start_waitup;
    remote->stop_waitdown = etchremote_stop_waitdown;

    /* transport methods */
    remote->transport_control = etchremote_transport_control;
    remote->transport_notify  = etchremote_transport_notify;
    remote->transport_query   = etchremote_transport_query;

    /* remote base */
    remote->new_message = etchremote_new_message;
    remote->send        = etchremote_send;
    remote->sendex      = etchremote_sendex;
    remote->begin_call  = etchremote_begincall;
    remote->end_call    = etchremote_endcall;

    /* helloworld service */
    if (iservice)
        remote->ihelloworld = iservice;
    else
    {   remote->ihelloworld = new_helloworld_service_interface();
        remote->is_service_interface_owned = TRUE;
    }
    remote->say_hello = remote->ihelloworld->say_hello;

    remote->user = remote->ihelloworld->user;

    return remote;
}


/**
 * destroy_helloworld_remote()
 * helloworld_remote destructor.
 */
int destroy_helloworld_remote (void* data)
{
    helloworld_remote* thisx = (helloworld_remote*)data;
    if (NULL == thisx) return -1;

    if (!is_etchobj_static_content(thisx))
    {
        if (thisx->is_service_interface_owned && thisx->ihelloworld)
            etch_object_destroy(thisx->ihelloworld);
    }

    return destroy_objectex((etch_object*)thisx);
}


/* - - - - - - - - - - - - - -  
 * remote methods
 * - - - - - - - - - - - - - -  
 */

/**
 * etchremote_new_message()
 * instantiates a message to be sent via this.send() or this.begin_call().
 * @param thisx this remote object.
 * @param message_type type of message, caller retains.
 * @return message object, which could wrap an exception.
 */
#if(0)
etch_message* etchremote_new_message ($helper.getRemoteName($intf, $mc)* thisx, etch_type* message_type)
{
    etch_message* msg = new_message(message_type, ETCH_DEFSIZE, thisx->vf);
    return msg;
}
#endif


/**
 * etchremote_send()
 * sends message to recipient without waiting for a response.
 * @param thisx this remote object.
 * @param msg message, caller relinquishes.
 * @return 0 success, -1 failure.
 */
#if(0)
int etchremote_send ($helper.getRemoteName($intf, $mc)* thisx, etch_message* msg)
{
    const int result = thisx->dsvc->itm->transport_message(thisx->dsvc, NULL, msg);
    return result;
}
#endif


/**
 * etchremote_begincall()
 * sends message beginning a call sequence.
 * @param thisx this remote object.
 * @param msg message, caller relinquishes.
 * @return in out parameter, a mailbox which can be used to retrieve the response.
 * @return 0 success, -1 failure.
 */

#if(0)
int etchremote_begincall ($helper.getRemoteName($intf, $mc)* thisx, etch_message* msg, i_mailbox** out)
{
    const int result = thisx->dsvc->begin_call(thisx->dsvc, msg, out);
    return result;
}
#endif


/**
 * etchremote_endcall()
 * finishes a call sequence by waiting for a response message.
 * @param thisx this remote object.
 * @param mbox a mailbox which will be used to read an expected message response.
 * @param response_type the message type of the expected response.
 * @return in out parameter, on success, the response.
 * @return 0 success, -1 failure.
 */
#if(0)
int etchremote_endcall ($helper.getRemoteName($intf, $mc)* thisx, i_mailbox* mbox, etch_type* response_type, etch_object** out)
{
    const int result = thisx->dsvc->end_call(thisx->dsvc, mbox, response_type, out);
    return result;
}
#endif


/**
 * etchremote_transport_control()
 * @param evt caller relinquishes
 * @param value caller relinquishes
 * @return 0 success, -1 failure.
 */
#if(0)
int etchremote_transport_control ($helper.getRemoteName($intf, $mc)* thisx, etch_event* evt, etch_int32* value)
{
    const int result = thisx->dsvc->itm->transport_control(thisx->dsvc, evt, value);
    return result;
}
#endif


/**
 * etchremote_transport_notify()
 * @param evt caller relinquishes
 * @return 0 success, -1 failure.
 */
#if(0)
int etchremote_transport_notify  ($helper.getRemoteName($intf, $mc)* thisx, etch_event* evt)
{
    const int result = thisx->dsvc->itm->transport_notify(thisx->dsvc, evt);
    return result;
}
#endif


/**
 * etchremote_transport_query()
 * @param query caller relinquishes
 * @return 0 success, -1 failure.
 */
#if(0)
etch_object* etchremote_transport_query ($helper.getRemoteName($intf, $mc)* thisx, etch_object* query) 
{
    etch_object* resultobj = thisx->dsvc->itm->transport_query(thisx->dsvc, query);
    return resultobj;
}
#endif


/**
 * etchremote_start_waitup()
 * start the transport and wait for it to come up.
 * @param thisx this remote object.
 * @param waitms how long to wait, in milliseconds.
 * @return 0 success, -1 failure.
 */
#if(0)
int etchremote_start_waitup ($helper.getRemoteName($intf, $mc)* thisx, const int waitms)
{
    const int result = thisx->transport_control(thisx, 
        new_etch_event(CLASSID_CONTROL_START_WAITUP, waitms), NULL);

    return result;
}
#endif


/**
 * etchremote_stop_waitdown()
 * stop the transport and wait for it to go down.
 * @param thisx this remote object.
 * @param waitms how long to wait, in milliseconds.
 * @return 0 success, -1 failure.
 */
#if(0)
int etchremote_stop_waitdown ($helper.getRemoteName($intf, $mc)* thisx, const int waitms)
{
    const int result = thisx->transport_control(thisx, 
        new_etch_event(CLASSID_CONTROL_STOP_WAITDOWN, waitms), NULL);

    return result;
}
#endif
