Skip to content

Commit

Permalink
Merge branch 'master' into import_create_group_with_ssid
Browse files Browse the repository at this point in the history
  • Loading branch information
akash1-kumar authored Oct 17, 2024
2 parents f9613e5 + d769d08 commit d28f556
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packaging/csapi-tizenfx.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Auto-generated from csapi-tizenfx.spec.in by makespec.sh

%define TIZEN_NET_API_VERSION 12
%define TIZEN_NET_RPM_VERSION 12.0.0.999+nui22344
%define TIZEN_NET_RPM_VERSION 12.0.0.999+nui22345
%define TIZEN_NET_NUGET_VERSION 12.0.0.99999

%define DOTNET_ASSEMBLY_PATH /usr/share/dotnet.tizen/framework
Expand Down
2 changes: 1 addition & 1 deletion packaging/version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RPM_VERSION=12.0.0.999
NUGET_VERSION=12.0.0.99999

# RPM Version Suffix
RPM_VERSION_SUFFIX=nui22344
RPM_VERSION_SUFFIX=nui22345
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SyncAdapter
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="syncParameters"> The sync job parameters corresponding to the sync request. </param>
[Obsolete("Deprecated since API12. Might be removed in API14")]
public delegate void CancelSyncCallback(SyncJobData syncParameters);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ public class Dataset: IDisposable
private IntPtr handle = IntPtr.Zero;
private bool disposed = false;

/// if false, model will be destroy dataset handle
private bool hasOwnership = true;

/// <summary>
/// Constructs the dataset.
/// </summary>
/// <since_tizen> 10 </since_tizen>
public Dataset()
{
NNTrainerError ret = Interop.Dataset.Create(out handle);
if (ret != NNTrainerError.None) {
handle = IntPtr.Zero;
}
NNTrainer.CheckException(ret, "Failed to create dataset instance");
Log.Info(NNTrainer.Tag, "Create Dataset");
}
Expand Down Expand Up @@ -82,6 +88,14 @@ protected virtual void Dispose(bool disposing)
{
// release managed object
}

disposed = true;

if (!hasOwnership){
Log.Info(NNTrainer.Tag, "Cannot destroy dataset already added in a Model. Model will destroy this dataset");
return;
}

// release unmanaged object
if (handle != IntPtr.Zero)
{
Expand All @@ -92,7 +106,6 @@ protected virtual void Dispose(bool disposing)

handle = IntPtr.Zero;
}
disposed = true;
}

/// <summary>
Expand Down Expand Up @@ -124,6 +137,11 @@ internal IntPtr GetHandle()
return handle;
}

internal void RemoveOwnership()
{
this.hasOwnership = false;
}

/// <summary>
/// Sets the neural network dataset property.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class Layer: IDisposable
public Layer(NNTrainerLayerType type)
{
NNTrainerError ret = Interop.Layer.Create(out handle, type);
if (ret != NNTrainerError.None) {
handle = IntPtr.Zero;
}
NNTrainer.CheckException(ret, "Failed to create model instance");
Log.Info(NNTrainer.Tag, $"Create layer with type:{type}");
}
Expand Down Expand Up @@ -98,7 +101,7 @@ protected virtual void Dispose(bool disposing)
disposed = true;

if (!hasOwnership){
Log.Error(NNTrainer.Tag, "Cannot destroy layer already added in a Model. Model will destroy this layer");
Log.Info(NNTrainer.Tag, "Cannot destroy layer already added in a Model. Model will destroy this layer");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public Model(string modelConf)
NNTrainer.CheckException(NNTrainerError.InvalidParameter, "modelConf is null");

NNTrainerError ret = Interop.Model.ConstructWithConf(modelConf, out handle);
if (ret != NNTrainerError.None) {
handle = IntPtr.Zero;
}
NNTrainer.CheckException(ret, "Failed to create model instance with modelConf");
Log.Info(NNTrainer.Tag, "Created Model with Conf path: "+ modelConf);
}
Expand Down Expand Up @@ -281,7 +284,7 @@ public void AddLayer(Layer layer)
public Layer GetLayer(string layerName)
{
IntPtr layerHandle = IntPtr.Zero;
if (string.IsNullOrEmpty(layerName))
if (string.IsNullOrEmpty(layerName))
NNTrainer.CheckException(NNTrainerError.InvalidParameter, "layerName is null");

NNTrainerError ret = Interop.Model.GetLayer(handle, layerName, out layerHandle);
Expand Down Expand Up @@ -311,6 +314,7 @@ public void SetOptimizer(Optimizer optimizer)

NNTrainerError ret = Interop.Model.SetOptimizer(handle, optimizer.GetHandle());
NNTrainer.CheckException(ret, "Failed to set optimizer");
optimizer.RemoveOwnership();
}

