1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/interfaces/IForwardSys.h Sat Nov 11 01:19:46 2006 +0000
1.3 @@ -0,0 +1,211 @@
1.4 +#ifndef _INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_
1.5 +#define _INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_
1.6 +
1.7 +#include <IForwardSys.h>
1.8 +#include <IPluginSys.h>
1.9 +
1.10 +#define SMINTERFACE_FORWARDMANAGER_NAME "IForwardManager"
1.11 +#define SMINTERFACE_FORWARDMANAGER_VERSION 1
1.12 +
1.13 +namespace SourceMod
1.14 +{
1.15 + enum ResultType
1.16 + {
1.17 + Pl_Continue = 0, /* No result */
1.18 + Pl_Handled = 1, /* Result was handled, stop at the end */
1.19 + Pl_Stop = 2, /* Result was handled, stop now */
1.20 + };
1.21 +
1.22 + enum ExecType
1.23 + {
1.24 + ET_Ignore = 0, /* Ignore all return values, return 0 */
1.25 + ET_Single = 1, /* Only return the first exec, ignore all others */
1.26 + ET_Event = 2, /* Acts as an event with the ResultTypes above, no mid-Stops allowed, returns highest */
1.27 + ET_Hook = 3, /* Acts as a hook with the ResultTypes above, mid-Stops allowed, returns highest */
1.28 + };
1.29 +
1.30 + /**
1.31 + * @brief Abstracts multiple function calling.
1.32 + *
1.33 + * NOTE: Parameters should be pushed in forward order, unlike
1.34 + * the virtual machine/IPluginContext order.
1.35 + */
1.36 + class IForward : public IPluginFunction
1.37 + {
1.38 + public:
1.39 + /**
1.40 + * @brief Returns the name of the forward.
1.41 + *
1.42 + * @return Forward name.
1.43 + */
1.44 + virtual const char *GetForwardName() =0;
1.45 +
1.46 + /**
1.47 + * @brief Pushes a cell onto the current call.
1.48 + *
1.49 + * @param cell Parameter value to push.
1.50 + * @return True if successful, false if type or count mismatch.
1.51 + */
1.52 + virtual bool PushCell(cell_t cell) =0;
1.53 +
1.54 + /**
1.55 + * @brief Pushes a float onto the current call.
1.56 + *
1.57 + * @param float Parameter value to push.
1.58 + * @return True if successful, false if type or count mismatch.
1.59 + */
1.60 + virtual bool PushFloat(float number) =0;
1.61 +
1.62 + /**
1.63 + * @brief Pushes an array of cells onto the current call, each cell individually.
1.64 + * NOTE: This is essentially a crippled version of PushArray().
1.65 + *
1.66 + * @param array Array of cells.
1.67 + * @param numcells Number of cells in array.
1.68 + * @param each Whether or not to push as an array or individual cells.
1.69 + * @return True if successful, false if too many cells were pushed.
1.70 + */
1.71 + virtual bool PushCells(cell_t array[], unsigned int numcells, bool each) =0;
1.72 +
1.73 + /**
1.74 + * @brief Pushes an array of cells onto the current call.
1.75 + *
1.76 + * @param array Array to copy, NULL if no initial array should be copied.
1.77 + * @param cells Number of cells to allocate and optionally read from the input array.
1.78 + * @param phys_addr Optional return address for physical array.
1.79 + * @param copyback Whether or not changes should be copied back to the input array.
1.80 + * @return True if successful, false otherwise.
1.81 + */
1.82 + virtual bool PushArray(cell_t *inarray, size_t cells, cell_t **phys_addr, bool copyback) =0;
1.83 +
1.84 + /**
1.85 + * @brief Pushes a string onto the current call.
1.86 + *
1.87 + * @param string String to push.
1.88 + * @return True if successful, false if type or count mismatch.
1.89 + */
1.90 + virtual bool PushString(const char *string) =0;
1.91 +
1.92 + /**
1.93 + * @brief Executes the forward, resets the pushed parameter list, and performs any copybacks.
1.94 + *
1.95 + * @param result Pointer to store return value in (dependent on forward type).
1.96 + * @param last_err Pointer to store number of successful executions in.
1.97 + * @return Error code, if any.
1.98 + */
1.99 + virtual int Execute(cell_t *result, unsigned int *num_functions) =0;
1.100 +
1.101 + /**
1.102 + * @brief Returns the number of functions in this forward.
1.103 + *
1.104 + * @return Number of functions in forward.
1.105 + */
1.106 + virtual unsigned int GetFunctionCount() =0;
1.107 +
1.108 + /**
1.109 + * @brief Returns the method of multi-calling this forward has.
1.110 + *
1.111 + * @return ResultType of the forward.
1.112 + */
1.113 + virtual ResultType GetResultType() =0;
1.114 + };
1.115 +
1.116 +
1.117 + class IChangeableForward : public IForward
1.118 + {
1.119 + public:
1.120 + /**
1.121 + * @brief Removes a function from the call list.
1.122 + *
1.123 + * @param func Function to remove.
1.124 + */
1.125 + virtual void RemoveFunction(IPluginFunction *func) =0;
1.126 +
1.127 + /**
1.128 + * @brief Removes all instances of a plugin from the call list.
1.129 + *
1.130 + * @param plugin Plugin to remove instances of.
1.131 + * @return Number of functions removed therein.
1.132 + */
1.133 + virtual void RemoveFunctionsOfPlugin(IPlugin *plugin) =0;
1.134 +
1.135 + /**
1.136 + * @brief Adds a function to the call list.
1.137 + *
1.138 + * @param func Function to add.
1.139 + */
1.140 + virtual void AddFunction(IPluginFunction *func) =0;
1.141 + };
1.142 +
1.143 + enum ParamType
1.144 + {
1.145 + Param_Any = 0,
1.146 + Param_Cell = 1,
1.147 + Param_Float = 2,
1.148 + Param_String = 3,
1.149 + Param_Array = 4,
1.150 + Param_VarArgs = 5,
1.151 + };
1.152 +
1.153 + class IForwardManager : public SMInterface
1.154 + {
1.155 + public:
1.156 + virtual const char *GetInterfaceName()
1.157 + {
1.158 + return SMINTERFACE_FORWARDMANAGER_NAME;
1.159 + }
1.160 + virtual unsigned int GetInterfaceVersion()
1.161 + {
1.162 + return SMINTERFACE_FORWARDMANAGER_VERSION;
1.163 + }
1.164 + public:
1.165 + /**
1.166 + * @brief Creates a managed forward. This forward exists globally.
1.167 + * The name used to create the forward is used as its public function in all target plugins.
1.168 + * As new non-private plugins become loaded or unloaded, they will be automatically added
1.169 + * or removed. This is ideal for global, static forwards that are never changed.
1.170 + *
1.171 + * @param name Name of public function to use in forward.
1.172 + * @param et Execution type to be used.
1.173 + * @param num_params Number of parameter this function will have.
1.174 + * NOTE: For varargs, this should include the vararg parameter.
1.175 + * @param types Array of type information about each parameter. If NULL, types
1.176 + * are read off the vararg stream.
1.177 + * @param ... If types is NULL, num_params ParamTypes should be pushed.
1.178 + * @return A new IForward on success, NULL if type combination is impossible.
1.179 + */
1.180 + virtual IForward *CreateForward(const char *name, ExecType et, int num_params, ParamType *types, ...) =0;
1.181 +
1.182 + /**
1.183 + * @brief Creates an unmanaged forward. This forward exists privately.
1.184 + * Unlike managed forwards, no functions are ever added by the Manager.
1.185 + * However, functions will be removed automatically if their parent plugin is unloaded.
1.186 + *
1.187 + * @param name Name of forward (unused except for lookup, can be NULL for anonymous).
1.188 + * @param et Execution type to be used.
1.189 + * @param num_params Number of parameter this function will have.
1.190 + * NOTE: For varargs, this should include the vararg parameter.
1.191 + * @param types Array of type information about each parameter. If NULL, types
1.192 + * are read off the vararg stream.
1.193 + * @param ... If types is NULL, num_params ParamTypes should be pushed.
1.194 + * @return A new IChangeableForward on success, NULL if type combination is impossible.
1.195 + */
1.196 + virtual IChangeableForward *CreateForwardEx(const char *name,
1.197 + ExecType et,
1.198 + int num_params,
1.199 + ParamType *types,
1.200 + ...) =0;
1.201 +
1.202 + /**
1.203 + * @brief Finds a forward by name. Does not return anonymous forwards (named NULL or "").
1.204 + *
1.205 + * @param name Name of forward.
1.206 + * @param ifchng Optionally store either NULL or an IChangeableForward pointer
1.207 + * depending on type of forward.
1.208 + * @return IForward pointer, or NULL if none found matching the name.
1.209 + */
1.210 + virtual IForward *FindForward(const char *name, IChangeableForward **ifchng) =0;
1.211 + };
1.212 +};
1.213 +
1.214 +#endif //_INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_