core/logic/NativeOwner.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed May 21 17:25:30 2014 -0400 (2014-05-21)
changeset 4377 7a44be5b7162
parent 4109 10eb68d668af
permissions -rw-r--r--
Trigger build for hl2sdk-l4d changes.
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet :
     3  * =============================================================================
     4  * SourcePawn
     5  * Copyright (C) 2004-2009 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 #ifndef _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
    32 #define _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
    33 
    34 #include <sp_vm_types.h>
    35 #include <sh_list.h>
    36 #include <am-linkedlist.h>
    37 #include <am-vector.h>
    38 #include "common_logic.h"
    39 #include "Native.h"
    40 
    41 struct Native;
    42 class CPlugin;
    43 
    44 using namespace SourceMod;
    45 
    46 struct WeakNative
    47 {
    48 	WeakNative(IPlugin *plugin, uint32_t index) : 
    49 		pl(plugin), idx(index)
    50 	{
    51 		pl = plugin;
    52 		idx = index;
    53 	}
    54 	IPlugin *pl;
    55 	uint32_t idx;
    56 };
    57 
    58 using namespace SourceHook;
    59 
    60 class CNativeOwner
    61 {
    62 public:
    63 	CNativeOwner();
    64 public:
    65 	virtual void DropEverything();
    66 public:
    67 	void AddNatives(const sp_nativeinfo_t *info);
    68 public:
    69 	void SetMarkSerial(unsigned int serial);
    70 	unsigned int GetMarkSerial();
    71 	void PropagateMarkSerial(unsigned int serial);
    72 public:
    73 	void AddDependent(CPlugin *pPlugin);
    74 	void AddWeakRef(const WeakNative & ref);
    75 	void DropRefsTo(CPlugin *pPlugin);
    76 private:
    77 	void DropWeakRefsTo(CPlugin *pPlugin);
    78 	void UnbindWeakRef(const WeakNative & ref);
    79 protected:
    80 	List<CPlugin *> m_Dependents;
    81 	unsigned int m_nMarkSerial;
    82 	List<WeakNative> m_WeakRefs;
    83 	ke::Vector<const sp_nativeinfo_t *> m_natives;
    84 	ke::Vector<ke::Ref<Native> > m_fakes;
    85 };
    86 
    87 extern CNativeOwner g_CoreNatives;
    88 
    89 #endif //_INCLUDE_SOURCEMOD_NATIVE_OWNER_H_