2 * Copyright (c) 2017-2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Lukasz Kostyra (l.kostyra@samsung.com)
19 * @brief TeecContext class declaration
22 #ifndef LIBTEEC_TEEC_CONTEXT_H_
23 #define LIBTEEC_TEEC_CONTEXT_H_
25 #include "TeecSession.h"
26 #include "TeecSharedMemory.h"
28 #include <unordered_map>
31 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
32 #include <tee_client_api.h>
37 using TeecSessionMap = std::unordered_map<std::string, TeecSessionPtr>;
38 using TeecSharedMemoryMap = std::unordered_map<std::string, TeecSharedMemoryPtr>;
40 class TeecContext final
43 TeecContext(const std::string& id);
46 // returns session ID used to recognize sessions in GetSession and CloseSession
47 std::string OpenSession(const std::string& uuidstr, uint32_t connectionMethod,
48 const void* connectionData, TEEC_Operation* operation,
49 uint32_t* returnOrigin);
50 TeecSessionPtr GetSession(const std::string& id) const;
51 void CloseSession(const std::string& id);
53 // returns memory ID used to recognise the memory further down the road
54 std::string CreateSharedMemory(size_t size, uint32_t flags);
55 std::string CreateSharedMemory(void* buffer, size_t size, uint32_t flags);
56 TeecSharedMemoryPtr GetSharedMemory(const std::string& memId) const;
57 void ReleaseSharedMemory(const std::string& memId);
60 TEEC_Context mContext;
61 TeecSessionMap mSessions;
62 TeecSharedMemoryMap mSharedMemories;
63 static const std::string teeFeatureName;
67 using TeecContextPtr = std::shared_ptr<TeecContext>;
69 } // namespace libteec
70 } // namespace extension
72 #endif // LIBTEEC_TEEC_CONTEXT_H_