/// <summary>
Expand All @@ -335,6 +339,7 @@ public void SetDataset(Dataset dataset)

NNTrainerError ret = Interop.Model.SetDataset(handle, dataset.GetHandle());
NNTrainer.CheckException(ret, "Failed to set dataset");
dataset.RemoveOwnership();
}

internal static TensorsInfo CreateTensorsInfoFormHandle(IntPtr handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class Optimizer: IDisposable
private IntPtr handle = IntPtr.Zero;
private bool disposed = false;

/// if false, model will be destroy optimizer handle
private bool hasOwnership = true;

/// <summary>
/// Creates a neural network optimizer.
/// </summary>
Expand All @@ -45,6 +48,9 @@ public class Optimizer: IDisposable
public Optimizer(NNTrainerOptimizerType type)
{
NNTrainerError ret = Interop.Optimizer.Create(out handle, type);
if (ret != NNTrainerError.None) {
handle = IntPtr.Zero;
}
NNTrainer.CheckException(ret, "Failed to create optimizer instance");
Log.Info(NNTrainer.Tag, $"Create optimizer with type:{type}");
}
Expand Down Expand Up @@ -83,6 +89,14 @@ protected virtual void Dispose(bool disposing)
{
// release managed object
}

disposed = true;

if (!hasOwnership){
Log.Info(NNTrainer.Tag, "Cannot destroy optimizer already added in a Model. Model will destroy this optimizer");
return;
}

// release unmanaged object
if (handle != IntPtr.Zero)
{
Expand All @@ -93,7 +107,6 @@ protected virtual void Dispose(bool disposing)

handle = IntPtr.Zero;
}
disposed = true;
}

/// <summary>
Expand Down Expand Up @@ -122,5 +135,10 @@ internal IntPtr GetHandle()
{
return handle;
}

internal void RemoveOwnership()
{
this.hasOwnership = false;
}
}
}
2 changes: 1 addition & 1 deletion src/Tizen.NUI/src/internal/Common/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static T GetValueByDescription<T>(this string description) where T : stru
}
}

