core/sourcehook/sourcehook_impl_ciface.h
author Scott Ehlert <ds@alliedmods.net>
Thu Jul 01 02:43:22 2010 -0500 (2010-07-01)
changeset 722 78f730f91439
parent 539 db914129ae01
child 733 2365240861a2
permissions -rw-r--r--
Fixed problem on OBV where alternately loaded plugins (CreateInterface_MMS) could be incorrectly told they were on the OB engine (bug 4491, r=dvander).

This only happened when there was more than one plugin that loaded this way. And the first plugin to load had to fail on OBV first so that OB could be tried. It was being permanently set to OB for future plugin loads and this caused problems.
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2008 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): Pavol "PM OnoTo" Marko
     8 * ============================
     9 */
    10 
    11 #ifndef __SOURCEHOOK_IMPL_CIFACE_H__
    12 #define __SOURCEHOOK_IMPL_CIFACE_H__
    13 
    14 #include "sh_list.h"
    15 
    16 namespace SourceHook
    17 {
    18 	namespace Impl
    19 	{
    20 		class CIface
    21 		{
    22 			// *** Data ***
    23 			void *m_Ptr;
    24 
    25 			List<CHook> m_PreHooks;
    26 			List<CHook> m_PostHooks;
    27 		public:
    28 
    29 			// *** Descriptor ***
    30 			typedef void* Descriptor;
    31 
    32 			// *** Interface ***
    33 			inline CIface(void *ptr);
    34 			inline ~CIface();
    35 			inline bool operator==(const Descriptor &other);
    36 			inline void *GetPtr() const;
    37 			inline List<CHook> &GetPreHookList();
    38 			inline List<CHook> &GetPostHookList();
    39 			inline const List<CHook> &GetPreHookList() const;
    40 			inline const List<CHook> &GetPostHookList() const;
    41 		};
    42 
    43 		// *** Implementation ***
    44 		inline CIface::CIface(void *ptr)
    45 			: m_Ptr(ptr)
    46 		{
    47 		}
    48 
    49 		inline CIface::~CIface()
    50 		{
    51 			// Before getting deleted, delete all remaining hook handlers
    52 			for (List<CHook>::iterator iter = m_PreHooks.begin(); iter != m_PreHooks.end(); ++iter)
    53 			{
    54 				iter->GetHandler()->DeleteThis();
    55 			}
    56 
    57 			for (List<CHook>::iterator iter = m_PostHooks.begin(); iter != m_PostHooks.end(); ++iter)
    58 			{
    59 				iter->GetHandler()->DeleteThis();
    60 			}
    61 		}
    62 
    63 		inline bool CIface::operator==(const Descriptor &other)
    64 		{
    65 			return m_Ptr == other;
    66 		}
    67 
    68 		inline void *CIface::GetPtr() const
    69 		{
    70 			return m_Ptr;
    71 		}
    72 
    73 		inline List<CHook> &CIface::GetPreHookList()
    74 		{
    75 			return m_PreHooks;
    76 		}
    77 
    78 		inline List<CHook> &CIface::GetPostHookList()
    79 		{
    80 			return m_PostHooks;
    81 		}
    82 
    83 		inline const List<CHook> &CIface::GetPreHookList() const
    84 		{
    85 			return m_PreHooks;
    86 		}
    87 
    88 		inline const List<CHook> &CIface::GetPostHookList() const
    89 		{
    90 			return m_PostHooks;
    91 		}
    92 	}
    93 }
    94 
    95 #endif
    96