--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+using System.Collections.Generic;
+
+using Tizen.Internals.Errors;
+
+namespace Tizen.Applications.CoreBackend
+{
+ internal abstract class DefaultCoreBackend : ICoreBackend
+ {
+ protected static readonly string LogTag = typeof(DefaultCoreBackend).Namespace;
+
+ protected Dictionary<EventType, object> _handlers = new Dictionary<EventType, object>();
+
+ private bool _disposedValue = false;
+
+ private Interop.AppCommon.AppEventCallback _lowMemoryCallback;
+ private Interop.AppCommon.AppEventCallback _lowBatteryCallback;
+ private Interop.AppCommon.AppEventCallback _localeChangedCallback;
+ private Interop.AppCommon.AppEventCallback _regionChangedCallback;
+
+ private IntPtr _lowMemoryEventHandle = IntPtr.Zero;
+ private IntPtr _lowBatteryEventHandle = IntPtr.Zero;
+ private IntPtr _localeChangedEventHandle = IntPtr.Zero;
+ private IntPtr _regionChangedEventHandle = IntPtr.Zero;
+
+ public DefaultCoreBackend()
+ {
+ _lowMemoryCallback = new Interop.AppCommon.AppEventCallback(OnLowMemoryNative);
+ _lowBatteryCallback = new Interop.AppCommon.AppEventCallback(OnLowBatteryNative);
+ _localeChangedCallback = new Interop.AppCommon.AppEventCallback(OnLocaleChangedNative);
+ _regionChangedCallback = new Interop.AppCommon.AppEventCallback(OnRegionChangedNative);
+ }
+
+ ~DefaultCoreBackend()
+ {
+ Dispose(false);
+ }
+
+ public void AddEventHandler(EventType evType, Action handler)
+ {
+ _handlers.Add(evType, handler);
+ }
+
+ public void AddEventHandler<TEventArgs>(EventType evType, Action<TEventArgs> handler) where TEventArgs : EventArgs
+ {
+ _handlers.Add(evType, handler);
+ }
+
+ public virtual void Run(string[] args)
+ {
+ TizenSynchronizationContext.Initialize();
+
+ ErrorCode err = ErrorCode.None;
+ err = AddAppEventCallback(out _lowMemoryEventHandle, Interop.AppCommon.AppEventType.LowMemory, _lowMemoryCallback);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to add event handler for LowMemory event. Err = " + err);
+ }
+ err = AddAppEventCallback(out _lowBatteryEventHandle, Interop.AppCommon.AppEventType.LowBattery, _lowBatteryCallback);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to add event handler for LowBattery event. Err = " + err);
+ }
+
+ err = AddAppEventCallback(out _localeChangedEventHandle, Interop.AppCommon.AppEventType.LanguageChanged, _localeChangedCallback);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to add event handler for LocaleChanged event. Err = " + err);
+ }
+
+ err = AddAppEventCallback(out _regionChangedEventHandle, Interop.AppCommon.AppEventType.RegionFormatChanged, _regionChangedCallback);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to add event handler for RegionFormatChanged event. Err = " + err);
+ }
+ }
+
+ public abstract void Exit();
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposedValue)
+ {
+ if (disposing)
+ {
+ // Release disposable objects
+ }
+
+ if (_lowMemoryEventHandle != IntPtr.Zero)
+ {
+ RemoveAppEventCallback(_lowMemoryEventHandle);
+ }
+ if (_lowBatteryEventHandle != IntPtr.Zero)
+ {
+ RemoveAppEventCallback(_lowBatteryEventHandle);
+ }
+ if (_localeChangedEventHandle != IntPtr.Zero)
+ {
+ RemoveAppEventCallback(_localeChangedEventHandle);
+ }
+ if (_regionChangedEventHandle != IntPtr.Zero)
+ {
+ RemoveAppEventCallback(_regionChangedEventHandle);
+ }
+
+ _disposedValue = true;
+ }
+ }
+
+ internal abstract ErrorCode AddAppEventCallback(out IntPtr handle, Interop.AppCommon.AppEventType type, Interop.AppCommon.AppEventCallback callback);
+
+ internal abstract void RemoveAppEventCallback(IntPtr handle);
+
+ private void OnLowMemoryNative(IntPtr infoHandle, IntPtr data)
+ {
+ LowMemoryStatus status = LowMemoryStatus.None;
+ ErrorCode err = Interop.AppCommon.AppEventGetLowMemoryStatus(infoHandle, out status);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to get memory status. Err = " + err);
+ }
+ if (_handlers.ContainsKey(EventType.LowMemory))
+ {
+ var handler = _handlers[EventType.LowMemory] as Action<LowMemoryEventArgs>;
+ handler?.Invoke(new LowMemoryEventArgs(status));
+ }
+ }
+
+ private void OnLowBatteryNative(IntPtr infoHandle, IntPtr data)
+ {
+ LowBatteryStatus status = LowBatteryStatus.None;
+ ErrorCode err = Interop.AppCommon.AppEventGetLowBatteryStatus(infoHandle, out status);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to get battery status. Err = " + err);
+ }
+ if (_handlers.ContainsKey(EventType.LowBattery))
+ {
+ var handler = _handlers[EventType.LowBattery] as Action<LowBatteryEventArgs>;
+ handler?.Invoke(new LowBatteryEventArgs(status));
+ }
+ }
+
+ private void OnLocaleChangedNative(IntPtr infoHandle, IntPtr data)
+ {
+ string lang;
+ ErrorCode err = Interop.AppCommon.AppEventGetLanguage(infoHandle, out lang);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to get changed language. Err = " + err);
+ }
+ if (_handlers.ContainsKey(EventType.LocaleChanged))
+ {
+ var handler = _handlers[EventType.LocaleChanged] as Action<LocaleChangedEventArgs>;
+ handler?.Invoke(new LocaleChangedEventArgs(lang));
+ }
+ }
+
+ private void OnRegionChangedNative(IntPtr infoHandle, IntPtr data)
+ {
+ string region;
+ ErrorCode err = Interop.AppCommon.AppEventGetRegionFormat(infoHandle, out region);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to get changed region format. Err = " + err);
+ }
+ if (_handlers.ContainsKey(EventType.RegionFormatChanged))
+ {
+ var handler = _handlers[EventType.RegionFormatChanged] as Action<RegionFormatChangedEventArgs>;
+ handler?.Invoke(new RegionFormatChangedEventArgs(region));
+ }
+ }
+ }
+}
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+namespace Tizen.Applications.CoreBackend
+{
+ /// <summary>
+ /// Class that represents the type of event for backends. This class can be converted from string type.
+ /// </summary>
+ public class EventType
+ {
+ /// <summary>
+ /// Pre-defined event type. "PreCreated"
+ /// </summary>
+ public static readonly EventType PreCreated = "PreCreated";
+
+ /// <summary>
+ /// Pre-defined event type. "Created"
+ /// </summary>
+ public static readonly EventType Created = "Created";
+
+ /// <summary>
+ /// Pre-defined event type. "Terminated"
+ /// </summary>
+ public static readonly EventType Terminated = "Terminated";
+
+ /// <summary>
+ /// Pre-defined event type. "AppControlReceived"
+ /// </summary>
+ public static readonly EventType AppControlReceived = "AppControlReceived";
+
+ /// <summary>
+ /// Pre-defined event type. "Resumed"
+ /// </summary>
+ public static readonly EventType Resumed = "Resumed";
+
+ /// <summary>
+ /// Pre-defined event type. "Paused"
+ /// </summary>
+ public static readonly EventType Paused = "Paused";
+
+ /// <summary>
+ /// Pre-defined event type. "LowMemory"
+ /// </summary>
+ public static readonly EventType LowMemory = "LowMemory";
+
+ /// <summary>
+ /// Pre-defined event type. "LowBattery"
+ /// </summary>
+ public static readonly EventType LowBattery = "LowBattery";
+
+ /// <summary>
+ /// Pre-defined event type. "LocaleChanged"
+ /// </summary>
+ public static readonly EventType LocaleChanged = "LocaleChanged";
+
+ /// <summary>
+ /// Pre-defined event type. "RegionFormatChanged"
+ /// </summary>
+ public static readonly EventType RegionFormatChanged = "RegionFormatChanged";
+
+ private string _typeName;
+
+ /// <summary>
+ /// Initializes the EventType class.
+ /// </summary>
+ /// <param name="name">The name of event type.</param>
+ public EventType(string name)
+ {
+ _typeName = name;
+ }
+
+ /// <summary>
+ /// Returns the name of event type.
+ /// </summary>
+ public override string ToString()
+ {
+ return _typeName;
+ }
+
+ /// <summary>
+ /// Returns the hash code for event type string.
+ /// </summary>
+ public override int GetHashCode()
+ {
+ return _typeName.GetHashCode();
+ }
+
+ /// <summary>
+ /// Determines whether this instance and a specified object.
+ /// </summary>
+ public override bool Equals(object obj)
+ {
+ return _typeName.Equals(obj);
+ }
+
+ /// <summary>
+ /// Determines whether this instance and a specified object.
+ /// </summary>
+ public bool Equals(EventType obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ return _typeName.Equals(obj._typeName);
+ }
+
+ /// <summary>
+ /// Converts a string to EventType instance.
+ /// </summary>
+ public static implicit operator EventType(string value)
+ {
+ return new EventType(value);
+ }
+ }
+}
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+
+namespace Tizen.Applications.CoreBackend
+{
+ /// <summary>
+ /// Interface that represents the backend lifecycles.
+ /// </summary>
+ public interface ICoreBackend : IDisposable
+ {
+ /// <summary>
+ /// Adds an event handler.
+ /// </summary>
+ /// <param name="evType">The type of event.</param>
+ /// <param name="handler">The handler method without arguments.</param>
+ void AddEventHandler(EventType evType, Action handler);
+
+ /// <summary>
+ /// Adds an event handler.
+ /// </summary>
+ /// <typeparam name="TEventArgs">The EventArgs type used in arguments of the handler method.</typeparam>
+ /// <param name="evType">The type of event.</param>
+ /// <param name="handler">The handler method with a TEventArgs type argument.</param>
+ void AddEventHandler<TEventArgs>(EventType evType, Action<TEventArgs> handler) where TEventArgs : EventArgs;
+
+ /// <summary>
+ /// Runs the mainloop of backend.
+ /// </summary>
+ /// <param name="args"></param>
+ void Run(string[] args);
+
+ /// <summary>
+ /// Exits the mainloop of backend.
+ /// </summary>
+ void Exit();
+ }
+}
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+
+using Tizen.Internals.Errors;
+
+namespace Tizen.Applications.CoreBackend
+{
+ internal class ServiceCoreBackend : DefaultCoreBackend
+ {
+ private Interop.Service.ServiceAppLifecycleCallbacks _callbacks;
+
+ public ServiceCoreBackend()
+ {
+ _callbacks.OnCreate = new Interop.Service.ServiceAppCreateCallback(OnCreateNative);
+ _callbacks.OnTerminate = new Interop.Service.ServiceAppTerminateCallback(OnTerminateNative);
+ _callbacks.OnAppControl = new Interop.Service.ServiceAppControlCallback(OnAppControlNative);
+ }
+
+ public override void Exit()
+ {
+ Interop.Service.Exit();
+ }
+
+ public override void Run(string[] args)
+ {
+ base.Run(args);
+
+ ErrorCode err = Interop.Service.Main(args.Length, args, ref _callbacks, IntPtr.Zero);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to run the application. Err = " + err);
+ }
+ }
+
+ private bool OnCreateNative(IntPtr data)
+ {
+ if (_handlers.ContainsKey(EventType.Created))
+ {
+ var handler = _handlers[EventType.Created] as Action;
+ handler?.Invoke();
+ }
+ return true;
+ }
+
+ private void OnTerminateNative(IntPtr data)
+ {
+ if (_handlers.ContainsKey(EventType.Terminated))
+ {
+ var handler = _handlers[EventType.Terminated] as Action;
+ handler?.Invoke();
+ }
+ }
+
+ private void OnAppControlNative(IntPtr appControlHandle, IntPtr data)
+ {
+ if (_handlers.ContainsKey(EventType.AppControlReceived))
+ {
+ var handler = _handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
+ handler.Invoke(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) });
+ }
+ }
+
+ internal override ErrorCode AddAppEventCallback(out IntPtr handle, Interop.AppCommon.AppEventType type, Interop.AppCommon.AppEventCallback callback)
+ {
+ return Interop.Service.AddEventHandler(out handle, type, callback, IntPtr.Zero);
+ }
+
+ internal override void RemoveAppEventCallback(IntPtr handle)
+ {
+ Interop.Service.RemoveEventHandler(handle);
+ }
+ }
+}
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+
+using Tizen.Internals.Errors;
+
+namespace Tizen.Applications.CoreBackend
+{
+ internal class UICoreBackend : DefaultCoreBackend
+ {
+ private Interop.Application.UIAppLifecycleCallbacks _callbacks;
+
+ public UICoreBackend()
+ {
+ _callbacks.OnCreate = new Interop.Application.AppCreateCallback(OnCreateNative);
+ _callbacks.OnTerminate = new Interop.Application.AppTerminateCallback(OnTerminateNative);
+ _callbacks.OnAppControl = new Interop.Application.AppControlCallback(OnAppControlNative);
+ _callbacks.OnResume = new Interop.Application.AppResumeCallback(OnResumeNative);
+ _callbacks.OnPause = new Interop.Application.AppPauseCallback(OnPauseNative);
+ }
+
+ public override void Exit()
+ {
+ Interop.Application.Exit();
+ }
+
+ public override void Run(string[] args)
+ {
+ base.Run(args);
+
+ ErrorCode err = Interop.Application.Main(args.Length, args, ref _callbacks, IntPtr.Zero);
+ if (err != ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to run the application. Err = " + err);
+ }
+ }
+
+ private bool OnCreateNative(IntPtr data)
+ {
+ if (_handlers.ContainsKey(EventType.PreCreated))
+ {
+ var handler = _handlers[EventType.PreCreated] as Action;
+ handler?.Invoke();
+ }
+
+ if (_handlers.ContainsKey(EventType.Created))
+ {
+ var handler = _handlers[EventType.Created] as Action;
+ handler?.Invoke();
+ }
+ return true;
+ }
+
+ private void OnTerminateNative(IntPtr data)
+ {
+ if (_handlers.ContainsKey(EventType.Terminated))
+ {
+ var handler = _handlers[EventType.Terminated] as Action;
+ handler?.Invoke();
+ }
+ }
+
+ private void OnAppControlNative(IntPtr appControlHandle, IntPtr data)
+ {
+ if (_handlers.ContainsKey(EventType.AppControlReceived))
+ {
+ var handler = _handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
+ handler.Invoke(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) });
+ }
+ }
+
+ private void OnResumeNative(IntPtr data)
+ {
+ if (_handlers.ContainsKey(EventType.Resumed))
+ {
+ var handler = _handlers[EventType.Resumed] as Action;
+ handler?.Invoke();
+ }
+ }
+
+ private void OnPauseNative(IntPtr data)
+ {
+ if (_handlers.ContainsKey(EventType.Paused))
+ {
+ var handler = _handlers[EventType.Paused] as Action;
+ handler?.Invoke();
+ }
+ }
+
+ internal override ErrorCode AddAppEventCallback(out IntPtr handle, Interop.AppCommon.AppEventType type, Interop.AppCommon.AppEventCallback callback)
+ {
+ return Interop.Application.AddEventHandler(out handle, type, callback, IntPtr.Zero);
+ }
+
+ internal override void RemoveAppEventCallback(IntPtr handle)
+ {
+ Interop.Application.RemoveEventHandler(handle);
+ }
+ }
+}
<Compile Include="Interop\Interop.PackageManager.cs" />
<Compile Include="Interop\Interop.Service.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Tizen.Applications.CoreBackend\EventType.cs" />
+ <Compile Include="Tizen.Applications.CoreBackend\DefaultCoreBackend.cs" />
+ <Compile Include="Tizen.Applications.CoreBackend\ICoreBackend.cs" />
+ <Compile Include="Tizen.Applications.CoreBackend\ServiceCoreBackend.cs" />
+ <Compile Include="Tizen.Applications.CoreBackend\UICoreBackend.cs" />
<Compile Include="Tizen.Applications\ApplicationInfoMetadataFilter.cs" />
<Compile Include="Tizen.Applications.Messages\MessagePort.cs" />
<Compile Include="Tizen.Applications.Messages\MessagePortErrorFactory.cs" />
<Compile Include="Tizen.Applications\ApplicationTerminatedEventArgs.cs" />
<Compile Include="Tizen.Applications\ApplicationType.cs" />
<Compile Include="Tizen.Applications\CertificateType.cs" />
+ <Compile Include="Tizen.Applications\CoreApplication.cs" />
+ <Compile Include="Tizen.Applications\CoreUIApplication.cs" />
<Compile Include="Tizen.Applications\DirectoryInfo.cs" />
<Compile Include="Tizen.Applications\PackageEventState.cs" />
<Compile Include="Tizen.Applications\LocaleChangedEventArgs.cs" />
<Compile Include="Tizen.Applications\NotificationManager.cs" />
<Compile Include="Tizen.Applications\ProgressNotification.cs" />
<Compile Include="Tizen.Applications\TizenSynchronizationContext.cs" />
- <Compile Include="Tizen.Applications\UIApplicationBase.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Tizen.Applications.snk" />
<Name>Tizen.UI</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <WCFMetadata Include="Service References\" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
using System;
-using Tizen.Internals.Errors;
-
namespace Tizen.Applications
{
/// <summary>
- /// The Application handles an application state change or system events and provides mechanisms that launch other applications.
+ /// Class that represents a Tizen application.
/// </summary>
public abstract class Application : IDisposable
{
private object _lock = new object();
- private Interop.AppCommon.AppEventCallback _lowMemoryCallback;
- private Interop.AppCommon.AppEventCallback _lowBatteryCallback;
- private Interop.AppCommon.AppEventCallback _localeChangedCallback;
- private Interop.AppCommon.AppEventCallback _regionChangedCallback;
-
- private IntPtr _lowMemoryEventHandle = IntPtr.Zero;
- private IntPtr _lowBatteryEventHandle = IntPtr.Zero;
- private IntPtr _localeChangedEventHandle = IntPtr.Zero;
- private IntPtr _regionChangedEventHandle = IntPtr.Zero;
-
private DirectoryInfo _directoryInfo;
private ApplicationInfo _applicationInfo;
/// <summary>
- /// Initializes the Application class.
- /// </summary>
- public Application()
- {
- _lowMemoryCallback = new Interop.AppCommon.AppEventCallback(OnLowMemoryNative);
- _lowBatteryCallback = new Interop.AppCommon.AppEventCallback(OnLowBatteryNative);
- _localeChangedCallback = new Interop.AppCommon.AppEventCallback(OnLocaleChangedNative);
- _regionChangedCallback = new Interop.AppCommon.AppEventCallback(OnRegionChangedNative);
- }
-
- /// <summary>
- /// Occurs when the application is launched.
- /// </summary>
- public event EventHandler Created;
-
- /// <summary>
- /// Occurs when the application is about to shutdown.
- /// </summary>
- public event EventHandler Terminated;
-
- /// <summary>
- /// Occurs whenever the application receives the appcontrol message.
- /// </summary>
- public event EventHandler<AppControlReceivedEventArgs> AppControlReceived;
-
- /// <summary>
- /// Occurs when the system memory is low.
- /// </summary>
- public event EventHandler<LowMemoryEventArgs> LowMemory;
-
- /// <summary>
- /// Occurs when the system battery is low.
- /// </summary>
- public event EventHandler<LowBatteryEventArgs> LowBattery;
-
- /// <summary>
- /// Occurs when the system language is chagned.
- /// </summary>
- public event EventHandler<LocaleChangedEventArgs> LocaleChanged;
-
- /// <summary>
- /// Occurs when the region format is changed.
- /// </summary>
- public event EventHandler<RegionFormatChangedEventArgs> RegionFormatChanged;
-
- /// <summary>
/// Gets the instance of current application.
/// </summary>
public static Application Current { get { return s_CurrentApplication; } }
{
throw new ArgumentNullException("args");
}
-
- TizenSynchronizationContext.Initialize();
-
s_CurrentApplication = this;
-
- ErrorCode err = ErrorCode.None;
- err = AddEventHandler(out _lowMemoryEventHandle, Interop.AppCommon.AppEventType.LowMemory, _lowMemoryCallback);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to add event handler for LowMemory event. Err = " + err);
- }
-
- err = AddEventHandler(out _lowBatteryEventHandle, Interop.AppCommon.AppEventType.LowBattery, _lowBatteryCallback);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to add event handler for LowBattery event. Err = " + err);
- }
-
- err = AddEventHandler(out _localeChangedEventHandle, Interop.AppCommon.AppEventType.LanguageChanged, _localeChangedCallback);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to add event handler for LocaleChanged event. Err = " + err);
- }
-
- err = AddEventHandler(out _regionChangedEventHandle, Interop.AppCommon.AppEventType.RegionFormatChanged, _regionChangedCallback);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to add event handler for RegionFormatChanged event. Err = " + err);
- }
}
/// <summary>
/// </summary>
public abstract void Exit();
- /// <summary>
- /// Overrides this method if want to handle behavior when the application is launched.
- /// If base.OnCreated() is not called, the event 'Created' will not be emitted.
- /// </summary>
- protected virtual void OnCreate()
- {
- Created?.Invoke(this, EventArgs.Empty);
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior when the application is terminated.
- /// If base.OnTerminate() is not called, the event 'Terminated' will not be emitted.
- /// </summary>
- protected virtual void OnTerminate()
- {
- Terminated?.Invoke(this, EventArgs.Empty);
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior when the application receives the appcontrol message.
- /// If base.OnAppControlReceived() is not called, the event 'AppControlReceived' will not be emitted.
- /// </summary>
- /// <param name="e"></param>
- protected virtual void OnAppControlReceived(AppControlReceivedEventArgs e)
- {
- AppControlReceived?.Invoke(this, e);
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior when the system memory is low.
- /// If base.OnLowMemory() is not called, the event 'LowMemory' will not be emitted.
- /// </summary>
- protected virtual void OnLowMemory(LowMemoryEventArgs e)
- {
- LowMemory?.Invoke(this, e);
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior when the system battery is low.
- /// If base.OnLowBattery() is not called, the event 'LowBattery' will not be emitted.
- /// </summary>
- protected virtual void OnLowBattery(LowBatteryEventArgs e)
- {
- LowBattery?.Invoke(this, e);
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior when the system language is changed.
- /// If base.OnLocaleChanged() is not called, the event 'LocaleChanged' will not be emitted.
- /// </summary>
- protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
- {
- LocaleChanged?.Invoke(this, e);
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior when the region format is changed.
- /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted.
- /// </summary>
- protected virtual void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
- {
- RegionFormatChanged?.Invoke(this, e);
- }
-
- internal virtual ErrorCode AddEventHandler(out IntPtr handle, Interop.AppCommon.AppEventType type, Interop.AppCommon.AppEventCallback callback)
- {
- handle = IntPtr.Zero;
- return ErrorCode.None;
- }
-
- internal virtual void RemoveEventHandler(IntPtr handle)
- {
- }
-
- private void OnLowMemoryNative(IntPtr infoHandle, IntPtr data)
- {
- LowMemoryStatus status = LowMemoryStatus.None;
- ErrorCode err = Interop.AppCommon.AppEventGetLowMemoryStatus(infoHandle, out status);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to get memory status. Err = " + err);
- }
- OnLowMemory(new LowMemoryEventArgs(status));
- }
-
- private void OnLowBatteryNative(IntPtr infoHandle, IntPtr data)
- {
- LowBatteryStatus status = LowBatteryStatus.None;
- ErrorCode err = Interop.AppCommon.AppEventGetLowBatteryStatus(infoHandle, out status);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to get battery status. Err = " + err);
- }
- OnLowBattery(new LowBatteryEventArgs(status));
- }
-
- private void OnLocaleChangedNative(IntPtr infoHandle, IntPtr data)
- {
- string lang;
- ErrorCode err = Interop.AppCommon.AppEventGetLanguage(infoHandle, out lang);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to get changed language. Err = " + err);
- }
- OnLocaleChanged(new LocaleChangedEventArgs(lang));
- }
-
- private void OnRegionChangedNative(IntPtr infoHandle, IntPtr data)
- {
- string region;
- ErrorCode err = Interop.AppCommon.AppEventGetRegionFormat(infoHandle, out region);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to get changed region format. Err = " + err);
- }
- OnRegionFormatChanged(new RegionFormatChangedEventArgs(region));
- }
-
#region IDisposable Support
- private bool disposedValue = false; // To detect redundant calls
+ private bool _disposedValue = false; // To detect redundant calls
/// <summary>
/// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
/// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
- if (!disposedValue)
+ if (!_disposedValue)
{
if (disposing)
{
}
}
- if (_lowMemoryEventHandle != IntPtr.Zero)
- {
- RemoveEventHandler(_lowMemoryEventHandle);
- }
- if (_lowBatteryEventHandle != IntPtr.Zero)
- {
- RemoveEventHandler(_lowBatteryEventHandle);
- }
- if (_localeChangedEventHandle != IntPtr.Zero)
- {
- RemoveEventHandler(_localeChangedEventHandle);
- }
- if (_regionChangedEventHandle != IntPtr.Zero)
- {
- RemoveEventHandler(_regionChangedEventHandle);
- }
-
- disposedValue = true;
+ _disposedValue = true;
}
}
using System;
using System.Collections.Generic;
-using System.Runtime.InteropServices;
namespace Tizen.Applications
{
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+
+using Tizen.Applications.CoreBackend;
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// Class that represents an application controlled lifecycles by the backend system.
+ /// </summary>
+ public class CoreApplication : Application
+ {
+ private readonly ICoreBackend _backend;
+ private bool _disposedValue = false;
+
+ /// <summary>
+ /// Initializes the CoreApplication class.
+ /// </summary>
+ /// <param name="backend">The backend instance implementing ICoreBacked interface.</param>
+ public CoreApplication(ICoreBackend backend)
+ {
+ _backend = backend;
+ }
+
+ /// <summary>
+ /// Occurs when the application is launched.
+ /// </summary>
+ public event EventHandler Created;
+
+ /// <summary>
+ /// Occurs when the application is about to shutdown.
+ /// </summary>
+ public event EventHandler Terminated;
+
+ /// <summary>
+ /// Occurs whenever the application receives the appcontrol message.
+ /// </summary>
+ public event EventHandler<AppControlReceivedEventArgs> AppControlReceived;
+
+ /// <summary>
+ /// Occurs when the system memory is low.
+ /// </summary>
+ public event EventHandler<LowMemoryEventArgs> LowMemory;
+
+ /// <summary>
+ /// Occurs when the system battery is low.
+ /// </summary>
+ public event EventHandler<LowBatteryEventArgs> LowBattery;
+
+ /// <summary>
+ /// Occurs when the system language is chagned.
+ /// </summary>
+ public event EventHandler<LocaleChangedEventArgs> LocaleChanged;
+
+ /// <summary>
+ /// Occurs when the region format is changed.
+ /// </summary>
+ public event EventHandler<RegionFormatChangedEventArgs> RegionFormatChanged;
+
+ /// <summary>
+ /// The backend instance.
+ /// </summary>
+ protected ICoreBackend Backend { get; private set; }
+
+ /// <summary>
+ /// Runs the application's main loop.
+ /// </summary>
+ /// <param name="args">Arguments from commandline.</param>
+ public override void Run(string[] args)
+ {
+ base.Run(args);
+
+ _backend.AddEventHandler(EventType.Created, OnCreate);
+ _backend.AddEventHandler(EventType.Terminated, OnTerminate);
+ _backend.AddEventHandler<AppControlReceivedEventArgs>(EventType.AppControlReceived, OnAppControlReceived);
+ _backend.AddEventHandler<LowMemoryEventArgs>(EventType.LowMemory, OnLowMemory);
+ _backend.AddEventHandler<LowBatteryEventArgs>(EventType.LowBattery, OnLowBattery);
+ _backend.AddEventHandler<LocaleChangedEventArgs>(EventType.LocaleChanged, OnLocaleChanged);
+ _backend.AddEventHandler<RegionFormatChangedEventArgs>(EventType.RegionFormatChanged, OnRegionFormatChanged);
+
+ _backend.Run(args);
+ }
+
+ /// <summary>
+ /// Exits the main loop of the application.
+ /// </summary>
+ public override void Exit()
+ {
+ _backend.Exit();
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the application is launched.
+ /// If base.OnCreated() is not called, the event 'Created' will not be emitted.
+ /// </summary>
+ protected virtual void OnCreate()
+ {
+ Created?.Invoke(this, EventArgs.Empty);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the application is terminated.
+ /// If base.OnTerminate() is not called, the event 'Terminated' will not be emitted.
+ /// </summary>
+ protected virtual void OnTerminate()
+ {
+ Terminated?.Invoke(this, EventArgs.Empty);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the application receives the appcontrol message.
+ /// If base.OnAppControlReceived() is not called, the event 'AppControlReceived' will not be emitted.
+ /// </summary>
+ /// <param name="e"></param>
+ protected virtual void OnAppControlReceived(AppControlReceivedEventArgs e)
+ {
+ AppControlReceived?.Invoke(this, e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the system memory is low.
+ /// If base.OnLowMemory() is not called, the event 'LowMemory' will not be emitted.
+ /// </summary>
+ protected virtual void OnLowMemory(LowMemoryEventArgs e)
+ {
+ LowMemory?.Invoke(this, e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the system battery is low.
+ /// If base.OnLowBattery() is not called, the event 'LowBattery' will not be emitted.
+ /// </summary>
+ protected virtual void OnLowBattery(LowBatteryEventArgs e)
+ {
+ LowBattery?.Invoke(this, e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the system language is changed.
+ /// If base.OnLocaleChanged() is not called, the event 'LocaleChanged' will not be emitted.
+ /// </summary>
+ protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
+ {
+ LocaleChanged?.Invoke(this, e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the region format is changed.
+ /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted.
+ /// </summary>
+ protected virtual void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
+ {
+ RegionFormatChanged?.Invoke(this, e);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (!_disposedValue)
+ {
+ if (disposing)
+ {
+ _backend.Dispose();
+ }
+
+ _disposedValue = true;
+ }
+ base.Dispose(disposing);
+ }
+ }
+}
--- /dev/null
+// Copyright 2016 by Samsung Electronics, Inc.,
+//
+// This software is the confidential and proprietary information
+// of Samsung Electronics, Inc. ("Confidential Information"). You
+// shall not disclose such Confidential Information and shall use
+// it only in accordance with the terms of the license agreement
+// you entered into with Samsung.
+
+using System;
+
+using Tizen.Applications.CoreBackend;
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// Represents an application that have UI screen. The events for resuming and pausing are provided.
+ /// </summary>
+ public class CoreUIApplication : CoreApplication
+ {
+ /// <summary>
+ /// Initializes the CoreUIApplication class.
+ /// </summary>
+ /// <remarks>
+ /// Default backend for UI application will be used.
+ /// </remarks>
+ public CoreUIApplication() : base(new UICoreBackend())
+ {
+ }
+
+ /// <summary>
+ /// Initializes the CoreUIApplication class.
+ /// </summary>
+ /// <remarks>
+ /// If want to change the backend, use this constructor.
+ /// </remarks>
+ /// <param name="backend">The backend instance implementing ICoreBacked interface.</param>
+ public CoreUIApplication(ICoreBackend backend) : base(backend)
+ {
+ }
+
+ /// <summary>
+ /// Occurs whenever the application is resumed.
+ /// </summary>
+ public event EventHandler Resumed;
+
+ /// <summary>
+ /// Occurs whenever the application is paused.
+ /// </summary>
+ public event EventHandler Paused;
+
+ /// <summary>
+ /// Runs the UI application's main loop.
+ /// </summary>
+ /// <param name="args">Arguments from commandline.</param>
+ public override void Run(string[] args)
+ {
+ Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
+ Backend.AddEventHandler(EventType.Resumed, OnResume);
+ Backend.AddEventHandler(EventType.Paused, OnPause);
+ base.Run(args);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior before calling OnCreate().
+ /// </summary>
+ protected virtual void OnPreCreate()
+ {
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the application is resumed.
+ /// If base.OnResume() is not called, the event 'Resumed' will not be emitted.
+ /// </summary>
+ protected virtual void OnResume()
+ {
+ Resumed?.Invoke(this, EventArgs.Empty);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior when the application is paused.
+ /// If base.OnPause() is not called, the event 'Paused' will not be emitted.
+ /// </summary>
+ protected virtual void OnPause()
+ {
+ Paused?.Invoke(this, EventArgs.Empty);
+ }
+ }
+}
// it only in accordance with the terms of the license agreement
// you entered into with Samsung.
+using System;
+
namespace Tizen.Applications
{
/// <summary>
///
/// </summary>
- public class LowBatteryEventArgs
+ public class LowBatteryEventArgs : EventArgs
{
/// <summary>
///
// it only in accordance with the terms of the license agreement
// you entered into with Samsung.
-using System;
-
-using Tizen.Internals.Errors;
+using Tizen.Applications.CoreBackend;
namespace Tizen.Applications
{
/// <summary>
/// Represents a service application.
/// </summary>
- public class ServiceApplication : Application
+ public class ServiceApplication : CoreApplication
{
- private Interop.Service.ServiceAppLifecycleCallbacks _callbacks;
-
/// <summary>
/// Initializes ServiceApplication class.
/// </summary>
- public ServiceApplication()
+ public ServiceApplication() : base(new ServiceCoreBackend())
{
- _callbacks.OnCreate = new Interop.Service.ServiceAppCreateCallback(OnCreateNative);
- _callbacks.OnTerminate = new Interop.Service.ServiceAppTerminateCallback(OnTerminateNative);
- _callbacks.OnAppControl = new Interop.Service.ServiceAppControlCallback(OnAppControlNative);
}
/// <summary>
public override void Run(string[] args)
{
base.Run(args);
-
- ErrorCode err = Interop.Service.Main(args.Length, args, ref _callbacks, IntPtr.Zero);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to run the service. Err = " + err);
- }
- }
-
- /// <summary>
- /// Exits the main loop of the service application.
- /// </summary>
- public override void Exit()
- {
- Interop.Service.Exit();
- }
-
- internal override ErrorCode AddEventHandler(out IntPtr handle, Interop.AppCommon.AppEventType type, Interop.AppCommon.AppEventCallback callback)
- {
- return Interop.Service.AddEventHandler(out handle, type, callback, IntPtr.Zero);
- }
-
- internal override void RemoveEventHandler(IntPtr handle)
- {
- Interop.Service.RemoveEventHandler(handle);
- }
-
- private bool OnCreateNative(IntPtr data)
- {
- OnCreate();
- return true;
- }
-
- private void OnTerminateNative(IntPtr data)
- {
- OnTerminate();
- }
-
- private void OnAppControlNative(IntPtr appControlHandle, IntPtr data)
- {
- OnAppControlReceived(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) });
}
}
}
/// <summary>
/// Represents an application that have UI screen. The UIApplication class has a default main window.
/// </summary>
- public class UIApplication : UIApplicationBase
+ public class UIApplication : CoreUIApplication
{
/// <summary>
/// The main window instance of the UIApplication.
+++ /dev/null
-// Copyright 2016 by Samsung Electronics, Inc.,
-//
-// This software is the confidential and proprietary information
-// of Samsung Electronics, Inc. ("Confidential Information"). You
-// shall not disclose such Confidential Information and shall use
-// it only in accordance with the terms of the license agreement
-// you entered into with Samsung.
-
-using System;
-using Tizen.Internals.Errors;
-
-namespace Tizen.Applications
-{
- /// <summary>
- /// Represents an application that have UI screen. It has additional events for handling 'Resumed' and 'Paused' states.
- /// </summary>
- public class UIApplicationBase : Application
- {
- private Interop.Application.UIAppLifecycleCallbacks _callbacks;
-
- /// <summary>
- /// Initializes UIApplicationBase class.
- /// </summary>
- public UIApplicationBase()
- {
- _callbacks.OnCreate = new Interop.Application.AppCreateCallback(OnCreateNative);
- _callbacks.OnTerminate = new Interop.Application.AppTerminateCallback(OnTerminateNative);
- _callbacks.OnAppControl = new Interop.Application.AppControlCallback(OnAppControlNative);
- _callbacks.OnResume = new Interop.Application.AppResumeCallback(OnResumeNative);
- _callbacks.OnPause = new Interop.Application.AppPauseCallback(OnPauseNative);
- }
-
- /// <summary>
- /// Occurs whenever the application is resumed.
- /// </summary>
- public event EventHandler Resumed;
-
- /// <summary>
- /// Occurs whenever the application is paused.
- /// </summary>
- public event EventHandler Paused;
-
- /// <summary>
- /// Runs the UI application's main loop.
- /// </summary>
- /// <param name="args">Arguments from commandline.</param>
- public override void Run(string[] args)
- {
- base.Run(args);
-
- ErrorCode err = Interop.Application.Main(args.Length, args, ref _callbacks, IntPtr.Zero);
- if (err != ErrorCode.None)
- {
- Log.Error(LogTag, "Failed to run the application. Err = " + err);
- }
- }
-
- /// <summary>
- /// Exits the main loop of the UI application.
- /// </summary>
- public override void Exit()
- {
- Interop.Application.Exit();
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior before calling OnCreate().
- /// </summary>
- protected virtual void OnPreCreate()
- {
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior when the application is resumed.
- /// If base.OnResume() is not called, the event 'Resumed' will not be emitted.
- /// </summary>
- protected virtual void OnResume()
- {
- Resumed?.Invoke(this, EventArgs.Empty);
- }
-
- /// <summary>
- /// Overrides this method if want to handle behavior when the application is paused.
- /// If base.OnPause() is not called, the event 'Paused' will not be emitted.
- /// </summary>
- protected virtual void OnPause()
- {
- Paused?.Invoke(this, EventArgs.Empty);
- }
-
- internal override ErrorCode AddEventHandler(out IntPtr handle, Interop.AppCommon.AppEventType type, Interop.AppCommon.AppEventCallback callback)
- {
- return Interop.Application.AddEventHandler(out handle, type, callback, IntPtr.Zero);
- }
-
- internal override void RemoveEventHandler(IntPtr handle)
- {
- Interop.Application.RemoveEventHandler(handle);
- }
-
- private bool OnCreateNative(IntPtr data)
- {
- OnPreCreate();
- OnCreate();
- return true;
- }
-
- private void OnTerminateNative(IntPtr data)
- {
- OnTerminate();
- }
-
- private void OnAppControlNative(IntPtr appControlHandle, IntPtr data)
- {
- OnAppControlReceived(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) });
- }
-
- private void OnResumeNative(IntPtr data)
- {
- OnResume();
- }
-
- private void OnPauseNative(IntPtr data)
- {
- OnPause();
- }
- }
-}