Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef __DNS_XMPP_H__ 7 : #define __DNS_XMPP_H__ 8 : 9 : #include <map> 10 : #include <string> 11 : 12 : #include <boost/function.hpp> 13 : #include <boost/system/error_code.hpp> 14 : 15 : #include <bind/bind_util.h> 16 : #include <xmpp/xmpp_channel.h> 17 : 18 : class XmppChannel; 19 : class Agent; 20 : class VmInterface; 21 : 22 : class AgentDnsXmppChannel { 23 : public: 24 : // Packet module is optional. Callback function to update the flow stats 25 : // for ACL. The callback is defined to avoid linking error 26 : // when flow is not enabled 27 : typedef boost::function<void(DnsUpdateData*, DnsAgentXmpp::XmppType, 28 : VmInterface const*, bool)> DnsMessageHandler; 29 : typedef boost::function<void(AgentDnsXmppChannel*)> DnsXmppEventHandler; 30 : 31 : explicit AgentDnsXmppChannel(Agent *agent, 32 : std::string xmpp_server, uint8_t xs_idx); 33 : virtual ~AgentDnsXmppChannel(); 34 : 35 : virtual std::string ToString() const; 36 : virtual bool SendMsg(uint8_t *msg, std::size_t len); 37 : virtual void ReceiveMsg(const XmppStanza::XmppMessage *msg); 38 0 : std::string GetXmppServer() { return xmpp_server_; } 39 0 : uint8_t GetXmppServerIdx() { return xs_idx_; } 40 2 : XmppChannel *GetXmppChannel() { return channel_; } 41 : void UpdateConnectionInfo(xmps::PeerState state); 42 : static void XmppClientChannelEvent(AgentDnsXmppChannel *peer, 43 : xmps::PeerState state); 44 : static void HandleXmppClientChannelEvent(AgentDnsXmppChannel *peer, 45 : xmps::PeerState state); 46 : static void set_dns_message_handler_cb(DnsMessageHandler cb); 47 : static void set_dns_xmpp_event_handler_cb(DnsXmppEventHandler cb); 48 0 : Agent *agent() const {return agent_;} 49 : void RegisterXmppChannel(XmppChannel *channel); 50 : void ReceiveDnsMessage(std::unique_ptr<XmlBase> impl); 51 : void TimedOut(); 52 : 53 : protected: 54 : virtual void WriteReadyCb(const boost::system::error_code &ec); 55 : 56 : private: 57 : void ReceiveInternal(const XmppStanza::XmppMessage *msg); 58 : XmppChannel *channel_; 59 : std::string xmpp_server_; 60 : uint8_t xs_idx_; 61 : static DnsMessageHandler dns_message_handler_cb_; 62 : static DnsXmppEventHandler dns_xmpp_event_handler_cb_; 63 : Agent *agent_; 64 : }; 65 : 66 : #endif // __DNS_XMPP_H__