Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUI.Gadget] Export NUIGadgetAssembly class for inhouse developers #6379

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;
Expand All @@ -35,16 +36,21 @@ protected override Assembly Load(AssemblyName name)
}
}

internal class NUIGadgetAssembly
/// <summary>
/// Represents a class that provides access to the methods and properties of the NUIGadgetAssembly.
/// </summary>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public 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; }
internal NUIGadgetAssembly(string assemblyPath) { _assemblyPath = assemblyPath; }

public void Load()
internal void Load()
{
lock (_assemblyLock)
{
Expand All @@ -65,17 +71,23 @@ public void Load()
}
}

public bool IsLoaded { get { return _assembly != null; } }
internal bool IsLoaded { get { return _assembly != null; } }

public NUIGadget CreateInstance(string className)
internal NUIGadget CreateInstance(string className)
{
lock (_assemblyLock)
{
return (NUIGadget)_assembly?.CreateInstance(className);
}
}

public void Unload()
/// <summary>
/// Property indicating whether the weak reference to the gadget assembly is still alive.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public bool IsAlive { get { return _assemblyRef.IsAlive; } }

internal void Unload()
{
lock (_assemblyLock)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public string ResourcePath

internal Assembly Assembly { get; set; }

internal NUIGadgetAssembly NUIGadgetAssembly { get; set; }
/// <summary>
/// Gets the assembly of the gadget.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public NUIGadgetAssembly NUIGadgetAssembly { get; set; }

internal static NUIGadgetInfo CreateNUIGadgetInfo(string packageId)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ private static void Unload(NUIGadgetInfo info)
if (info.NUIGadgetAssembly != null && info.NUIGadgetAssembly.IsLoaded)
{
info.NUIGadgetAssembly.Unload();
info.NUIGadgetAssembly = null;
}
}
}
Expand Down Expand Up @@ -221,7 +220,7 @@ private static void Load(NUIGadgetInfo info, bool useDefaultContext)
}
else
{
if (info.NUIGadgetAssembly == null)
if (info.NUIGadgetAssembly == null || !info.NUIGadgetAssembly.IsLoaded)
{
Log.Warn("NUIGadgetAssembly.Load(): " + info.ResourcePath + info.ExecutableFile + " ++");
info.NUIGadgetAssembly = new NUIGadgetAssembly(info.ResourcePath + info.ExecutableFile);
Expand Down
Loading