home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / sysmgt / ffst / probe / probe.c next >
Text File  |  1999-05-11  |  13KB  |  251 lines

  1. /***************************************************************************/
  2. /* probe.c: FFSTProbe sample                                              */
  3. /*                                                                        */
  4. /* This test program gives an example of using the FFSTProbe API via a      */
  5. /* 'wrapper' function. The dummy api, My_Dummy_Api returns a return code */
  6. /* which is then used as the basis of firing a FFSTProbe via the wrapper      */
  7. /* function, callFFST. callFFST can be modified to include more or less         */
  8. /* passed in data as needed.                                              */
  9. /**************************************************************************/
  10.  
  11. #define INCL_DOS
  12. #define INCL_DOSMEMMGR
  13. #define INCL_DOSPROCESS
  14. #define INCL_FFST
  15. #define NO_ERROR 0
  16.  
  17. #include <os2.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ffst.h>
  22.  
  23. /**************************************************************************/
  24. /* Define probe ID for FFSTProbe called when dummy api fails.                           */ 
  25. /* Probe ID is the unique identifier you use later to find the source of the failure   */
  26. /* It should be unique within a DMI triplet (explained later) or within your product */
  27. /**************************************************************************/
  28. #define DUMMY_API_PROBE                  22222
  29.  
  30. /**************************************************************************/
  31. /* callFFST is the FFSTProbe wrapper function. It allows you to code the           */
  32. /* FFSTProbe API once with data that is static as far as your usage is concerned */
  33. /* and allows you to pass in dynamic data.   It also helps insulate your code if you    */
  34. /* decide to change your 'static' options                                         */
  35. /**************************************************************************/
  36.  
  37. void callFFST ( ULONG input_version,        /* FFST 'Wrapper' Function */
  38.                 ULONG input_probe_flags,        /* FFSTProbe probe flags */
  39.                 ULONG input_severity,             /* FFSTProbe severity */
  40.                 ULONG input_probe_id,            /* FFSTProbe ID */
  41.                 CHAR* input_module_name,     /* module name passed to probe */
  42.                 ULONG input_log_data_length,  /* log data length for the system error log */
  43.                 PVOID input_pError_log_data,   /* pointer to the data for system error log */
  44.                 int   argc)
  45. {
  46.    APIRET  rc = 0;
  47.    PVOID   pvar_n0;
  48.    ULONG   pvar_n1;
  49.  
  50.    /***********************************************************************/
  51.    /* FFSTProbe API structures.    Described in the API Guide                                      */
  52.    /***********************************************************************/
  53.    FFSTPARMS     FFSTParms;
  54.    PRODUCTINFO   productInfo;
  55.    PRODUCTDATA   productData;
  56.    DMIDATA       DMIData;
  57.    DUMPUSERDATA  dumpUserData;
  58.    MSGINSDATA    msgInsData;
  59.  
  60.    /***********************************************************************/
  61.    /* The PRODUCTDATA structure defines the DMI triplet which allows      */
  62.    /* additional product information, including template repository         */
  63.    /* filename, to be retrieved from DMI.   DMI is a industry standare for desktop mgt  */
  64.    /***********************************************************************/
  65.    productData.packet_size            = sizeof ( productData );
  66.    productData.packet_revision_number = PRODUCTDATA_ASCII; /* data can be ASCII or UNI*/
  67.    productData.DMI_tag                = "FFSTProbe Sample";  /*Customize for your program*/
  68.    productData.DMI_vendor_tag         = "IBM";                   /*Customize for your company*/ 
  69.    productData.DMI_revision           = "1.00";                     /* Customize  */
  70.  
  71.    /**************************************************************************/
  72.    /* The DMIDATA structure below is the information which can either be     */
  73.    /* retrieved by DMI or passed in by the FFSTProbe function. The preferred */
  74.    /* method is to use DMI. In the example below, you can see the use of     */
  75.    /* either depending on whether or not a parm was passed on call to this program */
  76.    /**************************************************************************/
  77.  
  78.    if ( !(argc>1) )
  79.    {
  80.       /********************************************************************/
  81.       /* Setting this structure to NULL indicates that the information is */
  82.       /* to be retrieved from DMI using the DMI triplet as defined in the */
  83.       /* productData structure.  This is the preferred method.           */
  84.       /* Other files in this example show how to build your own DMI  */
  85.       /********************************************************************/
  86.       productInfo.pDMIData = NULL;
  87.  
  88.       /*********************************************************************/
  89.       /* Note: This shows the usage of message insert text and is NOT part */
  90.       /* of the information that could or could not be retrieved from DMI  */
  91.       /* This is included as an example of MsgInsTxt and how it can be used to send */
  92.       /* probe specific data to the SYSLOG (System Error Log)  */
  93.       /*********************************************************************/
  94.       msgInsData.MsgInsTxt[0].insert_number = 1;
  95.       msgInsData.MsgInsTxt[0].insert_text   = "We did use a DMI component";
  96.    }
  97.    else
  98.     {
  99.       /********************************************************************/
  100.       /* fill the DMI data structure - useful only in test environments   */
  101.       /********************************************************************/
  102.       DMIData.packet_size              = sizeof ( DMIData );
  103.       DMIData.packet_revision_number   = DMIDATA_ASCII;    /*could be unicode instead */
  104.       DMIData.DMI_product_ID           = "FFST_toolkt_sample"; /*note this is different than tag */
  105.       DMIData.DMI_modification_level   = "000000";
  106.       DMIData.DMI_fix_level            = "010101";
  107.       DMIData.template_filename        = "PROBE.REP";  /* this file must be on the DPATH */
  108.       DMIData.template_filename_length = strlen ( DMIData.template_filename )
  109.                                                 * sizeof ( char );  /* since ascii is being used */
  110.       productInfo.pDMIData             = &DMIData;
  111.  
  112.       /********************************************************************/
  113.       /* Note: This shows the usage of message insert text and is NOT a   */
  114.       /* of the information that could or could not be retrieved from DMI */
  115.       /********************************************************************/
  116.       msgInsData.MsgInsTxt[0].insert_number = 1;
  117.       msgInsData.MsgInsTxt[0].insert_text   = "We did not use a DMI component";
  118.     }
  119.  
  120.    /***********************************************************************/
  121.    /* set the pointers up for PRODUCTINFO                                 */
  122.    /***********************************************************************/
  123.  
  124.    productInfo.pProductData = &productData;   /* This points to the DMI related data */
  125.  
  126.    /***********************************************************************/
  127.    /* set up some DUMPUSERDATA items                                      */
  128.    /***********************************************************************/
  129.    pvar_n0 = "Kilroy was here";        /* Anything can be dumped here, up to 30K bytes */
  130.    pvar_n1 = 2;
  131.    dumpUserData.no_of_variables = 2;
  132.    dumpUserData.DumpDataVar[0].var_n_length = strlen("Kilroy was here");
  133.    dumpUserData.DumpDataVar[0].var_n        = pvar_n0;
  134.    dumpUserData.DumpDataVar[1].var_n_length = sizeof(ULONG);
  135.    dumpUserData.DumpDataVar[1].var_n        = (PVOID)(&pvar_n1);
  136.  
  137.    /***********************************************************************/
  138.    /* set up a couple of MSGINSDATA messages- just to show it can be done */
  139.    /***********************************************************************/
  140.    msgInsData.no_inserts   = 2;
  141.    msgInsData.MsgInsTxt[1].insert_number = 2;
  142.    msgInsData.MsgInsTxt[1].insert_text   = "Message insert variable 2";
  143.  
  144.    /***********************************************************************/
  145.    /* set the FFSTPARMS structure, most values from DEFINEs above.  See API GUIDE */
  146.    /* for details on each field and their possible values      */
  147.    /***********************************************************************/
  148.    FFSTParms.packet_size            = sizeof ( FFSTParms );
  149.    FFSTParms.packet_revision_number = FFSTPARMS_OS2_ASCII; /* ASCI vs UNICODE data*/
  150.    FFSTParms.module_name            = input_module_name;
  151.    FFSTParms.probe_ID               = input_probe_id;
  152.    FFSTParms.severity               = input_severity;      
  153.    FFSTParms.template_record_ID     = input_probe_id;
  154.    FFSTParms.pMsgInsData            = &msgInsData;           
  155.    FFSTParms.probe_flags            = input_probe_flags;
  156.    FFSTParms.pDumpUserData          = &dumpUserData;  /* dump data is stored in .DMP files*/
  157.    FFSTParms.log_user_data_length   = input_log_data_length;
  158.    FFSTParms.log_user_data          = input_pError_log_data;  /* log data is stored as part of the SYSLOG entry */
  159.  
  160.    /***********************************************************************/
  161.    /* Call the FFSProbe API                                               */
  162.    /***********************************************************************/
  163.    if ( input_version == 1)
  164.    {
  165.       rc = FFSTProbe ( &productInfo, &FFSTParms);
  166.    }
  167.  
  168.    printf("\n----- Fired the FFSTProbe, rc=%d\n",rc); /* for example only, do not do this in customer level code*/
  169.  
  170. }
  171.  
  172. /**************************************************************************/
  173. /*  This is the dummy  API for use in the example.  It can easily set non-zero rc's         */
  174. /**************************************************************************/
  175.  
  176. ULONG My_Dummy_API ( ULONG Mydata )
  177. {
  178.    if ( Mydata != 123456 )
  179.    {
  180.       return 1;
  181.    }
  182.    else
  183.    {
  184.       return 0;
  185.    }
  186. }
  187.  
  188. /**************************************************************************/
  189. /*                                                                        */
  190. /*  Main Application (this uses the callFFST wrapper function).           */
  191. /*                                                                        */
  192. /**************************************************************************/
  193.  
  194. int main ( int argc, char * argv[], char * envp  )
  195. {
  196.    ULONG  rc          = 0;
  197.    ULONG  Mydata      = 2;
  198.    ULONG  userDataLen = 0;
  199.    PVOID  pUserData   = NULL;
  200.  
  201.    system("cls");
  202.    printf ( "\n\n\nStarting FFSTProbe Sample\n" );
  203.  
  204.    /***********************************************************************/
  205.    /* call the 'dummy'  API so it returns a non-zero rc                                               */
  206.    /***********************************************************************/
  207.    rc = My_Dummy_API ( Mydata );
  208.    if ( rc != NO_ERROR )
  209.    {
  210.       /********************************************************************/
  211.       /* The API has failed. Setup the userData to contain the failing rc */
  212.       /********************************************************************/
  213.       pUserData = calloc ( 2, sizeof ( ULONG ) );
  214.       memcpy ( pUserData, &rc, sizeof ( ULONG ) );
  215.       memcpy ( ( PBYTE ) pUserData + sizeof ( ULONG )
  216.              , &Mydata, sizeof ( ULONG ) );
  217.  
  218.  
  219.       /********************************************************************/
  220.       /* Call the FFSTProbe wrapper function with a version of 1,       */
  221.       /* Have ffst post the process status and enviroment variables in the syslog, */
  222.       /* a severity of 4, a probe id of DUMMY_API_PROBE which was previously*/
  223.       /* defined as 22222, a the logUserData equal to the failing rc (1) as   */
  224.       /* setup above. Argc is passed in to determine whether or not data  */
  225.       /* should be retrieved from DMI.                                    */
  226.       /********************************************************************/
  227.       callFFST ( 1
  228.                , PSTAT_FLAG | PROC_ENV_FLAG
  229.                , SEVERITY4
  230.                , DUMMY_API_PROBE
  231.                , "my_module_1"
  232.                , 2 * sizeof ( ULONG )
  233.                , pUserData
  234.                , argc );
  235.    }
  236.  
  237.    if (pUserData != NULL) {free(pUserData); pUserData = NULL;}
  238.  
  239.    if (argc > 1)
  240.    {
  241.       printf("\nFFSTProbe sample ended not using DMI component:\n\n\n");
  242.    }
  243.    else
  244.    {
  245.       printf("\nFFSTProbe sample ended using DMI component:\n\n\n");
  246.    }
  247.  
  248.    return 0;
  249. }
  250.  
  251.