home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Collection - Online Library - January 1996 / CKITOS2196.ISO / diskette / gg244090.dsk / unc.dsk / CHAPTER.10 / DB_CLI.C < prev    next >
C/C++ Source or Header  |  1993-10-28  |  3KB  |  93 lines

  1. /*****************************************************************************/
  2. /* Module: database_client.c                                                 */
  3. /*                                                                           */
  4. /* Description:                                                              */
  5. /*    This module obtains and sets the binding information registered in     */
  6. /*    the name service. After setting the binding handle, this module calls  */
  7. /*    the database_access() that provides an online interface allowing you   */
  8. /*    to access the database managed by the database_server.exe.             */
  9. /*                                                                           */
  10. /*****************************************************************************/
  11. #include "db.h"
  12. #include "errorchk.h"
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <pthread_exc.h>
  16.  
  17. void database_access( db_context_t );
  18.  
  19. #define MAX_CALL_REQUESTS 3
  20.  
  21. int main( int argc, char *argv[] )
  22. {
  23.    unsigned32 st;
  24.    rpc_ns_handle_t       import_context;
  25.    rpc_binding_handle_t  binding_h;
  26.    db_context_t          context_h;
  27.  
  28.    sigset_t              sigset;
  29.    pthread_t             this_thread = pthread_self();
  30.  
  31. #ifdef IBMOS2
  32.    pthread_inst_exception_handler();
  33. #endif
  34.  
  35.    rpc_ns_binding_import_begin(
  36.       rpc_c_ns_syntax_default,         /* use default syntax                 */
  37.       ENTRY_NAME,                      /* defined in IDL file                */
  38.       Database_v1_0_c_ifspec,          /* ifspec generated by IDL compiler   */
  39.       NULL,                            /* not working with object UUID       */
  40.       &import_context,                 /* import context obtained            */
  41.       &st );
  42.    ERRORCK( "rpc_ss_binding_import_begin", st );
  43.  
  44.    while ( 1 ) {
  45.       rpc_ns_binding_import_next(
  46.          import_context,
  47.          &binding_h,
  48.          &st);
  49.       ERRORCK( "rpc_ss_binding_import_next", st );
  50.  
  51.       if ( binding_h == NULL ) exit( 1 );
  52.  
  53.       db_open( binding_h, &context_h, &st );
  54.                                        /* Obtain the context handle          */
  55.       if ( st == rpc_s_ok )
  56.          break;
  57.       else
  58.          rpc_binding_free( &binding_h, &st );
  59.    }
  60.  
  61.    sigemptyset ( &sigset );
  62.    sigaddset ( &sigset, SIGINT );
  63.    sigaddset ( &sigset, SIGTERM );
  64.    pthread_signal_to_cancel_np ( &sigset, &this_thread );
  65.  
  66.    TRY
  67.       if ( context_h != NULL ) {
  68.          printf( "Context handle: %08X\n\n", context_h );
  69.          database_access( context_h );
  70.       } else
  71.          printf( "   <Error: %d>\n", st );
  72.    FINALLY
  73.       db_close( &context_h, &st );
  74.       do {
  75.          rpc_binding_free( &binding_h, &st );
  76.          rpc_ns_binding_import_next(
  77.             import_context,            /* using this import context,         */
  78.             &binding_h,                /* import the first binding handle    */
  79.             &st);
  80.       } while( binding_h != NULL && st == rpc_s_ok );
  81.  
  82.       rpc_ns_binding_import_done(
  83.          &import_context,              /* free the import context            */
  84.          &st );
  85.  
  86. #ifdef IBMOS2
  87.       pthread_dinst_exception_handler();
  88. #endif
  89.       exit( 0 );
  90.    ENDTRY
  91. }
  92.  
  93.