Implement cynara_async_check_cache() 42/27742/20
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 18 Sep 2014 12:41:01 +0000 (14:41 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Mon, 13 Oct 2014 17:13:39 +0000 (19:13 +0200)
Change-Id: I1930cdf448dcfdf800d0d5c322ff100baf5a4987

src/client-async/logic/Logic.cpp
src/client-async/logic/Logic.h

index 04ae0de..e1574ce 100644 (file)
 
 #include <memory>
 
+#include <cache/CapacityCache.h>
 #include <common.h>
 #include <exceptions/Exception.h>
 #include <exceptions/UnexpectedErrorException.h>
 #include <log/log.h>
+#include <plugins/NaiveInterpreter.h>
 #include <protocol/ProtocolClient.h>
 #include <sockets/Socket.h>
 #include <sockets/SocketPath.h>
@@ -39,19 +41,23 @@ Logic::Logic(cynara_status_callback callback, void *userStatusData)
     : m_statusCallback(callback, userStatusData) {
     m_socketClient = std::make_shared<SocketClientAsync>(
         SocketPath::client, std::make_shared<ProtocolClient>());
+
+    m_cache = std::make_shared<CapacityCache>();
+    auto naiveInterpreter = std::make_shared<NaiveInterpreter>();
+    m_cache->registerPlugin(PredefinedPolicyType::ALLOW, naiveInterpreter);
+    m_cache->registerPlugin(PredefinedPolicyType::DENY, naiveInterpreter);
 }
 
 Logic::~Logic() {
     onDisconnected();
 }
 
-int Logic::checkCache(const std::string &client UNUSED, const std::string &session UNUSED,
-                      const std::string &user UNUSED, const std::string &privilege UNUSED) {
+int Logic::checkCache(const std::string &client, const std::string &session,
+                      const std::string &user, const std::string &privilege) {
     if (!checkCacheValid())
         return CYNARA_API_CACHE_MISS;
 
-    // MOCKUP
-    return CYNARA_API_SUCCESS;
+    return m_cache->get(session, PolicyKey(client, user, privilege));
 }
 
 int Logic::createRequest(const std::string &client UNUSED, const std::string &session UNUSED,
@@ -135,6 +141,7 @@ int Logic::completeConnection(bool &completed) {
 }
 
 void Logic::onDisconnected(void) {
+    m_cache->clear();
     m_statusCallback.onDisconnected();
 }
 
index bc43ad9..0475b08 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_
 #define SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_
 
+#include <cache/CacheInterface.h>
+
 #include <api/ApiInterface.h>
 #include <callback/StatusCallback.h>
 #include <cynara-client-async.h>
@@ -47,6 +49,7 @@ public:
 
 private:
     StatusCallback m_statusCallback;
+    PluginCachePtr m_cache;
     SocketClientAsyncPtr m_socketClient;
 
     bool checkCacheValid(void);