diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-10 15:19:49 -0700 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-10 15:19:49 -0700 |
commit | f08f5850fa39c42974e12e42fa101ffe51eef594 (patch) | |
tree | 4b42f9cdf56c1bd909b3c7f8e5297640c367176e /include/environment.h | |
parent | 37c38c70de43d9d9ee3c9f0e2f175e19bcc0b485 (diff) |
Renamed request to environment
Diffstat (limited to 'include/environment.h')
-rw-r--r-- | include/environment.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/include/environment.h b/include/environment.h new file mode 100644 index 0000000..b8b4f74 --- /dev/null +++ b/include/environment.h @@ -0,0 +1,113 @@ +/** + * Environment.h + * + * During the lifetime of the extension, multiple requests can be handled + * by it. For every request that is handled, an environment object is created. + * + * The base class for the environment is defined in this file. If you'd like + * to add state variables to the environment you can override this class and + * add the extra features you'd like. If you override this method, you should + * also override Extension::createEnvironment() to return an instance of a + * different class. + * + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> + * @copyright 2013 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Forward definitions + */ +class Extension; + +/** + * Class definition + */ +class Environment +{ +public: + /** + * Constructor + * @param extension + */ + Environment(Extension *extension) : _extension(extension) {} + + /** + * Disable copy and move operations + */ + Environment(const Environment &environment) = delete; + Environment(Environment &&environment) = delete; + + /** + * Destructor + */ + virtual ~Environment() {} + + /** + * Initialize the request + * + * This method is called directly after the object was destructed. You can + * override this method to add your own initialization code. + * + * @return bool + */ + virtual bool initialize() + { + return true; + } + + /** + * Finalize the request + * + * This method is called right before the object is destructed. Note that + * the object is going to be destructed anyway, even if this method returns + * false + * + * @return bool + */ + virtual bool finalize() + { + return true; + } + + /** + * Get access to the user supplied data + * @return void* + */ + virtual void *data() + { + return _data; + } + + /** + * Change the user supplied data + * @param data + */ + virtual void setData(void *data) + { + _data = data; + } + +protected: + /** + * The extension that this environment belongs to + * @var Extension* + */ + Extension *_extension; + + /** + * Pointer to user supplied data + * @var void* + */ + void *_data = NULL; +}; + +/** + * End of namespace + */ +} + |