|The API Corner: Providing Access to an Application Function, Part II|
|Programming - APIs|
|Written by Bruce Vining|
|Wednesday, 20 June 2012 00:00|
Learn the details behind the User Function Registration APIs.
In last month's API Corner, we took an initial look at the QsyRegisterFunction API of the set of APIs supporting User Function Registration. The API was used to first define a product, BVS_APPLICATIONS, and to then define a function within the product, BVS_CMD_LINE_WINDOW. For space reasons, the API parameters in that article were hard-coded and not explained in any detail. This month, we'll take a deeper dive into this API and see how you can customize access to various application features.
The QsyRegisterFunction API, which can also be called as a program using the name QSYRGFN, defines three parameters. The first parameter, Function ID, is a CHAR(30) input value where you name the function being registered. A discussion of how you might want to name your functions can be found in last month's article. The second parameter, Function controls, is a variable-length input value where you define various attributes of the Function ID being registered. The third parameter is the common Error code parameter found with most system APIs.
The Function controls parameter represents the meat of the API. This parameter, as mentioned earlier, is of varying length and can contain one or more variable-length records. These variable-length records define the function being registered. The first field of this parameter is a 4-byte binary value telling the API how many variable-length records are being provided. Then, following this field is that number of contiguous variable-length records.
Each variable-length record starts with three 4-byte binary fields and then a variable-length field that can contain either a character or a binary value. The first three binary fields represent the length of the current variable-length record, the key value identifying what attribute of the function being registered is being defined, and the length of the variable-length field that follows the third fixed field, respectively. This can be depicted as shown below.
Last month, we initialized the Function controls parameter, when registering the product BVS_APPLICATIONS, with the following data structure:
dPrdControls ds qualified
d NbrOfCtls 10i 0 inz(1)
d LenKey2Len 10i 0 inz(16)
d Key2 10i 0 inz(2)
d LenKey2Dta 10i 0 inz(1)
d Key2Dta 1a inz('1')
These control values correspond to the following: the API has one variable-length record (NbrOfCtls = 1), the variable-length record is a total of sixteen bytes in length (LenKey2Len = 16), the variable length record is defining a type of function (Key2 = 2), the length of the data associated with the function group is one byte (LenKey2Dta = 1), and the function type is a product (Key2Dta = '1'). The value of sixteen for LenKey2Len (as opposed to the thirteen bytes we actually used) is to accommodate the four bytes for LenKey2Len, the four bytes for Key2, the four bytes for LenKey2Dta, the one byte for Key2Dta, and three bytes to set the entire length of the variable-length record to a multiple of four. This multiple of four consideration is due to the API documented requirement that all variable-length records be aligned on a four-byte boundary. Though we're using only one variable-length record, it's easiest (for me anyway) to consistently extend all variable-length records to a multiple of four (in anticipation of needing a second record "someday"). Calling the QsyRegisterFunction API, with these values for the Function controls parameter, then registers the product BVS_APPLICATIONS.
Having registered the product, we then called the API a second time with the Function controls parameter initialized as shown below, to register the function BVS_CMD_LINE_WINDOW.
dFcnControls ds qualified
d NbrOfCtls 10i 0 inz(3)
d LenKey3Len 10i 0 inz(44)
d Key3 10i 0 inz(3)
d LenKey3Dta 10i 0 inz(30)
d Key3Dta 30a inz('BVS_APPLICATIONS')
d LenKey6Len 10i 0 inz(144)
d Key6 10i 0 inz(6)
d LenKey6dta 10i 0 inz(132)
d Key6Dta 132a inz('Provide command line -
d window access')
d LenKey11Len 10i 0 inz(16)
d Key11 10i 0 inz(11)
d LenKey11Dta 10i 0 inz(1)
d Key11Dta 1a inz('1')
These control values correspond to providing the API with three variable-length records (NbrOfCtls = 3).
The first variable-length record is a total of 44 bytes in length (LenKey3Len = 44), the variable-length record is declaring that the function being registered is part of a previously registered product (Key3 = 3), the length of the data associated with the product is 30 bytes (LenKey3Dta = 30), and the product is BVS_APPLICATIONS (Key3Dta = 'BVS_APPLICATIONS'). Two bytes of padding are provided to align the next variable-length record on a four-byte boundary.
The second variable-length record is a total of 144 bytes in length (LenKey6Len = 144), the variable length record is providing a descriptive name to associate with the function being registered (Key6 = 6), the length of the data associated with the descriptive name is 132 bytes (LenKey6Dta = 132), and the description is 'Provide command line window access' (Key6Dta). Note that in practice I would recommend using Key 5 rather than Key 6 when providing descriptive information. Key 5 allows you to provide a message file and message ID from which the QsyRegiserFunction API can extract the descriptive text (rather than coding the text within the program itself). I'm using Key 5 only to avoid having to create a message file and message description as part of this article.
The third variable-length record is a total of 16 bytes in length (LenKey11Len = 16), the variable-length record is providing a default usage value for the function being registered (Key11 = 11), the length of the data associated with the default usage is one byte (LenKey11Dta = 1), and the default value is '1' (Key11Dta = '1'). The Key11Dta value of '1' indicates that the default is to not allow access to the function being registered. Three bytes of padding are provided to align the next variable-length record (though there is currently no "next" record being defined).
While defining the Functions control parameter using a hard-coded data structure approach as shown above works (and more importantly makes for program source that would fit into last month's column), I would tend to take other approaches if I anticipated needing to register very many functions to the BVS_APPLICATIONS product. Next month, we'll look at one of these alternative approaches.
Meanwhile, if you have some free time, you may want to look at the QsyRegisterFunction API documentation. The fact that we only used Function control key values of 2, 3, 6, and 11 (and briefly mentioned key 5) should suggest that there are additional keys available to you.
As usual, if you have any API questions, send them to me at email@example.com. I'll see what I can do about answering your burning questions in future columns.
|Last Updated on Tuesday, 19 June 2012 22:08|