Add caching of App/Pkg data & use faster way to retrieve this data
[platform/core/security/askuser.git] / src / common / policy / AppInfo.h
1 /*
2  *  Copyright (c) 2017-2018 Samsung Electronics Co.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16 /**
17  * @file        src/common/policy/AppInfo.h
18  * @author      Zofia Abramowska <z.abramowska@samsung.com>
19  * @author      Tomasz Swierczek <t.swierczek@samsung.com>
20  * @brief       Definition of app-data wrapper/cache (sub)classes
21  */
22
23 #pragma once
24
25 #include <string>
26 #include <sys/types.h>
27
28 namespace AskUser {
29
30 class AppInfo {
31 public:
32
33     AppInfo() : m_uid(0) {};
34
35     virtual ~AppInfo() {};
36
37     virtual void purgeCache() {
38         m_appId.clear();
39         m_type.clear();
40         m_version.clear();
41         m_uid = 0;
42     }
43
44     virtual std::string type(const std::string &appId, uid_t uid) {
45         update(appId, uid);
46         return m_type;
47     }
48
49     virtual std::string apiVersion(const std::string &appId, uid_t uid) {
50         update(appId, uid);
51         return m_version;
52     }
53
54 protected:
55     virtual void fetch(const std::string &appId, uid_t uid) = 0;
56
57     virtual void update(const std::string &appId, uid_t uid) {
58         if (m_appId != appId || uid != m_uid) {
59             purgeCache();
60             fetch(appId, uid);
61         }
62     }
63
64     std::string m_appId;
65     uid_t m_uid;
66     std::string m_type;
67     std::string m_version;
68 };
69
70 class AulAppInfo : public AppInfo {
71 protected:
72     virtual void fetch(const std::string &appId, uid_t uid);
73 };
74
75 class PkgMgrAppInfo : public AppInfo {
76 protected:
77     virtual void fetch(const std::string &appId, uid_t uid);
78 };
79
80
81 } // namespace AskUser