/*
 *
 * 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_impl.h"
#include "helloworld_valufact.h"
#include "etch_url.h"
#include "etch_arrayval.h"
#include "etch_binary_tdo.h"
#include "etch_exception.h"
#include "etch_general.h"
#include "etch_log.h"
#include "etch_map.h"
#include <stdio.h>

unsigned short CLASSID_HELLOWORLD_SERVER_IMPL;


char* HELLOWORLD_ETCHSIMP = "SIMP";

/* generated signatures */
int destroy_helloworld_server_implx(void*);
helloworld_server_impl* init_helloworld_server_impl(struct helloworld_remote_client*, etch_object_destructor);


/* - - - - - - - -    
 * instantiation
 * - - - - - - - -   
 */
etch_string* say_hello_impl(void* thisx, helloworld_user* to_whom);


/**
 * new_helloworld_server_impl()
 * helloworld_server_impl constructor.
 * add your custom initialization and virtual method overrides here.
 */
helloworld_server_impl* new_helloworld_server_impl(struct helloworld_remote_client* client) 
{
    helloworld_server_impl* pserver  /* allocate object and assign default virtuals */
        = init_helloworld_server_impl(client, destroy_helloworld_server_implx);	
    i_helloworld_server* pserver_base = pserver->helloworld_server_base;
    ((etch_object*)pserver_base)->class_id = get_dynamic_classid_unique(&CLASSID_HELLOWORLD_SERVER_IMPL);

    etchmap_insertxw(pserver_base->virtuals, helloworld_valufact_get_static()->str_helloworld_say_hello, say_hello_impl, FALSE);
    
    return pserver;
}


/**
 * destroy_helloworld_server_implx()
 * destructor for any user allocated memory.
 * this code is invoked by the private perf_client_impl destructor,
 * via perf_client.destroyex(). add code here to destroy any memory you  
 * may have allocated for your custom perf_client implementation.
 */
int destroy_helloworld_server_implx(void* data)
{
    /*
      helloworld_server_impl* thisx = (helloworld_server_impl*)data;
     */
    return 0;
}

/* - - - - - - - - - - - - - - - - - - -
 * session interface method overrides
 * - - - - - - - - - - - - - - - - - - -
 */

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 * implementations of helloworld_server messages from server, if any 
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 */
 
etch_string* say_hello_impl(void* thisx, helloworld_user* to_whom){
  int len = (6 + wcslen(to_whom->name->v.valw) + 1);
  wchar_t* retw = (wchar_t*) malloc(len * sizeof(wchar_t));
  etch_string* ret = NULL;
  etch_snwprintf(retw, len, L"Hello %S\n", to_whom->name->v.valw);
  ret = new_stringw(retw);
  etch_object_destroy(to_whom);
  free(retw);
  return ret;
}
