File: classWt_1_1WFileResource.html

package info (click to toggle)
witty 3.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 45,512 kB
  • ctags: 35,832
  • sloc: cpp: 69,469; ansic: 66,945; xml: 4,383; sh: 594; perl: 108; makefile: 106
file content (220 lines) | stat: -rw-r--r-- 15,704 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Wt: Wt::WFileResource Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespaceWt.html">Wt</a>::<a class="el" href="classWt_1_1WFileResource.html">WFileResource</a>
  </div>
</div>
<div class="contents">
<h1>Wt::WFileResource Class Reference</h1><!-- doxytag: class="Wt::WFileResource" --><!-- doxytag: inherits="Wt::WResource" -->A resource which streams data from a local file.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;Wt/WFileResource&gt;</code>
<p>
<div class="dynheader">
Inheritance diagram for Wt::WFileResource:</div>
<div class="dynsection">
<p><center><img src="classWt_1_1WFileResource__inherit__graph.png" border="0" usemap="#Wt_1_1WFileResource__inherit__map" alt="Inheritance graph"></center>
<map name="Wt_1_1WFileResource__inherit__map">
<area shape="rect" href="classWt_1_1WResource.html" title="An object which can be rendered in the HTTP protocol." alt="" coords="16,80,128,107"><area shape="rect" href="classWt_1_1WObject.html" title="A base class for objects that participate in the signal/slot system." alt="" coords="24,5,120,32"></map>
<center><font size="2">[<a href="graph_legend.html">legend</a>]</font></center></div>

<p>
<a href="classWt_1_1WFileResource-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="b756e5ea65534bfa89dccfc1bd1ce06d"></a><!-- doxytag: member="Wt::WFileResource::WFileResource" ref="b756e5ea65534bfa89dccfc1bd1ce06d" args="(const std::string &amp;mimeType, const std::string &amp;fileName, WObject *parent=0)" -->
&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#b756e5ea65534bfa89dccfc1bd1ce06d">WFileResource</a> (const std::string &amp;mimeType, const std::string &amp;fileName, <a class="el" href="classWt_1_1WObject.html">WObject</a> *parent=0)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Creates a new resource with given mime-type and contents stored in filename. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#60bcdd2873274df4143c79444d178004">~WFileResource</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destructor.  <a href="#60bcdd2873274df4143c79444d178004"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#02a899ebef188895c4f1707e529c0ef3">setFileName</a> (const std::string &amp;fileName)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sets a (different) filename.  <a href="#02a899ebef188895c4f1707e529c0ef3"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="eec71fb64b2a1bef2ebb7f61f30639e3"></a><!-- doxytag: member="Wt::WFileResource::fileName" ref="eec71fb64b2a1bef2ebb7f61f30639e3" args="() const " -->
const std::string &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#eec71fb64b2a1bef2ebb7f61f30639e3">fileName</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns the filename. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="72db1d052a130e22a99e60e064e30006"></a><!-- doxytag: member="Wt::WFileResource::setMimeType" ref="72db1d052a130e22a99e60e064e30006" args="(const std::string &amp;mimeType)" -->
void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#72db1d052a130e22a99e60e064e30006">setMimeType</a> (const std::string &amp;mimeType)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sets the mime-type. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="b01b1ad9dea02d17a87d44c6dcae4c1c"></a><!-- doxytag: member="Wt::WFileResource::mimeType" ref="b01b1ad9dea02d17a87d44c6dcae4c1c" args="() const " -->
const std::string &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#b01b1ad9dea02d17a87d44c6dcae4c1c">mimeType</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns the mime-type. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#8f1eb8202a696db4e80e082d5d84a692">setBufferSize</a> (int size)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Configures the buffer size.  <a href="#8f1eb8202a696db4e80e082d5d84a692"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#c1fa1a9e6bc1f3ee726d3850a27e12b4">bufferSize</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns the buffer size.  <a href="#c1fa1a9e6bc1f3ee726d3850a27e12b4"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WFileResource.html#7a801fa115d455a2b8cc29938a29fe85">handleRequest</a> (const <a class="el" href="classWt_1_1Http_1_1Request.html">Http::Request</a> &amp;request, <a class="el" href="classWt_1_1Http_1_1Response.html">Http::Response</a> &amp;response)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Handles a request.  <a href="#7a801fa115d455a2b8cc29938a29fe85"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
A resource which streams data from a local file. 
<p>
To update the resource, either use <a class="el" href="classWt_1_1WFileResource.html#02a899ebef188895c4f1707e529c0ef3" title="Sets a (different) filename.">setFileName()</a> to point it to a new file, or emit the <a class="el" href="classWt_1_1WResource.html#148bff8e30470cfeaedc0807feeb992a" title="Signal emitted when the data presented in this resource has changed.">WResource::dataChanged()</a> signal when only the file contents has changed, but not the filename.<p>
The resource makes use of continuations to transmit data piecewise, without blocking a thread or requiring the entire file to be read in memory. The size of the buffer can be changed using <a class="el" href="classWt_1_1WFileResource.html#8f1eb8202a696db4e80e082d5d84a692" title="Configures the buffer size.">setBufferSize()</a>.<p>
Usage examples: <div class="fragment"><pre class="fragment"> <a class="code" href="classWt_1_1WFileResource.html" title="A resource which streams data from a local file.">Wt::WFileResource</a> *csvFile = <span class="keyword">new</span> <a class="code" href="classWt_1_1WFileResource.html" title="A resource which streams data from a local file.">Wt::WFileResource</a>(<span class="stringliteral">"text/csv"</span>, <span class="stringliteral">"/opt/files/afile.csv"</span>);
 csvFile-&gt;<a class="code" href="classWt_1_1WResource.html#8f2c3c2aa013cebecd73398dadc3d6d0" title="Suggests a filename to the user for the data streamed by this resource.">suggestFileName</a>(<span class="stringliteral">"data.csv"</span>);
 <a class="code" href="classWt_1_1WAnchor.html" title="A widget that represents an HTML anchor (to link to other documents).">Wt::WAnchor</a> *anchor = <span class="keyword">new</span> <a class="code" href="classWt_1_1WAnchor.html" title="A widget that represents an HTML anchor (to link to other documents).">Wt::WAnchor</a>(csvFile, <span class="stringliteral">"CSV data"</span>);

 <a class="code" href="classWt_1_1WFileResource.html" title="A resource which streams data from a local file.">Wt::WFileResource</a> *imageFile = <span class="keyword">new</span> <a class="code" href="classWt_1_1WFileResource.html" title="A resource which streams data from a local file.">Wt::WFileResource</a>(<span class="stringliteral">"image/png"</span>, <span class="stringliteral">"/opt/files/image.png"</span>);
 imageFile-&gt;<a class="code" href="classWt_1_1WResource.html#8f2c3c2aa013cebecd73398dadc3d6d0" title="Suggests a filename to the user for the data streamed by this resource.">suggestFileName</a>(<span class="stringliteral">"data.png"</span>);
 <a class="code" href="classWt_1_1WImage.html" title="A widget that displays an image.">Wt::WImage</a> *image = <span class="keyword">new</span> <a class="code" href="classWt_1_1WImage.html" title="A widget that displays an image.">Wt::WImage</a>(imageFile, <span class="stringliteral">"PNG version"</span>);
