CefV8Handler.g.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // DO NOT MODIFY! THIS IS AUTOGENERATED FILE!
  3. //
  4. namespace Xilium.CefGlue
  5. {
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Runtime.InteropServices;
  10. using System.Threading;
  11. using Xilium.CefGlue.Interop;
  12. // Role: HANDLER
  13. public abstract unsafe partial class CefV8Handler
  14. {
  15. private static Dictionary<IntPtr, CefV8Handler> _roots = new Dictionary<IntPtr, CefV8Handler>();
  16. private int _refct;
  17. private cef_v8handler_t* _self;
  18. internal static CefV8Handler FromNativeOrNull(cef_v8handler_t* ptr)
  19. {
  20. CefV8Handler value = null;
  21. bool found;
  22. lock (_roots)
  23. {
  24. found = _roots.TryGetValue((IntPtr)ptr, out value);
  25. // as we're getting the ref from the outside, it's our responsibility to decrement it
  26. value.release(ptr);
  27. }
  28. return found ? value : null;
  29. }
  30. internal static CefV8Handler FromNative(cef_v8handler_t* ptr)
  31. {
  32. var value = FromNativeOrNull(ptr);
  33. if (value == null) throw ExceptionBuilder.ObjectNotFound();
  34. return value;
  35. }
  36. private cef_v8handler_t.add_ref_delegate _ds0;
  37. private cef_v8handler_t.release_delegate _ds1;
  38. private cef_v8handler_t.has_one_ref_delegate _ds2;
  39. private cef_v8handler_t.has_at_least_one_ref_delegate _ds3;
  40. private cef_v8handler_t.execute_delegate _ds4;
  41. protected CefV8Handler()
  42. {
  43. _self = cef_v8handler_t.Alloc();
  44. _ds0 = new cef_v8handler_t.add_ref_delegate(add_ref);
  45. _self->_base._add_ref = Marshal.GetFunctionPointerForDelegate(_ds0);
  46. _ds1 = new cef_v8handler_t.release_delegate(release);
  47. _self->_base._release = Marshal.GetFunctionPointerForDelegate(_ds1);
  48. _ds2 = new cef_v8handler_t.has_one_ref_delegate(has_one_ref);
  49. _self->_base._has_one_ref = Marshal.GetFunctionPointerForDelegate(_ds2);
  50. _ds3 = new cef_v8handler_t.has_at_least_one_ref_delegate(has_at_least_one_ref);
  51. _self->_base._has_at_least_one_ref = Marshal.GetFunctionPointerForDelegate(_ds3);
  52. _ds4 = new cef_v8handler_t.execute_delegate(execute);
  53. _self->_execute = Marshal.GetFunctionPointerForDelegate(_ds4);
  54. }
  55. ~CefV8Handler()
  56. {
  57. Dispose(false);
  58. }
  59. protected virtual void Dispose(bool disposing)
  60. {
  61. if (_self != null)
  62. {
  63. cef_v8handler_t.Free(_self);
  64. _self = null;
  65. }
  66. }
  67. private void add_ref(cef_v8handler_t* self)
  68. {
  69. if (Interlocked.Increment(ref _refct) == 1)
  70. {
  71. lock (_roots) { _roots.Add((IntPtr)_self, this); }
  72. }
  73. }
  74. private int release(cef_v8handler_t* self)
  75. {
  76. if (Interlocked.Decrement(ref _refct) == 0)
  77. {
  78. lock (_roots) { _roots.Remove((IntPtr)_self); }
  79. return 1;
  80. }
  81. return 0;
  82. }
  83. private int has_one_ref(cef_v8handler_t* self)
  84. {
  85. return _refct == 1 ? 1 : 0;
  86. }
  87. private int has_at_least_one_ref(cef_v8handler_t* self)
  88. {
  89. return _refct != 0 ? 1 : 0;
  90. }
  91. internal cef_v8handler_t* ToNative()
  92. {
  93. add_ref(_self);
  94. return _self;
  95. }
  96. [Conditional("DEBUG")]
  97. private void CheckSelf(cef_v8handler_t* self)
  98. {
  99. if (_self != self) throw ExceptionBuilder.InvalidSelfReference();
  100. }
  101. }
  102. }