#include <ObserverManager.h>
An observer manager is responsible for managing observers.
Definition at line 18 of file ObserverManager.h.
◆ ObserverManager() [1/2]
Create an observer manager.
- Parameters
-
backend | the backend to observe. |
Definition at line 40 of file ObserverManager.cpp.
std::unique_ptr< Impl > impl_
QueryableBackendPtr backend_
◆ ~ObserverManager() [1/2]
ObserverManager::~ObserverManager |
( |
| ) |
|
◆ ObserverManager() [2/2]
Create an observer manager.
- Parameters
-
backend | the backend to observe. |
◆ ~ObserverManager() [2/2]
knowrob::ObserverManager::~ObserverManager |
( |
| ) |
|
◆ insert() [1/2]
Insert triples.
- Parameters
-
triples | the triples to insert. |
Definition at line 106 of file ObserverManager.cpp.
108 std::lock_guard<std::mutex> lock(
impl_->queueMutex_);
109 impl_->queue_.push({Impl::Mode::INSERT, triples});
111 impl_->queueCondition_.notify_one();
◆ insert() [2/2]
Insert triples.
- Parameters
-
triples | the triples to insert. |
◆ observe() [1/2]
Observe a query.
- Parameters
-
query | the query to observe. |
callback | the callback to invoke when the query matches. |
- Returns
- the observer.
Definition at line 75 of file ObserverManager.cpp.
76 auto job = std::make_shared<ObserverJob>(shared_from_this(),
query, callback);
78 std::lock_guard<std::mutex> lock(
impl_->jobMutex_);
79 impl_->jobs_.push_back(job);
81 return std::make_shared<Observer>(job);
void query(const GraphQueryPtr &query, const BindingsHandler &callback)
◆ observe() [2/2]
Observe a query.
- Parameters
-
query | the query to observe. |
callback | the callback to invoke when the query matches. |
- Returns
- the observer.
◆ query() [1/2]
Query the backend.
- Parameters
-
query | the query to execute. |
callback | the callback to invoke with the results. |
Definition at line 71 of file ObserverManager.cpp.
◆ query() [2/2]
Query the backend.
- Parameters
-
query | the query to execute. |
callback | the callback to invoke with the results. |
◆ remove() [1/2]
Remove triples.
- Parameters
-
triples | the triples to remove. |
Definition at line 114 of file ObserverManager.cpp.
116 std::lock_guard<std::mutex> lock(
impl_->queueMutex_);
117 impl_->queue_.push({Impl::Mode::REMOVE, triples});
119 impl_->queueCondition_.notify_one();
◆ remove() [2/2]
Remove triples.
- Parameters
-
triples | the triples to remove. |
◆ run() [1/2]
void ObserverManager::run |
( |
| ) |
|
|
protected |
Definition at line 122 of file ObserverManager.cpp.
123 while (
impl_->running_) {
124 std::pair<Impl::Mode,TripleContainerPtr> next;
126 std::unique_lock<std::mutex> lock(
impl_->queueMutex_);
127 if(
impl_->running_) {
128 impl_->queueCondition_.wait(lock, [
this] {
return !
impl_->running_ || !
impl_->queue_.empty(); });
130 if (!
impl_->running_) {
133 next =
impl_->queue_.front();
136 std::lock_guard<std::mutex> lock(
impl_->jobMutex_);
137 if (next.first == Impl::Mode::INSERT) {
138 for (
auto &job:
impl_->jobs_) {
139 job->processInsertion(next.second);
142 for (
auto &job:
impl_->jobs_) {
143 job->processRemoval(next.second);
148 std::unique_lock<std::mutex> lock(
impl_->queueMutex_);
150 if (
impl_->queue_.empty()) {
151 impl_->syncCondition_.notify_all();
◆ run() [2/2]
void knowrob::ObserverManager::run |
( |
| ) |
|
|
protected |
◆ stop() [1/2]
void ObserverManager::stop |
( |
| ) |
|
Stop the observer manager.
Definition at line 55 of file ObserverManager.cpp.
57 std::lock_guard<std::mutex> lock(
impl_->queueMutex_);
58 while (!
impl_->queue_.empty()) {
63 std::lock_guard<std::mutex> lock(
impl_->jobMutex_);
66 impl_->running_ =
false;
68 impl_->queueCondition_.notify_one();
◆ stop() [2/2]
void knowrob::ObserverManager::stop |
( |
| ) |
|
Stop the observer manager.
◆ stopObservation() [1/2]
void ObserverManager::stopObservation |
( |
const Observer & |
observer | ) |
|
Stop observing a query.
- Parameters
-
observer | the observer to stop. |
Definition at line 95 of file ObserverManager.cpp.
96 std::lock_guard<std::mutex> lock(
impl_->jobMutex_);
97 for (
auto it =
impl_->jobs_.begin(); it !=
impl_->jobs_.end(); ++it) {
99 if (job.get() == observer.
job().get()) {
100 impl_->jobs_.erase(it);
◆ stopObservation() [2/2]
void knowrob::ObserverManager::stopObservation |
( |
const Observer & |
observer | ) |
|
Stop observing a query.
- Parameters
-
observer | the observer to stop. |
◆ synchronize() [1/2]
void ObserverManager::synchronize |
( |
| ) |
|
Block until all observers have been synchronized.
Definition at line 84 of file ObserverManager.cpp.
86 std::lock_guard<std::mutex> lock(
impl_->queueMutex_);
87 if (
impl_->queue_.empty())
return;
90 std::unique_lock<std::mutex> lock(
impl_->syncMutex_);
91 impl_->syncCondition_.wait(lock, [
this] {
return impl_->queue_.empty(); });
◆ synchronize() [2/2]
void knowrob::ObserverManager::synchronize |
( |
| ) |
|
Block until all observers have been synchronized.
◆ backend_
◆ impl_
std::unique_ptr< Impl > knowrob::ObserverManager::impl_ |
|
protected |
The documentation for this class was generated from the following files: