f325a42fe01c849ac8a05ee0c1f3c9a309450875
[platform/core/security/cynara.git] / src / client / cache / CacheInterface.h
1 /*
2  *  Copyright (c) 2014 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  * @file        CacheInterface.h
18  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
19  * @author      Zofia Abramowska <z.abramowska@samsung.com>
20  * @version     1.0
21  * @brief       This file contains cache interface definitions.
22  */
23
24 #ifndef SRC_CLIENT_CACHE_CACHEINTERFACE_H_
25 #define SRC_CLIENT_CACHE_CACHEINTERFACE_H_
26
27 #include <map>
28 #include <memory>
29 #include <string>
30
31 #include <cynara-client.h>
32 #include <types/PolicyKey.h>
33 #include <types/PolicyResult.h>
34 #include <types/PolicyType.h>
35
36 namespace Cynara {
37
38 class InterpreterInterface;
39 typedef std::shared_ptr<InterpreterInterface> InterpreterInterfacePtr;
40
41 class PluginCache;
42 typedef std::shared_ptr<PluginCache> PluginCachePtr;
43
44 class ResultGetterInterface;
45 typedef std::shared_ptr<ResultGetterInterface> ResultGetterInterfacePtr;
46
47 class ResultGetterInterface {
48 public:
49     virtual int requestResult(const PolicyKey &key, PolicyResult &result) noexcept = 0;
50     virtual ~ResultGetterInterface() = default;
51 };
52
53 class InterpreterInterface {
54 public:
55     virtual bool isCacheable(const PolicyResult &result) noexcept = 0;
56     virtual bool isUsable(const PolicyResult &result) noexcept = 0;
57     virtual int toResult(const PolicyResult &result) noexcept = 0;
58
59     virtual ~InterpreterInterface() = default;
60 };
61
62 class PluginCache {
63 public:
64     PluginCache(ResultGetterInterfacePtr getter) : m_getter(getter) {}
65     virtual int get(const std::string &session, const PolicyKey &key) = 0;
66
67     void registerPlugin(const PolicyType policyType, InterpreterInterfacePtr plugin) {
68         m_plugins[policyType] = plugin;
69     }
70
71     virtual void clear(void) {
72         m_plugins.clear();
73     }
74
75     virtual ~PluginCache() = default;
76
77 protected:
78     std::map<PolicyType, InterpreterInterfacePtr> m_plugins;
79     ResultGetterInterfacePtr m_getter;
80 };
81
82 } // namespace Cynara
83
84 #endif // SRC_CLIENT_CACHE_CACHEINTERFACE_H_