Add logic implementation of configuration 69/33769/9
authorZofia Abramowska <z.abramowska@samsung.com>
Wed, 14 Jan 2015 13:06:07 +0000 (14:06 +0100)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 3 Feb 2015 15:36:44 +0000 (16:36 +0100)
Add optional configuration parameter to client logic creation.

Change-Id: I66091d539b66803e069bcf7c6223017cc5e65e39

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

index 82433da..273d5a2 100644 (file)
@@ -86,7 +86,7 @@ int cynara_async_configuration_set_cache_size(cynara_async_configuration *p_conf
 
 CYNARA_API
 int cynara_async_initialize(cynara_async **pp_cynara,
-                            const cynara_async_configuration *p_conf UNUSED,
+                            const cynara_async_configuration *p_conf,
                             cynara_status_callback callback, void *user_status_data) {
     if (!pp_cynara)
         return CYNARA_API_INVALID_PARAM;
@@ -94,7 +94,11 @@ int cynara_async_initialize(cynara_async **pp_cynara,
     init_log();
 
     return Cynara::tryCatch([&]() {
-        *pp_cynara = new cynara_async(new Cynara::Logic(callback, user_status_data));
+        if (p_conf && p_conf->impl)
+            *pp_cynara = new cynara_async(new Cynara::Logic(callback, user_status_data,
+                                                            *(p_conf->impl)));
+        else
+            *pp_cynara = new cynara_async(new Cynara::Logic(callback, user_status_data));
 
         LOGD("Cynara client async initialized");
 
index 7504c7e..d5edf79 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        src/client-async/logic/Logic.cpp
  * @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
  * @version     1.0
  * @brief       This file contains implementation of Logic class - main
  *              libcynara-client-async class
 
 namespace Cynara {
 
-Logic::Logic(cynara_status_callback callback, void *userStatusData)
-    : m_statusCallback(callback, userStatusData), m_operationPermitted(true),
-      m_inAnswerCancelResponseCallback(false) {
+Logic::Logic(cynara_status_callback callback, void *userStatusData, const Configuration &conf)
+    : m_statusCallback(callback, userStatusData),
+      m_operationPermitted(true), m_inAnswerCancelResponseCallback(false) {
+
     m_socketClient = std::make_shared<SocketClientAsync>(
         PathConfig::SocketPath::client, std::make_shared<ProtocolClient>());
 
-    m_cache = std::make_shared<CapacityCache>();
+    m_cache = std::make_shared<CapacityCache>(conf.getCacheSize());
     auto naiveInterpreter = std::make_shared<NaiveInterpreter>();
     for (auto &descr : naiveInterpreter->getSupportedPolicyDescr()) {
         m_cache->registerPlugin(descr, naiveInterpreter);
index 6d41412..6598375 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        src/client-async/logic/Logic.h
  * @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
  * @version     1.0
  * @brief       This file contains declaration of Logic class - main
  *              libcynara-client-async class
@@ -25,6 +26,7 @@
 #define SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_
 
 #include <cache/CacheInterface.h>
+#include <configuration/Configuration.h>
 #include <types/ProtocolFields.h>
 
 #include <api/ApiInterface.h>
@@ -38,7 +40,8 @@ namespace Cynara {
 
 class Logic : public ApiInterface {
 public:
-    Logic(cynara_status_callback callback, void *userStatusData);
+    Logic(cynara_status_callback callback, void *userStatusData,
+          const Configuration &conf = Configuration());
     virtual ~Logic();
 
     virtual int checkCache(const std::string &client, const std::string &session,
index 2b96c74..0aadd85 100644 (file)
@@ -85,7 +85,7 @@ int cynara_configuration_set_cache_size(cynara_configuration *p_conf, size_t cac
 }
 
 CYNARA_API
-int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf UNUSED)
+int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf)
 {
     if (!pp_cynara)
         return CYNARA_API_INVALID_PARAM;
@@ -93,7 +93,10 @@ int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf UNU
     init_log();
 
     return Cynara::tryCatch([&]() {
-        *pp_cynara = new cynara(new Cynara::Logic());
+        if (p_conf && p_conf->impl)
+            *pp_cynara = new cynara(new Cynara::Logic(*(p_conf->impl)));
+        else
+            *pp_cynara = new cynara(new Cynara::Logic());
 
         LOGD("Cynara client initialized");
 
index f8fc543..d34caa6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        src/client/logic/Logic.cpp
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
  * @version     1.0
  * @brief       This file contains implementation of Logic class - main libcynara-client class
  */
@@ -47,10 +48,10 @@ static ProtocolFrameSequenceNumber generateSequenceNumber(void) {
     return ++sequenceNumber;
 }
 
-Logic::Logic() {
+Logic::Logic(const Configuration &conf) {
     m_socket = std::make_shared<SocketClient>(PathConfig::SocketPath::client,
                                               std::make_shared<ProtocolClient>());
-    m_cache = std::make_shared<CapacityCache>();
+    m_cache = std::make_shared<CapacityCache>(conf.getCacheSize());
     auto naiveInterpreter = std::make_shared<NaiveInterpreter>();
     for (auto &descr : naiveInterpreter->getSupportedPolicyDescr()) {
         m_cache->registerPlugin(descr, naiveInterpreter);
index c72309c..0199250 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        src/client/logic/Logic.h
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
  * @version     1.0
  * @brief       This file contains definition of Logic class - main libcynara-client class
  */
 #include <types/PolicyKey.h>
 #include <types/PolicyResult.h>
 
+#include <configuration/Configuration.h>
+
 #include <api/ApiInterface.h>
 #include <cache/CacheInterface.h>
 
 namespace Cynara {
 
 class Logic : public ApiInterface {
+public:
+    explicit Logic(const Configuration &conf = Configuration());
+    virtual ~Logic() {};
+
+    virtual int check(const std::string &client, const ClientSession &session,
+                      const std::string &user, const std::string &privilege);
 private:
     SocketClientPtr m_socket;
     PluginCachePtr m_cache;
@@ -42,12 +51,6 @@ private:
     void onDisconnected(void);
     bool ensureConnection(void);
     int requestResult(const PolicyKey &key, PolicyResult &result);
-public:
-    Logic();
-    virtual ~Logic() {};
-
-    virtual int check(const std::string &client, const ClientSession &session,
-                      const std::string &user, const std::string &privilege);
 };
 
 } // namespace Cynara