/******************************************************************************/
/*                                                                            */
/* "@(#)48        1.4  src/examples/ems/supplier.c, examples.src, os2dce21.dss, 960602a.1  3/1/96  16:01:47"                                         */
/*                                                                            */
/* SAMPLE SUPPLIER: supplier.c                                                */
/*                                                                            */
/* COPYRIGHT:                                                                 */
/* ----------                                                                 */
/* Copyright (C) International Business Machines Corp., 1995.                 */
/*                                                                            */
/* DISCLAIMER OF WARRANTIES:                                                  */
/* -------------------------                                                  */
/* The following [enclosed] code is sample code created by IBM                */
/* Corporation.  This sample code is not part of any standard IBM product     */
/* and is provided to you solely for the purpose of assisting you in the      */
/* development of your applications.  The code is provided "AS IS",           */
/* without warranty of any kind.  IBM shall not be liable for any damages     */
/* arising out of your use of the sample code, even if they have been         */
/* advised of the possibility of such damages.                                */
/*                                                                            */
/******************************************************************************/
/*                                                                            */
/*  Sample to demonstrate an Event Management Service supplier for the        */
/*  sample consumer code... see consumer.c...                                 */
/*                                                                            */
/******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dce/dce.h>
#include <dce/pthread.h>
#include <dce/dce_msg.h>
#include <dce/dcefree.h>
#include <dce/ems.h>
#include <dce/dcesvcmsg.h>
#include <dce/dce_cf.h>
#include "dcesupmsg.h"
#include "dcesupsvc.h"
#include "dcesupmac.h"

dce_svc_handle_t sup_svc_handle;

#define COMP_NAME  "sup"

DCE_SVC_DEFINE_HANDLE( sup_svc_handle, sup_svc_table, COMP_NAME);


int main( int argc, char *argv[] )
{
   unsigned32 status;
   int        i;
   char      *hostname = NULL;
   int        nMessages=1;


   sup_svc_handle=dce_svc_register(sup_svc_table,(const idl_char*)"sup",&status);
   if (status)
   {
      printf("*** ERROR: dce_svc_register failed!\n");
      exit(1);
   }


/* parse input parameters */
   printf("Arg count = %d\n",argc);
   if (argc>3)
   {
      printf("***ERROR: Too many arguments specified!\n");
      printf("   %s [-n <nMessages>]   (n=1 if not specified)\n", argv[0]);
      exit(1);
   }

   if (argc==3)
   {
      if (strcmp(argv[1], "-n") == 0)
         nMessages = atoi(argv[2]);
      else
      {
         printf("***ERROR: Arguments (%s %s) not recognized!\n",argv[1],argv[2]);
         printf("   %s [-n <nMessages>]   (n=1 if not specified)\n", argv[0]);
         exit(1);
      }
   }
   else
      printf("Assuming: %s -n 1\n", argv[0]);


   dce_cf_get_host_name(&hostname, &status);
   if (status)
   {
      printf("*** ERROR: dce_cf_get_host_name failed!\n");
      exit(1);
   }

   dce_svc_set_progname("Sample Supplier", &status);
   if (status)
   {
      dce_free(hostname);
      printf("dce_svc_set_progname failed\n");
      exit(1);
   }

/* The sample supplier will issue the following 5 events for the specified  */
/*   message severities.  The user of this code is responsible for setting  */
/*   up the event filtering to enable EMS to receive the events.  This      */
/*   can be done by setting the following environment variables for this    */
/*   session.                                                               */
/*                                                                          */
/*         set SVC_FATAL=EMS:-;STDERR:-;                                    */
/*         set SVC_ERROR=EMS:-;STDERR:-;                                    */
/*         set SVC_WARNING=EMS:-;STDERR:-;                                  */
/*         set SVC_NOTICE=EMS:-;STDERR:-;                                   */
/*         set SVC_NOTICE_VERBOSE=EMS:-;STDERR:-;                           */
/*                                                                          */
/*   You can also refer to the DCE EMS online documentation for other ways  */
/*   of accomplishing this.                                                 */
/*                                                                          */

   for (i=0; i<nMessages; i++)
   {
   /* FATAL message i from hostname          */
      dce_svc_printf(SUP_S_TEST_FATAL_MSG,i,hostname);

   /* ERROR message i from hostname          */
      dce_svc_printf(SUP_S_TEST_ERROR_MSG,i,hostname);

   /* WARNING message i from hostname        */
      dce_svc_printf(SUP_S_TEST_WARNING_MSG,i,hostname);

   /* NOTICE message i from hostname         */
      dce_svc_printf(SUP_S_TEST_NOTICE_MSG,i,hostname);

   /* NOTICE_VERBOSE message i from hostname */
      dce_svc_printf(SUP_S_TEST_VERBOSE_MSG,i,hostname);
   }

   dce_free(hostname);
   return (0);
}
