/* @(#)68    1.9  src/examples/common/util.h, examples.src, os2dce21.dss, 960602a.1 2/14/96 13:16:07 */
/*
 * 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      :  util.h                                             *
 *********************************************************************
 *                                                                   *
 *  Functions :                                                      *
 *                                                                   *
 *  Comments  :  Common macros and declarations for use in           *
 *               developing client/server testcases.                 *
 *                                                                   *
 *********************************************************************/

#if defined (IBMOS2) && defined (INCL_PM)

#ifdef __BORLANDC__
#ifndef OS2_INCLUDED
#include <os2.h>
#endif
#include "dce_error.h"
#else
#include <os2.h>
#endif

extern HWND main_hwnd ;
#else
#include "dce_error.h"
#endif

#ifndef EXC_HANDLING
#include <dce/pthread_exc.h>
#endif

extern void print_exception (EXCEPTION *e);
extern unsigned32 get_local_host_net_addrs( int  *count, char addrstrv[20][16] );

/*
 *  String tag used to identify client and server output information.
 */

#define PROG_TAG_LEN  10
extern char    g_prog_tag[];

/*
 *  Macro used to prefix the process name to all output going to
 *  standard output.
 */

#define PRINT fflush(stdout); printf("%s:  ", g_prog_tag); printf

/*
 *  A very simple trace mechanism.  It only takes a string (no args).
 */

extern boolean32  g_trace;

#define TRACE(_str) \
    if( g_trace ) { \
        printf("%s:  ", g_prog_tag); \
        printf("%s",(_str)); \
        fflush(stdout); \
    }

/*
 *  Conditionally compiled macro that calls utility routine to
 *  print out the fields of a binding handle in string format.
 */

#ifdef _TM_DEBUG
#define PRINT_BINDING_HANDLE( _bh ) print_binding_handle( (_bh) );
#else
#define PRINT_BINDING_HANDLE( _bh )
#endif

/*
 *  Tags used to determine the action that the CHECK_STATUS macro
 *  should take when encountering an error in an RPC runtime routine.
 */

#define CONTINUE 0
#define RETURN   1
#define EXIT     2

/*
 *  Macro used to inspect the return code of an RPC runtime call,
 *  or any other DCE runtime call.
 */

#if defined (IBMOS2) && defined (INCL_PM)
#ifdef DEFINE_VARS
char unsigned _error_text[260];
char _tmp_buf[20];
int _rc;
#else
extern unsigned char _error_text[260];
extern char _tmp_buf[20];
extern int _rc;
#endif

/*             return(_val); \ */

#define CHECK_STATUS( _str, _val, _action ) \
{ \
    if ((_val)) { \
    strcpy((_error_text), _str) ; \
    strcat((_error_text), "\n"); \
        sprintf((_tmp_buf), "Error Code: %d\n", (_val)); \
    strcat((_error_text), (_tmp_buf)); \
        dce_error_inq_text( (_val), (_tmp_buf), &(_rc) ); \
        if ( (_rc) != 1 ) { \
          strcat((_error_text), "Error String:  ") ; \
      strcat((_error_text), (_tmp_buf)); \
        } \
    WinMessageBox(HWND_DESKTOP, main_hwnd, _error_text, "Error!", 0, MB_OK); \
        if ((_action) == RETURN) \
        { \
        } \
        if ((_action) == EXIT) \
        { \
            exit(1); \
        } \
        else if ((_action) != CONTINUE) \
        { \
            PRINT("Invalid CHECK_STATUS action!\n"); \
        } \
    } \
}

#else
#define CHECK_STATUS( _str, _val, _action ) \
{ \
    unsigned char _error_text[80]; \
    int _rc; \
    if ((_val)) { \
        PRINT(_str); \
        PRINT("Error Code: %d\n", (_val)); \
        dce_error_inq_text( (_val), (_error_text), &(_rc) ); \
        if ( (_rc) != 1 ) { \
            PRINT("Error String:  %s\n", (_error_text)); \
        } \
        switch (_action) \
        { \
           case RETURN: \
            return(_val); \
           case EXIT: \
            exit(1); \
           case CONTINUE: \
            break;\
           default:\
            PRINT("Invalid CHECK_STATUS action!\n"); \
            break;\
        } \
    } \
}
#endif
/*
 *  Generic macros.
 */

#ifndef max
#define  max(x,y)  ((x) > (y) ? (x) : (y))
#endif

/* EOF util.h */



