]> granicus.if.org Git - icinga2/blob - lib/icinga/checkable-comment.cpp
Merge pull request #6727 from Icinga/feature/cluster-config-sync-stage
[icinga2] / lib / icinga / checkable-comment.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "icinga/service.hpp"
4 #include "remote/configobjectutility.hpp"
5 #include "base/configtype.hpp"
6 #include "base/objectlock.hpp"
7 #include "base/timer.hpp"
8 #include "base/utility.hpp"
9 #include "base/logger.hpp"
10
11 using namespace icinga;
12
13
14 void Checkable::RemoveAllComments()
15 {
16         for (const Comment::Ptr& comment : GetComments()) {
17                 Comment::RemoveComment(comment->GetName());
18         }
19 }
20
21 void Checkable::RemoveCommentsByType(int type)
22 {
23         for (const Comment::Ptr& comment : GetComments()) {
24                 /* Do not remove persistent comments from an acknowledgement */
25                 if (comment->GetEntryType() == CommentAcknowledgement && comment->GetPersistent())
26                         continue;
27
28                 if (comment->GetEntryType() == type)
29                         Comment::RemoveComment(comment->GetName());
30         }
31 }
32
33 std::set<Comment::Ptr> Checkable::GetComments() const
34 {
35         boost::mutex::scoped_lock lock(m_CommentMutex);
36         return m_Comments;
37 }
38
39 void Checkable::RegisterComment(const Comment::Ptr& comment)
40 {
41         boost::mutex::scoped_lock lock(m_CommentMutex);
42         m_Comments.insert(comment);
43 }
44
45 void Checkable::UnregisterComment(const Comment::Ptr& comment)
46 {
47         boost::mutex::scoped_lock lock(m_CommentMutex);
48         m_Comments.erase(comment);
49 }