OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
xmpp_config.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "xmpp/xmpp_config.h"
6 
7 #include "base/logging.h"
8 #include <boost/algorithm/string.hpp>
9 
10 using namespace boost::asio::ip;
11 using namespace boost::property_tree;
12 using namespace std;
13 
15  ToAddr(""), FromAddr(""), NodeAddr(""), logUVE(false), auth_enabled(false),
16  path_to_server_cert(""), path_to_server_priv_key(""), path_to_ca_cert(""),
17  tcp_hold_time(XmppChannelConfig::kTcpHoldTime), gr_helper_disable(false),
18  xmpp_hold_time(90), dscp_value(0), isClient_(isClient) {
19 }
20 
22  int res;
23 
24  if (endpoint < rhs.endpoint) return -1;
25  if (endpoint > rhs.endpoint) return 1;
26  res = name.compare(rhs.name);
27  if (res) return res;
28 
29  return 0;
30 }
31 
33  const XmppConfigData::XmppChannelConfigMap &n_current =
34  current_->neighbors();
35  if (future_.get() == NULL) {
36  return;
37  }
38  const XmppConfigData::XmppChannelConfigMap &n_future = future_->neighbors();
39 
40  XmppConfigData::XmppChannelConfigMap::const_iterator icurr =
41  n_current.begin();
42  XmppConfigData::XmppChannelConfigMap::const_iterator inext =
43  n_future.begin();
44 
45  while (icurr != n_current.end() && inext != n_future.end()) {
46  if (icurr->first < inext->first) {
47  obs(DF_DELETE, icurr->second, NULL);
48  ++icurr;
49  } else if (icurr->first > inext->first) {
50  obs(DF_ADD, NULL, inext->second);
51  ++inext;
52  } else {
53  int cmp = icurr->second->CompareTo(*inext->second);
54  if (cmp != 0) {
55  obs(DF_CHANGE, icurr->second, inext->second);
56  }
57  ++icurr;
58  ++inext;
59  }
60  }
61  for (; icurr != n_current.end(); ++icurr) {
62  obs(DF_DELETE, icurr->second, NULL);
63  }
64  for (; inext != n_future.end(); ++inext) {
65  obs(DF_ADD, NULL, inext->second);
66  }
67 }
68 
70  future_.reset(future);
71 }
72 
74  current_.reset(future_.release());
75 }
76 
78  current_.reset();
79  future_.reset();
80 }
81 
83 }
boost::asio::ip::tcp::endpoint endpoint
Definition: xmpp_config.h:24
void PeerConfigDiff(PeerDiffObserver obs) const
Definition: xmpp_config.cc:32
int CompareTo(const XmppChannelConfig &rhs) const
Definition: xmpp_config.cc:21
std::unique_ptr< const XmppConfigData > future_
Definition: xmpp_config.h:105
std::unique_ptr< const XmppConfigData > current_
Definition: xmpp_config.h:104
XmppChannelConfig(bool isClient=false)
Definition: xmpp_config.cc:14
std::string name
Definition: xmpp_config.h:23
boost::function< void(DiffType, const XmppChannelConfig *, const XmppChannelConfig *)> PeerDiffObserver
Definition: xmpp_config.h:87
boost::ptr_map< boost::asio::ip::tcp::endpoint, XmppChannelConfig > XmppChannelConfigMap
Definition: xmpp_config.h:51
void SetFuture(const XmppConfigData *future)
Definition: xmpp_config.cc:69