core/systems/ShareSys.h
author David Anderson <dvander@alliedmods.net>
Mon Oct 01 18:04:37 2007 +0000 (2007-10-01)
changeset 1508 398538bce59b
parent 1456 69a68787c743
child 1572 adbc41dc9cd0
permissions -rw-r--r--
- fixed a bug where CS:S Tools could be loaded more than once on mapchange
- fixed a bug where Core did not interpet some file paths properly
- fixed a crash bug where SourceMod could pass invalid data to ISmmAPI on shutdown
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_SHARESYSTEM_H_
    33 #define _INCLUDE_SOURCEMOD_SHARESYSTEM_H_
    34 
    35 #include <IShareSys.h>
    36 #include <IHandleSys.h>
    37 #include <sh_list.h>
    38 #include "sm_globals.h"
    39 #include "sourcemod.h"
    40 
    41 using namespace SourceHook;
    42 
    43 namespace SourceMod
    44 {
    45 	struct IdentityToken_t
    46 	{
    47 		Handle_t ident;
    48 		void *ptr;
    49 		IdentityType_t type;
    50 	};
    51 };
    52 
    53 struct IfaceInfo
    54 {
    55 	bool operator ==(const IfaceInfo &info)
    56 	{
    57 		return (info.iface == iface && info.owner == owner);
    58 	}
    59 	SMInterface *iface;
    60 	IExtension *owner;
    61 };
    62 
    63 class ShareSystem : 
    64 	public IShareSys,
    65 	public SMGlobalClass,
    66 	public IHandleTypeDispatch
    67 {
    68 public:
    69 	ShareSystem();
    70 public: //IShareSys
    71 	bool AddInterface(IExtension *myself, SMInterface *pIface);
    72 	bool RequestInterface(const char *iface_name, 
    73 		unsigned int iface_vers,
    74 		IExtension *myself,
    75 		SMInterface **pIface);
    76 	void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives);
    77 	IdentityType_t CreateIdentType(const char *name);
    78 	IdentityType_t FindIdentType(const char *name);
    79 	IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr);
    80 	void DestroyIdentType(IdentityType_t type);
    81 	void DestroyIdentity(IdentityToken_t *identity);
    82 	void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload);
    83 public: //SMGlobalClass
    84 	/* Pre-empt in case anything tries to register idents early */
    85 	void OnSourceModStartup(bool late);
    86 	void OnSourceModShutdown();
    87 public: //IHandleTypeDispatch
    88 	void OnHandleDestroy(HandleType_t type, void *object);
    89 public:
    90 	IdentityToken_t *CreateCoreIdentity();
    91 	void RemoveInterfaces(IExtension *pExtension);
    92 public:
    93 	inline IdentityToken_t *GetIdentRoot()
    94 	{
    95 		return &m_IdentRoot;
    96 	}
    97 private:
    98 	List<IfaceInfo> m_Interfaces;
    99 	HandleType_t m_TypeRoot;
   100 	IdentityToken_t m_IdentRoot;
   101 	HandleType_t m_IfaceType;
   102 	IdentityType_t m_CoreType;
   103 };
   104 
   105 extern ShareSystem g_ShareSys;
   106 
   107 #endif //_INCLUDE_SOURCEMOD_SHARESYSTEM_H_