Add a UUID-specific config manager class 98/174798/3
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Wed, 13 Dec 2017 10:40:57 +0000 (11:40 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Thu, 12 Apr 2018 06:58:28 +0000 (06:58 +0000)
Change-Id: Iaceb3eb09ddba6e8e4d933b7074350db4fde36ac
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
simulatordaemon/CMakeLists.txt
simulatordaemon/inc/UUIDConfig.h [new file with mode: 0644]
simulatordaemon/inc/UUIDConfigManager.h [new file with mode: 0644]
simulatordaemon/inc/UUIDUtils.h [new file with mode: 0644]
simulatordaemon/src/UUIDComparator.cpp [new file with mode: 0644]
simulatordaemon/src/UUIDConfig.cpp [new file with mode: 0644]
simulatordaemon/src/UUIDConfigManager.cpp [new file with mode: 0644]

index 2f5e89f..a844f10 100644 (file)
@@ -50,6 +50,9 @@ SET(DAEMON_SOURCES
     ${DAEMON_PATH}/src/TAInstance.cpp
     ${DAEMON_PATH}/src/TEEConnectionHandler.cpp
     ${DAEMON_PATH}/src/TEEContext.cpp
+    ${DAEMON_PATH}/src/UUIDConfig.cpp
+    ${DAEMON_PATH}/src/UUIDConfigManager.cpp
+    ${DAEMON_PATH}/src/UUIDComparator.cpp
     ${DAEMON_PATH}/src/ClientCommands/CommandCloseSession.cpp
     ${DAEMON_PATH}/src/ClientCommands/CommandCloseTASession.cpp
     ${DAEMON_PATH}/src/ClientCommands/CommandFinContext.cpp
diff --git a/simulatordaemon/inc/UUIDConfig.h b/simulatordaemon/inc/UUIDConfig.h
new file mode 100644 (file)
index 0000000..50a8dd2
--- /dev/null
@@ -0,0 +1,41 @@
+
+/**
+ * Copyright (c) 2015-2018 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
+ * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.com)
+ * @brief  Class for storing UUID-specific user configuration.
+ */
+
+#ifndef UUIDCONFIG_H_
+#define UUIDCONFIG_H_
+
+#include <mutex>
+#include <boost/optional.hpp>
+#include <boost/none.hpp>
+
+class UUIDConfig {
+public:
+       boost::optional<uint32_t> getDebugPort();
+       void setDebugPort(uint32_t port);
+       void clearDebugPort();
+private:
+       boost::optional<uint32_t> m_debugPort = boost::none;
+       std::mutex m_lock{};
+};
+
+#endif /* UUIDCONFIG_H_ */
diff --git a/simulatordaemon/inc/UUIDConfigManager.h b/simulatordaemon/inc/UUIDConfigManager.h
new file mode 100644 (file)
index 0000000..d87f7a5
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2015-2018 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
+ * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.com)
+ * @brief  Class for storing UUID-specific user configuration.
+ */
+
+#ifndef UUIDCONFIGMANAGER_H_
+#define UUIDCONFIGMANAGER_H_
+
+#include <map>
+#include <memory>
+#include <mutex>
+
+#include "tee_client_api.h"
+#include "UUIDUtils.h"
+#include "UUIDConfig.h"
+
+class UUIDConfigManager {
+private:
+       static std::shared_ptr<UUIDConfigManager> instance;
+       std::map<TEEC_UUID, std::shared_ptr<UUIDConfig>, UUIDComparator> m_TAMap{};
+       std::mutex m_mapLock{};
+public:
+       static std::shared_ptr<UUIDConfigManager> getInstance();
+       std::shared_ptr<UUIDConfig> at(const TEEC_UUID &uuid);
+       std::shared_ptr<UUIDConfig> operator[](const TEEC_UUID &uuid);
+       void erase(const TEEC_UUID &uuid);
+};
+
+#endif /* UUIDCONFIGMANAGER_H_ */
diff --git a/simulatordaemon/inc/UUIDUtils.h b/simulatordaemon/inc/UUIDUtils.h
new file mode 100644 (file)
index 0000000..ca6a5cd
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2015-2018 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
+ * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.com)
+ * @brief  UUID handling utilities.
+ */
+
+#ifndef UUIDUTILS_H_
+#define UUIDUTILS_H_
+
+class UUIDComparator {
+public:
+       bool operator() (const TEEC_UUID &u1, const TEEC_UUID &u2);
+private:
+       bool compareSeq (const TEEC_UUID &u1, const TEEC_UUID &u2);
+};
+
+#endif /* UUIDUTILS_H_ */
diff --git a/simulatordaemon/src/UUIDComparator.cpp b/simulatordaemon/src/UUIDComparator.cpp
new file mode 100644 (file)
index 0000000..ef04f00
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2015-2018 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
+ * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.com)
+ * @brief  Class for storing UUID-specific user configuration.
+ */
+
+#include "tee_client_api.h"
+#include "UUIDUtils.h"
+
+bool UUIDComparator::operator() (const TEEC_UUID &u1, const TEEC_UUID &u2) {
+       if (u1.timeLow != u2.timeLow)
+               return u1.timeLow < u2.timeLow;
+       if (u1.timeMid != u2.timeMid)
+               return u1.timeMid < u2.timeMid;
+       if (u1.timeHiAndVersion != u2.timeHiAndVersion)
+               return u1.timeHiAndVersion < u2.timeHiAndVersion;
+       return compareSeq(u1, u2);
+}
+
+bool UUIDComparator::compareSeq(const TEEC_UUID &u1, const TEEC_UUID &u2) {
+       for (int i = 0; i < 8; i++) {
+               if (u1.clockSeqAndNode[i] !=
+                   u2.clockSeqAndNode[i])
+                       return (u1.clockSeqAndNode[i] <
+                               u2.clockSeqAndNode[i]);
+       }
+       return false;
+}
diff --git a/simulatordaemon/src/UUIDConfig.cpp b/simulatordaemon/src/UUIDConfig.cpp
new file mode 100644 (file)
index 0000000..b0e8ea0
--- /dev/null
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2015-2018 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
+ * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.com)
+ * @brief  Class for storing UUID-specific user configuration.
+ */
+
+#include <cstdint>
+#include <mutex>
+#include <boost/optional.hpp>
+#include <boost/none.hpp>
+#include "UUIDConfig.h"
+
+void UUIDConfig::setDebugPort(uint32_t port)
+{
+       std::lock_guard<std::mutex> guard(m_lock);
+       m_debugPort = port;
+}
+
+boost::optional<uint32_t> UUIDConfig::getDebugPort()
+{
+       std::lock_guard<std::mutex> guard(m_lock);
+       return m_debugPort;
+}
+
+void UUIDConfig::clearDebugPort()
+{
+       std::lock_guard<std::mutex> guard(m_lock);
+       m_debugPort = boost::none;
+}
diff --git a/simulatordaemon/src/UUIDConfigManager.cpp b/simulatordaemon/src/UUIDConfigManager.cpp
new file mode 100644 (file)
index 0000000..01acf4d
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2015-2018 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
+ * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.com)
+ * @brief  Class for storing UUID-specific user configuration.
+ */
+
+#include <map>
+#include <memory>
+#include <mutex>
+
+#include "tee_client_api.h"
+#include "UUIDUtils.h"
+#include "UUIDConfig.h"
+#include "UUIDConfigManager.h"
+
+
+std::shared_ptr<UUIDConfigManager> UUIDConfigManager::instance{};
+
+std::shared_ptr<UUIDConfigManager> UUIDConfigManager::getInstance()
+{
+       if (!instance) {
+               instance = std::shared_ptr<UUIDConfigManager>(
+                       new UUIDConfigManager);
+       }
+       return instance;
+}
+
+std::shared_ptr<UUIDConfig> UUIDConfigManager::at(const TEEC_UUID &uuid)
+{
+       std::lock_guard<std::mutex> guard(m_mapLock);
+       return m_TAMap.at(uuid);
+};
+
+std::shared_ptr<UUIDConfig> UUIDConfigManager::operator[](const TEEC_UUID &uuid)
+{
+       std::lock_guard<std::mutex> guard(m_mapLock);
+       try {
+               return m_TAMap.at(uuid);
+       } catch (std::out_of_range) {
+               std::shared_ptr<UUIDConfig> newUUIDConf =
+                       std::shared_ptr<UUIDConfig>(new UUIDConfig());
+               m_TAMap[uuid] = newUUIDConf;
+               return newUUIDConf;
+       }
+}
+
+void UUIDConfigManager::erase(const TEEC_UUID &uuid)
+{
+       std::lock_guard<std::mutex> guard(m_mapLock);
+       m_TAMap.erase(uuid);
+}