#ifdef AIX_PROD
/* @(#)48    1.4  src/examples/pubsex/strtree/server.c, examples.src, os2dce21.dss, 960602a.1 1/11/96 10:39:17 */
/*
 *   COMPONENT_NAME: examples.src
 *
 *   FUNCTIONS: check_error
 *              main
 *
 *   ORIGINS: 72
 *
 */
#endif /* AIX_PROD */


#include <stdio.h>
#include <stdlib.h>
#include <dce/dce_error.h>
#include <string_tree.h>                  /* header created by idl compiler */
#define check_error(s, msg) if(s != rpc_s_ok) {fprintf(stderr, "s",msg); exit(1);}

main ()
{
  unsigned32              status;                 /* error status (nbase.h) */
  rpc_binding_vector_p_t  binding_vector; /* set of binding handles (rpc.h) */

  rpc_server_register_if(            /* register interface with RPC runtime */
    string_tree_v0_0_s_ifspec,   /* interface specification (string_tree.h) */
    NULL,
    NULL,
    &status                                                 /* error status */
  );
  check_error(status, "Can't register interface\n");

  rpc_server_use_all_protseqs(              /* establish protocol sequences */
    rpc_c_protseq_max_calls_default, /* concurrent calls server takes (rpc.h) */
    &status
  );
  check_error(status, "Can't establish protocol sequences\n");

  rpc_server_inq_bindings(      /* get set of this server's binding handles */
    &binding_vector,
    &status
  );
  check_error(status, "Can't get binding handles\n");

  rpc_ep_register(           /* register addresses in endpoint map database */
    string_tree_v0_0_s_ifspec,   /* interface specification (string_tree.h) */
    binding_vector,                   /* the set of binding handles         */
    NULL,
    NULL,
    &status
  );
  check_error(status, "Can't add address to the endpoint database\n");

  rpc_ns_binding_export(         /* establish name service database entry   */
    rpc_c_ns_syntax_dce,         /* syntax of the entry name (rpc.h)        */
    (unsigned_char_p_t)
    "/.:/servers/string_tree",   /* entry name in name service              */
    string_tree_v0_0_s_ifspec,   /* interface specification (string_tree.h) */
    binding_vector,              /* the set of binding handles              */
    NULL,
    &status
  );
  check_error(status, "Can't export to name service\n");

  rpc_binding_vector_free(                   /* free set of binding handles */
    &binding_vector,
    &status
  );
  check_error(status, "Can't free binding handles and vector\n");

  printf("Listening...\n");
  rpc_server_listen(                             /* listen for remote calls */
    rpc_c_listen_max_calls_default, /* concurrent calls server executes (rpc.h) */
    &status
  );
  check_error(status, "rpc listen failed\n");
  return (0);
}
