initial import of proposed forward API

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40179
This commit is contained in:
David Anderson
2006-11-11 01:19:46 +00:00
parent 30956eae5b
commit 50e5307d32
5 changed files with 535 additions and 42 deletions
+211
View File
@@ -0,0 +1,211 @@
#ifndef _INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_
#define _INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_
#include <IForwardSys.h>
#include <IPluginSys.h>
#define SMINTERFACE_FORWARDMANAGER_NAME "IForwardManager"
#define SMINTERFACE_FORWARDMANAGER_VERSION 1
namespace SourceMod
{
enum ResultType
{
Pl_Continue = 0, /* No result */
Pl_Handled = 1, /* Result was handled, stop at the end */
Pl_Stop = 2, /* Result was handled, stop now */
};
enum ExecType
{
ET_Ignore = 0, /* Ignore all return values, return 0 */
ET_Single = 1, /* Only return the first exec, ignore all others */
ET_Event = 2, /* Acts as an event with the ResultTypes above, no mid-Stops allowed, returns highest */
ET_Hook = 3, /* Acts as a hook with the ResultTypes above, mid-Stops allowed, returns highest */
};
/**
* @brief Abstracts multiple function calling.
*
* NOTE: Parameters should be pushed in forward order, unlike
* the virtual machine/IPluginContext order.
*/
class IForward : public IPluginFunction
{
public:
/**
* @brief Returns the name of the forward.
*
* @return Forward name.
*/
virtual const char *GetForwardName() =0;
/**
* @brief Pushes a cell onto the current call.
*
* @param cell Parameter value to push.
* @return True if successful, false if type or count mismatch.
*/
virtual bool PushCell(cell_t cell) =0;
/**
* @brief Pushes a float onto the current call.
*
* @param float Parameter value to push.
* @return True if successful, false if type or count mismatch.
*/
virtual bool PushFloat(float number) =0;
/**
* @brief Pushes an array of cells onto the current call, each cell individually.
* NOTE: This is essentially a crippled version of PushArray().
*
* @param array Array of cells.
* @param numcells Number of cells in array.
* @param each Whether or not to push as an array or individual cells.
* @return True if successful, false if too many cells were pushed.
*/
virtual bool PushCells(cell_t array[], unsigned int numcells, bool each) =0;
/**
* @brief Pushes an array of cells onto the current call.
*
* @param array Array to copy, NULL if no initial array should be copied.
* @param cells Number of cells to allocate and optionally read from the input array.
* @param phys_addr Optional return address for physical array.
* @param copyback Whether or not changes should be copied back to the input array.
* @return True if successful, false otherwise.
*/
virtual bool PushArray(cell_t *inarray, size_t cells, cell_t **phys_addr, bool copyback) =0;
/**
* @brief Pushes a string onto the current call.
*
* @param string String to push.
* @return True if successful, false if type or count mismatch.
*/
virtual bool PushString(const char *string) =0;
/**
* @brief Executes the forward, resets the pushed parameter list, and performs any copybacks.
*
* @param result Pointer to store return value in (dependent on forward type).
* @param last_err Pointer to store number of successful executions in.
* @return Error code, if any.
*/
virtual int Execute(cell_t *result, unsigned int *num_functions) =0;
/**
* @brief Returns the number of functions in this forward.
*
* @return Number of functions in forward.
*/
virtual unsigned int GetFunctionCount() =0;
/**
* @brief Returns the method of multi-calling this forward has.
*
* @return ResultType of the forward.
*/
virtual ResultType GetResultType() =0;
};
class IChangeableForward : public IForward
{
public:
/**
* @brief Removes a function from the call list.
*
* @param func Function to remove.
*/
virtual void RemoveFunction(IPluginFunction *func) =0;
/**
* @brief Removes all instances of a plugin from the call list.
*
* @param plugin Plugin to remove instances of.
* @return Number of functions removed therein.
*/
virtual void RemoveFunctionsOfPlugin(IPlugin *plugin) =0;
/**
* @brief Adds a function to the call list.
*
* @param func Function to add.
*/
virtual void AddFunction(IPluginFunction *func) =0;
};
enum ParamType
{
Param_Any = 0,
Param_Cell = 1,
Param_Float = 2,
Param_String = 3,
Param_Array = 4,
Param_VarArgs = 5,
};
class IForwardManager : public SMInterface
{
public:
virtual const char *GetInterfaceName()
{
return SMINTERFACE_FORWARDMANAGER_NAME;
}
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_FORWARDMANAGER_VERSION;
}
public:
/**
* @brief Creates a managed forward. This forward exists globally.
* The name used to create the forward is used as its public function in all target plugins.
* As new non-private plugins become loaded or unloaded, they will be automatically added
* or removed. This is ideal for global, static forwards that are never changed.
*
* @param name Name of public function to use in forward.
* @param et Execution type to be used.
* @param num_params Number of parameter this function will have.
* NOTE: For varargs, this should include the vararg parameter.
* @param types Array of type information about each parameter. If NULL, types
* are read off the vararg stream.
* @param ... If types is NULL, num_params ParamTypes should be pushed.
* @return A new IForward on success, NULL if type combination is impossible.
*/
virtual IForward *CreateForward(const char *name, ExecType et, int num_params, ParamType *types, ...) =0;
/**
* @brief Creates an unmanaged forward. This forward exists privately.
* Unlike managed forwards, no functions are ever added by the Manager.
* However, functions will be removed automatically if their parent plugin is unloaded.
*
* @param name Name of forward (unused except for lookup, can be NULL for anonymous).
* @param et Execution type to be used.
* @param num_params Number of parameter this function will have.
* NOTE: For varargs, this should include the vararg parameter.
* @param types Array of type information about each parameter. If NULL, types
* are read off the vararg stream.
* @param ... If types is NULL, num_params ParamTypes should be pushed.
* @return A new IChangeableForward on success, NULL if type combination is impossible.
*/
virtual IChangeableForward *CreateForwardEx(const char *name,
ExecType et,
int num_params,
ParamType *types,
...) =0;
/**
* @brief Finds a forward by name. Does not return anonymous forwards (named NULL or "").
*
* @param name Name of forward.
* @param ifchng Optionally store either NULL or an IChangeableForward pointer
* depending on type of forward.
* @return IForward pointer, or NULL if none found matching the name.
*/
virtual IForward *FindForward(const char *name, IChangeableForward **ifchng) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_
+113 -20
View File
@@ -7,6 +7,8 @@
#define SMINTERFACE_PLUGINMANAGER_NAME "IPluginManager"
#define SMINTERFACE_PLUGINMANAGER_VERSION 1
#define SM_CONTEXTVAR_USER 3
namespace SourceMod
{
/**
@@ -34,31 +36,66 @@ namespace SourceMod
Plugin_BadLoad, /* Plugin failed to load */
};
/**
* @brief Describes the object lifetime of a plugin.
*/
enum PluginLifetime
enum PluginType
{
PluginLifetime_Forever, /* Plugin will never be unloaded */
PluginLifetime_Map /* Plugin will be unloaded at mapchange */
PluginType_Private, /* Plugin is privately managed and receives no forwards */
PluginType_MapUpdated, /* Plugin will never be unloaded unless for updates on mapchange */
PluginType_MapOnly, /* Plugin will be removed at mapchange */
PluginType_Global, /* Plugin will never be unloaded or updated */
};
class IPlugin;
/**
* @brief Encapsulates a basic function call.
* NOTE: Function calls must be atomic to one execution context.
* NOTE: This object should not be deleted. It lives for the lifetime of the plugin.
*/
class IPluginFunction
{
public:
virtual ~IPluginFunction()
{
}
/**
* @brief Executes the function with the given parameter array.
* Parameters are read in forward order (i.e. index 0 is parameter #1)
*
* @param param Array of cell parameters.
* @param num_params Number of parameters to push.
* @param result Pointer to store result of function on return.
* @return SourcePawn error code (if any).
*/
virtual int CallFunction(cell_t *params, unsigned int num_params, cell_t *result) =0;
/**
* @brief Returns which plugin this function belongs to.
*/
virtual IPlugin *GetParentPlugin() =0;
};
/**
* @brief Encapsulates a run-time plugin as maintained by SourceMod.
*/
class IPlugin /*: public IUnloadableParent*/
class IPlugin
{
public:
/*UnloadableParentType GetParentType()
virtual ~IPlugin()
{
return ParentType_Module;
}*/
public:
}
/**
* @brief Returns the lifetime of a plugin.
*/
virtual PluginLifetime GetLifetime() const =0;
virtual PluginType GetType() const =0;
/**
* @brief Returns the current API context being used in the plugin.
@@ -110,20 +147,26 @@ namespace SourceMod
*/
virtual bool SetPauseState(bool paused) =0;
/**
* @brief Locks or unlocks the plugin from being updated on mapchange.
*/
virtual void SetLockForUpdates(bool lock_status) =0;
/**
* @brief Returns whether the plugin is locked from being updated on mapchange.
*/
virtual bool GetLockForUpdates() const =0;
/**
* @brief Returns the unique serial number of a plugin.
*/
virtual unsigned int GetSerial() const =0;
/**
* @brief Returns a function by name.
*
* @param public_name Name of the function.
* @return A new IPluginFunction pointer, NULL if not found.
*/
virtual IPluginFunction *GetFunctionByName(const char *public_name) =0;
/**
* @brief Returns a function by its id.
*
* @param func_id Function ID.
* @return A new IPluginFunction pointer, NULL if not found.
*/
virtual IPluginFunction *GetFunctionById(funcid_t func_id) =0;
};
@@ -159,6 +202,42 @@ namespace SourceMod
virtual void Release() =0;
};
/**
* @brief Listens for plugin-oriented events.
*/
class IPluginsListener
{
public:
/**
* @brief Called when a plugin is created/mapped into memory.
*/
virtual void OnPluginCreated(IPlugin *plugin)
{
}
/**
* @brief Called when a plugin is fully loaded successfully.
*/
virtual void OnPluginLoaded(IPlugin *plugin)
{
}
/**
* @brief Called when a plugin is unloaded (only if fully loaded).
*/
virtual void OnPluginUnloaded(IPlugin *plugin)
{
}
/**
* @brief Called when a plugin is destroyed.
* NOTE: Always called if Created, even if load failed.
*/
virtual void OnPluginDestroyed(IPlugin *plugin)
{
}
};
/**
* @brief Manages the runtime loading and unloading of plugins.
@@ -188,7 +267,7 @@ namespace SourceMod
*/
virtual IPlugin *LoadPlugin(const char *path,
bool debug,
PluginLifetime lifetime,
PluginType type,
char error[],
size_t err_max) =0;
@@ -221,6 +300,20 @@ namespace SourceMod
* Note: This pointer must be freed using EITHER delete OR IPluginIterator::Release().
*/
virtual IPluginIterator *GetPluginIterator() =0;
/**
* @brief Adds a plugin manager listener.
*
* @param listener Pointer to a listener.
*/
virtual void AddPluginsListener(IPluginsListener *listener) =0;
/**
* @brief Removes a plugin listener.
*
* @param listener Pointer to a listener.
*/
virtual void RemovePluginsListener(IPluginsListener *listener) =0;
};
};