summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-08-30 07:47:55 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-08-30 07:47:55 -0700
commitc2343400688366e567f67e89a50d573786f98bec (patch)
treeca130b093bb72748f3c3f53e25968320ed828f7c /include
parent49faa66adb7870d9e20596d2ae7c41c9638045e3 (diff)
Further work in progress (that breaks everything)
Diffstat (limited to 'include')
-rw-r--r--include/extension.h98
-rw-r--r--include/function.h4
-rw-r--r--include/functions.h66
-rw-r--r--include/request.h6
4 files changed, 106 insertions, 68 deletions
diff --git a/include/extension.h b/include/extension.h
index 701da86..daff45e 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -11,14 +11,13 @@
* as module in a webserver) many requests are handled by the same extension
* instance.
*
+ * This is a template class. You need to pass in the type of an object
+ * that you use for storing request specific state information.
+ *
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2013 Copernica BV
*/
-
-/**
- * Forward declarations
- */
-struct _zend_module_entry;
+#include <php5/Zend/zend_modules.h>
/**
* Set up namespace
@@ -26,28 +25,29 @@ struct _zend_module_entry;
namespace PhpCpp {
/**
- * Forward definitions
- */
-class Functions;
-
-/**
* Class definition
*/
class Extension
{
public:
/**
- * Extension that defines a number of functions right away
+ * Constructor that defines a number of functions right away
* @param name Extension name
* @param version Extension version string
* @param functions The functions that are defined
*/
- Extension(const char *name, const char *version, const std::initializer_list<Function> &functions = {});
+ Extension(const char *name, const char *version, const Functions &functions);
+
+ /**
+ * No copy'ing and no moving
+ */
+ Extension(const Extension &extension) = delete;
+ Extension(Extension &&extension) = delete;
/**
* Destructor
*/
- virtual ~Extension();
+ virtual ~Extension() {}
/**
* Initialize the extension.
@@ -105,14 +105,14 @@ public:
*/
bool startRequest()
{
- // failure if we already have a request
- if (_request) return false;
-
- // create the request
- _request = request();
-
- // and initialize it
- return _request->initialize();
+// // failure if we already have a request
+// if (_request) return false;
+//
+// // create the request
+// _request = request();
+//
+// // and initialize it
+// return _request->initialize();
}
/**
@@ -125,57 +125,25 @@ public:
*/
bool endRequest()
{
- // request must exist
- if (!_request) return false;
-
- // finalize the request
- bool result = _request->finalize();
-
- // destruct the request object
- delete _request;
-
- // done
- return result;
+// // request must exist
+// if (!_request) return false;
+//
+// // finalize the request
+// bool result = _request->finalize();
+//
+// // destruct the request object
+// delete _request;
+//
+// // done
+// return result;
}
- /**
- * Internal method to get access to the entry
- * @return zend_module_entry
- * @internal
- */
- _zend_module_entry *entry();
-
private:
/**
- * Extension name
- * @var char*
- */
- const char *_name;
-
- /**
- * Extension version
- * @var char*
- */
- const char *_version;
-
- /**
- * The functions that are defined
- * @var vector
- */
- Functions *_functions;
-
- /**
* The information that is passed to the Zend engine
* @var zend_module_entry
*/
- _zend_module_entry *_entry = NULL;
-
- /**
- * The current request being processed
- * @var Request
- */
- Request *_request = NULL;
-
+ zend_module_entry _entry;
};
diff --git a/include/function.h b/include/function.h
index a7dc9b0..fec83e9 100644
--- a/include/function.h
+++ b/include/function.h
@@ -91,9 +91,7 @@ public:
* @param arguments The actual arguments that were passed
* @return Variable Return value
*/
- virtual Value invoke(const Request *request, const std::initializer_list<Value> &arguments)
- {
- }
+ virtual Value invoke(const Request *request, const std::initializer_list<Value> &arguments);
/**
* Get access to the internal object
diff --git a/include/functions.h b/include/functions.h
new file mode 100644
index 0000000..49f38b7
--- /dev/null
+++ b/include/functions.h
@@ -0,0 +1,66 @@
+/**
+ * Functions.h
+ *
+ * Internal helper class that parses the functions initializer list, and
+ * that converts it into a zend_function_entry array.
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace PhpCpp {
+
+/**
+ * Class definition
+ */
+class Functions
+{
+public:
+ /**
+ * Constructor
+ * @param functions The functions to parse
+ */
+ Functions(const std::initializer_list<Function> &functions);
+
+ /**
+ * Destructor
+ */
+ virtual ~Functions();
+
+private:
+ /**
+ * Retrieve the internal data
+ * @return zend_function_entry*
+ */
+ zend_function_entry *internal() const
+ {
+ return _entries;
+ }
+
+ /**
+ * The internal entries
+ * @var zend_function_entry*
+ */
+ zend_function_entry *_entries;
+
+ /**
+ * Vector of functions (we need this because the function objects must
+ * remain in memory, so that we can call the invoke methods on them)
+ * @var vector
+ */
+ std::vector<Function> _functions;
+
+ /**
+ * The extension has access to the private elements
+ */
+ friend class Extension;
+};
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/include/request.h b/include/request.h
index f1cf25b..f37a449 100644
--- a/include/request.h
+++ b/include/request.h
@@ -74,6 +74,12 @@ protected:
* @var Extension*
*/
Extension *_extension;
+
+ /**
+ * Optional extra data
+ * @var Type
+ */
+ Type _data;
};
/**