var value = type.GetFields(BindingFlags.Public | BindingFlags.Static).FirstOrDefault().GetValue(null);
var value = type.GetFields(BindingFlags.Public | BindingFlags.Static).FirstOrDefault()?.GetValue(null);
return value != null ? (T)value : default(T);
//throw new ArgumentException($"{description} can't be found.", "Description");
}
Expand Down
51 changes: 8 additions & 43 deletions src/Tizen.NUI/src/internal/Common/PropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ internal static class PropertyHelper
{
private static readonly Dictionary<string, VisualPropertyData> visualPropertyTable = new Dictionary<string, VisualPropertyData>()
{
{ "backgroundColor", new VisualPropertyData(View.Property.BACKGROUND, ColorVisualProperty.MixColor, ObjectColorToVector3, PropertyValueColorToVector3,
new VisualPropertyData(View.Property.BACKGROUND, Visual.Property.Opacity, ObjectColorToAlpha, PropertyValueColorToAlpha)) },
{ "backgroundColor", new VisualPropertyData(View.Property.BACKGROUND, ColorVisualProperty.MixColor, ObjectColorToVector4, PropertyValueColorToVector4) },
{ "backgroundOpacity", new VisualPropertyData(View.Property.BACKGROUND, Visual.Property.Opacity, ObjectIntToFloat) },
{ "boxShadow.BlurRadius", new VisualPropertyData(View.Property.SHADOW, ColorVisualProperty.BlurRadius) },
{ "boxShadow.Color", new VisualPropertyData(View.Property.SHADOW, ColorVisualProperty.MixColor, ObjectColorToVector3, PropertyValueColorToVector3,
new VisualPropertyData(View.Property.SHADOW, Visual.Property.Opacity, ObjectColorToAlpha, PropertyValueColorToAlpha)) },
{ "boxShadow.Color", new VisualPropertyData(View.Property.SHADOW, ColorVisualProperty.MixColor, ObjectColorToVector4, PropertyValueColorToVector4) },
{ "boxShadow.CornerRadius", new VisualPropertyData(View.Property.SHADOW, Visual.Property.CornerRadius, ObjectIntToFloat) },
{ "boxShadow.Offset", new VisualPropertyData(View.Property.SHADOW, (int)VisualTransformPropertyType.Offset) },
{ "boxShadow.Opacity", new VisualPropertyData(View.Property.SHADOW, Visual.Property.Opacity, ObjectIntToFloat) },
Expand Down Expand Up @@ -141,24 +139,24 @@ private static string LowerFirstLetter(string original)
return sb.ToString();
}

private static object ObjectColorToVector3(object value)
private static object ObjectColorToVector4(object value)
{
if (value is Vector4)
{
var colorValue = value as Vector4;
return new Vector3(colorValue.R, colorValue.G, colorValue.B);
return new Vector4(colorValue.R, colorValue.G, colorValue.B, colorValue.A);
}

if (value is Color)
{
var colorValue = value as Color;
return new Vector3(colorValue.R, colorValue.G, colorValue.B);
return new Vector4(colorValue.R, colorValue.G, colorValue.B, colorValue.A);
}

return null;
}

private static PropertyValue PropertyValueColorToVector3(PropertyValue value)
private static PropertyValue PropertyValueColorToVector4(PropertyValue value)
{
var valueType = value.GetType();

Expand All @@ -169,43 +167,10 @@ private static PropertyValue PropertyValueColorToVector3(PropertyValue value)

var colorValue = new Vector4();
value.Get(colorValue);
using (var v3 = new Vector3(colorValue.R, colorValue.G, colorValue.B))
using (var v4 = new Vector4(colorValue.R, colorValue.G, colorValue.B, colorValue.A))
{
colorValue.Dispose();
return new PropertyValue(v3);
}
}

private static object ObjectColorToAlpha(object value)
{
if (value is Vector4)
{
var colorValue = value as Vector4;
return colorValue.A;
}

if (value is Color)
{
var colorValue = value as Color;
return colorValue.A;
}

return null;
}

private static PropertyValue PropertyValueColorToAlpha(PropertyValue value)
{
var valueType = value.GetType();

if (valueType != PropertyType.Vector4)
{
return null;
}

using (var colorValue = new Vector4())
{
value.Get(colorValue);
return new PropertyValue(colorValue.A);
return new PropertyValue(v4);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Do()
var type = dict.GetType();
var method = type.GetMethods().FirstOrDefault(m => m.Name == "Add");

method.Invoke(dict, new object[] { key, value });
method?.Invoke(dict, new object[] { key, value });
}

private int parentIndex;
Expand Down
12 changes: 8 additions & 4 deletions src/Tizen.NUI/src/internal/WebView/WebContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class WebContext : Disposable
private readonly WebContextPasswordDataListAcquiredProxyCallback passwordDataListAcquiredProxyCallback;
private HttpRequestInterceptedCallback httpRequestInterceptedCallback;
private readonly WebContextHttpRequestInterceptedProxyCallback httpRequestInterceptedProxyCallback;
private DownloadStartedCallback downloadStartedCallback;
private MimeOverriddenCallback mimeOverriddenCallback;

internal WebContext(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
Expand Down Expand Up @@ -518,10 +520,11 @@ public void GetFormPasswordList(PasswordDataListAcquiredCallback callback)
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
{
downloadStartedCallback = callback;
IntPtr ip = IntPtr.Zero;
if (callback != null)
if (downloadStartedCallback != null)
{
ip = Marshal.GetFunctionPointerForDelegate(callback);
ip = Marshal.GetFunctionPointerForDelegate(downloadStartedCallback);
}
Interop.WebContext.RegisterDownloadStartedCallback(SwigCPtr, new HandleRef(this, ip));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
Expand All @@ -534,10 +537,11 @@ public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterMimeOverriddenCallback(MimeOverriddenCallback callback)
{
mimeOverriddenCallback = callback;
IntPtr ip = IntPtr.Zero;
if (callback != null)
if (mimeOverriddenCallback != null)
{
ip = Marshal.GetFunctionPointerForDelegate(callback);
ip = Marshal.GetFunctionPointerForDelegate(mimeOverriddenCallback);
}
Interop.WebContext.RegisterMimeOverriddenCallback(SwigCPtr, new HandleRef(this, ip));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
Expand Down
Loading

0 comments on commit d28f556

Please sign in to comment.