Skip to content

Commit 15ebc62

Browse files
Eunki Honghinohie
authored andcommitted
[NUI][API13_MR](Application) Implement NUIApplicationInitializer
Let we make some API to support non-NUIApplication could use NUI features. TODO : For now, we don't support to get defautl window for this case. We'd better make some unified logic to support it. For example, bind ApplicationController + UiContext at native, and make current NUIApplication use it. It is quite complex job. So need to seperate PR. Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
1 parent c366071 commit 15ebc62

6 files changed

Lines changed: 89 additions & 21 deletions

File tree

src/Tizen.NUI/src/internal/Application/Application.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -731,18 +731,7 @@ public event DaliEventHandler<object, NUIApplicationInitEventArgs> Initialized
731731
// Callback for Application InitSignal
732732
private void OnApplicationInit(IntPtr data)
733733
{
734-
Log.Info("NUI", $"[NUI] Preload : {NUIApplication.IsPreload} Support preload time view creation : {NUIApplication.SupportPreInitializedCreation}\n");
735-
736-
Log.Info("NUI", "[NUI] OnApplicationInit: ProcessorController Initialize");
737-
Tizen.Tracer.Begin("[NUI] OnApplicationInit: ProcessorController Initialize");
738-
ProcessorController.Instance.Initialize();
739-
Tizen.Tracer.End();
740-
741-
// Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
742-
Log.Info("NUI", "[NUI] OnApplicationInit: DisposeQueue Initialize");
743-
Tizen.Tracer.Begin("[NUI] OnApplicationInit: DisposeQueue Initialize");
744-
DisposeQueue.Instance.Initialize();
745-
Tizen.Tracer.End();
734+
NUIApplicationInitializer.Initialize();
746735

747736
// Note : Preload window might not be changed after application created. GetWindow again.
748737
Log.Info("NUI", "[NUI] OnApplicationInit: GetWindow");
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright(c) 2024 Samsung Electronics Co., Ltd.
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+
*
16+
*/
17+
using System;
18+
using System.Threading;
19+
20+
namespace Tizen.NUI
21+
{
22+
internal static class NUIApplicationInitializer
23+
{
24+
internal static bool IsStaticInitialized {get; set;}
25+
internal static bool IsInitialized {get; set;}
26+
27+
/// <summary>
28+
/// Initialize call at very early time of project. (Should only called once)
29+
/// </summary>
30+
public static void StaticInitialize()
31+
{
32+
Tizen.Log.Info("NUI", $"[NUI] IsStaticInitialized : {IsStaticInitialized}\n");
33+
if (!IsStaticInitialized)
34+
{
35+
Tizen.Log.Info("NUI", "[NUI] NUIApplicationInitializer: StaticInitialize");
36+
Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
37+
PropertyBridge.RegisterStringGetter();
38+
39+
IsStaticInitialized = true;
40+
Tizen.Log.Info("NUI", "[NUI] NUIApplicationInitializer: StaticInitialize done");
41+
}
42+
}
43+
44+
/// <summary>
45+
/// Initialize call at Application::OnInitialize(), or Preload() when SupportPreInitializedCreation == true.
46+
/// </summary>
47+
public static void Initialize()
48+
{
49+
Tizen.Log.Info("NUI", $"[NUI] Preload : {NUIApplication.IsPreload} Support preload time view creation : {NUIApplication.SupportPreInitializedCreation} IsStaticInitialized : {IsStaticInitialized} IsInitialized : {IsInitialized}\n");
50+
51+
if (!IsInitialized)
52+
{
53+
Tizen.Log.Info("NUI", "[NUI] NUIApplicationInitializer: ProcessorController Initialize");
54+
Tizen.Tracer.Begin("[NUI] NUIApplicationInitializer: ProcessorController Initialize");
55+
ProcessorController.Instance.Initialize();
56+
Tizen.Tracer.End();
57+
58+
// Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
59+
Tizen.Log.Info("NUI", "[NUI] NUIApplicationInitializer: DisposeQueue Initialize");
60+
Tizen.Tracer.Begin("[NUI] NUIApplicationInitializer: DisposeQueue Initialize");
61+
DisposeQueue.Instance.Initialize();
62+
Tizen.Tracer.End();
63+
64+
IsInitialized = true;
65+
}
66+
}
67+
}
68+
}

src/Tizen.NUI/src/internal/Common/Registry.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ internal Thread SavedApplicationThread
215215

216216
private static void RegistryCurrentThreadCheck()
217217
{
218-
218+
if (!NUIApplicationInitializer.IsStaticInitialized || !NUIApplicationInitializer.IsInitialized)
219+
{
220+
Tizen.Log.Fatal("NUI", $"Error! NUIApplicationInitializer.Initialize() not called! You cannot use NUI framework\n");
221+
return;
222+
}
219223
if (savedApplicationThread == null)
220224
{
221225
Tizen.Log.Fatal("NUI", $"Error! maybe main thread is created by other process\n");

src/Tizen.NUI/src/public/Application/NUIApplication.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ static public bool IsUsingXaml
103103

104104
static NUIApplication()
105105
{
106-
Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
107-
PropertyBridge.RegisterStringGetter();
106+
NUIApplicationInitializer.StaticInitialize();
108107
}
109108

110109
/// <summary>
@@ -879,6 +878,8 @@ static public void Preload()
879878
Log.Error("NUI", "[NUI] Preload() Should be called before application created. Ignore\n");
880879
return;
881880
}
881+
IsPreload = true;
882+
882883
Interop.Application.PreInitialize();
883884
SupportPreInitializedCreation = Interop.Application.IsSupportPreInitializedCreation();
884885

@@ -890,6 +891,8 @@ static public void Preload()
890891
// Get default window only if pre initialize creation supported.
891892
if (SupportPreInitializedCreation)
892893
{
894+
NUIApplicationInitializer.Initialize();
895+
893896
Log.Info("NUI", "[NUI] Preload: GetWindow");
894897
Tizen.Tracer.Begin("[NUI] Preload: GetWindow");
895898
var nativeWindow = Interop.Application.GetPreInitializeWindow();
@@ -911,8 +914,6 @@ static public void Preload()
911914

912915
// Initialize exception tasks. It must be called end of Preload()
913916
NDalicPINVOKE.Preload();
914-
915-
IsPreload = true;
916917
}
917918

918919
/// <summary>

src/Tizen.NUI/src/public/Application/NUIComponentApplication.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class NUIComponentApplication : CoreApplication
4141
[EditorBrowsable(EditorBrowsableState.Never)]
4242
public NUIComponentApplication(IDictionary<Type, string> typeInfo) : base(new NUIComponentCoreBackend())
4343
{
44-
Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
4544
if (typeInfo != null)
4645
{
4746
foreach (var component in typeInfo)
@@ -84,6 +83,11 @@ public void RegisterComponent(Type compType, string compId)
8483
}
8584
}
8685

86+
static NUIComponentApplication()
87+
{
88+
NUIApplicationInitializer.StaticInitialize();
89+
}
90+
8791
/// <summary>
8892
/// Runs the application's main loop.
8993
/// </summary>

src/Tizen.NUI/src/public/Application/NUIWidgetApplication.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class NUIWidgetApplication : CoreApplication
3636
/// <param name="widgetType">Derived widget class type.</param>
3737
public NUIWidgetApplication(System.Type widgetType) : base(new NUIWidgetCoreBackend())
3838
{
39-
Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
4039
NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
4140
core?.RegisterWidgetInfo(new Dictionary<System.Type, string> { { widgetType, ApplicationInfo.ApplicationId } });
4241
}
@@ -53,7 +52,6 @@ public NUIWidgetApplication(Dictionary<System.Type, string> widgetTypes) : base(
5352
}
5453
else
5554
{
56-
Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
5755
NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
5856
core?.RegisterWidgetInfo(widgetTypes);
5957
}
@@ -68,7 +66,6 @@ public NUIWidgetApplication(Dictionary<System.Type, string> widgetTypes) : base(
6866
/// <since_tizen> 4 </since_tizen>
6967
public NUIWidgetApplication(System.Type widgetType, string styleSheet) : base(new NUIWidgetCoreBackend(styleSheet))
7068
{
71-
Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
7269
NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
7370
core?.RegisterWidgetInfo(new Dictionary<System.Type, string> { { widgetType, ApplicationInfo.ApplicationId } });
7471
}
@@ -122,6 +119,11 @@ static public bool IsUsingXaml
122119
}
123120
}
124121

122+
static NUIWidgetApplication()
123+
{
124+
NUIApplicationInitializer.StaticInitialize();
125+
}
126+
125127
internal WidgetApplication ApplicationHandle
126128
{
127129
get

0 commit comments

Comments
 (0)