Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
signalfd.hpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Contact: Jan Olszak <j.olszak@samsung.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
17 */
18 
25 #ifndef COMMON_UTILS_SIGNALFD_HPP
26 #define COMMON_UTILS_SIGNALFD_HPP
27 
29 
30 #include <csignal>
31 #include <sys/signalfd.h>
32 
33 #include <functional>
34 #include <mutex>
35 #include <unordered_map>
36 #include <memory>
37 #include <vector>
38 
39 namespace utils {
40 
47 class SignalFD {
48 public:
49  typedef std::function<void(struct ::signalfd_siginfo&)> Callback;
50 
52  virtual ~SignalFD();
53 
54  SignalFD(const SignalFD& signalfd) = delete;
55  SignalFD& operator=(const SignalFD&) = delete;
56 
64  void setHandler(const int sigNum, const Callback&& callback);
65 
69  int getFD() const;
70 
71 private:
72  typedef std::unique_lock<std::mutex> Lock;
73 
74  int mFD;
75  ::sigset_t mSet;
76  std::mutex mMutex;
78  std::unordered_map<int, Callback> mCallbacks;
79  std::vector<int> mBlockedSignals;
80 
81  void handleInternal();
82 };
83 
84 } // namespace utils
85 
86 #endif // COMMON_UTILS_SIGNALFD_HPP
C++ epoll wrapper.
int getFD() const
Definition: signalfd.cpp:75
std::unordered_map< int, Callback > mCallbacks
Definition: signalfd.hpp:78
::sigset_t mSet
Definition: signalfd.hpp:75
std::unique_lock< std::mutex > Lock
Definition: signalfd.hpp:72
virtual ~SignalFD()
Definition: signalfd.cpp:55
cargo::ipc::epoll::EventPoll & mEventPoll
Definition: signalfd.hpp:77
int mFD
Definition: signalfd.hpp:74
SignalFD takes control over handling signals sent to the thread.
Definition: signalfd.hpp:47
std::function< void(struct::signalfd_siginfo &)> Callback
Definition: signalfd.hpp:49
SignalFD(cargo::ipc::epoll::EventPoll &eventPoll)
Definition: signalfd.cpp:35
This class waits on registered file descriptor for events.
Definition: event-poll.hpp:47
SignalFD & operator=(const SignalFD &)=delete
std::vector< int > mBlockedSignals
Definition: signalfd.hpp:79
std::mutex mMutex
Definition: signalfd.hpp:76
void handleInternal()
Definition: signalfd.cpp:115
void setHandler(const int sigNum, const Callback &&callback)
Add a callback for a specified signal.
Definition: signalfd.cpp:80