From: Hyunho Kang Date: Tue, 3 Sep 2019 06:12:06 +0000 (+0900) Subject: [Tizen.Applications.ComponentBased][TCSACR-265][Add] Add ComponentBased application... X-Git-Tag: submit/tizen/20190904.005213~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59a3d5c48d508826ca4289e4fb76518618d8f004;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Tizen.Applications.ComponentBased][TCSACR-265][Add] Add ComponentBased application APIs (#977) * Add component-based application Signed-off-by: hyunho * Remove error file Signed-off-by: hyunho * [ComponentBased] The initial impelementation of ComponentBased Application Signed-off-by: hyunho * Sync with native api name modification - frame_component_get_resource_id Signed-off-by: hyunho * Add component-type to base-component Signed-off-by: hyunho * Add app-event handling logic Signed-off-by: hyunho * Remove OnAction from component lifecycle Signed-off-by: hyunho * Add launch request API Signed-off-by: hyunho * Add missing implementations - Get Parent - FrameComponent's DisplayStatus Signed-off-by: hyunho * Fix naming issue Signed-off-by: hyunho * Modify unecessary internel setter to private Signed-off-by: hyunho * Modify component parent property setter to internal Signed-off-by: hyunho * Fix typo Signed-off-by: hyunho * Change OnFini to OnFinished To use verbose field name Signed-off-by: hyunho * Change a property name Window to WindowInfo It contains more proper meaning and parent interface name is changed to IWindowInfo. Signed-off-by: hyunho * Fix type compare bug Signed-off-by: hyunho * Modify application class naming Signed-off-by: hyunho * Add missing files Signed-off-by: hyunho * Fix some issues - Naming issue Factory -> StateManager - encapsulation issue -> add CreateWindowInfo method - Circular dependancy -> public to protected - Base Component creation -> Do not allow BaseComponent creation Signed-off-by: hyunho * Fix desc Signed-off-by: hyunho * Add some logs Signed-off-by: hyunho * Remove not used Dispose method override Signed-off-by: hyunho * Remove unused value Signed-off-by: hyunho --- diff --git a/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.EflCbApplication.cs b/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.EflCbApplication.cs new file mode 100644 index 000000000..a6e8ac46d --- /dev/null +++ b/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.EflCbApplication.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +internal static partial class Interop +{ + internal static partial class EflCBApplication + { + [DllImport(Libraries.CompApplication, EntryPoint = "frame_component_get_resource_id")] + internal static extern int GetResourceId(IntPtr win, out int resId); + } +} diff --git a/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.Elementary.cs b/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.Elementary.cs new file mode 100644 index 000000000..2166223be --- /dev/null +++ b/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.Elementary.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +internal static partial class Interop +{ + internal static partial class Elementary + { + [DllImport(Libraries.Elementary, EntryPoint = "elm_init")] + internal static extern void ElmInit(int argc, string[] argv); + + [DllImport(Libraries.Elementary, EntryPoint = "elm_config_accel_preference_set")] + internal static extern IntPtr ElmConfigAccelPreferenceSet(string preference); + + [DllImport(Libraries.Elementary, EntryPoint = "elm_run")] + internal static extern void ElmRun(); + + [DllImport(Libraries.Elementary, EntryPoint = "elm_exit")] + internal static extern void ElmExit(); + + [DllImport(Libraries.Elementary, EntryPoint = "elm_shutdown")] + internal static extern void ElmShutdown(); + } +} diff --git a/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.Libraries.cs b/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.Libraries.cs new file mode 100644 index 000000000..c2d928140 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased.Default/Interop/Interop.Libraries.cs @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2016 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. + */ + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string Elementary = "libelementary.so.1"; + public const string CompApplication = "libcomponent-based-application.so"; + } +} diff --git a/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default.csproj b/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default.csproj new file mode 100644 index 000000000..15f2a07d8 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default.csproj @@ -0,0 +1,25 @@ + + + + + netstandard2.0 + false + + + + portable + + + None + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default/EFLComponentBasedApplication.cs b/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default/EFLComponentBasedApplication.cs new file mode 100644 index 000000000..89c6490b9 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default/EFLComponentBasedApplication.cs @@ -0,0 +1,86 @@ +using ElmSharp; +using System; +using System.Collections.Generic; +using Tizen.Applications.ComponentBased.Common; + +namespace Tizen.Applications.ComponentBased.Default +{ + /// + /// The basic EFL component-based application class. + /// + /// 6 + public class EFLComponentBasedApplication : ComponentBasedApplication + { + private const string LogTag = "Tizen.Applications.ComponentBasedApplication"; + + /// + /// Initializes the ComponentBasedApplication class. + /// + /// The component type information. + /// The key should be a class type of BaseComponent subclass. + /// The value should be a component id which is declared in tizen-manifest.xml. + /// + /// 6 + public EFLComponentBasedApplication(IDictionary typeInfo) : base(typeInfo) + { + } + + /// + /// This method will be called before running main-loop + /// + /// + /// 6 + protected override void OnInit(string[] args) + { + Interop.Elementary.ElmInit(args.Length, args); + string hwacc = Environment.GetEnvironmentVariable("HWACC"); + + if (hwacc == "USE") + { + Interop.Elementary.ElmConfigAccelPreferenceSet("hw"); + Log.Info(LogTag, "elm_config_accel_preference_set: hw"); + } + else if (hwacc == "NOT_USE") + { + Interop.Elementary.ElmConfigAccelPreferenceSet("none"); + Log.Info(LogTag, "elm_config_accel_preference_set: none"); + } + else + { + Log.Info(LogTag, "elm_config_accel_preference_set is not called"); + } + } + + /// + /// This method will be called after exiting main-loop + /// + /// 6 + protected override void OnFinished() + { + Interop.Elementary.ElmShutdown(); + if (Environment.GetEnvironmentVariable("AUL_LOADER_INIT") == null) + return; + + Environment.SetEnvironmentVariable("AUL_LOADER_INIT", null); + Interop.Elementary.ElmShutdown(); + } + + /// + /// This method will be called to start main-loop + /// + /// 6 + protected override void OnRun() + { + Interop.Elementary.ElmRun(); + } + + /// + /// This method will be called to exit main-loop + /// + /// 6 + protected override void OnExit() + { + Interop.Elementary.ElmExit(); + } + } +} diff --git a/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default/EFLWindowInfo.cs b/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default/EFLWindowInfo.cs new file mode 100644 index 000000000..7d04b0b1e --- /dev/null +++ b/src/Tizen.Applications.ComponentBased.Default/Tizen.Applications.ComponentBased.Default/EFLWindowInfo.cs @@ -0,0 +1,49 @@ +using ElmSharp; +using System; +using Tizen.Applications.ComponentBased.Common; + +namespace Tizen.Applications.ComponentBased.Default +{ + /// + /// Window information class for ComponentBasedApplication + /// + /// 6 + public class EFLWindowInfo : IWindowInfo + { + private const string LogTag = "Tizen.Applications.EFLWindow"; + private Window _win; + private int _resId; + + /// + /// Initializes the EFLWindow class. + /// + /// The window object of component. + /// 6 + public EFLWindowInfo(Window win) + { + _win = win; + } + + /// + /// Gets the resource ID of window + /// + /// The native handle of window + /// 6 + public int ResourceId + { + get + { + if (_resId == 0) + { + int err = Interop.EflCBApplication.GetResourceId(_win.RealHandle, out _resId); + if (err != 0) + Log.Info(LogTag, "Fail to get resource ID"); + } + + return _resId; + } + } + + } + +} diff --git a/src/Tizen.Applications.ComponentBased/Interop/Interop.AppControl.cs b/src/Tizen.Applications.ComponentBased/Interop/Interop.AppControl.cs new file mode 100644 index 000000000..411047eda --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Interop/Interop.AppControl.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using Tizen.Applications; + +internal static partial class Interop +{ + internal static partial class AppControl + { + [DllImport(Libraries.AppControl, EntryPoint = "app_control_set_caller_instance_compId")] + internal static extern int SetCallerInstanceId(SafeAppControlHandle appControl, string instanceId); + } +} diff --git a/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs b/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs new file mode 100644 index 000000000..2fb3a98d6 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using Tizen.Applications; + +internal static partial class Interop +{ + internal static partial class CBApplication + { + internal delegate void CBAppInitCallback(int argc, string[] argv, IntPtr userData); + internal delegate void CBAppFiniCallback(IntPtr userData); + internal delegate void CBAppRunCallback(IntPtr userData); + internal delegate void CBAppExitCallback(IntPtr userData); + internal delegate IntPtr CBAppCreateCallback(IntPtr userData); + internal delegate void CBAppTerminateCallback(IntPtr userData); + [StructLayoutAttribute(LayoutKind.Sequential)] + internal struct CBAppLifecycleCallbacks + { + public CBAppInitCallback OnInit; + public CBAppFiniCallback OnFinished; + public CBAppRunCallback OnRun; + public CBAppExitCallback OnExit; + public CBAppCreateCallback OnCreate; + public CBAppTerminateCallback OnTerminate; + } + + internal enum ErrorCode : int + { + None = Tizen.Internals.Errors.ErrorCode.None, + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + InvalidContext = -0x03030000 | 0x01, + NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, + NotFound = -0x03030000 | 0x02, + LaunchRejected = -0x03030000 | 0x03, + LaunchFailed = -0x03030000 | 0x04, + TimedOut = Tizen.Internals.Errors.ErrorCode.TimedOut, + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, + } + + internal enum NativeComponentType + { + Frame = 0, + Service + } + + internal enum NativeDisplayStatus { + On, + Off + } + + internal delegate IntPtr FrameCreateCallback(IntPtr context, IntPtr userData); + internal delegate void FrameStartCallback(IntPtr context, IntPtr appControl, bool restarted, IntPtr userData); + internal delegate void FrameResumeCallback(IntPtr context, IntPtr userData); + internal delegate void FramePauseCallback(IntPtr context, IntPtr userData); + internal delegate void FrameStopCallback(IntPtr context, IntPtr userData); + internal delegate void FrameDestroyCallback(IntPtr context, IntPtr userData); + internal delegate void FrameRestoreCallback(IntPtr context, IntPtr content, IntPtr userData); + internal delegate void FrameSaveCallback(IntPtr context, IntPtr content, IntPtr userData); + internal delegate void FrameActionCallback(IntPtr context, string action, IntPtr appControl, IntPtr userData); + internal delegate void FrameDeviceOrientationChangedCallback(IntPtr context, int orientation, IntPtr userData); + internal delegate void FrameLanguageChangedCallback(IntPtr context, string language, IntPtr userData); + internal delegate void FrameRegionFormatChangedCallback(IntPtr context, string region, IntPtr userData); + internal delegate void FrameLowBatteryCallback(IntPtr context, int status, IntPtr userData); + internal delegate void FrameLowMemoryCallback(IntPtr context, int status, IntPtr userData); + internal delegate void FrameSuspendedStateCallback(IntPtr context, int state, IntPtr userData); + + internal struct FrameLifecycleCallbacks + { + public FrameCreateCallback OnCreate; + public FrameStartCallback OnStart; + public FrameResumeCallback OnResume; + public FramePauseCallback OnPause; + public FrameStopCallback OnStop; + public FrameDestroyCallback OnDestroy; + public FrameRestoreCallback OnRestore; + public FrameSaveCallback OnSave; + public FrameActionCallback OnAction; + public FrameDeviceOrientationChangedCallback OnDeviceOrientationChanged; + public FrameLanguageChangedCallback OnLanguageChanged; + public FrameRegionFormatChangedCallback OnRegionFormatChanged; + public FrameLowBatteryCallback OnLowBattery; + public FrameLowMemoryCallback OnLowMemory; + public FrameSuspendedStateCallback OnSuspendedState; + } + + internal delegate bool ServiceCreateCallback(IntPtr context, IntPtr userData); + internal delegate void ServiceStartCommandCallback(IntPtr context, IntPtr appControl, bool restarted, IntPtr userData); + internal delegate void ServiceDestroyCallback(IntPtr context, IntPtr userData); + internal delegate void ServiceRestoreCallback(IntPtr context, IntPtr content, IntPtr userData); + internal delegate void ServiceSaveCallback(IntPtr context, IntPtr content, IntPtr userData); + internal delegate void ServiceActionCallback(IntPtr context, string action, IntPtr appControl, IntPtr userData); + internal delegate void ServiceDeviceOrientationChangedCallback(IntPtr context, int orientation, IntPtr userData); + internal delegate void ServiceLanguageChangedCallback(IntPtr context, string language, IntPtr userData); + internal delegate void ServiceRegionFormatChangedCallback(IntPtr context, string region, IntPtr userData); + internal delegate void ServiceLowBatteryCallback(IntPtr context, int status, IntPtr userData); + internal delegate void ServiceLowMemoryCallback(IntPtr context, int status, IntPtr userData); + internal delegate void ServiceSuspendedStateCallback(IntPtr context, int state, IntPtr userData); + + internal struct ServiceLifecycleCallbacks + { + public ServiceCreateCallback OnCreate; + public ServiceStartCommandCallback OnStart; + public ServiceDestroyCallback OnDestroy; + public ServiceRestoreCallback OnRestore; + public ServiceSaveCallback OnSave; + public ServiceActionCallback OnAction; + public ServiceDeviceOrientationChangedCallback OnDeviceOrientationChanged; + public ServiceLanguageChangedCallback OnLanguageChanged; + public ServiceRegionFormatChangedCallback OnRegionFormatChanged; + public ServiceLowBatteryCallback OnLowBattery; + public ServiceLowMemoryCallback OnLowMemory; + public ServiceSuspendedStateCallback OnSuspendedState; + } + + internal delegate IntPtr BaseCreateCallback(IntPtr context, IntPtr userData); + internal delegate void BaseDestroyCallback(IntPtr context, IntPtr userData); + internal delegate void BaseRestoreCallback(IntPtr context, IntPtr content, IntPtr userData); + internal delegate void BaseSaveCallback(IntPtr context, IntPtr content, IntPtr userData); + internal delegate void BaseDeviceOrientationChangedCallback(IntPtr context, int orientation, IntPtr userData); + internal delegate void BaseLanguageChangedCallback(IntPtr context, string language, IntPtr userData); + internal delegate void BaseRegionFormatChangedCallback(IntPtr context, string region, IntPtr userData); + internal delegate void BaseLowBatteryCallback(IntPtr context, int status, IntPtr userData); + internal delegate void BaseLowMemoryCallback(IntPtr context, int status, IntPtr userData); + internal delegate void BaseSuspendedStateCallback(IntPtr context, int state, IntPtr userData); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "component_based_app_base_main")] + internal static extern ErrorCode BaseMain(int argc, string[] argv, ref CBAppLifecycleCallbacks callback, IntPtr userData); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "component_based_app_base_exit")] + internal static extern ErrorCode BaseExit(); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "component_based_app_base_add_frame_component")] + internal static extern IntPtr BaseAddFrameComponent(IntPtr comp_class, string compId, ref FrameLifecycleCallbacks callback, IntPtr userData); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "component_based_app_base_add_service_component")] + internal static extern IntPtr BaseAddServiceComponent(IntPtr comp_class, string compId, ref ServiceLifecycleCallbacks callback, IntPtr userData); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "base_frame_create_window")] + internal static extern IntPtr BaseFrameCreateWindow(out IntPtr winHandle, int winId, IntPtr raw); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "base_frame_window_get_compId")] + internal static extern IntPtr BaseFrameWindowGetId(IntPtr winHandle, out int winId); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "base_frame_window_get_raw")] + internal static extern IntPtr BaseFrameWindowGetRaw(IntPtr winHandle, out IntPtr raw); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "base_frame_get_display_status")] + internal static extern ErrorCode BaseFrameGetDisplayStatus(IntPtr context, out NativeDisplayStatus status); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "component_get_instance_id")] + internal static extern ErrorCode GetInstanceId(IntPtr context, out string instanceId); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ReplyCallback(IntPtr request, IntPtr reply, int result, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ResultCallback(IntPtr request, int result, IntPtr userData); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "component_send_launch_request_async")] + internal static extern ErrorCode SendLaunchRequestAsync(IntPtr context, SafeAppControlHandle appControl, + ResultCallback resultCallback, ReplyCallback replyCallback, IntPtr userData); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "component_send_launch_request_sync")] + internal static extern ErrorCode SendLaunchRequestSync(IntPtr context, SafeAppControlHandle appControl, + SafeAppControlHandle replyControl, out int result); + + [DllImport(Libraries.CompCoreBase, EntryPoint = "component_finish")] + internal static extern ErrorCode ComponentFinish(IntPtr context); + } +} diff --git a/src/Tizen.Applications.ComponentBased/Interop/Interop.Libraries.cs b/src/Tizen.Applications.ComponentBased/Interop/Interop.Libraries.cs new file mode 100644 index 000000000..50256474a --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Interop/Interop.Libraries.cs @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2016 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. + */ + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string CompCoreBase = "libcomponent-based-core-base.so"; + public const string CompApplication = "libcomponent-based-application.so"; + public const string CompAppControl = "libcomponent-based-app-control.so"; + public const string CompUri = "libcomponent-based-uri.so"; + public const string AppControl = "libcapi-appfw-app-control.so.0"; + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/BaseComponent.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/BaseComponent.cs new file mode 100644 index 000000000..87dba90f4 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/BaseComponent.cs @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2019 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.Threading.Tasks; + +namespace Tizen.Applications.ComponentBased.Common +{ + /// + /// This is a base-component class. + /// It provides common functions of FrameComponent and ServiceComponent. + /// + /// + /// This class cannot be registered by ComponentBased applications. + /// + /// 6 + public abstract class BaseComponent + { + internal IntPtr Handle; + + /// + /// Occurs when the system memory is low. + /// + /// 6 + public event EventHandler LowMemory; + + /// + /// Occurs when the system battery is low. + /// + /// 6 + public event EventHandler LowBattery; + + /// + /// Occurs when the system language is chagned. + /// + /// 6 + public event EventHandler LocaleChanged; + + /// + /// Occurs when the region format is changed. + /// + /// 6 + public event EventHandler RegionFormatChanged; + + /// + /// Occurs when the device orientation is changed. + /// + /// 6 + public event EventHandler DeviceOrientationChanged; + + /// + /// Occurs when the device orientation is changed. + /// + /// 6 + public event EventHandler SuspendedStateChanged; + + /// + /// A component instance ID. + /// It will be created after OnCreate method is invoked. + /// + /// 6 + public string Id { get; private set; } + + /// + /// A component ID + /// + /// 6 + public string ComponentId { get; private set; } + + /// + /// Parent object + /// + /// 6 + public ComponentBasedApplication Parent { get; private set; } + + /// + /// Finish current component + /// + /// 6 + public void Finish() + { + Interop.CBApplication.ComponentFinish(Handle); + } + + internal void Bind(IntPtr handle, string compId, string instanceId, ComponentBasedApplication parent) + { + Handle = handle; + Id = instanceId; + ComponentId = compId; + Parent = parent; + } + + /// + /// Overrides this method if want to handle behavior to restore the previous status. + /// + /// Contents. It can be used only in the callback. To use outside, make a copy. + /// 6 + public virtual void OnRestoreContents(Bundle c) + { + } + + /// + /// Overrides this method if want to handle behavior to save current status. + /// + /// Contents. It can be used only in the callback. To use outside, make a copy. + /// 6 + public virtual void OnSaveContent(Bundle c) + { + } + + internal void OnLanguageChangedCallback(string language) + { + LocaleChanged?.Invoke(this, new LocaleChangedEventArgs(language)); + } + + internal void OnDeviceOrientationChangedCallback(int orientation) + { + DeviceOrientationChanged?.Invoke(this, new DeviceOrientationEventArgs((DeviceOrientation)orientation)); + } + + internal void OnLowBatteryCallback(int status) + { + LowBattery?.Invoke(this, new LowBatteryEventArgs((LowBatteryStatus)status)); + } + + internal void OnLowMemoryCallback(int status) + { + LowMemory?.Invoke(this, new LowMemoryEventArgs((LowMemoryStatus)status)); + } + + internal void OnRegionFormatChangedCallback(string region) + { + RegionFormatChanged?.Invoke(this, new RegionFormatChangedEventArgs(region)); + } + + internal void OnSuspendedStateCallback(int state) + { + SuspendedStateChanged?.Invoke(this, new SuspendedStateEventArgs((SuspendedState)state)); + } + + /// + /// Sends the launch request asynchronously. + /// + /// + /// To use group mode, you must use this function instead of SendLaunchRequestAsync(). + /// + /// appcontrol object + /// The callback function to be called when the reply is delivered. + /// A task with the result of the launch request. + /// Thrown when failed because of the argument is invalid. + /// Thrown when fail to set component information to the AppControl. + /// Thrown when the application to run is not found. + /// Thrown when the launch request is rejected. + /// http://tizen.org/privilege/appmanager.launch + /// 6 + public Task SendLaunchRequestAsync(AppControl control, AppControlReplyCallback replyAfterLaunching) + { + int ret = Interop.AppControl.SetCallerInstanceId(control.SafeAppControlHandle, Id); + if (ret != 0) + throw new InvalidOperationException("Failed to set id"); + + return AppControl.SendLaunchRequestAsync(control, replyAfterLaunching); + } + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentBasedApplication.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentBasedApplication.cs new file mode 100644 index 000000000..827cc292a --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentBasedApplication.cs @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2019 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.Collections.Generic; + +namespace Tizen.Applications.ComponentBased.Common +{ + /// + /// The class for supporting multi-components based application model. + /// + /// 6 + public abstract class ComponentBasedApplication : Application + { + private const string LogTag = "Tizen.Applications.ComponentBasedApplicationBase"; + private Dictionary _componentFactories = new Dictionary(); + private Interop.CBApplication.CBAppLifecycleCallbacks _callbacks; + + /// + /// Initializes the ComponentBasedApplicationBase class. + /// + /// The component type information. + /// The key should be a class type of FrameComponent or SubComponent subclass. + /// The value should be a component id which is declared in tizen-manifest.xml. + /// + /// 6 + public ComponentBasedApplication(IDictionary typeInfo) + { + _callbacks.OnInit = new Interop.CBApplication.CBAppInitCallback(OnInitNative); + _callbacks.OnFinished = new Interop.CBApplication.CBAppFiniCallback(OnFinishedNative); + _callbacks.OnRun = new Interop.CBApplication.CBAppRunCallback(OnRunNative); + _callbacks.OnExit = new Interop.CBApplication.CBAppExitCallback(OnExitNative); + _callbacks.OnCreate = new Interop.CBApplication.CBAppCreateCallback(OnCreateNative); + _callbacks.OnTerminate = new Interop.CBApplication.CBAppTerminateCallback(OnTerminateNative); + + foreach (var component in typeInfo) + { + RegisterComponent(component.Key, component.Value); + } + } + + /// + /// Registers a component. + /// + /// Class type + /// Component ID + /// Thrown when component type is already added or not sub-class of FrameComponent or ServiceComponent + /// 6 + public void RegisterComponent(Type compType, string compId) + { + if (_componentFactories.ContainsKey(compType)) + { + throw new ArgumentException("Already exist type"); + } + + if (typeof(FrameComponent).IsAssignableFrom(compType)) + { + Log.Info(LogTag, "Add frame component"); + _componentFactories.Add(compType, new FrameComponentStateManager(compType, compId, this)); + } + else if (typeof(ServiceComponent).IsAssignableFrom(compType)) + { + Log.Info(LogTag, "Add service component"); + _componentFactories.Add(compType, new ServiceComponentStateManager(compType, compId, this)); + } + else + { + throw new ArgumentException("compType must be sub type of FrameComponent or ServiceComponent", "compType"); + } + } + + /// + /// Runs the application's main loop. + /// + /// Arguments from commandline. + /// Thrown when component type is already added to the component. + /// 6 + public override void Run(string[] args) + { + base.Run(args); + + string[] argsClone = new string[args.Length + 1]; + if (args.Length > 1) + { + args.CopyTo(argsClone, 1); + } + argsClone[0] = string.Empty; + + Interop.CBApplication.ErrorCode err = Interop.CBApplication.BaseMain(argsClone.Length, argsClone, ref _callbacks, IntPtr.Zero); + if (err != Interop.CBApplication.ErrorCode.None) + { + Log.Error(LogTag, "Failed to run the application. Err = " + err); + throw new InvalidOperationException("Fail to run application : err(" + err + ")"); + } + } + + /// + /// Exits the main loop of the application. + /// + /// 6 + public override void Exit() + { + Interop.CBApplication.BaseExit(); + } + + private IntPtr OnCreateNative(IntPtr data) + { + Log.Debug(LogTag, "On create"); + IntPtr nativeComponentFactoryMap = IntPtr.Zero; + foreach (KeyValuePair entry in _componentFactories) + { + nativeComponentFactoryMap = entry.Value.Bind(nativeComponentFactoryMap); + } + + return nativeComponentFactoryMap; + } + + private void OnTerminateNative(IntPtr data) + { + } + + private void OnRunNative(IntPtr data) + { + OnRun(); + } + + private void OnExitNative(IntPtr data) + { + OnExit(); + } + + private void OnInitNative(int argc, string[] argv, IntPtr userData) + { + OnInit(argv); + } + + private void OnFinishedNative(IntPtr data) + { + OnFinished(); + } + + /// + /// This method will be called before running main-loop + /// + /// + /// 6 + protected virtual void OnInit(string[] args) + { + } + + /// + /// This method will be called after exiting main-loop + /// + /// 6 + protected virtual void OnFinished() + { + } + + /// + /// This method will be called to start main-loop + /// + /// 6 + protected abstract void OnRun(); + + /// + /// This method will be called to exit main-loop + /// + /// 6 + protected virtual void OnExit() + { + } + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentStateManger.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentStateManger.cs new file mode 100644 index 000000000..83d5bebff --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentStateManger.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Tizen.Applications.CoreBackend; +using static Interop.CBApplication; +using static Tizen.Applications.CoreBackend.DefaultCoreBackend; + +namespace Tizen.Applications.ComponentBased.Common +{ + internal abstract class ComponentStateManger + { + private IList ComponentInstances { get; } + public IEnumerable Instances => ComponentInstances; + protected void AddComponent(BaseComponent comp) + { + ComponentInstances.Add(comp); + } + + protected void RemoveComponent(BaseComponent comp) + { + ComponentInstances.Remove(comp); + } + public Type ComponentClassType { get; } + public string ComponentId { get; } + protected ComponentBasedApplication Parent { get; set; } + + internal ComponentStateManger(Type ctype, string id, ComponentBasedApplication parent) + { + ComponentClassType = ctype; + ComponentId = id; + ComponentInstances = new List(); + Parent = parent; + } + + protected void OnLanguageChangedCallback(IntPtr context, string language, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + com.OnLanguageChangedCallback(language); + } + } + } + + protected void OnDeviceOrientationChangedCallback(IntPtr context, int orientation, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + com.OnDeviceOrientationChangedCallback(orientation); + } + } + } + + protected void OnLowBatteryCallback(IntPtr context, int status, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + com.OnLowBatteryCallback(status); + } + } + } + + protected void OnLowMemoryCallback(IntPtr context, int status, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + com.OnLowMemoryCallback(status); + } + } + } + + protected void OnRegionFormatChangedCallback(IntPtr context, string region, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + com.OnRegionFormatChangedCallback(region); + } + } + } + + protected void OnSuspendedStateCallback(IntPtr context, int state, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + com.OnSuspendedStateCallback(state); + } + } + } + + protected void OnRestoreCallback(IntPtr context, IntPtr content, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + Bundle bundle = null; + + if (content != IntPtr.Zero) + bundle = new Bundle(new SafeBundleHandle(content, false)); + com.OnRestoreContents(bundle); + break; + } + } + } + + protected void OnSaveCallback(IntPtr context, IntPtr content, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + Bundle bundle = null; + + if (content != IntPtr.Zero) + bundle = new Bundle(new SafeBundleHandle(content, false)); + com.OnSaveContent(bundle); + break; + } + } + } + + internal abstract IntPtr Bind(IntPtr h); + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/DisplayStatus.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/DisplayStatus.cs new file mode 100644 index 000000000..12217dbbd --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/DisplayStatus.cs @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 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.Threading.Tasks; + +namespace Tizen.Applications.ComponentBased.Common +{ + /// + /// Enumeration for display status. + /// + /// 6 + public enum DisplayStatus + { + /// + /// The display status is on + /// + On = Interop.CBApplication.NativeDisplayStatus.On, + + /// + /// The display status is off + /// + Off = Interop.CBApplication.NativeDisplayStatus.Off + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponent.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponent.cs new file mode 100644 index 000000000..8930608b7 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponent.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tizen.Applications.ComponentBased.Common +{ + /// + /// The class for showing UI module + /// + /// 6 + public abstract class FrameComponent : BaseComponent + { + /// + /// Gets the display status of a component. + /// + /// Thrown when component type is already added to the component. + /// 6 + public DisplayStatus DisplayStatus + { + get + { + Interop.CBApplication.NativeDisplayStatus status; + Interop.CBApplication.ErrorCode err = Interop.CBApplication.BaseFrameGetDisplayStatus(Handle, out status); + if (err != Interop.CBApplication.ErrorCode.None) + throw new InvalidOperationException("Fail to get display status : err(" + err + ")"); + + return (DisplayStatus)status; + } + } + + /// + /// Overrides this method to handle behavior when the component is launched. + /// + /// True if a service component is successfully created + /// 6 + public abstract bool OnCreate(); + + /// + /// Overrides this method to create window. It will be called before OnCreate method. + /// + /// Window object to use + /// 6 + public abstract IWindowInfo CreateWindowInfo(); + + /// + /// Overrides this method if want to handle behavior when the component receives the appcontrol message. + /// + /// appcontrol object + /// True if it was restarted + /// 6 + public virtual void OnStart(AppControl appControl, bool restarted) + { + } + + /// + /// Overrides this method if you want to handle the behavior when the component is resumed. + /// + /// 6 + public virtual void OnResume() + { + } + + /// + /// Overrides this method if you want to handle the behavior when the component is paused. + /// + /// 6 + public virtual void OnPause() + { + } + + /// + /// Overrides this method if you want to handle the behavior when the component is stopped. + /// + /// 6 + public virtual void OnStop() + { + } + + /// + /// Overrides this method if want to handle behavior when the component is destroyed. + /// + /// 6 + public virtual void OnDestroy() + { + } + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponentStateManager.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponentStateManager.cs new file mode 100644 index 000000000..e584b8cea --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponentStateManager.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tizen.Applications.ComponentBased.Common +{ + internal class FrameComponentStateManager : ComponentStateManger + { + private Interop.CBApplication.FrameLifecycleCallbacks _callbacks; + private const string LogTag = "Tizen.Applications.FrameComponentStateManager"; + + internal FrameComponentStateManager(Type ctype, string id, ComponentBasedApplication parent) : base(ctype, id, parent) + { + _callbacks.OnAction = new Interop.CBApplication.FrameActionCallback(OnActionCallback); + _callbacks.OnDeviceOrientationChanged = new Interop.CBApplication.FrameDeviceOrientationChangedCallback(OnDeviceOrientationChangedCallback); + _callbacks.OnLanguageChanged = new Interop.CBApplication.FrameLanguageChangedCallback(OnLanguageChangedCallback); + _callbacks.OnLowBattery = new Interop.CBApplication.FrameLowBatteryCallback(OnLowBatteryCallback); + _callbacks.OnLowMemory = new Interop.CBApplication.FrameLowMemoryCallback(OnLowMemoryCallback); + _callbacks.OnRegionFormatChanged = new Interop.CBApplication.FrameRegionFormatChangedCallback(OnRegionFormatChangedCallback); + _callbacks.OnRestore = new Interop.CBApplication.FrameRestoreCallback(OnRestoreCallback); + _callbacks.OnSave = new Interop.CBApplication.FrameSaveCallback(OnSaveCallback); + _callbacks.OnSuspendedState = new Interop.CBApplication.FrameSuspendedStateCallback(OnSuspendedStateCallback); + _callbacks.OnCreate = new Interop.CBApplication.FrameCreateCallback(OnCreateCallback); + _callbacks.OnDestroy = new Interop.CBApplication.FrameDestroyCallback(OnDestroyCallback); + _callbacks.OnPause = new Interop.CBApplication.FramePauseCallback(OnPauseCallback); + _callbacks.OnResume = new Interop.CBApplication.FrameResumeCallback(OnResumeCallback); + _callbacks.OnStart = new Interop.CBApplication.FrameStartCallback(OnStartCallback); + _callbacks.OnStop = new Interop.CBApplication.FrameStopCallback(OnStopCallback); + Parent = parent; + } + + private IntPtr OnCreateCallback(IntPtr context, IntPtr userData) + { + FrameComponent fc = Activator.CreateInstance(ComponentClassType) as FrameComponent; + if (fc == null) + { + Log.Error(LogTag, "Fail to create instance"); + return IntPtr.Zero; + } + + string id; + Interop.CBApplication.GetInstanceId(context, out id); + fc.Bind(context, ComponentId, id, Parent); + + IntPtr winHandle; + IWindowInfo win = fc.CreateWindowInfo(); + if (win == null) + return IntPtr.Zero; + + if (!fc.OnCreate()) + { + Log.Error(LogTag, "OnCreate fail"); + return IntPtr.Zero; + } + Interop.CBApplication.BaseFrameCreateWindow(out winHandle, win.ResourceId, IntPtr.Zero); + + AddComponent(fc); + return winHandle; + } + + private void OnStartCallback(IntPtr context, IntPtr appControl, bool restarted, IntPtr userData) + { + foreach (FrameComponent fc in Instances) + { + if (fc.Handle == context) + { + SafeAppControlHandle handle = new SafeAppControlHandle(appControl, false); + AppControl control = new AppControl(handle); + fc.OnStart(control, restarted); + break; + } + } + } + + private void OnResumeCallback(IntPtr context, IntPtr userData) + { + foreach (FrameComponent fc in Instances) + { + if (fc.Handle == context) + { + fc.OnResume(); + break; + } + } + } + + private void OnPauseCallback(IntPtr context, IntPtr userData) + { + foreach (FrameComponent fc in Instances) + { + if (fc.Handle == context) + { + fc.OnPause(); + break; + } + } + } + + private void OnStopCallback(IntPtr context, IntPtr userData) + { + foreach (FrameComponent fc in Instances) + { + if (fc.Handle == context) + { + fc.OnStop(); + break; + } + } + } + + private void OnDestroyCallback(IntPtr context, IntPtr userData) + { + foreach (FrameComponent fc in Instances) + { + if (fc.Handle == context) + { + fc.OnDestroy(); + RemoveComponent(fc); + break; + } + } + return; + } + + private void OnActionCallback(IntPtr context, string action, IntPtr appControl, IntPtr userData) + { + } + + internal override IntPtr Bind(IntPtr h) + { + return Interop.CBApplication.BaseAddFrameComponent(h, ComponentId, ref _callbacks, IntPtr.Zero); + } + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/IWindowInfo.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/IWindowInfo.cs new file mode 100644 index 000000000..16df43641 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/IWindowInfo.cs @@ -0,0 +1,17 @@ +using System; + +namespace Tizen.Applications.ComponentBased.Common +{ + /// + /// Interface for window information + /// + /// 6 + public interface IWindowInfo + { + /// + /// Gets window resource ID + /// + /// + int ResourceId { get; } + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponent.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponent.cs new file mode 100644 index 000000000..3a5921f85 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponent.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tizen.Applications.ComponentBased.Common +{ + /// + /// The class for showing service module + /// + /// 6 + public abstract class ServiceComponent : BaseComponent + { + /// + /// Overrides this method to handle behavior when the component is created. + /// + /// True if a service component is successfully created + public abstract bool OnCreate(); + + /// + /// Overrides this method if want to handle behavior when the component receives the start command message. + /// + /// appcontrol object + /// True if it was restarted + /// 6 + public virtual void OnStartCommand(AppControl appControl, bool restarted) + { + } + + /// + /// Overrides this method if want to handle behavior when the component is destroyed. + /// + /// 6 + public virtual void OnDestroy() + { + } + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponentStateManager.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponentStateManager.cs new file mode 100644 index 000000000..8d0becc2f --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponentStateManager.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tizen.Applications.ComponentBased.Common +{ + internal class ServiceComponentStateManager : ComponentStateManger + { + private Interop.CBApplication.ServiceLifecycleCallbacks _callbacks; + + internal ServiceComponentStateManager(Type ctype, string id, ComponentBasedApplication parent) : base(ctype, id, parent) + { + _callbacks.OnAction = new Interop.CBApplication.ServiceActionCallback(OnActionCallback); + _callbacks.OnDeviceOrientationChanged = new Interop.CBApplication.ServiceDeviceOrientationChangedCallback(OnDeviceOrientationChangedCallback); + _callbacks.OnLanguageChanged = new Interop.CBApplication.ServiceLanguageChangedCallback(OnLanguageChangedCallback); + _callbacks.OnLowBattery = new Interop.CBApplication.ServiceLowBatteryCallback(OnLowBatteryCallback); + _callbacks.OnLowMemory = new Interop.CBApplication.ServiceLowMemoryCallback(OnLowMemoryCallback); + _callbacks.OnRegionFormatChanged = new Interop.CBApplication.ServiceRegionFormatChangedCallback(OnRegionFormatChangedCallback); + _callbacks.OnRestore = new Interop.CBApplication.ServiceRestoreCallback(OnRestoreCallback); + _callbacks.OnSave = new Interop.CBApplication.ServiceSaveCallback(OnSaveCallback); + _callbacks.OnSuspendedState = new Interop.CBApplication.ServiceSuspendedStateCallback(OnSuspendedStateCallback); + _callbacks.OnCreate = new Interop.CBApplication.ServiceCreateCallback(OnCreateCallback); + _callbacks.OnDestroy = new Interop.CBApplication.ServiceDestroyCallback(OnDestroyCallback); + _callbacks.OnStart = new Interop.CBApplication.ServiceStartCommandCallback(OnStartCallback); + Parent = parent; + } + + private bool OnCreateCallback(IntPtr context, IntPtr userData) + { + ServiceComponent sc = Activator.CreateInstance(ComponentClassType) as ServiceComponent; + if (sc == null) + return false; + + string id; + Interop.CBApplication.GetInstanceId(context, out id); + sc.Bind(context, ComponentId, id, Parent); + + if (!sc.OnCreate()) + { + return false; + } + + AddComponent(sc); + return true; + } + + private void OnStartCallback(IntPtr context, IntPtr appControl, bool restarted, IntPtr userData) + { + foreach (ServiceComponent sc in Instances) + { + if (sc.Handle == context) + { + SafeAppControlHandle handle = new SafeAppControlHandle(appControl, false); + AppControl control = new AppControl(handle); + sc.OnStartCommand(control, restarted); + break; + } + } + } + + private void OnDestroyCallback(IntPtr context, IntPtr userData) + { + foreach (ServiceComponent sc in Instances) + { + if (sc.Handle == context) + { + sc.OnDestroy(); + RemoveComponent(sc); + break; + } + } + return; + } + + private void OnActionCallback(IntPtr context, string action, IntPtr appControl, IntPtr userData) + { + } + + internal override IntPtr Bind(IntPtr h) + { + return Interop.CBApplication.BaseAddServiceComponent(h, ComponentId, ref _callbacks, IntPtr.Zero); + } + } +} diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.csproj b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.csproj new file mode 100644 index 000000000..39031113a --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.csproj @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.sln b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.sln new file mode 100644 index 000000000..04e112b46 --- /dev/null +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.sln @@ -0,0 +1,107 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.ComponentBased", "Tizen.Applications.ComponentBased.csproj", "{AD96625A-6D22-4488-AB3A-2EAD2A895931}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.Common", "..\Tizen.Applications.Common\Tizen.Applications.Common.csproj", "{355E4947-6FCB-44B8-8EEF-2A97FA942502}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Log", "..\Tizen.Log\Tizen.Log.csproj", "{2C5A9D7F-0527-4012-9566-70E2BC97B619}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen", "..\Tizen\Tizen.csproj", "{518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElmSharp", "..\ElmSharp\ElmSharp.csproj", "{EC949A36-62F5-41B7-9D1F-7139F1D53C99}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Applications.ComponentBased.Default", "..\Tizen.Applications.ComponentBased.Default\Tizen.Applications.ComponentBased.Default.csproj", "{AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Debug|x64.ActiveCfg = Debug|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Debug|x64.Build.0 = Debug|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Debug|x86.ActiveCfg = Debug|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Debug|x86.Build.0 = Debug|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Release|Any CPU.Build.0 = Release|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Release|x64.ActiveCfg = Release|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Release|x64.Build.0 = Release|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Release|x86.ActiveCfg = Release|Any CPU + {AD96625A-6D22-4488-AB3A-2EAD2A895931}.Release|x86.Build.0 = Release|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Debug|Any CPU.Build.0 = Debug|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Debug|x64.ActiveCfg = Debug|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Debug|x64.Build.0 = Debug|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Debug|x86.ActiveCfg = Debug|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Debug|x86.Build.0 = Debug|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Release|Any CPU.ActiveCfg = Release|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Release|Any CPU.Build.0 = Release|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Release|x64.ActiveCfg = Release|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Release|x64.Build.0 = Release|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Release|x86.ActiveCfg = Release|Any CPU + {355E4947-6FCB-44B8-8EEF-2A97FA942502}.Release|x86.Build.0 = Release|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Debug|x64.ActiveCfg = Debug|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Debug|x64.Build.0 = Debug|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Debug|x86.ActiveCfg = Debug|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Debug|x86.Build.0 = Debug|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Release|Any CPU.Build.0 = Release|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Release|x64.ActiveCfg = Release|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Release|x64.Build.0 = Release|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Release|x86.ActiveCfg = Release|Any CPU + {2C5A9D7F-0527-4012-9566-70E2BC97B619}.Release|x86.Build.0 = Release|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Debug|x64.ActiveCfg = Debug|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Debug|x64.Build.0 = Debug|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Debug|x86.ActiveCfg = Debug|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Debug|x86.Build.0 = Debug|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Release|Any CPU.Build.0 = Release|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Release|x64.ActiveCfg = Release|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Release|x64.Build.0 = Release|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Release|x86.ActiveCfg = Release|Any CPU + {518F51D4-0C4E-4B37-82B0-93DC5C5DB45F}.Release|x86.Build.0 = Release|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Debug|x64.ActiveCfg = Debug|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Debug|x64.Build.0 = Debug|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Debug|x86.ActiveCfg = Debug|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Debug|x86.Build.0 = Debug|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Release|Any CPU.Build.0 = Release|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Release|x64.ActiveCfg = Release|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Release|x64.Build.0 = Release|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Release|x86.ActiveCfg = Release|Any CPU + {EC949A36-62F5-41B7-9D1F-7139F1D53C99}.Release|x86.Build.0 = Release|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Debug|x64.ActiveCfg = Debug|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Debug|x64.Build.0 = Debug|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Debug|x86.ActiveCfg = Debug|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Debug|x86.Build.0 = Debug|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Release|Any CPU.Build.0 = Release|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Release|x64.ActiveCfg = Release|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Release|x64.Build.0 = Release|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Release|x86.ActiveCfg = Release|Any CPU + {AA75A4EC-AE72-4954-AD43-A9B2FAA69CDF}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {32D5E43C-CB76-49CC-A427-0A9C98ADEF3B} + EndGlobalSection +EndGlobal