core/logic/ShareSys.h
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 4109 10eb68d668af
permissions -rw-r--r--
Update CS:GO team score gamedata.
dvander@370
     1
/**
dvander@4067
     2
 * vim: set ts=4 sw=4 tw=99 noet :
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@4108
    37
#include <am-string.h>
dvander@4108
    38
#include <am-utility.h>
dvander@4109
    39
#include <am-refcounting.h>
dvander@229
    40
#include <sh_list.h>
dvander@4067
    41
#include <sm_stringhashmap.h>
dvander@4067
    42
#include <sm_namehashset.h>
dvander@3872
    43
#include "common_logic.h"
dvander@4109
    44
#include "Native.h"
dvander@229
    45
dvander@229
    46
using namespace SourceHook;
dvander@229
    47
dvander@229
    48
namespace SourceMod
dvander@229
    49
{
dvander@229
    50
	struct IdentityToken_t
dvander@229
    51
	{
dvander@229
    52
		Handle_t ident;
dvander@868
    53
		void *ptr;
dvander@868
    54
		IdentityType_t type;
dvander@229
    55
	};
dvander@229
    56
};
dvander@229
    57
dvander@229
    58
struct IfaceInfo
dvander@229
    59
{
dvander@1456
    60
	bool operator ==(const IfaceInfo &info)
dvander@1456
    61
	{
dvander@1456
    62
		return (info.iface == iface && info.owner == owner);
dvander@1456
    63
	}
dvander@229
    64
	SMInterface *iface;
dvander@304
    65
	IExtension *owner;
dvander@229
    66
};
dvander@229
    67
dvander@2086
    68
class CNativeOwner;
dvander@2086
    69
class CPlugin;
dvander@2086
    70
dvander@2841
    71
struct Capability
dvander@2841
    72
{
dvander@2841
    73
	IExtension *ext;
dvander@2841
    74
	IFeatureProvider *provider;
dvander@2841
    75
};
dvander@2841
    76
dvander@2841
    77
class ShareSystem :
dvander@229
    78
	public IShareSys,
dvander@229
    79
	public SMGlobalClass,
dvander@229
    80
	public IHandleTypeDispatch
dvander@229
    81
{
dvander@2086
    82
	friend class CNativeOwner;
dvander@229
    83
public:
dvander@229
    84
	ShareSystem();
dvander@229
    85
public: //IShareSys
dvander@304
    86
	bool AddInterface(IExtension *myself, SMInterface *pIface);
dvander@229
    87
	bool RequestInterface(const char *iface_name, 
dvander@229
    88
		unsigned int iface_vers,
ds@741
    89
		IExtension *myself,
dvander@229
    90
		SMInterface **pIface);
dvander@312
    91
	void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives);
dvander@229
    92
	IdentityType_t CreateIdentType(const char *name);
dvander@229
    93
	IdentityType_t FindIdentType(const char *name);
dvander@868
    94
	IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr);
dvander@229
    95
	void DestroyIdentType(IdentityType_t type);
dvander@229
    96
	void DestroyIdentity(IdentityToken_t *identity);
dvander@324
    97
	void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload);
dvander@1572
    98
	void RegisterLibrary(IExtension *myself, const char *name);
dvander@1689
    99
	void OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives);
dvander@2841
   100
	void AddCapabilityProvider(IExtension *myself, IFeatureProvider *provider,
dvander@2841
   101
		                       const char *name);
dvander@2841
   102
	void DropCapabilityProvider(IExtension *myself, IFeatureProvider *provider,
dvander@2841
   103
		                        const char *name);
dvander@229
   104
public: //SMGlobalClass
dvander@229
   105
	/* Pre-empt in case anything tries to register idents early */
dvander@1770
   106
	void Initialize();
dvander@229
   107
	void OnSourceModShutdown();
dvander@229
   108
public: //IHandleTypeDispatch
dvander@229
   109
	void OnHandleDestroy(HandleType_t type, void *object);
dvander@229
   110
public:
dvander@229
   111
	IdentityToken_t *CreateCoreIdentity();
dvander@304
   112
	void RemoveInterfaces(IExtension *pExtension);
dvander@2841
   113
	FeatureStatus TestFeature(IPluginRuntime *pRuntime, FeatureType feature, const char *name);
dvander@2841
   114
	FeatureStatus TestNative(IPluginRuntime *pRuntime, const char *name);
dvander@2841
   115
	FeatureStatus TestCap(const char *name);
dvander@229
   116
public:
dvander@229
   117
	inline IdentityToken_t *GetIdentRoot()
dvander@229
   118
	{
dvander@229
   119
		return &m_IdentRoot;
dvander@229
   120
	}
dvander@2086
   121
public:
dvander@2086
   122
	void BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly);
dvander@4109
   123
	void BindNativeToPlugin(CPlugin *pPlugin, const ke::Ref<Native> &pEntry);
dvander@4109
   124
	ke::PassRef<Native> AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func);
dvander@4109
   125
	ke::PassRef<Native> FindNative(const char *name);
dvander@2086
   126
private:
dvander@4109
   127
	ke::PassRef<Native> AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv);
dvander@2086
   128
	void ClearNativeFromCache(CNativeOwner *pOwner, const char *name);
dvander@4109
   129
	void BindNativeToPlugin(CPlugin *pPlugin, sp_native_t *ntv,  uint32_t index, const ke::Ref<Native> &pEntry);
dvander@229
   130
private:
dvander@4109
   131
	typedef NameHashSet<ke::Ref<Native>, Native> NativeCache;
dvander@4109
   132
dvander@229
   133
	List<IfaceInfo> m_Interfaces;
dvander@229
   134
	HandleType_t m_TypeRoot;
dvander@229
   135
	IdentityToken_t m_IdentRoot;
dvander@229
   136
	HandleType_t m_IfaceType;
dvander@229
   137
	IdentityType_t m_CoreType;
dvander@4109
   138
	NativeCache m_NtvCache;
dvander@4067
   139
	StringHashMap<Capability> m_caps;
dvander@229
   140
};
dvander@229
   141
dvander@229
   142
extern ShareSystem g_ShareSys;
dvander@229
   143
dvander@229
   144
#endif //_INCLUDE_SOURCEMOD_SHARESYSTEM_H_