#include <WResource>
Public Member Functions | |
WResource (WObject *parent=0) | |
Create a new resource. | |
~WResource () | |
Destroy the resource. | |
void | suggestFileName (const std::string &name) |
Suggest a filename to the user for the data streamed by this resource. | |
const std::string | generateUrl () const |
Generate an URL for this resource. | |
bool | reentrant () const |
Can this resource be streamed reentrantly ? | |
void | setReentrant (bool reentrant) |
Specify if this resource may be streamed reentrantly. | |
Public Attributes | |
Signal< void > | dataChanged |
Emit this signal if the data presented in this resource has changed. | |
Protected Member Functions | |
virtual const std::string | resourceMimeType () const =0 |
Return the mimetype. | |
virtual bool | streamResourceData (std::ostream &stream, const ArgumentMap &arguments)=0 |
Stream the data for this resource. | |
void | flush () |
Flush data for this resource. | |
virtual void | setArguments (const ArgumentMap &arguments) |
Set the arguments. | |
void | addHeader (const std::string &name, const std::string &value) |
Add a HTTP header. |
Besides the main page, other objects may be rendered as additional resources, such as frames or dynamic images.
Wt::WResource::~WResource | ( | ) |
Destroy the resource.
It is up to the user to make sure that the resource is nog longer in use.
void Wt::WResource::suggestFileName | ( | const std::string & | name | ) |
Suggest a filename to the user for the data streamed by this resource.
For resources, intended to be downloaded by the user, suggest a name used for saving. The extension will help the browser to identify the correct program for opening the resource as well.
const std::string Wt::WResource::generateUrl | ( | ) | const |
Generate an URL for this resource.
For every call, a new url is generated that refers to this resource. The url is unique to assure that it is not cached by the web browser. Therefore, when the signal dataChanged() is emitted, the widget that uses this resource should call generateUrl() to refer to the changed version of this resource.
bool Wt::WResource::reentrant | ( | ) | const [inline] |
Can this resource be streamed reentrantly ?
Reentrant resources may be streamed concurrently to the user. Thus, its resourceMimeType() and streamResourceData() functions must be implemented in a thread-safe way.
void Wt::WResource::setReentrant | ( | bool | reentrant | ) |
Specify if this resource may be streamed reentrantly.
A reentrant resource may stream its data concurrently with other resources (and with the main event handling ? perhaps this is not necessary...)
virtual const std::string Wt::WResource::resourceMimeType | ( | ) | const [protected, pure virtual] |
Return the mimetype.
Implement this method to return the correct mime type for your resource, e.g. "text/html".
Implemented in Wt::WFileResource, Wt::WMemoryResource, Wt::WSvgImage, Wt::WWidget, and Wt::Ext::DataStore.
virtual bool Wt::WResource::streamResourceData | ( | std::ostream & | stream, | |
const ArgumentMap & | arguments | |||
) | [protected, pure virtual] |
Stream the data for this resource.
Implement this method to output the data for this resource.
Returns whether all data has been streamed. If not, call flush() from outside the mean event loop to indicate that more data is available. This is how "server-push" is implemented. The stream is not closed until this function returns true.
void Wt::WResource::flush | ( | ) | [protected] |
Flush data for this resource.
This is only valid when a previous call to streamResourceData() returned false.
This will trigger a call to streamResourceData() to retrieve more data to be transmitted.
void Wt::WResource::setArguments | ( | const ArgumentMap & | arguments | ) | [protected, virtual] |
Set the arguments.
This method is called before asking reosurceMimeType() and calling streamResourceData() (with the same arguments repeated).
The default implementation does nothing.
void Wt::WResource::addHeader | ( | const std::string & | name, | |
const std::string & | value | |||
) | [protected] |
Add a HTTP header.
This may only be called from within the setArguments(), and not from within streamResourceData() !