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

  1. /**********************************************************************
  2.     Filename: names.c
  3.  
  4.     Copyright (c) 1993 - 1994, International Business Machines, Corporation. All rights reserved.
  5.  
  6.     Description: Example of an OS/2 Runtime component built using the
  7.                  component skeleton code. (ciskel.c)  Under OS/2 a
  8.                  runtime component is a DLL.
  9.  
  10. ************************* INCLUDES ***********************************/
  11.  
  12. #include "dmiapi.h"
  13.  
  14. /************************ PUBLICS ************************************/
  15. /* Get the specified attribute. */
  16. DmiCiAttribute_t * DMI_FUNC_ENTRY CiGetAttribute(DMI_UNSIGNED componentId,
  17.                                    DMI_UNSIGNED groupId,
  18.                                    DMI_UNSIGNED attributeId,
  19.                                    DMI_UNSIGNED keyCount,
  20.                                    DmiCiAttribute_t const _FAR *const keyList);
  21.  
  22. /* Get the attribute with the same ID, but one row further within the table. */
  23. DmiCiAttribute_t * DMI_FUNC_ENTRY CiGetNextAttribute(DMI_UNSIGNED componentId,
  24.                                     DMI_UNSIGNED groupId,
  25.                                     DMI_UNSIGNED attributeId,
  26.                                     DMI_UNSIGNED keyCount,
  27.                                     DmiCiAttribute_t const _FAR *const keyList);
  28.  
  29. /* Release the specified attribute. */
  30. enum CiBoolean DMI_FUNC_ENTRY CiReleaseAttribute(DMI_UNSIGNED componentId,
  31.                                     DMI_UNSIGNED groupId,
  32.                                     DMI_UNSIGNED attributeId,
  33.                                     DMI_UNSIGNED keyCount,
  34.                                     DmiCiAttribute_t const _FAR *const keyList,
  35.                                     void const _FAR *const attributeValue);
  36.  
  37. /* Reserve the specified attribute. */
  38. enum CiBoolean DMI_FUNC_ENTRY CiReserveAttribute(DMI_UNSIGNED componentId,
  39.                                     DMI_UNSIGNED groupId,
  40.                                     DMI_UNSIGNED attributeId,
  41.                                     DMI_UNSIGNED keyCount,
  42.                                     DmiCiAttribute_t const _FAR *const keyList,
  43.                                     void const _FAR *const attributeValue);
  44.  
  45. /* Set the specified attribute. */
  46. enum CiBoolean DMI_FUNC_ENTRY CiSetAttribute(DMI_UNSIGNED componentId,
  47.                                    DMI_UNSIGNED groupId,
  48.                                    DMI_UNSIGNED attributeId,
  49.                                    DMI_UNSIGNED keyCount,
  50.                                    DmiCiAttribute_t const _FAR *const keyList,
  51.                                    void const _FAR *const attributeValue);
  52.  
  53. /*********************************************************************/
  54.  
  55. /************************ DEFINES ************************************/
  56.  
  57. /*
  58.     CI_MAX_KEY_COUNT is used to reserve space within the CI skeleton for
  59.     building key lists.  If the instrumentation code is supporting a component
  60.     that has keyed groups, then CI_MAX_KEY_COUNT should be set to the number
  61.     of keys in the group that has the longest key list.  If the component has
  62.     no keyed groups, this can be set to zero.
  63. */
  64.  
  65. #define CI_MAX_KEY_COUNT 1
  66.  
  67. /*********************************************************************/
  68.  
  69. /************************ GLOBALS ************************************/
  70.  
  71. /*
  72.     The actual command control structure for this Component.
  73. */
  74.  
  75. DmiCiControl_t CiCommandBlock = { 0 };
  76.  
  77. /*********************************************************************/
  78.  
  79. /*
  80.     The main entry point of the instrumentation.  The Service Layer calls this
  81.     procedure.  This procedure builds a CiCommand Block, and passes the package
  82.     to DmiCiProcess() in DMIAPI.LIB.  Based on the function ptrs provided,
  83.     DmiCiProcess() function will call those user-provided functions when
  84.     required.
  85. */
  86.  
  87. DMI_UNSIGNED DMI_FUNC_ENTRY DmiCiInvoke(void _FAR *dmiCommand)
  88. {
  89.  
  90. static void _FAR    *thisDmiCommand = (void _FAR *) 0;
  91. static DMI_UNSIGNED    status = 0;
  92.  
  93. /*
  94.     This static array is where the Ci-style key lists are built.  Note that the
  95.     size of this static array is fairly small since the actual values are not
  96.     copied from the Service Layer request and confirm buffers.  The value
  97.     pointers in the array of CiAttribute objects point back into the buffers
  98.     themselves.
  99. */
  100.  
  101.     static DmiCiAttribute_t    ciKeyList[CI_MAX_KEY_COUNT] = { 0 };
  102.  
  103. /*
  104.     Save the current command block pointer.
  105. */
  106.  
  107.     thisDmiCommand = dmiCommand;
  108.  
  109.     CiCommandBlock.CiGetAttribute = CiGetAttribute;
  110.     CiCommandBlock.CiGetNextAttribute = CiGetNextAttribute;
  111.     CiCommandBlock.CiReleaseAttribute = CiReleaseAttribute;
  112.     CiCommandBlock.CiReserveAttribute = CiReserveAttribute;
  113.     CiCommandBlock.CiSetAttribute = CiSetAttribute;
  114.  
  115. /*
  116.     Set the maximum number of keys used and the key list pointer.
  117. */
  118.  
  119.     CiCommandBlock.MaxKeyCount = CI_MAX_KEY_COUNT;
  120.     CiCommandBlock.ciKeyList = ciKeyList;
  121.  
  122. /*
  123.     Call the DMIAPI.LIB function to process command.
  124. */
  125.  
  126.     status = DmiCiProcess(&CiCommandBlock, thisDmiCommand);
  127.  
  128. /*
  129.     Return to the Service Layer.
  130. */
  131.  
  132.     return status;
  133. }
  134.  
  135. /*
  136.     The cancel entry point of the instrumentation.  The Service Layer calls
  137.     this procedure when it has been requested to cancel a DMI command that
  138.     this instrumentation code is handling.  This procedure only sets the global
  139.     cicancelFlag.  If the instrumentation author wishes to use the state of
  140.     the cancel flag, then logic must be added to the user-written
  141.     procedures in the "public" section.
  142. */
  143.  
  144. DMI_UNSIGNED DMI_FUNC_ENTRY DmiCiCancel(void)
  145. {
  146.  
  147.     CiCommandBlock.ciCancelFlag = CiTrue;
  148.     return SLERR_NO_ERROR;
  149.  
  150. }
  151.  
  152. #define FILL_IN
  153.  
  154. #ifdef FILL_IN
  155.  
  156. #define NAMES_INDEX 1
  157. #define NAMES_OS  2
  158. #define NAMES_COMPANY  3
  159. #define NAMES_SL    4
  160. #define NUM_NAMES sizeof Names / sizeof Names[0]
  161.  
  162. typedef struct {
  163.     DMI_UNSIGNED  length;
  164.     char           body[30];
  165. } CMP_STRING;
  166.  
  167. /* This macro builds an initialized CMP_STRING object initialized with
  168.    the string passed into it. */
  169.  
  170. #define MIF_iString(n, s) CMP_STRING n = { sizeof(s) - 1, s }
  171.  
  172.  
  173. typedef struct _Name{
  174.     DMI_UNSIGNED    index;
  175.     CMP_STRING    *osname;
  176.     CMP_STRING    *company;
  177.     CMP_STRING    *SL;
  178. } Name;
  179.  
  180.  
  181. MIF_iString(os1, "OS/2 Warp");
  182. MIF_iString(os2, "OS/2 Warp Connect (PowerPC)");
  183. MIF_iString(os3, "AIX");
  184. MIF_iString(comp1,"IBM Corp.");
  185. MIF_iString(comp2,"IBM Corp.");
  186. MIF_iString(comp3,"IBM Corp.");
  187.  
  188. MIF_iString(sl1,"WARP SL Kit");
  189. MIF_iString(sl2,"WARP for PowerPC SL Kit");
  190. MIF_iString(sl3,"AIX SL Kit");
  191.  
  192.  
  193. Name Names[] = {1, &os1,&comp1,&sl1, 2, &os2,&comp2,
  194.      &sl2, 3, &os3,&comp3,&sl3};
  195.  
  196.  
  197. /*
  198.     The following four procedures are the ones that the instrumenation provider
  199.     needs to "fill in."  None of the procedures above the line should ever
  200.     need to be modified.
  201. */
  202.  
  203. /*
  204.     Return a pointer to a DmiCiAttribute_t object that contains the ID, type, and
  205.     pointer to value for the requested attribute.  The component ID, group ID,
  206.     and attribute ID are passed in as parameters.
  207.  
  208.     If the given group is not a table, then keyCount will be zero, and keyList
  209.     will be a NIL pointer.
  210.  
  211.     If the group is a table a keyList may or may not be given.  If it is
  212.     provided, then the attribute value from the requested row should be
  213.     returned.  If there is no key list, then the attribute value from the
  214.     first row should be returned.
  215. */
  216.  
  217. DmiCiAttribute_t * DMI_FUNC_ENTRY CiGetAttribute(DMI_UNSIGNED componentId,
  218.                                    DMI_UNSIGNED groupId,
  219.                                    DMI_UNSIGNED attributeId,
  220.                                    DMI_UNSIGNED keyCount,
  221.                                    DmiCiAttribute_t const _FAR *const keyList)
  222. {
  223. static DmiCiAttribute_t GetAttr;
  224. ULONG Index;
  225.  
  226.     Index = 0;     /* default to the first element in the table */
  227.     if(keyCount && (keyList != (DmiCiAttribute_t _FAR *)NULL)){   /* need to check the key list */
  228.         Index = *(ULONG *)(keyList->pAttributeValue);  /* get the key value */
  229.         if((Index < 1) || (Index > 3)) return (DmiCiAttribute_t *)NULL;
  230.         Index--;   /* decrement it to allign with the array offset */
  231.     }
  232.     switch((GetAttr.iAttributeId = attributeId)){
  233.         case 1:  /* index number */
  234.             GetAttr.iAttributeType = MIF_INTEGER;
  235.             GetAttr.pAttributeValue = &(Names[Index].index);
  236.             break;
  237.         case 2:  /* Operating System */
  238.             GetAttr.iAttributeType = MIF_DISPLAYSTRING;
  239.             GetAttr.pAttributeValue = Names[Index].osname;
  240.             break;
  241.         case 3:  /* Operating system manufacturer */
  242.             GetAttr.iAttributeType = MIF_DISPLAYSTRING;
  243.             GetAttr.pAttributeValue = Names[Index].company;
  244.             break;
  245.         case 4:  /* The SL for the operating system */
  246.             GetAttr.iAttributeType = MIF_DISPLAYSTRING;
  247.             GetAttr.pAttributeValue = Names[Index].SL;
  248.             break;
  249.         default:    /* this is not an attribute ID we understand */
  250.             return (DmiCiAttribute_t *)NULL;
  251.     }
  252.     return (DmiCiAttribute_t *)&GetAttr;
  253. }
  254.  
  255.  
  256. /*
  257.     Return a pointer to a CiATtribute object that cotains the ID, type, and
  258.     pointer to value for the SUCCESSOR of the specified attribute.  For example:
  259.  
  260.     {1, "Red"}
  261.     {2, "Green"}
  262.     {3, "Blue"}
  263.  
  264.     Assume that the previous is a small table.  Also assume that the table is
  265.     component 2, group 2.  Assume further that the columns of this table are
  266.     attributes 1 and 2, and that attribute 1 is the key.  Then, if the caller
  267.     requests CiGetNextAttribute(2, 2, 2, 1, keyList) and the key list contains
  268.     1, then this procedure should return a DmiCiAttribute_t object with the value
  269.     2.  If 2 is in the key list, the result should be 3.  And finally, if 3 is
  270.     in the key list the procedure should retun NIL as this is the last row in
  271.     the table.
  272. */
  273.  
  274. DmiCiAttribute_t * DMI_FUNC_ENTRY CiGetNextAttribute(DMI_UNSIGNED componentId,
  275.                                        DMI_UNSIGNED groupId,
  276.                                        DMI_UNSIGNED attributeId,
  277.                                        DMI_UNSIGNED keyCount,
  278.                                        DmiCiAttribute_t const _FAR *const keyList)
  279. {
  280. static DmiCiAttribute_t GetAttr;
  281. ULONG Index;
  282.  
  283.     Index = 0;     /* default to the first element in the table */
  284.     if(keyCount && (keyList != (DmiCiAttribute_t _FAR *)NULL)){   /* need to check the key list */
  285.         Index = *(ULONG *)(keyList->pAttributeValue);  /* get the key value */
  286.         Index++;
  287.         if((Index < 1) || (Index > 3)) return (DmiCiAttribute_t *)NULL;
  288.         Index--;   /* decrement it to allign with the array offset */
  289.     }
  290.     switch((GetAttr.iAttributeId = attributeId)){
  291.         case 1:  /* index number */
  292.             GetAttr.iAttributeType = MIF_INTEGER;
  293.             GetAttr.pAttributeValue = &(Names[Index].index);
  294.             break;
  295.         case 2:  /* Operating System */
  296.             GetAttr.iAttributeType = MIF_DISPLAYSTRING;
  297.             GetAttr.pAttributeValue = Names[Index].osname;
  298.             break;
  299.         case 3:  /* Operating system manufacturer */
  300.             GetAttr.iAttributeType = MIF_DISPLAYSTRING;
  301.             GetAttr.pAttributeValue = Names[Index].company;
  302.             break;
  303.         case 4:  /* The SL for the operating system */
  304.             GetAttr.iAttributeType = MIF_DISPLAYSTRING;
  305.             GetAttr.pAttributeValue = Names[Index].SL;
  306.             break;
  307.         default:    /* this is not an attribute ID we understand */
  308.             return (DmiCiAttribute_t *)NULL;
  309.     }
  310.     return (DmiCiAttribute_t *)&GetAttr;
  311. }
  312.  
  313. /*
  314.     The caller is asking the instrumentation code to decommit from a set
  315.     operation after a reserve has been issued.  Return CiTrue if successful,
  316.     CiFalse otherwise.
  317. */
  318.  
  319. enum CiBoolean DMI_FUNC_ENTRY CiReleaseAttribute(DMI_UNSIGNED componentId,
  320.                                   DMI_UNSIGNED groupId,
  321.                                   DMI_UNSIGNED attributeId,
  322.                                   DMI_UNSIGNED keyCount,
  323.                                   DmiCiAttribute_t const _FAR *const keyList,
  324.                                   void const _FAR *const attributeValue)
  325. {
  326.     return CiTrue;
  327. }
  328.  
  329. /*
  330.     The caller is asking if the specified attribute could be set if these
  331.     same parameters were passed to the CiSetAttribute procedure.  Return CiTrue
  332.     or CiFalse.
  333. */
  334.  
  335. enum CiBoolean DMI_FUNC_ENTRY CiReserveAttribute(DMI_UNSIGNED componentId,
  336.                                   DMI_UNSIGNED groupId,
  337.                                   DMI_UNSIGNED attributeId,
  338.                                   DMI_UNSIGNED keyCount,
  339.                                   DmiCiAttribute_t const _FAR *const keyList,
  340.                                   void const _FAR *const attributeValue)
  341. {
  342.     return CiTrue;
  343. }
  344.  
  345. /*
  346.     Set the specified attribute with the given value.  If successful, return
  347.     CiTrue, otherwise return CiFalse.  The component ID, group ID, and
  348.     attribute ID are passed in as parameters.
  349.  
  350.     If the given group is not a table, then keyCount will be zero, and keyList
  351.     will be a NIL pointer.
  352.  
  353.     If the group is a table a keyList may or may not be given.  If it is
  354.     provided, then the attribute in the specified row should be set.  If there
  355.     is no key list, then the attribute in the first row should be set.
  356. */
  357.  
  358. enum CiBoolean DMI_FUNC_ENTRY CiSetAttribute(DMI_UNSIGNED componentId,
  359.                               DMI_UNSIGNED groupId,
  360.                               DMI_UNSIGNED attributeId,
  361.                               DMI_UNSIGNED keyCount,
  362.                               DmiCiAttribute_t const _FAR *const keyList,
  363.                               void const _FAR *const attributeValue)
  364. {
  365.     return CiFalse;
  366. }
  367.  
  368. #endif
  369.  
  370.