/* @(#)87    1.15  src/examples/type_mgr/server_type1_ops.c, examples.src, os2dce21.dss, 960602a.1 1/12/96 14:30:59 */
/*
 * COMPONENT_NAME:  examples.src
 *
 * FUNCTIONS:
 *
 * ORIGINS: 27
 *
 * (C) COPYRIGHT International Business Machines Corp. 1992, 1994
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 */

/*********************************************************************
 *  File      :  server_type1_ops.c                                  *
 *********************************************************************
 *                                                                   *
 *  Functions :  RPC routines defined in idl file.                   *
 *                                                                   *
 *  Comments  :  The routines in this file correspond to the RPC     *
 *               interface defined in the idl file for this client/  *
 *               server testcase.                                    *
 *                                                                   *
 *********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <dce/dce_error.h>
#include "cust_if.h"
#include "type_mgr.h"
#include "util.h"

extern char g_server_ns_entry[];

/*
 *  In this example program, types are identified by names, rather
 *  than their assigned uuid.  This simplifies object administration.
 */

const char  g_type1_name[] = TYPE1_NAME;

/*
 *  Each type uuid corresponds 1:1 with a set of manager routines for
 *  objects of that type.  The type uuid is used strictly within
 *  rpc runtime to route rpc calls that act on objects of that type
 *  to the appropriate manager routines (via a manager entry point
 *  vector - mepv).
 *
 *  Since the type uuid, in essence, represents the manager routines, the
 *  type uuid string can be created when the manager routines are
 *  written and declared as constant data.
 *
 *  Manager versioning is taken care of by the version component of the
 *  interface specification.  Although the type uuid may be changed for
 *  a new version of the manager routines, this is not strictly necessary.
 *  The rpc calls to act on an object will be routed to a manager based
 *  on: first the interface specification (including the version component);
 *  and then the type the object (uuid specified in the call) was
 *  associated with in rpc runtime.  What is significant is the
 *  interface specification the object is exported to the namespace
 *  and registered in the endpoint mapper with.
 */

const char         g_type1_uuid_str[] = "006588E4-4072-1AD7-9B34-10005AA8889C";


/*********************************************************************
 *   Function    :  rpc_type1_op_A()                                 *
 *********************************************************************
 *                                                                   *
 *   Description :  Sample routine for the first operation declared  *
 *                 in the idl file for type type1.                   *
 *                                                                   *
 *   Returns     :  the communication error                          *
 *                                                                   *
 *********************************************************************/

error_status_t rpc_type1_op_A( handle_t  h,
                            idl_char *server_name,
                          idl_char  *server_msg )
{

    strcpy( server_name, g_server_ns_entry );
    strcpy( server_msg, "TYPE MANAGER NO. 1 : type_mgr_op_A()" );

    return rpc_s_ok;
}


/*********************************************************************
 *   Function    :  rpc_type1_op_B()                                 *
 *********************************************************************
 *                                                                   *
 *   Description :  Sample routine for the second operation declared *
 *                 in the idl file for type type1.                   *
 *                                                                   *
 *   Returns     :  the communication error                          *
 *                                                                   *
 *********************************************************************/

error_status_t rpc_type1_op_B( handle_t  h,
                          idl_char  *client_uuid,
                          idl_char  *server_msg )
{
    error_status_t    status;
    uuid_t            o_uuid;
    char              *uuid_str;

    strcpy(server_msg,"TYPE MANAGER NO. 1 : type_mgr_op_B()");

    /*
     * get the client's object uuid from the binding handle.
     */

    rpc_binding_inq_object( h,
                            &o_uuid,
                            &status );

    CHECK_STATUS( "MANAGER Error: Can't get the object uuid.\n",
                  status,
                  RETURN );

    uuid_to_string( &o_uuid,
                    &uuid_str,
                    &status );

    CHECK_STATUS( "MANAGER Error: Can't convert_uuid to str.\n",
                  status,
                  RETURN );

    strcpy(client_uuid, uuid_str);

    rpc_string_free( &uuid_str,
                     &status );

    return rpc_s_ok;
}


/*********************************************************************
 *   Function    :  rpc_type1_op_C()                                 *
 *********************************************************************
 *                                                                   *
 *   Description :  Sample routine for the third operation declared  *
 *                 in the idl file for type type1.                   *
 *                                                                   *
 *   Returns     :  the communication error                          *
 *                                                                   *
 *********************************************************************/

error_status_t rpc_type1_op_C( handle_t  h,
                               uuid_t    *client_uuid,
                               idl_char  *server_msg )
{
    error_status_t    status;

    strcpy(server_msg,"TYPE MANAGER NO. 1 : type_mgr_op_C()");

    /*
     * get the client's object uuid from the binding handle.
     */

    rpc_binding_inq_object( h,
                            client_uuid,
                            &status );

    CHECK_STATUS( "MANAGER Error: Can't get the object uuid.\n",
                  status,
                  RETURN );

    return rpc_s_ok;
}

/*
 *  Entry point vector for TYPE1.  See the idl generated .h file
 *  for details of the type declaration.
 */

globaldef type_mgr_v1_0_epv_t  type1_v1_0_manager_epv =
{
    rpc_type1_op_A,
    rpc_type1_op_B,
    rpc_type1_op_C
};

/* EOF server_type1_ops.c */

