📄 c-adding2.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Adding Tools to Tornado </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-adding.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-adding.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-adding1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-adding3.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="84391">6.2 Creating a Tornado Application</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84393"> </a>This section describes how to build and install a simple Tornado application based on the WTX protocol. It also describes how to generate HTML documentation for the new tool.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84394">6.2.1 Example Specifications</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84397"> </a>The Tornado tool we build and install in this example was presented in <a href="c-wtx.html#84379"><i class="title">4. The WTX Protocol</i></a> as an example of using the WTX C API. It allocates memory from the target memory pool managed by the target server until no more memory is available. It then frees the allocated memory and repeats this sequence until the user issues a <b class="symbol_UC">CTRL</b><b>+C</b>. The tool is called <b class="command">wtxapp</b>. When the tool is used with the Tornado browser in auto-update mode, it displays a changing memory-in-use chart.</p><dd><p class="Body"><a name="84399"> </a>The tool main program is made up of two files, <b class="file">wtxapp.h</b> and <b class="file">wtxapp.c</b>. It makes use of the WTX C API requests <b class="routine"><i class="routine">wtxMemAlloc</i></b><b>( )</b> and <b class="routine"><i class="routine">wtxMemFree</i></b><b>( )</b>. The code for the application is located in <a href="c-wtx5.html#85780"><i class="title">4.5.6 Application Example</i></a>. </p><dd><p class="Body"><a name="84403"> </a>Note that the <b class="command">wtxapp</b> tool installs a signal handler that not only stops the program on <b class="symbol_UC">CTRL</b><b>+C</b> but also terminates the communication session with the target server properly. All Tornado tools should implement this type of signal handling.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84404">6.2.2 Directories and File Naming</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84406"> </a>Wind River Systems recommends creating a dedicated directory for each Tornado tool in <i class="textVariable">installDir</i><b class="file">/host/src</b>. This directory contains all source and header files that constitute the tool plus a makefile. For <b class="command">wtxapp</b> the files are:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84407"> </a><i class="textVariable">installDir</i><b class="file">/host/src/wtxapp/Makefile</b></li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84408"> </a><i class="textVariable">installDir</i><b class="file">/host/src/wtxapp/wtxapp.c</b></li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84409"> </a><i class="textVariable">installDir</i><b class="file">/host/src/wtxapp/wtxapp.h</b></li></ul></p></dl></dl><dl class="margin"><dd><b class="file"><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="85095"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>For UNIX hosts, <i class="textVariable">installDir</i> is <b class="symbol_UC">$WIND_BASE</b>. For Windows users who use the command line, <i class="textVariable">installDir</i> is <b class="symbol_UC">%WIND_BASE%</b>. </div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout></b></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84825">6.2.3 Building the Application</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84412"> </a>Use a makefile<b class="file"> </b>that incorporates the Tornado generic makefile rules and macros found in the directory <i class="textVariable">installDir</i><b class="file">/host/include/make</b> to build Tornado applications. This type of makefile automatically generates a secondary makefile called <b class="file">Makefile.gen</b> that contains the dependencies list. It installs the <b class="command">wtxapp</b> executable in the <b class="file">bin</b> directory for the host (for example, in <i class="textVariable">installDir</i><b class="file">/host/sun4-solaris2/bin</b>). The makefile for <b class="command">wtxapp</b> appears in <a href="c-adding2.html#84421">Example 6-1</a>.</p><dd><p class="Body"><a name="84416"> </a>The Tornado include files are located in the <i class="textVariable">installDir</i><b class="file">/host/include</b> directory. This path is available in the makefile through the <b class="symbol_UC">INCLUDES</b> macro. </p><dd><p class="Body"><a name="84418"> </a><b class="command">wtxapp</b> uses routines from <b class="library">libwtxapi</b> shared library. This library is included by the <b class="symbol_UC">$UTIL_LIB </b>macro in the makefile. <b class="file">wtxapp </b>is also linked with extra libraries required by a particular tool chain on a given host. These extra libraries are defined by <b class="symbol_UC">EXTRA_LIBS </b>in the makefile.</p><dd><p class="Body"><a name="84419"> </a>For more information about the available makefile macros defined with Tornado, see <i class="textVariable">installDir</i><b class="file">/host/include/make/generic.mh. </b></p></dl></dl><h4 class="EntityTitle"><a name="84421"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-1: wtxapp Makefile</font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="85028"># Makefile - for simple Tornado Application # # modification history # -------------------- # 01c,28jan99,wcc add $(CFLAGS) to $(WTXAPP) rule # 01b,13jan97,bcc port to Windows # 01a,25jul95,p_m written # # DESCRIPTION # This file contains the makefile rules for building a simple # Tornado application # # SUBSTITUTION # # INCLUDES # $(WIND_BASE)/host/include/make/generic.mh # $(WIND_BASE)/host/include/make/$(HOST).mh # $(WIND_BASE)/host/include/make/generic2.mh # include $(WIND_BASE)/host/include/make/generic.mh include $(WIND_BASE)/host/include/make/$(HOST).mh INCLUDES = $(WIND_INC) WTXAPP = $(WIND_BIN)/wtxapp # documentation related variables DOC_FILES = wtxapp.c DOC_DIR = $(DOCS_ROOT)/tornado-app/wtxapp VERSION_DEFINE = $(CFLAGS) LIBRARIES = PROGRAMS = $(WTXAPP) TESTS = DOCS = doc ## Add special build targets and default here. default: prog $(WTXAPP): wtxapp.c $(SH_UTIL_LIB) $(CC) $(CFLAGS) -DHOST=$(HOST) $(INCLUDES) wtxapp.c -o $@ \ $(UTIL_LIB) $(EXTRA_LIBS) doc: $(DOC_FILES) $(WIND_BIN)/refgen $(REFGEN_OPT) -book Tornado_Applications \ -chapter WTX_Applications -out $(DOC_DIR) $(DOC_FILES) $(WIND_BIN)/htmlLink $(DOC_DIR) include $(WIND_BASE)/host/include/make/generic2.mh</a></b></pre></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84476">6.2.4 Compiling the Application</a></i></h4></font><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84477">UNIX Hosts</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84479"> </a>The specific commands for compiling <b class="command">wtxapp</b> depend on your host. For example, to compile on a Sun4 workstation running Solaris 2.5.1., issue the following commands from a UNIX shell (this example assume the c-shell; issue the appropriate commands for your shell):</p><dl class="margin"><dd><pre class="Code2"><b><a name="84480"></b><tt class="output">%</tt><b> setenv WIND_BASE <i class="textVariable">installdir </i></b><tt class="output">%</tt><b> setenv WIND_HOST_TYPE sun4-solaris2 </b><tt class="output">%</tt><b> set path=(<i class="textVariable">installDir</i>/host/$WIND_HOST_TYPE/bin $path) </b><tt class="output">%</tt><b> cd <i class="textVariable">installDir</i>/host/src/wtxapp </b><tt class="output">%</tt><b> make HOST=$WIND_HOST_TYPE</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84481">Windows Hosts</a></i></h4></font><dl class="margin"><dl class="margin">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -