[NUI.Gadget] Remove Unload() method (#5918)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Fri, 26 Jan 2024 05:35:22 +0000 (14:35 +0900)
committerGitHub <noreply@github.com>
Fri, 26 Jan 2024 05:35:22 +0000 (14:35 +0900)
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs [deleted file]
src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs
src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs

diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs
deleted file mode 100644 (file)
index b5dd7e0..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-* Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the License);
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an AS IS BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.IO;
-using System.Reflection;
-using System.Runtime.Loader;
-
-using SystemIO = System.IO;
-
-namespace Tizen.NUI
-{
-    internal class NUIGadgetAssemblyLoadContext : AssemblyLoadContext
-    {
-        public NUIGadgetAssemblyLoadContext() : base(isCollectible: true)
-        {
-        }
-
-        protected override Assembly Load(AssemblyName name)
-        {
-            return null;
-        }
-    }
-
-    internal class NUIGadgetAssembly
-    {
-        private static readonly object _assemblyLock = new object();
-        private readonly string _assemblyPath;
-        private WeakReference _assemblyRef;
-        private Assembly _assembly = null;
-
-        public NUIGadgetAssembly(string assemblyPath) { _assemblyPath = assemblyPath; }
-
-        public void Load()
-        {
-            lock (_assemblyLock)
-            {
-                if (_assembly != null)
-                {
-                    return;
-                }
-
-                Log.Warn("Load(): " + _assemblyPath + " ++");
-                NUIGadgetAssemblyLoadContext context = new NUIGadgetAssemblyLoadContext();
-                _assemblyRef = new WeakReference(context);
-                string directoryPath = SystemIO.Path.GetDirectoryName(_assemblyPath);
-                string fileName = SystemIO.Path.GetFileNameWithoutExtension(_assemblyPath);
-                string nativeImagePath = directoryPath + "/" + fileName + ".ni.dll";
-                Log.Debug("NativeImagePath=" + nativeImagePath + ", AssemblyPath=" + _assemblyPath);
-                _assembly = context.LoadFromNativeImagePath(nativeImagePath, _assemblyPath);
-                Log.Warn("Load(): " + _assemblyPath + " --");
-            }
-        }
-
-        public bool IsLoaded { get { return _assembly != null; } }
-
-        public NUIGadget CreateInstance(string className)
-        {
-            lock (_assemblyLock)
-            {
-                return (NUIGadget)_assembly?.CreateInstance(className);
-            }
-        }
-
-        public void Unload()
-        {
-            lock (_assemblyLock)
-            {
-                if (_assembly == null)
-                {
-                    return;
-                }
-
-                Log.Warn("Unload(): " + _assemblyPath + " ++");
-                if (_assemblyRef.IsAlive)
-                {
-                    (_assemblyRef.Target as NUIGadgetAssemblyLoadContext).Unload();
-                }
-
-                _assembly = null;
-                Log.Warn("Unload(): " + _assemblyPath + " --");
-            }
-        }
-    }
-}
\ No newline at end of file
index b0381a0..fda1346 100755 (executable)
@@ -85,7 +85,7 @@ namespace Tizen.NUI
 
         internal string ResourceClassName { get; set; }
 
-        internal NUIGadgetAssembly Assembly { get; private set; }
+        internal Assembly Assembly { get; set; }
 
         internal static NUIGadgetInfo CreateNUIGadgetInfo(string packageId)
         {
@@ -177,7 +177,6 @@ namespace Tizen.NUI
             }
 
             info.ResourcePath = SystemIO.Path.GetDirectoryName(Application.Current.ApplicationInfo.ExecutablePath) + "/";
-            info.Assembly = new NUIGadgetAssembly(info.ResourcePath + info.ExecutableFile);
             return info;
         }
     }
index f547ec2..84b98e0 100755 (executable)
@@ -26,6 +26,8 @@ using System.Reflection;
 using System.Threading.Tasks;
 using System.Security.AccessControl;
 
+using SystemIO = System.IO;
+
 namespace Tizen.NUI
 {
     /// <summary>
@@ -160,9 +162,12 @@ namespace Tizen.NUI
             {
                 lock (info)
                 {
-                    if (!info.Assembly.IsLoaded)
+                    if (info.Assembly == null)
                     {
-                        info.Assembly.Load();
+
+                        Log.Warn("NUIGadgetAssembly.Load(): " + info.ResourcePath + info.ExecutableFile + " ++");
+                        info.Assembly = Assembly.Load(SystemIO.Path.GetFileNameWithoutExtension(info.ExecutableFile));
+                        Log.Warn("NUIGadgetAssembly.Load(): " + info.ResourcePath + info.ExecutableFile + " --");
                     }
                 }
             }
@@ -177,39 +182,6 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Unloads the loaded assembly of the NUIGadget.
-        /// </summary>
-        /// <param name="resourceType">The resource type of the NUIGadget package.</param>
-        /// <exception cref="ArgumentException">Thrown when failed because of a invalid argument.</exception>
-        /// <since_tizen> 11 </since_tizen>
-        public static void Unload(string resourceType)
-        {
-            if (string.IsNullOrEmpty(resourceType))
-            {
-                throw new ArgumentException("Invalid argument");
-            }
-
-            NUIGadgetInfo info = Find(resourceType);
-            Unload(info);
-        }
-
-        private static void Unload(NUIGadgetInfo info)
-        {
-            if (info == null)
-            {
-                throw new ArgumentException("Invalid argument");
-            }
-
-            lock (info)
-            {
-                if (info.Assembly.IsLoaded)
-                {
-                    info.Assembly.Unload();
-                }
-            }
-        }
-
-        /// <summary>
         /// Adds a NUIGadget to the NUIGadgetManager.
         /// </summary>
         /// <param name="resourceType">The resource type of the NUIGadget package.</param>
@@ -228,7 +200,7 @@ namespace Tizen.NUI
             NUIGadgetInfo info = Find(resourceType);
             Load(info);
 
-            NUIGadget gadget = info.Assembly.CreateInstance(className);
+            NUIGadget gadget = info.Assembly.CreateInstance(className, true) as NUIGadget;
             if (gadget == null)
             {
                 throw new InvalidOperationException("Failed to create instance. className: " + className);