Tizen 2.1 base
[platform/framework/native/app-service.git] / inc / AppService.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #ifndef _APP_SERVICE_H_
19 #define _APP_SERVICE_H_
20
21
22 #include <FSystem.h>
23 #include <FAppTypes.h>
24
25 #include <FApp_IAppManagerEventListener.h>
26
27 namespace Tizen { namespace App
28 {
29 class _AppManagerStub;
30 class _ConditionManagerStub;
31 class _ContextManager;
32 class _CommunicationDispatcher;
33 class _PackageManagerStub;
34 class _NotificationManagerStub;
35 }}
36
37 namespace Tizen { namespace Io
38 {
39 class _IpcServer;
40 class _MmcStorageManagerStub;
41 }}
42
43 namespace Tizen { namespace System
44 {
45 class _DeviceManagerService;
46 class _SystemService;
47 class _AlarmService;
48 class _AccessoryManagerService;
49 }}
50
51 /**
52  * @class       AppService
53  * @brief       This creates and initializes major system services such as channel, appmanager, and others.
54  * And ContextManager watchs running apps(processes) and callbacks to appmanager when app destroyed.
55  *
56  * @ remarks AppService is system service of OSP, and starts at first among them.
57  */
58 class AppService
59         : public Tizen::App::ServiceApp
60         , public Tizen::App::Package::IPackageInstallationEventListener
61         , public Tizen::App::_IAppManagerEventListener
62         , virtual public Tizen::Base::Runtime::IEventListener
63 {
64 public:
65         static Tizen::App::ServiceApp* CreateInstance(void);
66
67         AppService();
68         virtual ~AppService();
69
70         virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);
71         virtual bool OnAppInitialized(void);
72         virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
73         virtual void OnLowMemory(void);
74         virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
75         virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList *pArgs);
76
77         // IPackageInstallationEventListener
78         virtual void OnPackageInstallationCompleted(const Tizen::App::PackageId& packageId, Tizen::App::Package::PackageInstallationResult installationResult);
79         virtual void OnPackageUninstallationCompleted(const Tizen::App::PackageId& packageId, bool uninstallationResult);
80         virtual void OnPackageInstallationInProgress(const Tizen::App::PackageId& packageId, int progress);
81
82         static void OnPowerOffNotiReceived(void* pData);
83
84 private:
85         bool InitializeIpc(void);
86         bool InitializeServices(void);
87
88         bool LaunchSystemServices(void);
89         bool LaunchUserServices(void);
90         bool LaunchChannelService(void);
91         bool LaunchSecurityService(void);
92         Tizen::Base::Collection::ArrayList* GetPackageEventArgsN(const Tizen::App::AppId& appId);
93         virtual void OnApplicationLaunched(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
94         virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
95
96         static int CreateProcess(const Tizen::Base::String& appId);
97         static result SetOomAdj(int pid, int adj);
98
99 private:
100         class _TaskHandlerThread
101                 : public Tizen::Base::Runtime::Thread
102         {
103         public:
104                 _TaskHandlerThread(AppService& mgr);
105                 virtual ~_TaskHandlerThread(void);
106
107                 virtual bool OnStart(void);
108                 virtual void OnStop(void);
109                 virtual void OnUserEventReceivedN(RequestId reqId, Tizen::Base::Collection::IList* pArgs);
110
111         private:
112                 AppService&     __mgr;
113         };
114
115         Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
116         Tizen::App::_ContextManager* __pContextMgr;
117         Tizen::App::_AppManagerStub* __pAppManagerStub;
118         Tizen::App::_ConditionManagerStub* __pConditionManagerStub;
119         _TaskHandlerThread      __handlerThread;
120         Tizen::System::_DeviceManagerService* __pDeviceManagerService;
121         Tizen::System::_SystemService* __pSystemService;
122         Tizen::System::_AccessoryManagerService* __pAccessoryManagerService;
123         Tizen::System::_AlarmService* __pAlarmService;
124         Tizen::App::_PackageManagerStub* __pPackageManagerStub;
125         Tizen::App::_NotificationManagerStub* __pNotificationManagerStub;
126         Tizen::Io::_MmcStorageManagerStub* __pMmcStorageManagerStub;
127 };      // AppService
128
129 #endif