/*
 *
 * 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!
/*
 * helloworld_client_main.c
 */
 
#include "helloworld_client_main.h"
#include "etch_objecttypes.h"
#include "etch_runtime.h"
#include "etch_arrayval.h"
#include "etch_nativearray.h"
#include "etch_binary_tdo.h"
#include "etch_general.h"


/**
 * new_helloworld_client().
 * callback constructor for client implementation object.
 * this callback address is passed to start_helloworld_client() in [main].
 * @param server the remote server. 
 * @remarks this callback must be supplied, i.e. its functionality cannot be 
 * defaulted, since the client implementation constructor new_helloworld_client_impl()
 * is not known to start_helloworld_client().
 */
static i_helloworld_client* helloworld_client_create(void* factory_thisx, helloworld_remote_server* server)
{
    helloworld_client_impl* client = new_helloworld_client_impl(server);
    return client? client->helloworld_client_base:NULL;
}

/**
 * main()
 */
int main(int argc, char* argv[])
{
    etch_status_t etch_status    = ETCH_SUCCESS;
    helloworld_remote_server* remote = NULL;
    int result = -1, is_waitkey  = TRUE, waitupms = 4000;
    helloworld_user* user = new_helloworld_user();
    etch_string* answer = NULL;
    
    wchar_t* uri = L"tcp://127.0.0.1:4004";	
	
    etch_config_t* config = NULL;
    etch_config_create(&config);
    // set properties or read file

    etch_status = etch_runtime_initialize(config);
    if(etch_status != ETCH_SUCCESS) {
        // error
        return 1;
    }

    etch_status = helloworld_helper_remote_server_create(&remote, uri, NULL, helloworld_client_create);
    if(etch_status != ETCH_SUCCESS) {
        // error
    }

    etch_status = helloworld_helper_remote_server_start_wait(remote, waitupms);
    if(etch_status != ETCH_SUCCESS) {
        // error
    }
	
	//add your implementation here
    
    user->name = new_stringw(L"Testuser");
    answer = remote->say_hello(remote,user);
    if(answer && ! is_etch_exception(answer)){
        wprintf(L"Server said: %s\n", answer->v.valw);
    }else{
        wprintf(L"Remote call failed, is the server running?\n");
    }

    // wait until key press
    waitkey();

    etch_status = helloworld_helper_remote_server_stop_wait(remote, waitupms);
    if(etch_status != ETCH_SUCCESS) {
        // error
    }

    etch_status = helloworld_helper_remote_server_destroy(remote);
    if(etch_status != ETCH_SUCCESS) {
        // error
    }
	etch_config_destroy(config);
	return 0;
}
  
