summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eo_mono/NativeModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/mono/eo_mono/NativeModule.cs')
-rw-r--r--src/bindings/mono/eo_mono/NativeModule.cs60
1 files changed, 49 insertions, 11 deletions
diff --git a/src/bindings/mono/eo_mono/NativeModule.cs b/src/bindings/mono/eo_mono/NativeModule.cs
index 41f663e..932b453 100644
--- a/src/bindings/mono/eo_mono/NativeModule.cs
+++ b/src/bindings/mono/eo_mono/NativeModule.cs
@@ -1,19 +1,32 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1using System; 16using System;
2 17
3namespace Efl 18namespace Efl.Eo
4{
5
6namespace Eo
7{ 19{
8 20
9///<summary>Wraps a native module that was opened with dlopen/LoadLibrary.</summary> 21///<summary>Wraps a native module that was opened with dlopen/LoadLibrary.</summary>
10public partial class NativeModule : IDisposable 22internal partial class NativeModule : IDisposable
11{ 23{
12 private Lazy<IntPtr> module; 24 private Lazy<IntPtr> module;
25 private bool disposed = false;
13 26
14 ///<summary>Lazily tries to load the module with the given name.</summary> 27 ///<summary>Lazily tries to load the module with the given name.</summary>
15 ///<param name="libName">The name of the module to load.</param> 28 ///<param name="libName">The name of the module to load.</param>
16 public NativeModule(string libName) 29 internal NativeModule(string libName)
17 { 30 {
18 module = new Lazy<IntPtr> 31 module = new Lazy<IntPtr>
19 (() => 32 (() =>
@@ -23,7 +36,7 @@ public partial class NativeModule : IDisposable
23 } 36 }
24 37
25 ///<summary>The module that was loaded.</summary> 38 ///<summary>The module that was loaded.</summary>
26 public IntPtr Module 39 internal IntPtr Module
27 { 40 {
28 get 41 get
29 { 42 {
@@ -31,14 +44,39 @@ public partial class NativeModule : IDisposable
31 } 44 }
32 } 45 }
33 46
34 ///<summary>Unload and released the handle to the wrapped module.</summary> 47 /// <summary>Finalizer to be called from the Garbage Collector.</summary>
48 ~NativeModule()
49 {
50 Dispose(false);
51 }
52
53 /// <summary>Unload and released the handle to the wrapped module.</summary>
35 public void Dispose() 54 public void Dispose()
36 { 55 {
37 UnloadLibrary(module.Value); 56 Dispose(true);
38 module = null; 57 GC.SuppressFinalize(this);
39 } 58 }
40}
41 59
60 /// <summary>Unload and released the handle to the wrapped module.</summary>
61 protected virtual void Dispose(bool disposing)
62 {
63 if (disposed)
64 {
65 return;
66 }
67
68 if (disposing)
69 {
70 module = null;
71 }
72
73 if (module.IsValueCreated)
74 {
75 UnloadLibrary(module.Value);
76 }
77
78 disposed = true;
79 }
42} 80}
43 81
44} 82}