</pre></div><p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1WMemoryResource.html" title="A resource which streams data from memory.">WMemoryResource</a> </dd></dl>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="60bcdd2873274df4143c79444d178004"></a><!-- doxytag: member="Wt::WFileResource::~WFileResource" ref="60bcdd2873274df4143c79444d178004" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Wt::WFileResource::~WFileResource           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Destructor. 
<p>
It is up to the user to make sure that the resource is no longer in use (by e.g. a <a class="el" href="classWt_1_1WImage.html" title="A widget that displays an image.">WImage</a>). 
</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="02a899ebef188895c4f1707e529c0ef3"></a><!-- doxytag: member="Wt::WFileResource::setFileName" ref="02a899ebef188895c4f1707e529c0ef3" args="(const std::string &amp;fileName)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WFileResource::setFileName           </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>fileName</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Sets a (different) filename. 
<p>
Set the location of the file on the local filesystem which must be streamed for this resource. 
</div>
</div><p>
<a class="anchor" name="8f1eb8202a696db4e80e082d5d84a692"></a><!-- doxytag: member="Wt::WFileResource::setBufferSize" ref="8f1eb8202a696db4e80e082d5d84a692" args="(int size)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WFileResource::setBufferSize           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>size</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Configures the buffer size. 
<p>
This configures the size of the buffer used to transmit the file piece by piece. 
</div>
</div><p>
<a class="anchor" name="c1fa1a9e6bc1f3ee726d3850a27e12b4"></a><!-- doxytag: member="Wt::WFileResource::bufferSize" ref="c1fa1a9e6bc1f3ee726d3850a27e12b4" args="() const " -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Wt::WFileResource::bufferSize           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td> const<code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Returns the buffer size. 
<p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1WFileResource.html#8f1eb8202a696db4e80e082d5d84a692" title="Configures the buffer size.">setBufferSize()</a> </dd></dl>

</div>
</div><p>
<a class="anchor" name="7a801fa115d455a2b8cc29938a29fe85"></a><!-- doxytag: member="Wt::WFileResource::handleRequest" ref="7a801fa115d455a2b8cc29938a29fe85" args="(const Http::Request &amp;request, Http::Response &amp;response)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WFileResource::handleRequest           </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="classWt_1_1Http_1_1Request.html">Http::Request</a> &amp;&nbsp;</td>
          <td class="paramname"> <em>request</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classWt_1_1Http_1_1Response.html">Http::Response</a> &amp;&nbsp;</td>
          <td class="paramname"> <em>response</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Handles a request. 
<p>
Reimplement this method so that a proper response is generated for the given request. From the <code>request</code> object you can access request parameters and whether the request is a continuation request. In the <code>response</code> object, you should set the mime type and stream the output data.<p>
A request may also concern a continuation, indicated in <a class="el" href="classWt_1_1Http_1_1Request.html#2d4f88961a222be846460a8238823ae0" title="Returns a continuation object.">Http::Request::continuation()</a>, in which case the next part for a previously created continuation should be served.<p>
While handling a request, which may happen at any time together with event handling, the library makes sure that the resource is not being concurrently deleted, but multiple requests may happend simultaneously for a single resource. 
<p>Implements <a class="el" href="classWt_1_1WResource.html#3a740f8cc29e2e6e4e58defc9c88b8b6">Wt::WResource</a>.</p>

</div>
</div><p>
</div>
<hr size="1"><address style="align: right;"><small>
Generated on Fri Mar 26 17:12:07 2010 for <a href="http://www.webtoolkit.eu/wt/">Wt</a> by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
</body>
</html>