<Compile Include="Tizen.Application\ApplicationContext.cs" />
<Compile Include="Tizen.Application\CodeExample.cs" />
<Compile Include="Tizen.Application\Page.cs" />
+ <Compile Include="Tizen.Application\Service.cs" />
+ <Compile Include="Tizen.Application\ServiceManager.cs" />
<Compile Include="Tizen.Application\Window.cs" />
<Compile Include="Tizen.Application\TizenSynchronizationContext.cs" />
</ItemGroup>
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project>
\ No newline at end of file
_context.StartActor(actor, appControl);
}
+ protected void StartService(Type serviceType, AppControl appControl)
+ {
+ Application.StartService(serviceType, appControl);
+ }
+ protected void StopService(Type serviceType)
+ {
+ Application.StopService(serviceType);
+ }
+
public void Finish()
{
throw new NotImplementedException();
Interop.AppControl.GetUri(handle, out _uri);
}
+ internal bool isService
+ {
+ get {return false;}
+ }
+
public AppControl(string operation, string mime, string uri)
{
_operation = operation;
private static Dictionary<AppControlFilter, Type> _filterMap = new Dictionary<AppControlFilter, Type>();
private static List<ApplicationContext> _contextList = new List<ApplicationContext>();
private static Window _window = null;
+ private static ServiceManager _serviceManager = new ServiceManager();
public static event EventHandler ApplicationInit;
public static event EventHandler ApplicationExit;
ops.OnCreate = (userData) =>
{
ApplicationInit(null, null);
- if (_window == null)
- _window = new Window();
return true;
};
ops.OnPause = (userData) =>
ops.OnAppControl = (appControlHandle, userData) =>
{
AppControl appControl = new AppControl(appControlHandle);
- foreach (var item in _filterMap)
+ if (appControl.isService)
{
- if (item.Key.IsMatch(appControl))
+ _serviceManager.OnAppControl(appControl);
+ } else {
+ foreach (var item in _filterMap)
{
- if (CurrentContext == null || !appControl.IsLaunchOperation())
+ if (item.Key.IsMatch(appControl))
{
- ApplicationContext ctx = new ApplicationContext();
- ctx.ReleaseContext += Ctx_ReleaseContext;
- _contextList.Add(ctx);
- Actor actor = ctx.StartActor(item.Value, appControl);
- if (!_window.Visible) {
- _window.Active();
- _window.Show();
- ctx.Resume();
+ // Window was created when the first UI Actor was created
+ if (_window == null)
+ _window = new Window();
+ if (CurrentContext == null || !appControl.IsLaunchOperation())
+ {
+ ApplicationContext ctx = new ApplicationContext();
+ ctx.ReleaseContext += Ctx_ReleaseContext;
+ _contextList.Add(ctx);
+ Actor actor = ctx.StartActor(item.Value, appControl);
+ if (!_window.Visible)
+ {
+ _window.Active();
+ _window.Show();
+ ctx.Resume();
+ }
}
+ break;
}
- break;
}
}
};
public static void Hide()
{
- throw new NotImplementedException();
+ if (_window != null)
+ _window.InActive();
}
public static void Exit()
Hide();
} else
{
+ // TODO. If running service was existed, application should not terminated, but Send the message to AUL(UI App terminate)
Exit();
}
}
}
}
+ public static void AddServiceHandler(Type clazz)
+ {
+ AddServiceHandler(clazz, new AppControlFilter[0] { });
+ }
+
+ public static void AddServiceHandler(Type clazz, AppControlFilter filter)
+ {
+ AddServiceHandler(clazz, new AppControlFilter[] { filter });
+ }
+
+ public static void AddServiceHandler(Type clazz, AppControlFilter[] filters)
+ {
+ _serviceManager.AddServiceHandler(clazz, filters);
+ }
+
+ internal static void StartService(Type clazz, AppControl appControl)
+ {
+ _serviceManager.StartService(clazz, appControl);
+ }
+ internal static void StopService(Type clazz)
+ {
+ _serviceManager.StopService(clazz);
+ }
}
--- /dev/null
+namespace Tizen.Application {
+ public class Service {
+ public Service() { }
+
+ public void Terminate()
+ {
+ Application.StopService(GetType());
+ }
+
+ protected virtual void OnCreate() { }
+ protected virtual void OnTerminate() { }
+ protected virtual void OnAppControl(AppControl appControl) { }
+
+ internal void DidCreate()
+ {
+ OnCreate();
+ }
+ internal void DidTerminate()
+ {
+ OnTerminate();
+ }
+ internal void DidAppControl(AppControl appControl)
+ {
+ OnAppControl(appControl);
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+
+namespace Tizen.Application
+{
+ public class ServiceManager
+ {
+ private Dictionary<AppControlFilter, Type> _filterMap = new Dictionary<AppControlFilter, Type>();
+ private Dictionary<Type, Service> _runningService = new Dictionary<Type, Service>();
+
+ public ServiceManager() { }
+ internal void AddServiceHandler(Type clazz, AppControlFilter[] filters)
+ {
+ if (!clazz.IsSubclassOf(typeof(Service)))
+ throw new ArgumentException(clazz.FullName + " is not a subclass of Service.");
+
+ foreach (var prop in clazz.GetProperties())
+ {
+ foreach (var attr in prop.GetCustomAttributes(false))
+ {
+ var filter = attr as AppControlFilter;
+ if (filter != null)
+ {
+ _filterMap.Add(filter, clazz);
+ }
+ }
+ }
+ if (filters != null)
+ {
+ foreach (var filter in filters)
+ {
+ _filterMap.Add(filter, clazz);
+ }
+ }
+ }
+ internal void OnAppControl(AppControl appControl)
+ {
+ foreach (var item in _filterMap)
+ {
+ if (item.Key.IsMatch(appControl))
+ {
+ StartService(item.Value, appControl);
+ break;
+ }
+ }
+ }
+
+ internal void StartService(Type clazz, AppControl appControl)
+ {
+ lock (_runningService)
+ {
+ if (_runningService.ContainsKey(clazz))
+ {
+ _runningService[clazz].DidAppControl(appControl);
+ } else
+ {
+ _runningService[clazz] = (Service)Activator.CreateInstance(clazz);
+ _runningService[clazz].DidCreate();
+ _runningService[clazz].DidAppControl(appControl);
+ }
+ }
+ }
+
+ internal void StopService(Type clazz)
+ {
+ lock (_runningService)
+ {
+ if (_runningService.ContainsKey(clazz))
+ {
+ _runningService[clazz].DidTerminate();
+ _runningService.Remove(clazz);
+ }
+ }
+ }
+
+ internal bool ServiceAlived
+ {
+ get
+ {
+ lock (_runningService)
+ {
+ return _runningService.Count > 0;
+ }
+ }
+ }
+ }
+}