/* @(#)77    1.16  src/examples/type_mgr/client.c, examples.src, os2dce21.dss, 960602a.1 2/16/96 11:41:03 */
/*
 * 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      :  client.c                                            *
 *********************************************************************
 *                                                                   *
 *  Functions :  main()                                              *
 *                                                                   *
 *  Comments  :  RPC client application program.  This file serves   *
 *               as a skeleton that gives the client program a       *
 *               consistent look and feel.                           *
 *                                                                   *
 *********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#ifdef IBMOS2
# include <os2def.h>
#endif
#include <dce/rpc.h>
#include "cust_if.h"
#include "type_mgr.h"
#include <util.h>
#include "client.h"
#include <bind_util.h>

/*
 *  Status Messages.
 */

char *tm_msg[] =
{
"Success",
"Failure",
"No match",
"No more entries",
"Object already exists",
"Coding error",
"Object database created",
"Object database restarted",
"Object database initialization in progress",
"Object database unititialized"
};

/*
 *  Global variable used to identify the process.  It can be overridden
 *  by the -n <name> command line argument.
 */

char    g_prog_tag[PROG_TAG_LEN] = "CLIENT";

extern unsigned32 client_args (unsigned32 argc, char *argv[]);
extern unsigned32 client_calls (rpc_binding_handle_t *binding_h);

/*********************************************************************
 *   Function    :  main()                                           *
 *********************************************************************
 *                                                                   *
 *   Description :  Skeleton control of the client program.  Issues  *
 *                  calls to sub-routines that obtain a binding      *
 *                  handle, and make the RPC.                        *
 *                                                                   *
 *   Returns     :  (0) success, (1) failure                         *
 *                                                                   *
 *********************************************************************/

int main( unsigned32  argc,
                 char        *argv[] )
{
    unsigned32           status = 0;
    boolean32            done = FALSE;
    rpc_binding_handle_t binding_handle;
    binding_ctx_handle_t binding_context;

    /*
     *  Parse the command line arguments.  The main program does not
     *  deal with them.  See client_args.c for how cmd line args are used.
     */

    if (status = client_args( argc, argv ))
    {
        goto QUICK_EXIT;
    }

    /*
     *  Start the process of obtaining a binding handle.
     */

    if (status = get_binding_begin( g_object_entry,
                                    type_mgr_v1_0_c_ifspec,
                                    NULL,
                                    TRUE,
                                    NULL,
                                    &binding_context ))
    {
        goto CLEANUP;
    }

    /*
     *  We cycle thru the available binding handles, trying each one
     *  until either:  1) the RPC calls succeed, or 2) all of the
     *  binding handles have been tried.
     */

    while (!done)
    {
        if (status = get_binding_next( binding_context,
                       NULL,
                                       &binding_handle ))
        {
            goto CLEANUP;
        }

        if ((status = client_calls( &binding_handle )) == rpc_s_ok)
        {
            done = TRUE;
        }

        rpc_binding_free( &binding_handle,
                          &status );

        CHECK_STATUS( "rpc_binding_free()\n",
                      status,
                      RETURN );
    }

CLEANUP:

    /*
     *  Free up the binding context.
     */

    if (status = get_binding_done( &binding_context ))
    {
        /* ??? */
    }

QUICK_EXIT:

    if (status)
    {
        status = 1;
    }

    return( status );

} /* end main() */

/* EOF client.c */

