📄 c-wtx5.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> The WTX Protocol </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-wtx.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-wtx.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-wtx4.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-wtx6.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="85723">4.5 WTX C API</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85725"> </a>This section introduces the WTX C API and provides an extensive code example. To experiment interactively with the WTX protocol, you may wish to work through the examples given in the <a href="c-wtx4.html#85250"><i class="title">4.4 WTX Tcl API</i></a>. All WTX primitives are available to both APIs; thus a single detailed explanation of many items that are common to both the Tcl and C APIs is included in that section.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85729">4.5.1 Description</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85731"> </a>The WTX C API is a binding of the WTX protocol to the ANSI C language. This allows C applications to call target server services. Every WTX protocol request is accessible through the WTX C interface.</p><dd><p class="Body"><a name="85732"> </a>There is a WTX C routine for each WTX protocol request. For example, the C function<b class="symbol_UC"> </b><b class="routine"><i class="routine">wtxMemRead</i></b><b>( )</b> corresponds to <b class="symbol_UC">WTX_MEM_READ</b>. The names of all WTX C routines are derived from the protocol request names according to the <i class="title">VxWorks Programmer's Guide: Coding Conventions</i>; in other words, underscores are removed and all words but the first are capitalized. </p><dd><p class="Body"><a name="85733"> </a>Each WTX C interface has an online reference entry under <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado API Guide>WTX C Library</font></b>. For information on the online reference material, see the <i class="title">Tornado User's Guide: Documentation Guide</i> and <i class="title">Tornado Getting Started</i>. All WTX C routines provide access to error status through <b class="routine"><i class="routine">wtxErrorGet</i></b><b>( )</b>. Throughout the remainder of this section, please refer to the reference entries for more information on the WTX C API.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85735">4.5.2 WTX C API Archive</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85737"> </a>The WTX C API is archived in <i class="textVariable">installDir</i><b class="symbol_UC">/</b><b class="file">host/</b><i class="textVariable">hostType</i><b class="file">/lib/</b><b class="library">libwtxapi</b>. For a complete description of the use of this library to build a Tornado application see <a href="c-adding.html#84379"><i class="title">6. Adding Tools to Tornado</i></a>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85741">4.5.3 Initializing a Session</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="89843"> </a>Before connecting an application to a particular target server you must initialize a session by calling <b class="routine"><i class="routine">wtxInitialize</i></b><b>( )</b>. The following code example initializes the specified session handle <b class="symbol_lc">wtxh</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="89852">include "wtx.h" ... { HWTX wtxh; ... /* initialize session */ if (wtxInitialize (&wtxh) != OK) return (ERROR);</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85751">4.5.4 Obtaining Target Server Information</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85753"> </a>The Tornado registry maintains information about executing target servers. To find the list of registered target servers, you can call <b class="routine"><i class="routine">wtxInfoQ</i></b><b>( )</b>. To find information on a particular target server, you can call <b class="routine"><i class="routine">wtxInfo</i></b><b>( )</b>.</p><dl class="margin"><dd><pre class="Code2"><b><a name="89856">#include "wtx.h" ... WTX_DESC * pWtxDesc; /* target server information */ ... /* get information about a target server using the Tornado registry*/ if ((pWtxTsInfo = wtxInfo (wtxh, "tJohn")) == NULL) return (ERROR); ...</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85765">4.5.5 Attaching to a Target Server</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85767"> </a>An application must bind an initialized handle to an executing target server before the majority of the WTX C interface routines can be called. This can be accomplished calling <b class="routine"><i class="routine">wtxToolAttach</i></b><b>( )</b>, which takes an initialized <b class="symbol_UC">HWTX</b> handle, a regular expression, and a tool name. The regular expression must uniquely match a registered server for the binding to succeed. The tool name is the application name. The target server records it and reports this name to any tool that requests a list of attached tools with <b class="routine"><i class="routine">wtxTsInfoGet</i></b><b>( )</b>.</p><dl class="margin"><dd><pre class="Code2"><b><a name="89860">#include "wtx.h" ... /* attach to a target server */ if (wtxToolAttach (wtxh, "tJohn.*", "newapp") != OK) { wtxTerminate (wtxh); /* terminate session */ return (ERROR); } ...</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85780">4.5.6 Application Example</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85782"> </a>The following code examples demonstrate a complete application of the WTX C API. This application attaches to the specified target server and allocates and de-allocates target memory in an endless cycle. Note that the number of blocks to allocate is specified in a separate header file to conform to the Wind River coding conventions. For more information about compiling this example see <a href="c-adding.html#84379"><i class="title">6. Adding Tools to Tornado</i></a>.</p><dd><p class="Body"><a name="85786"> </a>To observe this application, start the target browser as well as the application:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85787"></b><tt class="output">%</tt><b> wtxapp <i class="textVariable">targetServerName</i> & </b><tt class="output">%</tt><b> browser <i class="textVariable">targetServerName</i> &</a></b></pre></dl><dd><p class="Body"><a name="85789"> </a>If you place the browser in auto-update mode, the memory usage charts demonstrate the functionality of this simple application. On UNIX, if the Tornado launcher is running and your target server is selected, you can observe <b class="command">wtxapp</b> in the list of attached tools.</p></dl></dl><h4 class="EntityTitle"><a name="85790"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 4-2: WTX C API Application </font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="89913">/* wtxapp.h - Simple WTX C API application header */ /* Copyright 1995-99 Wind River Systems, Inc. */ /* modification history -------------------- 01a,08apr95-99,p_m written */ /* defines */ #define NUM_BLOCKS 26 /* number of memory blocks to allocate */</a></b></pre></dl><dl class="margin"><dd><hr class="Line"></dl><dl class="margin"><dd><pre class="Code"><b><a name="90790">/* wtxapp.c - Simple WTX C API application */ /* Copyright 1995-99 Wind River Systems, Inc. */ /* modification history -------------------- 01c,05jan99,fle doc : made it documentable 01b,11jul95,p_m implemented better error reporting and added comments added signals handling 01a,08apr95,p_m written */ #include <signal.h> #include <stdio.h> #include "host.h" #include "wtx.h" #include "wtxapp.h" /* DESCRIPTION This is a simple program demonstrating the use of the WTX C API. It attaches to a target server and allocates and free memory from the target memory pool managed by the target server. SEE ALSO tgtsvr, wtxtcl, wtx, WTX */ /* defines */ /* globals */ HWTX wtxh; /* WTX API handle */ TGT_ADDR_T blockTab[NUM_BLOCKS]; /* allocated blocks table */ /* forward declarations */ LOCAL STATUS wtxAppSigInit (void); #ifdef WIN32 BOOL WINAPI wtxAppSigHandler (DWORD dwCtrlType); #else LOCAL void wtxAppSigHandler (int signal, int code); #endif LOCAL void wtxAppTerminate (void); /*********************************************************************** * * wtxapp - Simple WTX application example * * This is a simple WTX tool example showing the WTX C API. It * allocates blocks of memory from the target-server-managed target memory * pool then frees them. The effects of this program can be easily * viewed by using a Tornado browser attached to the same target server.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -