コード例 #1
0
ファイル: HookManager.cs プロジェクト: tomasdeml/hyphen
        public static void CreateHook(HookDescriptor hook)
        {
            try
            {
                SynchronizationHelper.BeginDescriptorUpdate(hook);

                switch (hook.HookType)
                {
                    case HookType.EventHook:
                        {
                            HookEvent(hook);
                            break;
                        }
                    case HookType.ServiceFunction:
                        {
                            CreateServiceFunction(hook);
                            break;
                        }
                    default:
                        throw new ArgumentException("descriptor");
                }
            }
            finally
            {
                SynchronizationHelper.EndUpdate(hook);
            }
        }
コード例 #2
0
ファイル: HookManager.cs プロジェクト: tomasdeml/hyphen
        private static void CreateServiceFunction(HookDescriptor hook)
        {
            if (!ServiceManager.ServiceExists(hook.Name))
            {
                hook.MirandaHandle = MirandaContext.Current.PluginLink.NativePluginLink.CreateServiceFunction(hook.Name, hook.Callback);

                if (hook.MirandaHandle == IntPtr.Zero)
                    throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable1_ServiceFunctionCreationFailed, hook.Name));
            }
            else
            {
                if (!hook.Owner.ServiceFunctions.Exists(delegate(HookDescriptor _hook)
                {
                    return _hook.Equals(hook) && _hook.MirandaHandle != IntPtr.Zero;
                }))
                    throw new InvalidOperationException(String.Format(TextResources.ExceptionMsg_Formatable1_ServiceFunctionAlreadyExists, hook.Name));
            }
        }
コード例 #3
0
ファイル: TranslationCPU.cs プロジェクト: rte-se/emul8
        public void AddHook(uint addr, Action<uint> hook)
        {
            lock(hooks)
            {
                if(!hooks.ContainsKey(addr))
                {
                    hooks[addr] = new HookDescriptor(this, addr);
                }

                hooks[addr].AddCallback(hook);
                this.DebugLog("Added hook @ 0x{0:X}", addr);
            }
        }
コード例 #4
0
ファイル: HookManager.cs プロジェクト: tomasdeml/hyphen
        private static void HookEvent(HookDescriptor hook)
        {
            hook.MirandaHandle = MirandaContext.Current.PluginLink.NativePluginLink.HookEvent(hook.Name, hook.Callback);

            if (hook.MirandaHandle == IntPtr.Zero)
                throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable1_EventHookingFailed, hook.Name));
        }
コード例 #5
0
ファイル: HookManager.cs プロジェクト: tomasdeml/hyphen
        private static void DestroyServiceFunction(HookDescriptor descriptor)
        {
            if (descriptor == null)
                throw new ArgumentNullException("descriptor");

            if (descriptor.HookType != HookType.ServiceFunction)
                throw new ArgumentOutOfRangeException("descriptor");

            if (descriptor.MirandaHandle == IntPtr.Zero)
                return;

            try
            {
                SynchronizationHelper.BeginDescriptorUpdate(descriptor);

                int result = MirandaContext.Current.PluginLink.NativePluginLink.DestroyServiceFunction(descriptor.MirandaHandle);
                Debug.Assert(result == 0);

                descriptor.MirandaHandle = IntPtr.Zero;
            }
            finally
            {
                SynchronizationHelper.EndUpdate(descriptor);
            }
        }