2 using System.Collections.Generic;
5 namespace Tizen.Applications.ComponentBased.Common
7 internal class ServiceComponentStateManager : ComponentStateManger
9 private Interop.CBApplication.ServiceLifecycleCallbacks _callbacks;
11 internal ServiceComponentStateManager(Type ctype, string id, ComponentBasedApplication parent) : base(ctype, id, parent)
13 _callbacks.OnAction = new Interop.CBApplication.ServiceActionCallback(OnActionCallback);
14 _callbacks.OnDeviceOrientationChanged = new Interop.CBApplication.ServiceDeviceOrientationChangedCallback(OnDeviceOrientationChangedCallback);
15 _callbacks.OnLanguageChanged = new Interop.CBApplication.ServiceLanguageChangedCallback(OnLanguageChangedCallback);
16 _callbacks.OnLowBattery = new Interop.CBApplication.ServiceLowBatteryCallback(OnLowBatteryCallback);
17 _callbacks.OnLowMemory = new Interop.CBApplication.ServiceLowMemoryCallback(OnLowMemoryCallback);
18 _callbacks.OnRegionFormatChanged = new Interop.CBApplication.ServiceRegionFormatChangedCallback(OnRegionFormatChangedCallback);
19 _callbacks.OnRestore = new Interop.CBApplication.ServiceRestoreCallback(OnRestoreCallback);
20 _callbacks.OnSave = new Interop.CBApplication.ServiceSaveCallback(OnSaveCallback);
21 _callbacks.OnSuspendedState = new Interop.CBApplication.ServiceSuspendedStateCallback(OnSuspendedStateCallback);
22 _callbacks.OnCreate = new Interop.CBApplication.ServiceCreateCallback(OnCreateCallback);
23 _callbacks.OnDestroy = new Interop.CBApplication.ServiceDestroyCallback(OnDestroyCallback);
24 _callbacks.OnStart = new Interop.CBApplication.ServiceStartCommandCallback(OnStartCallback);
28 private bool OnCreateCallback(IntPtr context, IntPtr userData)
30 ServiceComponent sc = Activator.CreateInstance(ComponentClassType) as ServiceComponent;
35 Interop.CBApplication.GetInstanceId(context, out id);
36 sc.Bind(context, ComponentId, id, Parent);
47 private void OnStartCallback(IntPtr context, IntPtr appControl, bool restarted, IntPtr userData)
49 foreach (ServiceComponent sc in Instances)
51 if (sc.Handle == context)
53 SafeAppControlHandle handle = new SafeAppControlHandle(appControl, false);
54 AppControl control = new AppControl(handle);
55 sc.OnStartCommand(control, restarted);
61 private void OnDestroyCallback(IntPtr context, IntPtr userData)
63 foreach (ServiceComponent sc in Instances)
65 if (sc.Handle == context)
75 private void OnActionCallback(IntPtr context, string action, IntPtr appControl, IntPtr userData)
79 internal override IntPtr Bind(IntPtr h)
81 return Interop.CBApplication.BaseAddServiceComponent(h, ComponentId, ref _callbacks, IntPtr.Zero);