core/ShareSys.h
author Asher Baker <asherkin@gmail.com>
Sat Sep 08 21:02:46 2012 +0100 (2012-09-08)
changeset 3652 e0a6517dcd89
parent 2841 dde3dd0b4b8b
permissions -rw-r--r--
Include the auto-version file in the build, so 3rd party plugins compiled aginst the includes get useful versioning info (bug 5453, r=dvander).
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@370
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@370
    28
 *
dvander@370
    29
 * Version: $Id$
dvander@370
    30
 */
dvander@370
    31
dvander@229
    32
#ifndef _INCLUDE_SOURCEMOD_SHARESYSTEM_H_
dvander@229
    33
#define _INCLUDE_SOURCEMOD_SHARESYSTEM_H_
dvander@229
    34
dvander@229
    35
#include <IShareSys.h>
dvander@229
    36
#include <IHandleSys.h>
dvander@229
    37
#include <sh_list.h>
dvander@2086
    38
#include <sm_trie_tpl.h>
dvander@229
    39
#include "sm_globals.h"
dvander@229
    40
#include "sourcemod.h"
dvander@229
    41
dvander@229
    42
using namespace SourceHook;
dvander@229
    43
dvander@229
    44
namespace SourceMod
dvander@229
    45
{
dvander@229
    46
	struct IdentityToken_t
dvander@229
    47
	{
dvander@229
    48
		Handle_t ident;
dvander@868
    49
		void *ptr;
dvander@868
    50
		IdentityType_t type;
dvander@229
    51
	};
dvander@229
    52
};
dvander@229
    53
dvander@229
    54
struct IfaceInfo
dvander@229
    55
{
dvander@1456
    56
	bool operator ==(const IfaceInfo &info)
dvander@1456
    57
	{
dvander@1456
    58
		return (info.iface == iface && info.owner == owner);
dvander@1456
    59
	}
dvander@229
    60
	SMInterface *iface;
dvander@304
    61
	IExtension *owner;
dvander@229
    62
};
dvander@229
    63
dvander@2086
    64
class CNativeOwner;
dvander@2086
    65
class CPlugin;
dvander@2086
    66
struct NativeEntry;
dvander@2086
    67
dvander@2086
    68
struct ReplaceNative
dvander@2086
    69
{
dvander@2086
    70
	CNativeOwner *owner;
dvander@2086
    71
	SPVM_NATIVE_FUNC func;
dvander@2086
    72
};
dvander@2086
    73
dvander@2086
    74
struct FakeNative
dvander@2086
    75
{
dvander@2086
    76
	char name[64];
dvander@2086
    77
	IPluginContext *ctx;
dvander@2086
    78
	IPluginFunction *call;
dvander@2086
    79
};
dvander@2086
    80
dvander@2086
    81
struct NativeEntry
dvander@2086
    82
{
dvander@2086
    83
	CNativeOwner *owner;
dvander@2086
    84
	SPVM_NATIVE_FUNC func;
dvander@2086
    85
	const char *name;
dvander@2086
    86
	ReplaceNative replacement;
dvander@2086
    87
	FakeNative *fake;
dvander@2086
    88
};
dvander@2086
    89
dvander@2841
    90
struct Capability
dvander@2841
    91
{
dvander@2841
    92
	IExtension *ext;
dvander@2841
    93
	IFeatureProvider *provider;
dvander@2841
    94
};
dvander@2841
    95
dvander@2841
    96
class ShareSystem :
dvander@229
    97
	public IShareSys,
dvander@229
    98
	public SMGlobalClass,
dvander@229
    99
	public IHandleTypeDispatch
dvander@229
   100
{
dvander@2086
   101
	friend class CNativeOwner;
dvander@229
   102
public:
dvander@229
   103
	ShareSystem();
dvander@229
   104
public: //IShareSys
dvander@304
   105
	bool AddInterface(IExtension *myself, SMInterface *pIface);
dvander@229
   106
	bool RequestInterface(const char *iface_name, 
dvander@229
   107
		unsigned int iface_vers,
ds@741
   108
		IExtension *myself,
dvander@229
   109
		SMInterface **pIface);
dvander@312
   110
	void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives);
dvander@229
   111
	IdentityType_t CreateIdentType(const char *name);
dvander@229
   112
	IdentityType_t FindIdentType(const char *name);
dvander@868
   113
	IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr);
dvander@229
   114
	void DestroyIdentType(IdentityType_t type);
dvander@229
   115
	void DestroyIdentity(IdentityToken_t *identity);
dvander@324
   116
	void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload);
dvander@1572
   117
	void RegisterLibrary(IExtension *myself, const char *name);
dvander@1689
   118
	void OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives);
dvander@2841
   119
	void AddCapabilityProvider(IExtension *myself, IFeatureProvider *provider,
dvander@2841
   120
		                       const char *name);
dvander@2841
   121
	void DropCapabilityProvider(IExtension *myself, IFeatureProvider *provider,
dvander@2841
   122
		                        const char *name);
dvander@229
   123
public: //SMGlobalClass
dvander@229
   124
	/* Pre-empt in case anything tries to register idents early */
dvander@1770
   125
	void Initialize();
dvander@229
   126
	void OnSourceModShutdown();
dvander@229
   127
public: //IHandleTypeDispatch
dvander@229
   128
	void OnHandleDestroy(HandleType_t type, void *object);
dvander@229
   129
public:
dvander@229
   130
	IdentityToken_t *CreateCoreIdentity();
dvander@304
   131
	void RemoveInterfaces(IExtension *pExtension);
dvander@2841
   132
	FeatureStatus TestFeature(IPluginRuntime *pRuntime, FeatureType feature, const char *name);
dvander@2841
   133
	FeatureStatus TestNative(IPluginRuntime *pRuntime, const char *name);
dvander@2841
   134
	FeatureStatus TestCap(const char *name);
dvander@229
   135
public:
dvander@229
   136
	inline IdentityToken_t *GetIdentRoot()
dvander@229
   137
	{
dvander@229
   138
		return &m_IdentRoot;
dvander@229
   139
	}
dvander@2086
   140
public:
dvander@2086
   141
	void BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly);
dvander@2086
   142
	void BindNativeToPlugin(CPlugin *pPlugin, NativeEntry *pEntry);
dvander@2086
   143
	NativeEntry *AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func);
dvander@2545
   144
	NativeEntry *FindNative(const char *name);
dvander@2086
   145
private:
dvander@2086
   146
	NativeEntry *AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv);
dvander@2086
   147
	void ClearNativeFromCache(CNativeOwner *pOwner, const char *name);
dvander@2086
   148
	void BindNativeToPlugin(CPlugin *pPlugin, 
dvander@2086
   149
		sp_native_t *ntv, 
dvander@2086
   150
		uint32_t index, 
dvander@2086
   151
		NativeEntry *pEntry);
dvander@229
   152
private:
dvander@229
   153
	List<IfaceInfo> m_Interfaces;
dvander@229
   154
	HandleType_t m_TypeRoot;
dvander@229
   155
	IdentityToken_t m_IdentRoot;
dvander@229
   156
	HandleType_t m_IfaceType;
dvander@229
   157
	IdentityType_t m_CoreType;
dvander@2086
   158
	KTrie<NativeEntry *> m_NtvCache;
dvander@2841
   159
	KTrie<Capability> m_caps;
dvander@229
   160
};
dvander@229
   161
dvander@229
   162
extern ShareSystem g_ShareSys;
dvander@229
   163
dvander@229
   164
#endif //_INCLUDE_SOURCEMOD_SHARESYSTEM_H_