1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 7.0.1.0 for Windows">
6<META http-equiv="Content-Style-Type" content="text/css">
7<TITLE>Environmental Resource Management Overview </TITLE>
8<LINK rel="stylesheet" href="../css/nitro.css" type="text/css">
9</HEAD>
10<BODY>
11<H1 align="left">Environment Resources Overview</H1>
12<H2>Description</H2>
13<P>The Environmental Resources (ENV) library provides a method for easily getting values defined as resources from a program. Resources are various parameters and configuration values for which the resource names have been defined. Resource values are obtained from a program by specifying a resource name.</P>
14<P>The ENV library provides a convenient way to test operations during program development by changing parameters or by using shared configuration values on multiple programs.</P>
15<HR>
16<H3>Resource Definitions</H3>
17<P>In this ENV library, resource values are returned in response to queries about resource names. A resource name comprises a class name, a period (&quot;.&quot;), and a member name.</P>
18<BLOCKQUOTE style="background-color:#ffffcc;"><B>Example:</B><BR>In the case of the resource <CODE>myServer.Hostname</CODE>, <CODE>myServer</CODE> is the class name, and <CODE>Hostname</CODE> is the member name.</BLOCKQUOTE>
19<P>These types of resources can be given any of the following as values: <CODE>u8</CODE>, <CODE>s8</CODE>, <CODE>u16</CODE>, <CODE>s16</CODE>, <CODE>u32</CODE>, <CODE>s32</CODE>, <CODE>u64</CODE>, <CODE>s64</CODE>, <CODE>BOOL</CODE>, <CODE>string</CODE>, or <CODE>binary</CODE>. String data is labeled <CODE>string</CODE>, and binary data is labeled <CODE>binary</CODE>.</P>
20<P>Resources are managed internally with a single <CODE>ENVResource</CODE> structure. (Two structures are used for 64-bit resource values.)</P>
21<BLOCKQUOTE style="background-color:#ffffcc;">
22<P><CODE>struct ENVResource<BR> {<BR> char*  name;<BR> u16   len;<BR> u16   type;<BR> void*  ptr;<BR> };</CODE></P>
23</BLOCKQUOTE>
24<P>The <CODE>name</CODE> element is a pointer to the resource name. The <CODE>len</CODE> element is the length of the resource. The <CODE>type</CODE> element is the information type when the resource is declared. The <CODE>ptr</CODE> element is the pointer to the location where the string and data are actually stored for <CODE>string</CODE> and <CODE>binary</CODE>. Values for <CODE>u8</CODE>, <CODE>s8</CODE>, <CODE>u16</CODE>, <CODE>s16</CODE>, <CODE>u32</CODE>, <CODE>s32</CODE>, or <CODE>BOOL</CODE> are assigned to <CODE>ptr</CODE>. <CODE>u64</CODE> and <CODE>s64</CODE> use two continuous data resources.</P>
25<HR>
26<H3>Description of the Resource Data<BR>
27</H3>
28<P>Resource data are defined with an <CODE>ENVResource</CODE> structure array. The following macros have be prepared to define the <CODE>len</CODE>, <CODE>type</CODE>, and <CODE>ptr</CODE> members for the above-mentioned <CODE>ENVResource</CODE> structure all at once. These macros make it easier to describe resources.
29</P>
30<TABLE border="1">
31  <TBODY>
32    <TR>
33<TD><CODE>ENV_U8</CODE></TD>
34<TD>A macro for a <CODE>u8</CODE> value.</TD>
35    </TR>
36    <TR>
37<TD><CODE>ENV_S8</CODE></TD>
38<TD>A macro for an <CODE>s8</CODE> value.</TD>
39    </TR>
40    <TR>
41<TD><CODE>ENV_U16</CODE></TD>
42<TD>A macro for a <CODE>u16</CODE> value.</TD>
43    </TR>
44    <TR>
45<TD><CODE>ENV_S16</CODE></TD>
46<TD>A macro for an <CODE>s16</CODE> value.</TD>
47    </TR>
48    <TR>
49<TD><CODE>ENV_U32</CODE></TD>
50<TD>A macro for a <CODE>u32</CODE> value.</TD>
51    </TR>
52    <TR>
53<TD><CODE>ENV_S32</CODE></TD>
54<TD>A macro for an <CODE>s32</CODE> value.</TD>
55    </TR>
56    <TR>
57<TD><CODE>ENV_U64</CODE></TD>
58<TD>A macro for a <CODE>u64</CODE> value.</TD>
59    </TR>
60    <TR>
61<TD><CODE>ENV_S64</CODE></TD>
62<TD>A macro for an <CODE>s64</CODE> value.</TD>
63    </TR>
64    <TR>
65<TD><CODE>ENV_BOOL</CODE></TD>
66<TD>A macro for a <CODE>BOOL</CODE> value.</TD>
67    </TR>
68    <TR>
69<TD><CODE>ENV_STRING</CODE></TD>
70<TD>A macro for <CODE>string</CODE> data.</TD>
71    </TR>
72    <TR>
73<TD><CODE>ENV_BINARY</CODE></TD>
74<TD>A macro for <CODE>binary</CODE> data.</TD>
75    </TR>
76  </TBODY>
77</TABLE>
78<P>By using these macros, resources are defined as combination of resource names and resource macros, as shown below.</P>
79<BLOCKQUOTE style="background-color:#ffffcc;"><CODE>ENVResource&nbsp;myResource[]&nbsp;=&nbsp;{<BR>&quot;myClass.str1&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENV_STRING(&nbsp;&quot;mario&quot;&nbsp;),<BR>&quot;myClass.bin1&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENV_BINARY(&nbsp;&quot;\x12\x34\x56\x78&quot;&nbsp;),<BR>&quot;myClass2.data1&quot;,&nbsp;&nbsp;&nbsp;&nbsp;ENV_S32(&nbsp;-500&nbsp;),<BR>&quot;myClass2.data2&quot;,&nbsp;&nbsp;&nbsp;&nbsp;ENV_U16(&nbsp;0x8000&nbsp;),<BR>ENV_RESOURCE_END<BR>};</CODE></BLOCKQUOTE>
80<P><CODE><FONT color="#ff0033">Add <CODE>ENV_RESOURCE_END</CODE> at the end of the data.</FONT></CODE></P>
81<P>The resource array defined above is then managed internally.</P>
82<BLOCKQUOTE><CODE><IMG src="image_envResource1.gif" border="0"><BR></CODE></BLOCKQUOTE>
83<HR>
84<H3>Resource Array List</H3>
85<P>Searches for resources are performed from the resource array. In the ENV library, multiple resource arrays can be registered in the system. The resource arrays are linked together as a list inside the system. When a search is performed, it is conducted on every array in that list. Searches are performed from the very beginning of the list and from the very beginning of the arrays. If the same resource exists in both, the first one found is used.</P>
86<P>The <A href="ENV_AppendResourceSet.html"><CODE>ENV_AppendResourceSet</CODE></A> function adds new resource arrays to the end of the list.<BR>The <A href="ENV_PrependResourceSet.html"><CODE>ENV_PrependResourceSet</CODE></A> function adds new resource arrays to the beginning of the list.<BR>The <A href="ENV_InsertResourceSet.html"><CODE>ENV_InsertResourceSet</CODE></A> function adds new resource arrays to a location of the user's choice.<BR></P>
87<P>The <A href="ENV_SetResourceSet.html"><CODE>ENV_SetResourceSet</CODE></A> and <A href="ENV_SetResourceSetArray.html"><CODE>ENV_SetResourceSetArray</CODE></A> functions delete lists that have been registered up to this point and then register a specified list.</P>
88<P>There is a limit to the number of resource arrays that can be registered. The number is <CODE>ENV_RESOURCE_SET_MAX</CODE>. (Defined as 8.)</P>
89<BLOCKQUOTE><IMG src="image_envResource2.gif" border="0"></BLOCKQUOTE>
90<HR>
91<H3>Declaring Resource Arrays</H3>
92<P>The <A href="ENV_Init.html"><CODE>ENV_Init</CODE></A> function specifies resource arrays using the <A href="ENV_Init.html"><CODE>ENVResource* resourceArray[]</CODE></A> array, as shown below.</P>
93<BLOCKQUOTE style="background:#ffffcc"><CODE><FONT color="#ff0000">SDK_WEAK_SYMBOL</FONT> ENVResource *<FONT color="#ff0000">resourceArray</FONT>[] = { NULL };<BR> <BR> void ENV_Init(void)<BR> {<BR> :<BR><FONT color="#ff0000">ENV_SetResourceSetArray( resourceArray );</FONT><BR> }</CODE></BLOCKQUOTE>
94<P><CODE>resourceArray[]</CODE> is an array that holds resource arrays. Because <CODE>resourceArray[]</CODE> is an array of <CODE>NULL</CODE> members that is defined with the WEAK symbol in the system, it is useful for the application to define the array itself. Because <CODE>resourceArray[]</CODE> is an array of resource arrays, it can specify a number of necessary resource arrays all at once.</P>
95
96<HR>
97<H3>Getting Resource Values</H3>
98<P>Use the functions that get resource values from resource names based on the resource definition, as shown below.
99</P>
100<TABLE border="1">
101  <TBODY>
102    <TR>
103<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetU8</CODE></A></TD>
104<TD>A <CODE>u8</CODE> value defined with <CODE>ENV_U8</CODE>.</TD>
105    </TR>
106    <TR>
107<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetS8</CODE></A></TD>
108<TD>An <CODE>s8</CODE> value defined with <CODE>ENV_S8</CODE>.</TD>
109    </TR>
110    <TR>
111<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetU16</CODE></A></TD>
112<TD>A <CODE>u16</CODE> value defined with <CODE>ENV_U16</CODE>.</TD>
113    </TR>
114    <TR>
115<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetS16</CODE></A></TD>
116<TD>An <CODE>s16</CODE> value defined with <CODE>ENV_S16</CODE>.</TD>
117    </TR>
118    <TR>
119<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetU32</CODE></A></TD>
120<TD>A <CODE>u32</CODE> value defined with <CODE>ENV_U32</CODE>.</TD>
121    </TR>
122    <TR>
123<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetS32</CODE></A></TD>
124<TD>An <CODE>s32</CODE> value defined with <CODE>ENV_S32</CODE>.</TD>
125    </TR>
126    <TR>
127<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetU64</CODE></A></TD>
128<TD>A <CODE>u64</CODE> value defined with <CODE>ENV_U64</CODE>.</TD>
129    </TR>
130    <TR>
131<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetS64</CODE></A></TD>
132<TD>An <CODE>s64</CODE> value defined with <CODE>ENV_S64</CODE>.</TD>
133    </TR>
134    <TR>
135<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetBOOL</CODE></A></TD>
136<TD>A <CODE>BOOL</CODE> value defined with <CODE>ENV_BOOL</CODE>.</TD>
137    </TR>
138    <TR>
139<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetString</CODE></A></TD>
140<TD>String data defined with <CODE>ENV_STRING</CODE>.</TD>
141    </TR>
142    <TR>
143<TD><A href="ENV_GetXXX.html"><CODE>ENV_GetBinary</CODE></A></TD>
144<TD>Binary data defined with <CODE>ENV_BINARY</CODE>.</TD>
145    </TR>
146  </TBODY>
147</TABLE>
148<P>The obtained values are stored at the beginning of the pointer designated in the arguments. The function return value indicates whether the values were successfully obtained.</P>
149<P>Two functions have been prepared that get strings and binaries along with their sizes: <A href="ENV_GetXXX.html"><CODE>ENV_GetStringAndLength</CODE></A> and <A href="ENV_GetXXX.html"><CODE>ENV_GetBinaryAndSize</CODE></A>.</P>
150<HR>
151<H3>Omitting Class Names</H3>
152<P>By passing the class names to the ENV library in advance, the class name part can be omitted, and the member name can be used alone to designate with the functions that require resource names. When designating a member name by itself, be sure to add a period (&quot;.&quot;) before the name.</P>
153<P>Use the <A href="ENV_SetClass.html"><CODE>ENV_SetClass</CODE></A> function to declare class names.</P>
154<BLOCKQUOTE style="background-color:#ffffcc;"><B>Example:</B><BR>All of the following, where the class name is declared, <BR><CODE>u32&nbsp;d1,&nbsp;d2,&nbsp;d3;<BR>(void)ENV_GetU32(&nbsp;&quot;myClass.myData1&quot;,&nbsp;&amp;d1&nbsp;);<BR>(void)ENV_GetU32(&nbsp;&quot;myClass.myData2&quot;,&nbsp;&amp;d2&nbsp;);<BR>(void)ENV_GetU32(&nbsp;&quot;myClass.myData3&quot;,&nbsp;&amp;d3&nbsp;);<BR></CODE><BR>can be designated in the following forms, with only the member names:<BR><CODE>u32&nbsp;d1,&nbsp;d2,&nbsp;d3;<BR>ENV_SetClass(&nbsp;&quot;myClass&quot;&nbsp;);<BR>(void)ENV_GetU32(&nbsp;&quot;.myData1&quot;,&nbsp;&amp;d1&nbsp;);<BR>(void)ENV_GetU32(&nbsp;&quot;.myData2&quot;,&nbsp;&amp;d2&nbsp;);<BR>(void)ENV_GetU32(&nbsp;&quot;.myData3&quot;,&nbsp;&amp;d3&nbsp;);<BR></CODE><BR></BLOCKQUOTE>
155<P>The function used to obtain the current configuration values is <CODE><A href="ENV_GetClass.html">ENV_GetClass()</A></CODE>.</P>
156<HR>
157<H3>Example of Using the ENV Library</H3>
158<P>Below is an example of using the ENV library.</P>
159<BLOCKQUOTE style="background-color:#ffffcc;"><CODE>ENVResource myResource1[] = {<BR> &quot;server1.hostName&quot;,  ENV_STRING( &quot;myserver&quot; ),<BR> &quot;server1.IP&quot;,  ENV_BINARY( &quot;\xc0\xA8\x00\x01&quot; ),<BR> &quot;server1.port&quot;,  ENV_U16( 5000 ),<BR> <B><FONT color="#ff0033">ENV_RESOUCE_END</FONT></B><BR> };<BR> <BR> ENVResource myResource2[] = {<BR> &quot;server2.hostName&quot;,  ENV_STRING( &quot;ftpserver&quot; ),<BR> &quot;server2.IP&quot;,  ENV_BINARY( &quot;\xc0\xA8\x00\x02&quot; ),<BR> &quot;server2.port&quot;,  ENV_U16( 21 ),<BR> <B><FONT color="#ff0033">ENV_RESOUCE_END</FONT></B><BR> };<BR> <BR> ENVResource* resourceArray[]={ myResource1, myResource2, NULL };<BR> <BR> <BR> <BR> main()<BR> {<BR> char* hostname;<BR> u8* ipAddress;<BR> int ipSize;<BR> u16 portNum;<BR> :<BR>//---- ENV system initialization<BR> ENV_Init( myResources );<BR> <BR> //---- Class name designation when omitted<BR> ENV_SetClass( &quot;server1&quot; );<BR> <BR> //---- Get resource<BR> if ( ! ENV_GetString( &quot;.hostName&quot;, &amp;hostname ) )<BR>&nbsp;{<BR> OS_Printf( &quot;error: <CODE>hostname is not defined.\n&quot; );<BR> };<BR> if&nbsp;(&nbsp;!</CODE><CODE>ENV_GetBinaryAndSize( &quot;.IP&quot;, &amp;ipAddress, &amp;ipSize ) )<BR> {<BR> OS_Printf( &quot;error:</CODE>ipAddress is not defined.\n&quot; );<BR> };<BR> if ( ! <CODE>ENV_GetU16( &quot;.port&quot;, &amp;portNum ) )<BR> {<BR> OS_Printf( &quot;error:</CODE><CODE>portNum is not defined.\n&quot; );<BR> };<BR> :<BR></CODE><BR> }<BR></CODE></BLOCKQUOTE>
160<HR>
161<H3>Searching for Resources Under Specified Conditions</H3>
162<P>The <CODE>ENVResourceIter</CODE> structure has been defined to search for resources using specified class names or member names. This is used as a search iterator. The functions that get the resource by using the iterators are <A href="ENV_InitIter.html"><CODE>ENV_InitIter</CODE></A>, <A href="ENV_SearchByClass.html"><CODE>ENV_SearchByClass</CODE></A>, <A href="ENV_SearchByMember.html"><CODE>ENV_SearchByMember</CODE></A>, <A href="ENV_SearchByType.html"><CODE>ENV_SearchByType</CODE></A>, and <A href="ENV_SearchByPartialName.html"><CODE>ENV_SearchByPartialName</CODE></A>.</P>
163<P>The following shows the resource with the specified class <CODE>className</CODE> being obtained.</P>
164<BLOCKQUOTE style="background-color:#ffffcc;"><B><CODE>ENVResourceiter&nbsp;&nbsp;iter;</CODE></B><CODE><BR>ENVResource*&nbsp;&nbsp;&nbsp;&nbsp;p;<BR> <BR><B>ENV_InitIter( &amp;iter );</B><BR>while(&nbsp;(p&nbsp;= <B>ENV_SearchByClass( &amp;iter,<BR>&quot;className&quot; )</B>&nbsp;)&nbsp;)<BR>{<BR>OS_Printf( &quot;resource = %s\n&quot;, p-&gt;name );<BR>}</CODE></BLOCKQUOTE>
165<P>To search for a resource with the specific name &quot;<CODE>memberName</CODE>,&quot; use the following statements. The member name is a text string that does not contain a period (&quot;.&quot;). If there are any periods other than the delimiter between the class and member, the comparison is performed on the member name up to the location of the first period.</P>
166<BLOCKQUOTE style="background-color:#ffffcc;"><CODE><B>ENVResourceIter  iter;</B></CODE><CODE><BR>ENVResource*&nbsp;&nbsp;&nbsp;&nbsp;p;<BR>&nbsp;<BR><B>ENV_InitIter( &amp;iter );</B><BR>while(&nbsp;(p&nbsp;=&nbsp;<B>ENV_SearchByMember( &amp;iter, <BR>&quot;memberName&quot; )</B>&nbsp;)&nbsp;)<BR>{<BR>OS_Printf(&nbsp;&quot;resource&nbsp;= %s\n&quot;, p-&gt;name );<BR>}</CODE></BLOCKQUOTE>
167<P>For example, when searching with the member name &quot;<CODE>member</CODE>,&quot;</P>
168<BLOCKQUOTE style="background-color:#ffffcc;"><CODE>&quot;class.member&quot;<BR>&quot;class.member.001&quot;<BR>&quot;class.member.class&quot;</CODE></BLOCKQUOTE>
169<P><CODE>has a match, but</CODE></P>
170<BLOCKQUOTE style="background-color:#ffffcc;"><CODE>&quot;class.member001&quot;<BR>&quot;class.member2.member&quot;</CODE></BLOCKQUOTE>
171<P>do not match.</P>
172<HR>
173<H3>Resource Array That Includes Resource</H3>
174<P>It is also possible to get the resource array that includes the resource obtained with <A href="ENV_GetLastResourceSetFromIter.html"><CODE>ENV_GetLastResourceSetFromIter</CODE></A> function immediately after an iterator-based resource search.</P>
175<P>Specify the resource and use the <A href="ENV_GetBelongingResourceSet.html"><CODE>ENV_GetBelongingResourceSet</CODE></A> function to get the resource array to which the resource belongs.<BR>
176</P>
177<H2>See Also</H2>
178<P><A href="list_env.html">ENV function list</A></P>
179<H2>Revision History</H2>
180<P>2005/08/29 Added support for multiple registrations of a resource array.<BR> 2005/08/17 Initial version.</P>
181<hr><p>CONFIDENTIAL</p></body>
182</HTML>