Tizen 2.1 base
[platform/framework/native/app-service.git] / inc / FApp_ContextManager.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 /**
19  * @file         FApp_ContextManager.h
20  * @brief       This is the header file of the _ContextManager class.
21  *
22  * This header file contains the declarations of the _ContextManager class.
23  */
24
25 #ifndef _FAPP_INTERNAL_CONTEXT_MANAGER_H_
26 #define _FAPP_INTERNAL_CONTEXT_MANAGER_H_
27
28 #include <map>
29
30 #include <FBaseObject.h>
31 #include <FBaseString.h>
32 #include <FBaseColArrayListT.h>
33 #include <FAppTypes.h>
34 #include <FBaseRtIEventListener.h>
35
36 #include <FApp_Types.h>
37
38 namespace Tizen { namespace Base { namespace Collection { class ArrayList; } } }
39
40 namespace Tizen { namespace App {
41
42 enum _OomAppType
43 {
44         OOM_APP_TYPE_SYSTEM,
45         OOM_APP_TYPE_LAUNCHING,
46         OOM_APP_TYPE_FOREGROUND_HIGH,
47         OOM_APP_TYPE_SERVICE_HIGH,
48         OOM_APP_TYPE_FOREGROUND,
49         OOM_APP_TYPE_SERVICE_MID,
50         OOM_APP_TYPE_BACKGROUND_HIGH,
51         OOM_APP_TYPE_SERVICE_LOW,
52         OOM_APP_TYPE_BACKGROUND
53 };
54
55 class _AppContext
56 {
57 public:
58         _AppContext(const AppId& appId,
59                         const Tizen::Base::String& executableName,
60                         _AppType appType,
61                         int pid,
62                         int ipcClientId,
63                         bool isSystemService
64                         );
65
66         ~_AppContext(void)
67         {
68         }
69
70         Tizen::Base::String ToString(void) const;
71
72 public:
73         AppId appId;
74         Tizen::Base::String executableName;
75         _AppType appType;
76         int pId;
77         int ipcClientId;
78         AppUiState uiState;
79         bool isRegistered;
80         bool isSystemService;
81 };      //_AppContext
82
83 class _IContextManagerEventListener
84         : virtual public Tizen::Base::Runtime::IEventListener
85 {
86 public:
87         virtual void OnApplicationTerminated(const _AppContext& appInfo) = 0;
88 };
89
90 /**
91  * @class        _ContextManager
92  * @brief
93  * @since 2.1
94  *
95  *
96  */
97 class _ContextManager
98 {
99         typedef std::map<int, _AppContext*> AppContexts;
100
101 public:
102         _ContextManager(void);
103         ~_ContextManager(void);
104
105         result Construct(void);
106         result Register(const PackageId& appId, const Tizen::Base::String& executableName, _AppType appType, int pid, int ipcClientId, bool isSystemService);
107         result Unregister(int pid);
108         const _AppContext* Find(const AppId& appId, const Tizen::Base::String& executableName) const;
109         const _AppContext* Find(int pid);
110         result GetAppListN(Tizen::Base::Collection::ArrayList* pArray) const;
111         void SetEventListener(_IContextManagerEventListener& listener);
112
113         void AbonormalAppTerminationHanlder(int pid, const AppId& appId, const Tizen::Base::String& execName);
114         static int OnAppTerminate(int pid, void *data);// app_dead_signal_listener
115         void Dump(void) const;
116
117
118 private:
119         _ContextManager(const _ContextManager& rhs);
120         _ContextManager& operator=(const _ContextManager& rhs);
121         _OomAppType GetOomAppType(const AppId& appId, const int pid) const;
122         bool IsErrorProneApp(const AppId& appId) const;
123
124 public:
125         /**
126          * This is static helper class
127          */
128         class _Util
129         {
130         public:
131                 static Tizen::Base::String QueryFeatureFromPackageManager(const AppId& appId, const Tizen::Base::String& execName, const Tizen::Base::String& feature);
132 //              static Tizen::Base::String GetExecNameFromPackageName(const Tizen::Base::String& packageName);
133         };
134
135 private:
136         const unsigned long __magic;
137         AppContexts __appContexts;
138         _IContextManagerEventListener* __pEventListener;
139         Tizen::Base::Collection::ArrayListT<Tizen::Base::String> __errorProneAppIds;
140 };      //_ContextManager
141
142 } } // Tizen::App
143
144 #endif //_FAPP_INTERNAL_CONTEXT_MANAGER_H_
145