Fix AES GCM IV setting in KeyProvider
[platform/core/security/key-manager.git] / src / manager / client-async / connection-thread.h
1 /*
2  *  Copyright (c) 2014 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16 /*
17  * @file       connection-thread.h
18  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
19  * @version    1.0
20  */
21
22 #pragma once
23
24 #include <thread>
25 #include <mutex>
26 #include <string>
27 #include <dpl/exception.h>
28 #include <noncopyable.h>
29 #include <client-common.h>
30 #include <async-request.h>
31 #include <descriptor-set.h>
32 #include <service.h>
33
34 namespace CKM {
35
36 class ConnectionThread {
37 public:
38         DECLARE_EXCEPTION_TYPE(CKM::Exception, EventFdError)
39
40         ConnectionThread();
41         virtual ~ConnectionThread();
42
43         NONCOPYABLE(ConnectionThread);
44
45         void run();
46
47         void sendMessage(AsyncRequest &&request);
48
49         bool finished() const
50         {
51                 return m_finished;
52         }
53
54 private:
55         void threadLoop();
56
57         void newRequest(short revents);
58
59         // reads notification event fd
60         void readEventFd(short revents);
61
62         Service &getService(const std::string &interface);
63
64         // Helper class that creates an event fd before thread is started
65         class EventFd {
66         public:
67                 EventFd();
68                 ~EventFd();
69
70                 NONCOPYABLE(EventFd);
71
72                 void notify();
73                 int get() const
74                 {
75                         return m_fd;
76                 }
77
78                 void read();
79
80         private:
81                 int m_fd;
82         };
83         // shared vars
84         EventFd m_eventFd;
85         AsyncRequest::Queue m_waitingReqs;
86         std::mutex m_mutex;
87         bool m_join;
88         bool m_finished;
89
90         // parent thread vars
91         std::thread m_thread;
92
93         // child thread vars
94         std::map<std::string, Service> m_services;
95         DescriptorSet m_descriptors;
96 };
97
98 } /* namespace CKM */