summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-09-09 15:02:22 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-09-09 15:02:22 -0700
commite220af8dc07d845efb81082f3159460406ece9ca (patch)
tree0730a4d27a0aea3e826674c237cb581b56a9dcdc /include
parent49e349c494e0134570a158e56ba8b5b9f26b94f6 (diff)
work in progress
Diffstat (limited to 'include')
-rw-r--r--include/extension.h33
-rw-r--r--include/function.h15
-rw-r--r--include/functions.h71
-rw-r--r--include/hiddenpointer.h264
-rw-r--r--include/request.h2
5 files changed, 178 insertions, 207 deletions
diff --git a/include/extension.h b/include/extension.h
index 5dabb8e..ad00593 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -11,8 +11,8 @@
* 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.
+ * 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
@@ -29,6 +29,20 @@ struct _zend_module_entry;
namespace Php {
/**
+ * A couple of predefined native callback functions that can be registered.
+ * These are functions that optional accept a Request and/or Parameters object,
+ * and that either return void or a Value object.
+ */
+typedef void (*native_callback_0)();
+typedef void (*native_callback_1)(Parameters &);
+typedef void (*native_callback_2)(Request &);
+typedef void (*native_callback_3)(Request &, Parameters &);
+typedef Value (*native_callback_4)();
+typedef Value (*native_callback_5)(Parameters &);
+typedef Value (*native_callback_6)(Request &);
+typedef Value (*native_callback_7)(Request &, Parameters &);
+
+/**
* Class definition
*/
class Extension
@@ -159,6 +173,21 @@ public:
Function &add(const char *name, const Function &function);
/**
+ * Add a native function directly to the extension
+ * @param name Name of the function
+ * @param function The function to add
+ * @return Function The added function
+ */
+ Function &add(const char *name, native_callback_0 function);
+ Function &add(const char *name, native_callback_1 function);
+ Function &add(const char *name, native_callback_2 function);
+ Function &add(const char *name, native_callback_3 function);
+ Function &add(const char *name, native_callback_4 function);
+ Function &add(const char *name, native_callback_5 function);
+ Function &add(const char *name, native_callback_6 function);
+ Function &add(const char *name, native_callback_7 function);
+
+ /**
* Retrieve the module entry
*
* This is the memory address that should be exported by the get_module()
diff --git a/include/function.h b/include/function.h
index 67d2332..daf8572 100644
--- a/include/function.h
+++ b/include/function.h
@@ -26,6 +26,18 @@ namespace Php {
class Function
{
public:
+
+// Function(std::function<Value()> &function);
+// Function(std::function<Value(Value&)> &function);
+// Function(std::function<Value(Value&,Value&)> &function);
+// Function(std::function<Value(Value&,Value&,Value&)> &function);
+// Function(std::function<Value(Value&,Value&,Value&,Value&)> &function);
+// Function(std::function<void()> &function);
+// Function(std::function<void(Value&)> &function);
+// Function(std::function<void(Value&,Value&)> &function);
+// Function(std::function<void(Value&,Value&,Value&)> &function);
+// Function(std::function<void(Value&,Value&,Value&,Value&)> &function);
+
/**
* Constructor
* @param min Min number of arguments
@@ -87,10 +99,11 @@ public:
/**
* Method that gets called every time the function is executed
+ * @param request Request object
* @param params The parameters that were passed
* @return Variable Return value
*/
- virtual Value invoke(Parameters &params)
+ virtual Value invoke(Request &request, Parameters &params)
{
return 0;
}
diff --git a/include/functions.h b/include/functions.h
deleted file mode 100644
index 69653b4..0000000
--- a/include/functions.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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
- */
-
-/**
- * Define structures
- */
-struct _zend_function_entry;
-
-/**
- * Set up namespace
- */
-namespace Php {
-
-/**
- * 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/hiddenpointer.h b/include/hiddenpointer.h
index bcb44ba..f29082f 100644
--- a/include/hiddenpointer.h
+++ b/include/hiddenpointer.h
@@ -1,50 +1,50 @@
/**
- * HiddenPointer.h
+ * HiddenPointer.h
*
- * Helper class that we use to hide a pointer in a string. We do this
- * by creating a string buffer that is a littlebit bigger, and put
- * the hidden pointer in front of the name
+ * Helper class that we use to hide a pointer in a string. We do this
+ * by creating a string buffer that is a littlebit bigger, and put
+ * the hidden pointer in front of the name
*
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
*/
/**
- * Set up namespace
+ * Set up namespace
*/
namespace Php {
/**
- * Class definition
+ * Class definition
*/
template <typename Type>
class HiddenPointer
{
public:
- /**
- * Constructor to hide the pointer in a buffer
- * @param pointer The pointer to hide
- * @param text The visible text
- * @param size Optional text size
- */
- HiddenPointer(Type *pointer, const char *text, int size=-1)
- {
- // calculate size
- if (size < 0) size = strlen(text);
+ /**
+ * Constructor to hide the pointer in a buffer
+ * @param pointer The pointer to hide
+ * @param text The visible text
+ * @param size Optional text size
+ */
+ HiddenPointer(Type *pointer, const char *text, int size=-1)
+ {
+ // calculate size
+ if (size < 0) size = strlen(text);
- // reserve enough room for the text and the pointer
- _data.reserve(size + sizeof(Type *));
-
- // store the pointer
- _data.assign(std::string((const char *)&pointer, sizeof(Type *)));
-
- // append the text
- _data.append(text, size);
-
- // store pointers
- _pointer = pointer;
- _text = _data.c_str() + sizeof(Type *);
- }
+ // reserve enough room for the text and the pointer
+ _data.reserve(size + sizeof(Type *));
+
+ // store the pointer
+ _data.assign(std::string((const char *)&pointer, sizeof(Type *)));
+
+ // append the text
+ _data.append(text, size);
+
+ // store pointers
+ _pointer = pointer;
+ _text = _data.c_str() + sizeof(Type *);
+ }
/**
* Hide pointer in buffer
@@ -53,114 +53,114 @@ public:
*/
HiddenPointer(Type *pointer, const std::string &text) : HiddenPointer(pointer, text.c_str(), text.size()) {}
- /**
- * Constructor to retrieve the object given a buffer
- * @param text The visible text
- * @param size Size of the text
- */
- HiddenPointer(const char *text, int size=-1)
- {
- // calculate size
- if (size < 0) size = strlen(text);
-
- // the pointer is stored right in front of the name
- _pointer = *((Type **)(text - sizeof(Type *)));
- _text = text;
- }
-
- /**
- * Copy constructor
- * @param that
- */
- HiddenPointer(const HiddenPointer<Type> &that) : _pointer(that._pointer), _text(that._text), _data(that._data)
- {
- // if data is filled, the text is located inside the data
- if (_data.size() > 0) _text = _data.c_str() + sizeof(Type *);
- }
-
- /**
- * Destructor
- */
- virtual ~HiddenPointer() {}
-
- /**
- * Assignment operator
- * @param that
- * @return HiddenPointer
- */
- HiddenPointer<Type> operator=(const HiddenPointer &that)
- {
- // skip self assignment
- if (&that == this) return *this;
-
- // copy members
- _pointer = that._pointer;
- _text = that._text;
- _data = that._data;
+ /**
+ * Constructor to retrieve the object given a buffer
+ * @param text The visible text
+ * @param size Size of the text
+ */
+ HiddenPointer(const char *text, int size=-1)
+ {
+ // calculate size
+ if (size < 0) size = strlen(text);
+
+ // the pointer is stored right in front of the name
+ _pointer = *((Type **)(text - sizeof(Type *)));
+ _text = text;
+ }
+
+ /**
+ * Copy constructor
+ * @param that
+ */
+ HiddenPointer(const HiddenPointer<Type> &that) : _pointer(that._pointer), _text(that._text), _data(that._data)
+ {
+ // if data is filled, the text is located inside the data
+ if (_data.size() > 0) _text = _data.c_str() + sizeof(Type *);
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~HiddenPointer() {}
+
+ /**
+ * Assignment operator
+ * @param that
+ * @return HiddenPointer
+ */
+ HiddenPointer<Type> operator=(const HiddenPointer &that)
+ {
+ // skip self assignment
+ if (&that == this) return *this;
+
+ // copy members
+ _pointer = that._pointer;
+ _text = that._text;
+ _data = that._data;
- // if data is filled, the text is located inside the data
- if (_data.size() > 0) _text = _data.c_str() + sizeof(Type *);
- }
-
- /**
- * Retrieve the pointer
- * @return Type*
- */
- Type *pointer()
- {
- return _pointer;
- }
-
- /**
- * Retrieve the text
- * @return const char *
- */
- const char *text()
- {
- return _text;
- }
-
- /**
- * Cast to the pointer
- * @return Type*
- */
- operator Type* ()
- {
- return _pointer;
- }
-
- /**
- * Cast to text
- * @return const char *
- */
- operator const char * ()
- {
- return _text;
- }
+ // if data is filled, the text is located inside the data
+ if (_data.size() > 0) _text = _data.c_str() + sizeof(Type *);
+ }
+
+ /**
+ * Retrieve the pointer
+ * @return Type*
+ */
+ Type *pointer()
+ {
+ return _pointer;
+ }
+
+ /**
+ * Retrieve the text
+ * @return const char *
+ */
+ const char *text()
+ {
+ return _text;
+ }
+
+ /**
+ * Cast to the pointer
+ * @return Type*
+ */
+ operator Type* ()
+ {
+ return _pointer;
+ }
+
+ /**
+ * Cast to text
+ * @return const char *
+ */
+ operator const char * ()
+ {
+ return _text;
+ }
private:
- /**
- * The actual pointer
- * @var Type*
- */
- Type *_pointer;
-
- /**
- * The original text
- * @var text
- */
- const char *_text;
-
- /**
- * Optional data buffer
- * @var string
- */
- std::string _data;
+ /**
+ * The actual pointer
+ * @var Type*
+ */
+ Type *_pointer;
+
+ /**
+ * The original text
+ * @var text
+ */
+ const char *_text;
+
+ /**
+ * Optional data buffer
+ * @var string
+ */
+ std::string _data;
};
/**
- * End of namespace
+ * End of namespace
*/
}
diff --git a/include/request.h b/include/request.h
index 4183966..d204e85 100644
--- a/include/request.h
+++ b/include/request.h
@@ -77,7 +77,7 @@ protected:
/**
* Optional extra data
- * @var Type
+ * @var Type
*/
Type _data;
};