]> granicus.if.org Git - icinga2/blob - icinga/endpoint.h
Replaced custom event code with Boost.Signals.
[icinga2] / icinga / endpoint.h
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef ENDPOINT_H
21 #define ENDPOINT_H
22
23 namespace icinga
24 {
25
26 class EndpointManager;
27
28 /**
29  * An endpoint that can be used to send and receive messages.
30  *
31  * @ingroup icinga
32  */
33 class I2_ICINGA_API Endpoint : public Object
34 {
35 public:
36         typedef shared_ptr<Endpoint> Ptr;
37         typedef weak_ptr<Endpoint> WeakPtr;
38
39         typedef set<string>::const_iterator ConstTopicIterator;
40
41         Endpoint(void);
42
43         virtual string GetAddress(void) const = 0;
44
45         string GetIdentity(void) const;
46         void SetIdentity(string identity);
47
48         void SetReceivedWelcome(bool value);
49         bool HasReceivedWelcome(void) const;
50
51         void SetSentWelcome(bool value);
52         bool HasSentWelcome(void) const;
53
54         shared_ptr<EndpointManager> GetEndpointManager(void) const;
55         void SetEndpointManager(weak_ptr<EndpointManager> manager);
56
57         void RegisterSubscription(string topic);
58         void UnregisterSubscription(string topic);
59         bool HasSubscription(string topic) const;
60
61         void RegisterPublication(string topic);
62         void UnregisterPublication(string topic);
63         bool HasPublication(string topic) const;
64
65         virtual bool IsLocal(void) const = 0;
66         virtual bool IsConnected(void) const = 0;
67
68         virtual void ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message) = 0;
69         virtual void ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message) = 0;
70
71         virtual void Stop(void) = 0;
72
73         void ClearSubscriptions(void);
74         void ClearPublications(void);
75
76         ConstTopicIterator BeginSubscriptions(void) const;
77         ConstTopicIterator EndSubscriptions(void) const;
78
79         ConstTopicIterator BeginPublications(void) const;
80         ConstTopicIterator EndPublications(void) const;
81
82         boost::signal<void (const EventArgs&)> OnIdentityChanged;
83         boost::signal<void (const EventArgs&)> OnSessionEstablished;
84
85 private:
86         string m_Identity; /**< The identity of this endpoint. */
87         set<string> m_Subscriptions; /**< The topics this endpoint is
88                                           subscribed to. */
89         set<string> m_Publications; /**< The topics this endpoint is
90                                          publishing. */
91         bool m_ReceivedWelcome; /**< Have we received a welcome message
92                                      from this endpoint? */
93         bool m_SentWelcome; /**< Have we sent a welcome message to this
94                                  endpoint? */
95
96         weak_ptr<EndpointManager> m_EndpointManager; /**< The endpoint manager
97                                                           this endpoint is
98                                                           registered with. */
99 };
100
101 }
102
103 #endif /* ENDPOINT_H */