Remove dynamic exceptions
[anna.git] / source / comm / Device.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <anna/core/functions.hpp>
10
11 #include <anna/comm/Device.hpp>
12 #include <anna/comm/functions.hpp>
13
14 #include <anna/xml/Node.hpp>
15 #include <anna/xml/Attribute.hpp>
16
17 using namespace std;
18 using namespace anna;
19
20 string comm::Device::asString() const
21 {
22   string result("comm::Device { IP: ");
23   result += asString(a_address);
24   return result += anna::functions::asString(" | Status: %s }", (a_status == Status::Up) ? "Up" : "Down");
25 }
26
27 xml::Node* comm::Device::asXML(xml::Node* parent) const
28 noexcept(false) {
29   xml::Node* result = parent->createChild("comm.Device");
30   result->createAttribute("IP", asString(a_address));
31   result->createAttribute("Status", (a_status == Status::Up) ? "Up" : "Down");
32   return result;
33 }
34
35 void comm::Device::asAttribute(xml::Node* node) const
36 noexcept(false) {
37   node->createAttribute("IP", asString(a_address));
38   node->createAttribute("Status", (a_status == Status::Up) ? "Up" : "Down");
39 }
40
41 std::string comm::Device::asString(const in_addr_t& address)
42 {
43   struct in_addr in;
44   in.s_addr = address;
45   return string(inet_ntoa(in));
46 }
47
48