2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Applications.ComponentBased.Common
21 internal class ServiceComponentStateManager : ComponentStateManger
23 private Interop.CBApplication.ServiceLifecycleCallbacks _callbacks;
25 internal ServiceComponentStateManager(Type ctype, string id, ComponentBasedApplication parent) : base(ctype, id, parent)
27 _callbacks.OnAction = new Interop.CBApplication.ServiceActionCallback(OnActionCallback);
28 _callbacks.OnDeviceOrientationChanged = new Interop.CBApplication.ServiceDeviceOrientationChangedCallback(OnDeviceOrientationChangedCallback);
29 _callbacks.OnLanguageChanged = new Interop.CBApplication.ServiceLanguageChangedCallback(OnLanguageChangedCallback);
30 _callbacks.OnLowBattery = new Interop.CBApplication.ServiceLowBatteryCallback(OnLowBatteryCallback);
31 _callbacks.OnLowMemory = new Interop.CBApplication.ServiceLowMemoryCallback(OnLowMemoryCallback);
32 _callbacks.OnRegionFormatChanged = new Interop.CBApplication.ServiceRegionFormatChangedCallback(OnRegionFormatChangedCallback);
33 _callbacks.OnRestore = new Interop.CBApplication.ServiceRestoreCallback(OnRestoreCallback);
34 _callbacks.OnSave = new Interop.CBApplication.ServiceSaveCallback(OnSaveCallback);
35 _callbacks.OnSuspendedState = new Interop.CBApplication.ServiceSuspendedStateCallback(OnSuspendedStateCallback);
36 _callbacks.OnCreate = new Interop.CBApplication.ServiceCreateCallback(OnCreateCallback);
37 _callbacks.OnDestroy = new Interop.CBApplication.ServiceDestroyCallback(OnDestroyCallback);
38 _callbacks.OnStart = new Interop.CBApplication.ServiceStartCommandCallback(OnStartCallback);
39 _callbacks.OnTimeZoneChanged = new Interop.CBApplication.ServiceTimeZoneChangedCallback(OnTimeZoneChangedCallback);
43 private bool OnCreateCallback(IntPtr context, IntPtr userData)
45 ServiceComponent sc = Activator.CreateInstance(ComponentClassType) as ServiceComponent;
50 Interop.CBApplication.GetInstanceId(context, out id);
51 sc.Bind(context, ComponentId, id, Parent);
62 private void OnStartCallback(IntPtr context, IntPtr appControl, bool restarted, IntPtr userData)
64 foreach (ServiceComponent sc in Instances)
66 if (sc.Handle == context)
68 using SafeAppControlHandle handle = new SafeAppControlHandle(appControl, false);
69 AppControl control = new AppControl(handle);
70 sc.OnStartCommand(control, restarted);
76 private void OnDestroyCallback(IntPtr context, IntPtr userData)
78 foreach (ServiceComponent sc in Instances)
80 if (sc.Handle == context)
90 private void OnActionCallback(IntPtr context, string action, IntPtr appControl, IntPtr userData)
94 internal override IntPtr Bind(IntPtr h)
96 return Interop.CBApplication.BaseAddServiceComponent(h, ComponentId, ref _callbacks, IntPtr.Zero);