m_cache = std::make_shared<CapacityCache>();
auto naiveInterpreter = std::make_shared<NaiveInterpreter>();
- for (auto &type : naiveInterpreter->getSupportedPolicyTypes()) {
- m_cache->registerPlugin(type, naiveInterpreter);
+ for (auto &descr : naiveInterpreter->getSupportedPolicyDescr()) {
+ m_cache->registerPlugin(descr, naiveInterpreter);
}
}
SET(LIB_CYNARA_COMMON_SOURCES
${LIB_CYNARA_COMMON_PATH}/cache/CapacityCache.cpp
- ${LIB_CYNARA_COMMON_PATH}/plugins/NaiveInterpreter.cpp
)
ADD_DEFINITIONS("-fvisibility=default")
#include <cynara-client.h>
#include <cynara-client-plugin.h>
#include <types/ClientSession.h>
+#include <types/PolicyDescription.h>
#include <types/PolicyKey.h>
#include <types/PolicyResult.h>
-#include <types/PolicyType.h>
namespace Cynara {
const PolicyKey &key,
const PolicyResult &result) = 0;
- void registerPlugin(const PolicyType policyType, ClientPluginInterfacePtr plugin) {
- m_plugins[policyType] = plugin;
+ void registerPlugin(const PolicyDescription &policyDescr, ClientPluginInterfacePtr plugin) {
+ m_plugins[policyDescr] = plugin;
}
virtual void clear(void) {
virtual ~PluginCache() {};
protected:
- std::map<PolicyType, ClientPluginInterfacePtr> m_plugins;
+ std::map<PolicyDescription, ClientPluginInterfacePtr> m_plugins;
};
} // namespace Cynara
+++ /dev/null
-/*
- * Copyright (c) 2014 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/plugins/NaiveInterpreter.cpp
- * @author Zofia Abramowska <z.abramowska@samsung.com>
- * @version 1.0
- * @brief This file contains NaiveInterpreter supported types definition.
- */
-
-#include <plugins/NaiveInterpreter.h>
-
-namespace Cynara {
-
- const std::vector<PolicyType> NaiveInterpreter::s_supportedTypes =
- {PredefinedPolicyType::ALLOW, PredefinedPolicyType::DENY};
-
-}
#include <attributes/attributes.h>
#include <cache/CacheInterface.h>
#include <cynara-error.h>
+#include <cynara-client-plugin.h>
namespace Cynara {
return CYNARA_API_ACCESS_DENIED;
}
- const std::vector<PolicyType> &getSupportedPolicyTypes(void) {
- return s_supportedTypes;
+ const std::vector<PolicyDescription> &getSupportedPolicyDescr(void) {
+ return predefinedPolicyDescr;
}
void invalidate(void) {}
-private:
- static const std::vector<PolicyType> s_supportedTypes;
};
} // namespace Cynara
std::make_shared<ProtocolClient>());
m_cache = std::make_shared<CapacityCache>();
auto naiveInterpreter = std::make_shared<NaiveInterpreter>();
- for (auto &type : naiveInterpreter->getSupportedPolicyTypes()) {
- m_cache->registerPlugin(type, naiveInterpreter);
+ for (auto &descr : naiveInterpreter->getSupportedPolicyDescr()) {
+ m_cache->registerPlugin(descr, naiveInterpreter);
}
}
${COMMON_PATH}/sockets/Socket.cpp
${COMMON_PATH}/sockets/SocketClient.cpp
${COMMON_PATH}/types/PolicyBucket.cpp
+ ${COMMON_PATH}/types/PolicyDescription.cpp
${COMMON_PATH}/types/PolicyKey.cpp
${COMMON_PATH}/types/PolicyKeyHelpers.cpp
${COMMON_PATH}/types/PolicyResult.cpp
+ ${COMMON_PATH}/types/PolicyType.cpp
)
IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
#include <vector>
-#include <types/PolicyType.h>
+#include <types/PolicyDescription.h>
namespace Cynara {
class ExternalPluginInterface {
public:
-
/**
- * Policy type supported by plugin.
+ * Policy types supported by plugin.
*/
- virtual const std::vector<PolicyType> &getSupportedPolicyTypes(void) = 0;
+ virtual const std::vector<PolicyDescription> &getSupportedPolicyDescr(void) = 0;
/**
* Informs, that every data stored based on previously given input
return m_plugins[pType];
}
+std::vector<PolicyDescription> PluginManager::getPolicyDescriptions(void) const {
+ std::vector<PolicyDescription> descriptions;
+ descriptions.reserve(m_plugins.size());
+ for (auto &plugin : m_plugins) {
+ descriptions.push_back(plugin.first);
+ }
+ return descriptions;
+}
+
void PluginManager::invalidateAll(void) {
for (auto &plugin : m_plugins) {
plugin.second->invalidate();
return;
}
- auto policies = pluginPtr->getSupportedPolicyTypes();
+ auto policies = pluginPtr->getSupportedPolicyDescr();
if (policies.empty()) {
LOGE("Plugin <%s> does not support any type!", path.c_str());
return;
}
- for (auto type : policies) {
- if (!m_plugins.insert(std::make_pair(type, pluginPtr)).second) {
- LOGW("policyType [%" PRIu16 "] was already supported.", type);
+ for (auto &desc : policies) {
+ if (!m_plugins.insert(std::make_pair(desc, pluginPtr)).second) {
+ LOGW("policy type: [%" PRIu16 "] name: <%s> was already supported.",
+ desc.type, desc.name.c_str());
}
}
#include <map>
#include <memory>
#include <string>
+#include <vector>
#include <plugin/ExternalPluginInterface.h>
+#include <types/PolicyDescription.h>
namespace Cynara {
typedef std::shared_ptr<ExternalPluginInterface> ExternalPluginPtr;
public:
PluginManager(const std::string &pluginDir);
ExternalPluginPtr getPlugin(PolicyType pType);
+ std::vector<PolicyDescription> getPolicyDescriptions(void) const;
void invalidateAll(void);
~PluginManager();
typedef std::list<PluginLibPtr> PluginLibs;
std::string m_dir;
- std::map<PolicyType, ExternalPluginPtr> m_plugins;
+ std::map<PolicyDescription, ExternalPluginPtr> m_plugins;
PluginLibs m_pluginLibs;
void loadPlugins(void);
--- /dev/null
+/*
+ * Copyright (c) 2014 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/common/types/PolicyDescription.cpp
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @version 1.0
+ * @brief Implementation of functions for Cynara::PolicyDescription
+ */
+
+#include "PolicyDescription.h"
+
+namespace Cynara {
+
+const std::vector<PolicyDescription> predefinedPolicyDescr = {
+ PolicyDescription(PredefinedPolicyType::ALLOW, "Allow"),
+ PolicyDescription(PredefinedPolicyType::DENY, "Deny")
+};
+
+bool operator<(const PolicyDescription &left, const PolicyDescription &right) {
+ return left.type < right.type;
+}
+
+} // namespace Cynara
--- /dev/null
+/*
+ * Copyright (c) 2014 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/common/types/PolicyDescription.h
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @version 1.0
+ * @brief This file defines PolicyDescription for storing policy type
+ * description.
+ */
+
+#ifndef SRC_COMMON_TYPES_POLICYDESCRIPTION_H_
+#define SRC_COMMON_TYPES_POLICYDESCRIPTION_H_
+
+#include <types/PolicyType.h>
+
+#include <vector>
+#include <string>
+
+namespace Cynara {
+
+struct PolicyDescription {
+ PolicyDescription(const PolicyType &pType, const std::string &pName) : type(pType), name(pName)
+ {};
+ PolicyDescription(const PolicyType &pType) : type(pType) {};
+ PolicyType type;
+ std::string name;
+};
+
+extern const std::vector<PolicyDescription> predefinedPolicyDescr;
+
+bool operator<(const PolicyDescription &left, const PolicyDescription &right);
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_TYPES_POLICYDESCRIPTION_H_ */
*/
class ClientPluginInterface : public ExternalPluginInterface {
public:
-
/**
* Return entry cacheability
*/
virtual bool isCacheable(const ClientSession &session, const PolicyResult &result) = 0;
/**
- * Return entry cacheability
+ * Return entry usability
*/
virtual bool isUsable(const ClientSession &session, const ClientSession &prevSession,
bool &updateSession, PolicyResult &result) = 0;