Skip to content

Commit

Permalink
introduced common directory that will contain implementation files th…
Browse files Browse the repository at this point in the history
…at are used for hhvm and zend, and introduced hhvm file for the implementation of hhvmcpp
  • Loading branch information
EmielBruijntjes committed Apr 6, 2014
1 parent 35fd3cc commit 43cfaa8
Show file tree
Hide file tree
Showing 8 changed files with 401 additions and 136 deletions.
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ MKDIR = mkdir -p
# The source files
#
# For this we use a special Makefile function that automatically scans the
# src/, zend/ and hhvm/ directories for all *.cpp files. No changes are
# common/, zend/ and hhvm/ directories for all *.cpp files. No changes are
# probably necessary here
#

SOURCES = $(wildcard src/*.cpp)
COMMON_SOURCES = $(wildcard common/*.cpp)
PHP_SOURCES = $(wildcard zend/*.cpp)
HHVM_SOURCES = $(wildcard hhvm/*.cpp)

Expand All @@ -137,7 +137,7 @@ HHVM_SOURCES = $(wildcard hhvm/*.cpp)
# takes all source files.
#

OBJECTS = $(SOURCES:%.cpp=%.o)
COMMON_OBJECTS = $(COMMON_SOURCES:%.cpp=%.o)
PHP_OBJECTS = $(PHP_SOURCES:%.cpp=%.o)
HHVM_OBJECTS = $(HHVM_SOURCES:%.cpp=%.o)

Expand All @@ -149,17 +149,21 @@ HHVM_OBJECTS = $(HHVM_SOURCES:%.cpp=%.o)

all: ${PHP_LIBRARY}

${PHP_LIBRARY}: ${OBJECTS} ${PHP_OBJECTS}
phpcpp: ${PHP_LIBRARY}

hhvmcpp: ${HHVM_LIBRARY}

${PHP_LIBRARY}: ${COMMON_OBJECTS} ${PHP_OBJECTS}
${LINKER} ${PHP_LINKER_FLAGS} -o $@ ${OBJECTS} ${PHP_OBJECTS}

${HHVM_LIBRARY}: ${OBJECTS} ${HHVM_OBJECTS}
${HHVM_LIBRARY}: ${COMMON_OBJECTS} ${HHVM_OBJECTS}
${LINKER} ${HHVM_LINKER_FLAGS} -o $@ ${OBJECTS} ${HHVM_OBJECTS}

clean:
${RM} ${OBJECTS} ${PHP_OBJECTS} ${HHVM_OBJECTS} ${PHP_LIBRARY} ${HHVM_LIBRARY}
${RM} ${COMMON_OBJECTS} ${PHP_OBJECTS} ${HHVM_OBJECTS} ${PHP_LIBRARY} ${HHVM_LIBRARY}

${OBJECTS}:
${COMPILER} ${PHP_COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp}
${COMMON_OBJECTS}:
${COMPILER} ${COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp}

${PHP_OBJECTS}:
${COMPILER} ${PHP_COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp}
Expand Down
138 changes: 138 additions & 0 deletions common/extensionbase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* ExtensionBase.h
*
* Base class for ExtensionImpl objects. Common code used by both the Zend
* and HHVM engine.
*
* @author Emiel Bruijntjes <[email protected]>
* @copyright 2013, 2014 Copernica BV
*/

/**
* Set up namespace
*/
namespace Php {

/**
* Class definition
*/
class ExtensionBase
{
protected:
/**
* Pointer to the extension object that is filled by the extension programmer
* @var Extension
*/
Extension *_data;

/**
* Callback that is called after the engine is initialized and before the
* pageviews are going to be handled
* @var Callback
*/
Callback _onStartup;

/**
* Callback that is called in front of each request
* @var Callback
*/
Callback _onRequest;

/**
* Callback that is called right after each request
* @var Callback
*/
Callback _onIdle;

/**
* Callback that is called right before the engine is closing down
* @var Callback
*/
Callback _onShutdown;

public:
/**
* Constructor
* @param data Extension object created by the extension programmer
*/
ExtensionBase(Extension *data) : _data(data) {}

/**
* No copy'ing and no moving
*/
ExtensionBase(const ExtensionImpl &extension) = delete;
ExtensionBase(ExtensionImpl &&extension) = delete;

/**
* Destructor
*/
virtual ~ExtensionBase() {}

/**
* Register a function to be called when the PHP engine is ready
*
* The callback will be called after all extensions are loaded, and all
* functions and classes are available, but before the first pageview/request
* is handled. You can register this callback if you want to be notified
* when the engine is ready, for example to initialize certain things.
*
* @param callback
*/
void onStartup(const Callback &callback)
{
// copy callback
_onStartup = callback;
}

/**
* Register a function to be called when the PHP engine is going to stop
*
* The callback will be called right before the process is going to stop.
* You can register a function if you want to clean up certain things.
*
* @param callback
*/
void onShutdown(const Callback &callback)
{
// copy callback
_onShutdown = callback;
}

/**
* Register a callback that is called at the beginning of each pageview/request
*
* You can register a callback if you want to initialize certain things
* at the beginning of each request. Remember that the extension can handle
* multiple requests after each other, and you may want to set back certain
* global variables to their initial variables in front of each request
*
* @param callback
*/
void onRequest(const Callback &callback)
{
// copy callback
_onRequest = callback;
}

/**
* Register a callback that is called to cleanup things after a pageview/request
*
* The callback will be called after _each_ request, so that you can clean up
* certain things and make your extension ready to handle the next request.
* This method is called onIdle because the extension is idle in between
* requests.
*
* @param callback
*/
void onIdle(const Callback &callback)
{
// copy callback
_onIdle = callback;
}
};

/**
* End of namespace
*/
}

103 changes: 103 additions & 0 deletions hhvm/extension.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* Extension.cpp
*
* @author Emiel Bruijntjes <[email protected]>
* @copyright 2013, 2014 Copernica BV
*/
#include "includes.h"

/**
* Set up namespace
*/
namespace Php {

/**
* Constructor that defines a number of functions right away
* @param name Extension name
* @param version Extension version string
*/
Extension::Extension(const char *name, const char *version) :
Namespace(""), _impl(new ExtensionImpl(this, name, version)) {}

/**
* Destructor
*/
Extension::~Extension()
{
// get rid of the implementation object
delete _impl;
}

/**
* Register a function to be called when the PHP engine is ready
* @param callback
* @return Extension
*/
Extension &Extension::onStartup(const Callback &callback)
{
// pass on to the implementation
_impl->onStartup(callback);

// allow chaining
return *this;
}

/**
* Register a function to be called when the PHP engine is going to stop
* @param callback
* @return Extension
*/
Extension &Extension::onShutdown(const Callback &callback)
{
// pass on to the implementation
_impl->onShutdown(callback);

// allow chaining
return *this;
}

/**
* Register a callback that is called at the beginning of each pageview/request
* @param callback
*/
Extension &Extension::onRequest(const Callback &callback)
{
// pass on to the implementation
_impl->onRequest(callback);

// allow chaining
return *this;
}

/**
* Register a callback that is called to cleanup things after a pageview/request
* @param callback
*/
Extension &Extension::onIdle(const Callback &callback)
{
// pass on to the implementation
_impl->onIdle(callback);

// allow chaining
return *this;
}

/**
* Retrieve the module pointer
*
* This is the memory address that should be exported by the get_module()
* function.
*
* @return void*
*/
void *Extension::module()
{
// pass on to the implementation
return _impl->module();
}

/**
* End of namespace
*/
}

55 changes: 55 additions & 0 deletions hhvm/extensionimpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* ExtensionImpl.h
*
* Implementation of the extension object for the HHVM engine
*
* @author Emiel Bruijntjes <[email protected]>
* @copyright 2014 Copernica BV
*/

/**
* Namespace
*/
namespace Php {

/**
* Class definition
*/
class ExtensionImpl : public ExtensionBase
{
private:
/**
* Pointer to the extension object that is filled by the extension programmer
* @var Extension
*/
Extension *_data;

public:
/**
* Constructor
* @param data Pointer to the extension object created by the extension programmer
* @param name Name of the extension
* @param version Version identifier of the extension
*/
ExtensionImpl(Extension *data, const char *name, const char *version) : ExtensionBase(data) {}

/**
* Destructor
*/
virtual ~ExtensionImpl() {}

/**
* Pointer to the module that is loaded by HHVM
* @return void*
*/
void *module()
{
return nullptr;
}
};

/**
* End of namespace
*/
}

Loading

0 comments on commit 43cfaa8

Please sign in to comment.