Kea  1.5.0
watched_thread.h
Go to the documentation of this file.
1 // Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef WATCHED_THREAD_H
8 #define WATCHED_THREAD_H
9 
10 #include <util/watch_socket.h>
11 #include <util/threads/thread.h>
12 
13 #include <boost/shared_ptr.hpp>
14 
15 namespace isc {
16 namespace util {
17 namespace thread {
18 
27 public:
30  enum WatchType {
31  ERROR = 0,
32  READY = 1,
33  TERMINATE = 2
34  };
35 
38 
40  virtual ~WatchedThread(){}
41 
46  int getWatchFd(WatchType watch_type);
47 
51  void markReady(WatchType watch_type);
52 
57  bool isReady(WatchType watch_type);
58 
62  void clearReady(WatchType watch_type);
63 
71  bool shouldTerminate();
72 
78  void start(const boost::function<void()>& thread_main);
79 
81  bool isRunning() {
82  return (thread_ != 0);
83  }
84 
90  void stop();
91 
98  void setError(const std::string& error_msg);
99 
103  std::string getLastError();
104 
106  std::string last_error_;
107 
117 
120 };
121 
123 typedef boost::shared_ptr<WatchedThread> WatchedThreadPtr;
124 
125 }; // namespace isc::util::thread
126 }; // namespace isc::util
127 }; // namespace isc
128 
129 #endif // WATCHED_THREAD_H
isc::util::thread::WatchedThread::isRunning
bool isRunning()
Returns true if the thread is running.
Definition: watched_thread.h:81
isc::util::thread::WatchedThread::last_error_
std::string last_error_
Error message of the last error encountered.
Definition: watched_thread.h:106
isc::util::thread::WatchedThread::READY
@ READY
Definition: watched_thread.h:32
isc::util::thread::WatchedThread::shouldTerminate
bool shouldTerminate()
Checks if the thread should terminate.
Definition: watched_thread.cc:44
isc::util::thread::WatchedThread::WatchedThread
WatchedThread()
Constructor.
Definition: watched_thread.h:37
isc::util::thread::WatchedThread::clearReady
void clearReady(WatchType watch_type)
Sets a watch socket state to not ready.
Definition: watched_thread.cc:39
watch_socket.h
isc::util::thread::WatchedThread::isReady
bool isReady(WatchType watch_type)
Indicates if a watch socket state is ready.
Definition: watched_thread.cc:34
isc::util::thread::WatchedThread::~WatchedThread
virtual ~WatchedThread()
Virtual destructor.
Definition: watched_thread.h:40
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::util::thread::WatchedThread::sockets_
WatchSocket sockets_[TERMINATE+1]
WatchSockets that are used to communicate with the owning thread There are three:
Definition: watched_thread.h:116
isc::util::thread::WatchedThread::ERROR
@ ERROR
Definition: watched_thread.h:31
isc::util::thread::WatchedThread::getWatchFd
int getWatchFd(WatchType watch_type)
Fetches the fd of a watch socket.
Definition: watched_thread.cc:24
isc::util::thread::WatchedThread::start
void start(const boost::function< void()> &thread_main)
Creates and runs the thread.
Definition: watched_thread.cc:15
isc::util::thread::WatchedThread::setError
void setError(const std::string &error_msg)
Sets the error state.
Definition: watched_thread.cc:67
isc::util::thread::WatchedThread::WatchType
WatchType
Enumerates the list of watch sockets used to mark events These are used as arguments to watch socket ...
Definition: watched_thread.h:30
isc::util::thread::WatchedThread::TERMINATE
@ TERMINATE
Definition: watched_thread.h:33
isc::util::thread::WatchedThreadPtr
boost::shared_ptr< WatchedThread > WatchedThreadPtr
Defines a pointer to a WatchedThread.
Definition: watched_thread.h:123
isc::util::thread::WatchedThread::thread_
thread::ThreadPtr thread_
Current thread instance.
Definition: watched_thread.h:119
isc::util::thread::ThreadPtr
boost::shared_ptr< Thread > ThreadPtr
Thread pointer type.
Definition: thread.h:101
isc::util::thread::WatchedThread
Provides a thread and controls for monitoring its activities.
Definition: watched_thread.h:26
isc::util::WatchSocket
Provides an IO "ready" semaphore for use with select() or poll() WatchSocket exposes a single open fi...
Definition: watch_socket.h:47
isc::util::thread::WatchedThread::stop
void stop()
Terminates the thread.
Definition: watched_thread.cc:54
thread.h
isc::util::thread::WatchedThread::markReady
void markReady(WatchType watch_type)
Sets a watch socket state to ready.
Definition: watched_thread.cc:29
isc::util::thread::WatchedThread::getLastError
std::string getLastError()
Fetches the error message text for the most recent error.
Definition: watched_thread.cc:73