private void RemoveManagedCallback()
        {
            NativeMethods.Services_RemoveManagedCallbacks();

            ResultCallbacks = null;
            Callbacks       = null;

            nativeCallbackHandle       = null;
            nativeResultCallbackHandle = null;
        }
        private Steam(CultureInfo activeCulture)
        {
            Culture = activeCulture;

            bufferedExceptions = new List<Exception>();

            //keep a handle in this class to delegates so that GC knows not to collect them
            nativeCallbackHandle = NativeCallbacks;
            nativeResultCallbackHandle   = NativeResultCallbacks;
            
            NativeMethods.Services_RegisterManagedCallbacks(nativeCallbackHandle, nativeResultCallbackHandle);
        }
        private Steam(CultureInfo activeCulture)
        {
            Culture = activeCulture;

            bufferedExceptions = new List <Exception>();

            //keep a handle in this class to delegates so that GC knows not to collect them
            nativeCallbackHandle       = NativeCallbacks;
            nativeResultCallbackHandle = NativeResultCallbacks;

            NativeMethods.Services_RegisterManagedCallbacks(nativeCallbackHandle, nativeResultCallbackHandle);
        }
        private void RegisterManagedCallback()
        {
            // TODO Provide a comparer object to avoid boxing
            Callbacks       = new Dictionary <CallbackID, NativeCallback>();
            ResultCallbacks = new Dictionary <ResultID, NativeResultCallback>();

            bufferedExceptions = new List <Exception>();

            NativeCallbacksDelegate       = NativeCallbacks;
            NativeResultCallbacksDelegate = NativeResultCallbacks;

            NativeMethods.Services_RegisterManagedCallbacks(NativeCallbacksDelegate, NativeResultCallbacksDelegate);
        }
Exemple #5
0
        static void ProcessManagedCallbacks()
        {
            while (true)
            {
                ManagedCallback managedCallback = null;

                lock (mutex)
                {
                    if (managedCallbacks.Count == 0)
                    {
                        break;
                    }

                    managedCallback = managedCallbacks.Dequeue();
                    if (!isCompletionQueued && managedCallbacks.Count > 0)
                    {
                        QueueCompletionCallback();
                    }
                }
                managedCallback.Invoke();
            }
        }
        private void RemoveManagedCallback()
        {
            NativeMethods.Services_RemoveManagedCallbacks();

            ResultCallbacks = null;
            Callbacks = null;

            nativeCallbackHandle = null;
            nativeResultCallbackHandle = null;
        }
        private void RegisterManagedCallback()
        {
            // TODO Provide a comparer object to avoid boxing
            Callbacks = new Dictionary<CallbackID, NativeCallback>();
            ResultCallbacks = new Dictionary<ResultID, NativeResultCallback>();
            
            bufferedExceptions = new List<Exception>();

            NativeCallbacksDelegate = NativeCallbacks;
            NativeResultCallbacksDelegate = NativeResultCallbacks;
            
            NativeMethods.Services_RegisterManagedCallbacks(NativeCallbacksDelegate, NativeResultCallbacksDelegate);
        }
Exemple #8
0
        static void Ispc_TestCallback()
        {
            //read more about callback from ispc
            //on  https://ispc.github.io/ispc.html => section "Interoperability with The Application"

            string module  = "callback_test";
            bool   rebuild = NeedRebuildIspc(module);

            if (rebuild)
            {
                IspcBuilder ispcBuilder = new IspcBuilder();
                ispcBuilder.ProjectConfigKind = BridgeBuilder.Vcx.ProjectConfigKind.Debug;
                ispcBuilder.IspcFilename      = module + ".ispc";
                ispcBuilder.AutoCsTargetFile  = $"..\\..\\AutoGenBinders\\{module}.cs";

                string currentDir = Directory.GetCurrentDirectory();
                ispcBuilder.AdditionalInputItems = new string[]
                {
                    currentDir + "\\callback_test1.cpp"
                };
                ispcBuilder.RebuildLibraryAndAPI();
            }

            string dllName = module + ".dll";
            IntPtr dllPtr  = LoadLibrary(dllName);

            if (dllPtr == IntPtr.Zero)
            {
                throw new NotSupportedException();
            }

            GetManagedDelegate(dllPtr, "set_managed_callback", out s_setManagedCallback);
            if (s_setManagedCallback == null)
            {
                throw new NotSupportedException();
            }

            //-----------
            m_callback = (int a) =>
            {
#if DEBUG
                //System.Diagnostics.Debugger.Break();
                System.Diagnostics.Debug.WriteLine("callback from ispc");
#endif
            };
            m_callback_ptr = Marshal.GetFunctionPointerForDelegate(m_callback);
            s_setManagedCallback(m_callback_ptr);

            //-----------
            //test call to ispc
            //test1
            int[] inputData = new int[]
            {
                1 << 16, 2 << 16, 3 << 16, 4 << 16,
                    5 << 16, 6 << 16, 7 << 16, 8 << 16,
                    9 << 16, 10 << 16, 11 << 16, 12 << 16,
            };
            unsafe
            {
                fixed(int *h = &inputData[0])
                {
                    callback_test_ispc.NativeMethods.clear(h, 0, inputData.Length);
                }
            }
        }
 internal static extern void Services_RegisterManagedCallbacks(ManagedCallback callback, ManagedResultCallback resultCallback);