Add caching of App/Pkg data & use faster way to retrieve this data
[platform/core/security/askuser.git] / src / client / impl / ApiInterfaceImpl.h
1 /*
2  *  Copyright (c) 2017 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
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 /**
18  * @file        ApiInterfaceImpl.h
19  * @author      Piotr Sawicki <p.sawicki2@partner.samsung.com>
20  * @brief       The declaration of ApiInterfaceImpl.
21  */
22
23 #pragma once
24
25 #include <memory>
26 #include <vector>
27
28 #include <ApiInterface.h>
29 #include <policy/AppInfo.h>
30 #include <policy/PkgInfo.h>
31 #include <StatusCallbackClosure.h>
32
33 #include <client-channel.h>
34
35 #include <askuser-notification-client.h>
36
37 namespace AskUser {
38
39 namespace Client {
40
41 class ApiInterfaceImpl : public ApiInterface {
42 public:
43     explicit ApiInterfaceImpl(const StatusCallbackClosure &closure);
44     ApiInterfaceImpl(const ApiInterfaceImpl& orig) = delete;
45     virtual ~ApiInterfaceImpl();
46
47     ApiInterface &operator=(const ApiInterfaceImpl& orig) = delete;
48
49     virtual int process(int fd, int events);
50     virtual askuser_check_result checkPrivilege(const std::string &privilege);
51     virtual RequestId popupRequest(const std::string &privilege,
52                                    const askuser_popup_response_callback callback,
53                                    void *userData);
54     virtual bool popupRequestInProgress(const std::string &privilege) const;
55
56     void updateConnection(Protocol::ConnectionFd fd, int mask);
57     void popupResponse(Protocol::RequestId id, int response);
58
59 private:
60     void respondToAllRequests(askuser_call_cause cause, askuser_popup_result result);
61
62     struct Request {
63         Protocol::RequestId m_requestId;
64         Protocol::ConnectionFd m_fd;
65         std::string m_privilege;
66         askuser_popup_response_callback m_callback;
67         void *m_userData;
68     };
69
70     StatusCallbackClosure m_statusClosure;
71     std::unique_ptr<Protocol::ClientChannel> m_channel;
72     std::vector<Request> m_requests;
73     AulAppInfo m_appInfo;
74     AulPkgInfo m_pkgInfo;
75 };
76
77 } // namespace Client
78
79 } // namespace AskUser
80