2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is not open source and may not be copied without explicit
7 * written permission of AlliedModders LLC. This file may not be redistributed
8 * in whole or significant part.
9 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
14 #ifndef _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
15 #define _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
17 #include <IForwardSys.h>
18 #include <IPluginSys.h>
19 #include "sm_globals.h"
22 #include "sourcemod.h"
24 using namespace SourceHook;
26 typedef List<IPluginFunction *>::iterator FuncIter;
28 //:TODO: a global name max define for sourcepawn, should mirror compiler's sNAMEMAX
29 #define FORWARDS_NAME_MAX 64
46 class CForward : public IChangeableForward
49 virtual int PushCell(cell_t cell);
50 virtual int PushCellByRef(cell_t *cell, int flags);
51 virtual int PushFloat(float number);
52 virtual int PushFloatByRef(float *number, int flags);
53 virtual int PushArray(cell_t *inarray, unsigned int cells, cell_t **phys_addr, int flags);
54 virtual int PushString(const char *string);
55 virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
56 virtual void Cancel();
58 virtual const char *GetForwardName() const;
59 virtual unsigned int GetFunctionCount() const;
60 virtual ExecType GetExecType() const;
61 virtual int Execute(cell_t *result, IForwardFilter *filter);
62 public: //IChangeableForward
63 virtual bool RemoveFunction(IPluginFunction *func);
64 virtual unsigned int RemoveFunctionsOfPlugin(IPlugin *plugin);
65 virtual bool AddFunction(IPluginFunction *func);
66 virtual bool AddFunction(IPluginContext *ctx, funcid_t index);
68 static CForward *CreateForward(const char *name,
70 unsigned int num_params,
73 void PushPausedFunctions(IPlugin *plugin);
74 void PopPausedFunctions(IPlugin *plugin);
76 void _Int_PushArray(cell_t *inarray, unsigned int cells, int flags);
77 void _Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags);
78 inline int SetError(int err)
84 /* :TODO: I want a caching list type here.
85 * Destroying these things and using new/delete for their members feels bad.
87 mutable List<IPluginFunction *> m_functions;
88 List<IPluginFunction *> m_paused;
90 /* Type and name information */
91 FwdParamInfo m_params[SP_MAX_EXEC_PARAMS];
92 ParamType m_types[SP_MAX_EXEC_PARAMS];
93 char m_name[FORWARDS_NAME_MAX+1];
94 unsigned int m_numparams;
95 unsigned int m_varargs;
98 /* State information */
99 unsigned int m_curparam;
103 class CForwardManager :
104 public IForwardManager,
105 public IPluginsListener,
108 friend class CForward;
109 public: //IForwardManager
110 IForward *CreateForward(const char *name,
112 unsigned int num_params,
115 IChangeableForward *CreateForwardEx(const char *name,
120 IForward *FindForward(const char *name, IChangeableForward **ifchng);
121 void ReleaseForward(IForward *forward);
122 public: //IPluginsListener
123 void OnPluginLoaded(IPlugin *plugin);
124 void OnPluginUnloaded(IPlugin *plugin);
125 void OnPluginPauseChange(IPlugin *plugin, bool paused);
126 public: //SMGlobalClass
127 void OnSourceModAllInitialized();
128 void OnSourceModShutdown();
130 CForward *ForwardMake();
131 void ForwardFree(CForward *fwd);
133 CStack<CForward *> m_FreeForwards;
134 List<CForward *> m_managed;
135 List<CForward *> m_unmanaged;
138 extern CForwardManager g_Forwards;
140 #endif //_INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_