Add optional configuration parameter to client logic creation.
Change-Id: I66091d539b66803e069bcf7c6223017cc5e65e39
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;
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");
/*
- * 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.
/**
* @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);
/*
- * 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.
/**
* @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
#define SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_
#include <cache/CacheInterface.h>
+#include <configuration/Configuration.h>
#include <types/ProtocolFields.h>
#include <api/ApiInterface.h>
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,
}
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;
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");
/*
- * 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.
/**
* @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
*/
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);
/*
- * 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.
/**
* @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;
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