Add api side implementation of configuration 68/33768/9
authorZofia Abramowska <z.abramowska@samsung.com>
Wed, 14 Jan 2015 12:49:46 +0000 (13:49 +0100)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 3 Feb 2015 15:36:44 +0000 (16:36 +0100)
Add implementation of cynara client (both async and sync) configuration
initialization, destruction and cache size option setting.

Change-Id: I34a81cb7c1578fc9a51944b73478ace3b623b9cc

src/client-async/api/client-async-api.cpp
src/client-common/configuration/Configuration.h [new file with mode: 0644]
src/client/api/client-api.cpp

index e3e4ef1..82433da 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/api/client-async-api.cpp
  * @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
  * @version     1.0
  * @brief       Implementation of external libcynara-client-async API
  */
@@ -27,6 +28,7 @@
 #include <log/log.h>
 
 #include <api/ApiInterface.h>
+#include <configuration/Configuration.h>
 #include <cynara-client-async.h>
 #include <logic/Logic.h>
 
@@ -41,6 +43,47 @@ struct cynara_async {
     }
 };
 
+struct cynara_async_configuration {
+    Cynara::Configuration* impl;
+
+    cynara_async_configuration(Cynara::Configuration *_impl) : impl(_impl) {}
+
+    ~cynara_async_configuration() {
+        delete impl;
+    }
+};
+
+CYNARA_API
+int cynara_async_configuration_create(cynara_async_configuration **pp_conf) {
+    if (!pp_conf)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        Cynara::ConfigurationUniquePtr ptr(new Cynara::Configuration());
+        *pp_conf = new cynara_async_configuration(ptr.get());
+        ptr.release();
+        LOGD("Cynara configuration initialized");
+        return CYNARA_API_SUCCESS;
+    });
+}
+
+CYNARA_API
+void cynara_async_configuration_destroy(cynara_async_configuration *p_conf) {
+    delete p_conf;
+}
+
+CYNARA_API
+int cynara_async_configuration_set_cache_size(cynara_async_configuration *p_conf,
+                                              size_t cache_size) {
+    if (!p_conf || !p_conf->impl)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        p_conf->impl->setCacheSize(cache_size);
+        return CYNARA_API_SUCCESS;
+    });
+}
+
 CYNARA_API
 int cynara_async_initialize(cynara_async **pp_cynara,
                             const cynara_async_configuration *p_conf UNUSED,
diff --git a/src/client-common/configuration/Configuration.h b/src/client-common/configuration/Configuration.h
new file mode 100644 (file)
index 0000000..1d2e031
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (c) 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.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/**
+ * @file        src/client-common/configuration/Configuration.h
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       This file contains client configuration class.
+ */
+
+#ifndef SRC_CLIENT_COMMON_CONFIGURATION_CONFIGURATION_H_
+#define SRC_CLIENT_COMMON_CONFIGURATION_CONFIGURATION_H_
+
+#include <cstddef>
+#include <memory>
+
+#include <cache/CapacityCache.h>
+
+namespace Cynara {
+
+class Configuration;
+typedef std::unique_ptr<Configuration> ConfigurationUniquePtr;
+
+class Configuration {
+public:
+    Configuration() : m_cacheSize(CapacityCache::CACHE_DEFAULT_CAPACITY) {};
+
+    void setCacheSize(std::size_t size) {
+        m_cacheSize = size;
+    }
+    std::size_t getCacheSize(void) const {
+        return m_cacheSize;
+    }
+    ~Configuration() {}
+private:
+    std::size_t m_cacheSize;
+};
+
+} /* namespace Cynara */
+
+#endif /* SRC_CLIENT_COMMON_CONFIGURATION_CONFIGURATION_H_ */
index 0bd7c91..2b96c74 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/api/client-api.cpp
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
  * @version     1.0
  * @brief       Implementation of external libcynara-client API
  */
@@ -27,6 +28,7 @@
 #include <exceptions/TryCatch.h>
 #include <log/log.h>
 
+#include <configuration/Configuration.h>
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <api/ApiInterface.h>
@@ -42,6 +44,46 @@ struct cynara {
     }
 };
 
+struct cynara_configuration {
+    Cynara::Configuration* impl;
+
+    cynara_configuration(Cynara::Configuration *_impl) : impl(_impl) {}
+
+    ~cynara_configuration() {
+        delete impl;
+    }
+};
+
+CYNARA_API
+int cynara_configuration_create(cynara_configuration **pp_conf) {
+    if (!pp_conf)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        Cynara::ConfigurationUniquePtr ptr(new Cynara::Configuration());
+        *pp_conf = new cynara_configuration(ptr.get());
+        ptr.release();
+        LOGD("Cynara configuration initialized");
+        return CYNARA_API_SUCCESS;
+    });
+}
+
+CYNARA_API
+void cynara_configuration_destroy(cynara_configuration *p_conf) {
+    delete p_conf;
+}
+
+CYNARA_API
+int cynara_configuration_set_cache_size(cynara_configuration *p_conf, size_t cache_size) {
+    if (!p_conf || !p_conf->impl)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        p_conf->impl->setCacheSize(cache_size);
+        return CYNARA_API_SUCCESS;
+    });
+}
+
 CYNARA_API
 int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf UNUSED)
 {
@@ -51,7 +93,7 @@ int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf UNU
     init_log();
 
     return Cynara::tryCatch([&]() {
-        *pp_cynara = new cynara(new Cynara::Logic);
+        *pp_cynara = new cynara(new Cynara::Logic());
 
         LOGD("Cynara client initialized");