Skip to content

Commit

Permalink
Merge pull request #1532 from peternewman/protobuf-3.6
Browse files Browse the repository at this point in the history
Various tidying up/improvements
  • Loading branch information
peternewman committed Jan 8, 2019
2 parents cb021b4 + 458fbb9 commit b1f0773
Show file tree
Hide file tree
Showing 26 changed files with 230 additions and 132 deletions.
3 changes: 3 additions & 0 deletions .codespellignore
Expand Up @@ -166,3 +166,6 @@ function ok(a,b){for(var c=a.wa[b].data.items,d=c.length,g=N(a.wa[b].id),h="",i=
UIntValidator(0, UINT_MAX), UIntValidator(0, UINT_MAX),
// On win32 TRUE and FALSE are #define'd. We can #undef them here but that // On win32 TRUE and FALSE are #define'd. We can #undef them here but that
* A #define'd value HAVE_LIBLO which lets us know within the code if the OSC * A #define'd value HAVE_LIBLO which lets us know within the code if the OSC
import java.nio.ByteOrder;
byte[] header = ByteBuffer.allocate(4).order(ByteOrder.nativeOrder()).putInt(headerContent).array();
int headerValue = ByteBuffer.wrap(header).order(ByteOrder.nativeOrder()).getInt();
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -271,6 +271,7 @@ cache:
- $HOME/.cache/pip # pip cache - $HOME/.cache/pip # pip cache
- $HOME/.npm # npm cache - $HOME/.npm # npm cache
- $HOME/.ccache # ccache cache - $HOME/.ccache # ccache cache
- $HOME/.m2 # maven cache


before_cache: before_cache:
- rm -f $HOME/.cache/pip/log/debug.log # erase log - rm -f $HOME/.cache/pip/log/debug.log # erase log
Expand Down
11 changes: 9 additions & 2 deletions common/base/Flags.cpp
Expand Up @@ -358,8 +358,15 @@ void FlagRegistry::GenManPage() {
str << " <" << flag->arg_type() << ">"; str << " <" << flag->arg_type() << ">";
} }
if (flag->short_opt()) { if (flag->short_opt()) {
short_flag_lines.push_back( if (flag->name() == FLAGS_version.name()) {
OptionPair(str.str(), iter->second->help())); std::ostringstream help_str;
help_str << "Print\n.B " << exe_name << "\nversion information.";
short_flag_lines.push_back(
OptionPair(str.str(), help_str.str()));
} else {
short_flag_lines.push_back(
OptionPair(str.str(), iter->second->help()));
}
} else { } else {
long_flag_lines.push_back( long_flag_lines.push_back(
OptionPair(str.str(), iter->second->help())); OptionPair(str.str(), iter->second->help()));
Expand Down
4 changes: 2 additions & 2 deletions common/network/AdvancedTCPConnectorTest.cpp
Expand Up @@ -399,7 +399,7 @@ uint16_t AdvancedTCPConnectorTest::ReservePort() {
void AdvancedTCPConnectorTest::AcceptedConnection(TCPSocket *new_socket) { void AdvancedTCPConnectorTest::AcceptedConnection(TCPSocket *new_socket) {
OLA_ASSERT_NOT_NULL(new_socket); OLA_ASSERT_NOT_NULL(new_socket);
GenericSocketAddress address = new_socket->GetPeerAddress(); GenericSocketAddress address = new_socket->GetPeerAddress();
OLA_ASSERT_TRUE(address.Family() == AF_INET); OLA_ASSERT_EQ(address.Family(), static_cast<uint16_t>(AF_INET));
OLA_INFO << "Connection from " << address; OLA_INFO << "Connection from " << address;


// terminate the ss when this connection is closed // terminate the ss when this connection is closed
Expand All @@ -415,7 +415,7 @@ void AdvancedTCPConnectorTest::OnConnect(TCPSocket *socket) {
OLA_ASSERT_NOT_NULL(socket); OLA_ASSERT_NOT_NULL(socket);


GenericSocketAddress address = socket->GetPeerAddress(); GenericSocketAddress address = socket->GetPeerAddress();
OLA_ASSERT_TRUE(address.Family() == AF_INET); OLA_ASSERT_EQ(address.Family(), static_cast<uint16_t>(AF_INET));
OLA_ASSERT_EQ(m_localhost, address.V4Addr().Host()); OLA_ASSERT_EQ(m_localhost, address.V4Addr().Host());


m_connected_socket = socket; m_connected_socket = socket;
Expand Down
21 changes: 19 additions & 2 deletions common/network/Interface.cpp
Expand Up @@ -117,16 +117,32 @@ Interface& Interface::operator=(const Interface &other) {
} }




bool Interface::operator==(const Interface &other) { bool Interface::operator==(const Interface &other) const {
return (name == other.name && return (name == other.name &&
ip_address == other.ip_address && ip_address == other.ip_address &&
bcast_address == other.bcast_address &&
subnet_mask == other.subnet_mask && subnet_mask == other.subnet_mask &&
hw_address == other.hw_address &&
loopback == other.loopback && loopback == other.loopback &&
index == other.index && index == other.index &&
type == other.type); type == other.type);
} }




string Interface::ToString(const string &separator) const {
std::ostringstream str;
str << name << separator
<< "Index: " << index << separator
<< "IP: " << ip_address << separator
<< "Broadcast: " << bcast_address << separator
<< "Subnet: " << subnet_mask << separator
<< "Type: " << type << separator
<< "MAC: " << hw_address << separator
<< "Loopback: " << loopback;
return str.str();
}


/** /**
* Create a new interface builder * Create a new interface builder
*/ */
Expand Down Expand Up @@ -228,8 +244,9 @@ Interface InterfaceBuilder::Construct() {
bool InterfaceBuilder::SetAddress(const string &str, bool InterfaceBuilder::SetAddress(const string &str,
IPV4Address *target) { IPV4Address *target) {
IPV4Address tmp_address; IPV4Address tmp_address;
if (!IPV4Address::FromString(str, &tmp_address)) if (!IPV4Address::FromString(str, &tmp_address)) {
return false; return false;
}
*target = tmp_address; *target = tmp_address;
return true; return true;
} }
Expand Down
24 changes: 14 additions & 10 deletions common/network/InterfacePicker.cpp
Expand Up @@ -44,7 +44,7 @@ using std::vector;
* @param iface, the interface to populate * @param iface, the interface to populate
* @param ip_or_name the IP address or interface name of the local interface * @param ip_or_name the IP address or interface name of the local interface
* we'd prefer to use. * we'd prefer to use.
* @param options a Options struct configuring ChooseInterface * @param options an Options struct configuring ChooseInterface
* @return true if we found an interface, false otherwise * @return true if we found an interface, false otherwise
*/ */
// TODO(Simon): Change these to callback based code to reduce duplication. // TODO(Simon): Change these to callback based code to reduce duplication.
Expand Down Expand Up @@ -84,13 +84,15 @@ bool InterfacePicker::ChooseInterface(
} }
} }


if (!found && options.specific_only) if (!found && options.specific_only) {
return false; // No match and being fussy return false; // No match and being fussy
}


if (!found) if (!found) {
*iface = interfaces[0]; *iface = interfaces[0];
OLA_DEBUG << "Using interface " << iface->name << " (" << }
iface->ip_address << ")"; OLA_DEBUG << "Using interface " << iface->name << " ("
<< iface->ip_address << ")";
return true; return true;
} }


Expand All @@ -99,7 +101,7 @@ bool InterfacePicker::ChooseInterface(
* Select an interface to use by index * Select an interface to use by index
* @param iface, the interface to populate * @param iface, the interface to populate
* @param index the index of the local interface we'd prefer to use. * @param index the index of the local interface we'd prefer to use.
* @param options a Options struct configuring ChooseInterface * @param options an Options struct configuring ChooseInterface
* @return true if we found an interface, false otherwise * @return true if we found an interface, false otherwise
*/ */
// TODO(Simon): Change these to callback based code to reduce duplication. // TODO(Simon): Change these to callback based code to reduce duplication.
Expand All @@ -125,13 +127,15 @@ bool InterfacePicker::ChooseInterface(
} }
} }


if (!found && options.specific_only) if (!found && options.specific_only) {
return false; // No match and being fussy return false; // No match and being fussy
}


if (!found) if (!found) {
*iface = interfaces[0]; *iface = interfaces[0];
OLA_DEBUG << "Using interface " << iface->name << " (" << }
iface->ip_address << ") with index " << iface->index; OLA_DEBUG << "Using interface " << iface->name << " ("
<< iface->ip_address << ") with index " << iface->index;
return true; return true;
} }


Expand Down
22 changes: 8 additions & 14 deletions common/network/InterfacePickerTest.cpp
Expand Up @@ -75,13 +75,7 @@ void InterfacePickerTest::testGetInterfaces() {
vector<Interface>::iterator iter; vector<Interface>::iterator iter;
cout << endl; cout << endl;
for (iter = interfaces.begin(); iter != interfaces.end(); ++iter) { for (iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
cout << iter->name << endl; cout << iter->ToString("\n ") << endl;
cout << " index: " << iter->index << endl;
cout << " ip: " << iter->ip_address << endl;
cout << " bcast: " << iter->bcast_address << endl;
cout << " subnet: " << iter->subnet_mask << endl;
cout << " type: " << iter->type << endl;
cout << " hw_addr: " << iter->hw_address << endl;
cout << endl; cout << endl;
cout << "---------------" << endl; cout << "---------------" << endl;
} }
Expand Down Expand Up @@ -133,7 +127,7 @@ void InterfacePickerTest::testChooseInterface() {


FakeInterfacePicker picker2(interfaces); FakeInterfacePicker picker2(interfaces);
OLA_ASSERT_TRUE(picker2.ChooseInterface(&iface, "192.168.1.1")); OLA_ASSERT_TRUE(picker2.ChooseInterface(&iface, "192.168.1.1"));
OLA_ASSERT_TRUE(iface1 == iface); OLA_ASSERT_EQ(iface1, iface);


// check that preferred works // check that preferred works
Interface iface2; Interface iface2;
Expand All @@ -144,24 +138,24 @@ void InterfacePickerTest::testChooseInterface() {


FakeInterfacePicker picker3(interfaces); FakeInterfacePicker picker3(interfaces);
OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, "192.168.1.1")); OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, "192.168.1.1"));
OLA_ASSERT_TRUE(iface2 == iface); OLA_ASSERT_EQ(iface2, iface);


// now check for iface name // now check for iface name
OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, "eth0")); OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, "eth0"));
OLA_ASSERT_TRUE(iface1 == iface); OLA_ASSERT_EQ(iface1, iface);


OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, "eth1")); OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, "eth1"));
OLA_ASSERT_TRUE(iface2 == iface); OLA_ASSERT_EQ(iface2, iface);


// a invalid address should return the first one // a invalid address should return the first one
OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, "foo")); OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, "foo"));
OLA_ASSERT_TRUE(iface1 == iface); OLA_ASSERT_EQ(iface1, iface);


// now check by iface index // now check by iface index
OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, 2)); OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, 2));
OLA_ASSERT_TRUE(iface2 == iface); OLA_ASSERT_EQ(iface2, iface);


// an invalid index should return the first one // an invalid index should return the first one
OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, 3)); OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, 3));
OLA_ASSERT_TRUE(iface1 == iface); OLA_ASSERT_EQ(iface1, iface);
} }
18 changes: 17 additions & 1 deletion common/network/InterfaceTest.cpp
Expand Up @@ -112,7 +112,7 @@ void InterfaceTest::testBuilder() {
// now build from IPV4Address and MACAddress objects // now build from IPV4Address and MACAddress objects
IPV4Address ip_address, netmask, broadcast_address; IPV4Address ip_address, netmask, broadcast_address;
IPV4Address::FromString("10.0.0.1", &ip_address); IPV4Address::FromString("10.0.0.1", &ip_address);
IPV4Address::FromString("10.0.255.255", &netmask); IPV4Address::FromString("255.255.0.0", &netmask);
IPV4Address::FromString("10.0.255.255", &broadcast_address); IPV4Address::FromString("10.0.255.255", &broadcast_address);
MACAddress mac_address; MACAddress mac_address;
MACAddress::FromString("ba:98:76:54:32:10", &mac_address); MACAddress::FromString("ba:98:76:54:32:10", &mac_address);
Expand All @@ -129,4 +129,20 @@ void InterfaceTest::testBuilder() {
OLA_ASSERT_EQ(broadcast_address, interface.bcast_address); OLA_ASSERT_EQ(broadcast_address, interface.bcast_address);
OLA_ASSERT_EQ(netmask, interface.subnet_mask); OLA_ASSERT_EQ(netmask, interface.subnet_mask);
OLA_ASSERT_EQ(mac_address, interface.hw_address); OLA_ASSERT_EQ(mac_address, interface.hw_address);

// test stringification
OLA_ASSERT_EQ(string("eth1, Index: -1, IP: 10.0.0.1, Broadcast: "
"10.0.255.255, Subnet: 255.255.0.0, Type: 65535, MAC: "
"ba:98:76:54:32:10, Loopback: 0"),
interface.ToString());
OLA_ASSERT_EQ(string("eth1|Index: -1|IP: 10.0.0.1|Broadcast: 10.0.255.255|"
"Subnet: 255.255.0.0|Type: 65535|MAC: "
"ba:98:76:54:32:10|Loopback: 0"),
interface.ToString("|"));
std::ostringstream str;
str << interface;
OLA_ASSERT_EQ(string("eth1, Index: -1, IP: 10.0.0.1, Broadcast: "
"10.0.255.255, Subnet: 255.255.0.0, Type: 65535, MAC: "
"ba:98:76:54:32:10, Loopback: 0"),
str.str());
} }
4 changes: 2 additions & 2 deletions common/network/SocketTest.cpp
Expand Up @@ -343,7 +343,7 @@ void SocketTest::ReceiveSendAndClose(ConnectedDescriptor *socket) {
void SocketTest::NewConnectionSend(TCPSocket *new_socket) { void SocketTest::NewConnectionSend(TCPSocket *new_socket) {
OLA_ASSERT_TRUE(new_socket); OLA_ASSERT_TRUE(new_socket);
GenericSocketAddress address = new_socket->GetPeerAddress(); GenericSocketAddress address = new_socket->GetPeerAddress();
OLA_ASSERT_TRUE(address.Family() == AF_INET); OLA_ASSERT_EQ(address.Family(), static_cast<uint16_t>(AF_INET));
OLA_INFO << "Connection from " << address; OLA_INFO << "Connection from " << address;
ssize_t bytes_sent = new_socket->Send( ssize_t bytes_sent = new_socket->Send(
static_cast<const uint8_t*>(test_cstring), static_cast<const uint8_t*>(test_cstring),
Expand All @@ -361,7 +361,7 @@ void SocketTest::NewConnectionSend(TCPSocket *new_socket) {
void SocketTest::NewConnectionSendAndClose(TCPSocket *new_socket) { void SocketTest::NewConnectionSendAndClose(TCPSocket *new_socket) {
OLA_ASSERT_NOT_NULL(new_socket); OLA_ASSERT_NOT_NULL(new_socket);
GenericSocketAddress address = new_socket->GetPeerAddress(); GenericSocketAddress address = new_socket->GetPeerAddress();
OLA_ASSERT_TRUE(address.Family() == AF_INET); OLA_ASSERT_EQ(address.Family(), static_cast<uint16_t>(AF_INET));
OLA_INFO << "Connection from " << address; OLA_INFO << "Connection from " << address;
ssize_t bytes_sent = new_socket->Send( ssize_t bytes_sent = new_socket->Send(
static_cast<const uint8_t*>(test_cstring), static_cast<const uint8_t*>(test_cstring),
Expand Down
2 changes: 1 addition & 1 deletion common/network/TCPConnectorTest.cpp
Expand Up @@ -279,7 +279,7 @@ void TCPConnectorTest::testEarlyDestruction() {
void TCPConnectorTest::AcceptedConnection(TCPSocket *new_socket) { void TCPConnectorTest::AcceptedConnection(TCPSocket *new_socket) {
OLA_ASSERT_NOT_NULL(new_socket); OLA_ASSERT_NOT_NULL(new_socket);
GenericSocketAddress address = new_socket->GetPeerAddress(); GenericSocketAddress address = new_socket->GetPeerAddress();
OLA_ASSERT_TRUE(address.Family() == AF_INET); OLA_ASSERT_EQ(address.Family(), static_cast<uint16_t>(AF_INET));
OLA_INFO << "Connection from " << address; OLA_INFO << "Connection from " << address;


// terminate the ss when this connection is closed // terminate the ss when this connection is closed
Expand Down
6 changes: 3 additions & 3 deletions data/rdm/manufacturer_pids.proto
Expand Up @@ -3556,7 +3556,7 @@ manufacturer {
set_sub_device_range: ROOT_DEVICE set_sub_device_range: ROOT_DEVICE
} }
pid { pid {
name: "LIGHTSENSOR_LEVEL_TRIGGER_ENABLE" name: "LIGHT_SENSOR_LEVEL_TRIGGER_ENABLE"
value: 33032 value: 33032
get_request { get_request {
} }
Expand All @@ -3578,7 +3578,7 @@ manufacturer {
set_sub_device_range: ROOT_DEVICE set_sub_device_range: ROOT_DEVICE
} }
pid { pid {
name: "CAPTURE_CURRENT_SENSOR_VALUE" name: "CAPTURE_CURRENT_LIGHT_LEVEL"
value: 33033 value: 33033
set_request { set_request {
} }
Expand All @@ -3587,7 +3587,7 @@ manufacturer {
set_sub_device_range: ROOT_DEVICE set_sub_device_range: ROOT_DEVICE
} }
pid { pid {
name: "LIGHTSENSOR_TRIGGER_LEVEL" name: "LIGHT_SENSOR_TRIGGER_LEVEL"
value: 33034 value: 33034
get_request { get_request {
} }
Expand Down
6 changes: 3 additions & 3 deletions include/ola/network/IPV4Address.h
Expand Up @@ -139,8 +139,8 @@ class IPV4Address {
* should be at least LENGTH bytes. * should be at least LENGTH bytes.
* @note The address is copied in network byte order. * @note The address is copied in network byte order.
*/ */
void Get(uint8_t ptr[LENGTH]) { void Get(uint8_t ptr[LENGTH]) const {
memcpy(ptr, reinterpret_cast<uint8_t*>(&m_address), LENGTH); memcpy(ptr, reinterpret_cast<const uint8_t*>(&m_address), LENGTH);
} }


/** /**
Expand All @@ -153,7 +153,7 @@ class IPV4Address {
* @brief Write the string representation of this IPV4Address to an * @brief Write the string representation of this IPV4Address to an
* ostream. * ostream.
* @param out the ostream to write to. * @param out the ostream to write to.
* @param address to address to write. * @param address the address to write.
*/ */
friend std::ostream& operator<<(std::ostream &out, friend std::ostream& operator<<(std::ostream &out,
const IPV4Address &address) { const IPV4Address &address) {
Expand Down
20 changes: 19 additions & 1 deletion include/ola/network/Interface.h
Expand Up @@ -47,7 +47,25 @@ class Interface {
uint16_t type = ARP_VOID_TYPE); uint16_t type = ARP_VOID_TYPE);
Interface(const Interface &other); Interface(const Interface &other);
Interface& operator=(const Interface &other); Interface& operator=(const Interface &other);
bool operator==(const Interface &other); bool operator==(const Interface &other) const;

/**
* @brief Convert the Interface to a string.
* @param separator the separator to use between items, defaults to ", ".
* @returns the string representation of this Interface.
*/
std::string ToString(const std::string &separator = ", ") const;

/**
* @brief Write the string representation of this Interface to an
* ostream.
* @param out the ostream to write to.
* @param iface the iface to write.
*/
friend std::ostream& operator<<(std::ostream &out,
const Interface &iface) {
return out << iface.ToString();
}


std::string name; std::string name;
IPV4Address ip_address; IPV4Address ip_address;
Expand Down
2 changes: 1 addition & 1 deletion include/ola/testing/TestUtils.h
Expand Up @@ -168,7 +168,7 @@ inline void _FailIf(const SourceLine &source_line,
ola::testing::ASSERT_DATA_EQUALS(OLA_SOURCELINE(), \ ola::testing::ASSERT_DATA_EQUALS(OLA_SOURCELINE(), \
(expected.GetRaw()), (expected.Size()), \ (expected.GetRaw()), (expected.Size()), \
(actual.GetRaw()), (actual.Size())); \ (actual.GetRaw()), (actual.Size())); \
OLA_ASSERT_TRUE(expected == actual) OLA_ASSERT_EQ(expected, actual)


#define OLA_ASSERT_NULL(value) \ #define OLA_ASSERT_NULL(value) \
CPPUNIT_NS::Asserter::failIf( \ CPPUNIT_NS::Asserter::failIf( \
Expand Down
2 changes: 1 addition & 1 deletion include/olad/PluginAdaptor.h
Expand Up @@ -96,7 +96,7 @@ class PluginAdaptor: public ola::io::SelectServerInterface {
* @brief Return the instance name for the OLA server * @brief Return the instance name for the OLA server
* @return a string which is the instance name * @return a string which is the instance name
*/ */
const std::string InstanceName(); const std::string InstanceName() const;


ExportMap *GetExportMap() const { ExportMap *GetExportMap() const {
return m_export_map; return m_export_map;
Expand Down
8 changes: 5 additions & 3 deletions libs/acn/E131Node.cpp
Expand Up @@ -171,12 +171,14 @@ bool E131Node::Start() {
return false; return false;
} }


if (!m_socket.Bind( if (!m_socket.Bind(IPV4SocketAddress(IPV4Address::WildCard(),
IPV4SocketAddress(IPV4Address::WildCard(), m_options.port))) m_options.port))) {
return false; return false;
}


if (!m_socket.EnableBroadcast()) if (!m_socket.EnableBroadcast()) {
return false; return false;
}


m_socket.SetTos(m_options.dscp); m_socket.SetTos(m_options.dscp);
m_socket.SetMulticastInterface(m_interface.ip_address); m_socket.SetMulticastInterface(m_interface.ip_address);
Expand Down
6 changes: 4 additions & 2 deletions libs/acn/e131_loadtest.cpp
Expand Up @@ -52,8 +52,9 @@ bool SendFrames(E131Node *node, DmxBuffer *buffer,
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
ola::AppInit(&argc, argv, "", "Run the E1.31 load test."); ola::AppInit(&argc, argv, "", "Run the E1.31 load test.");


if (FLAGS_universes == 0 || FLAGS_fps == 0) if (FLAGS_universes == 0 || FLAGS_fps == 0) {
return -1; return -1;
}


unsigned int fps = min(40u, static_cast<unsigned int>(FLAGS_fps)); unsigned int fps = min(40u, static_cast<unsigned int>(FLAGS_fps));
uint16_t universes = FLAGS_universes; uint16_t universes = FLAGS_universes;
Expand All @@ -63,8 +64,9 @@ int main(int argc, char* argv[]) {
SelectServer ss; SelectServer ss;


E131Node node(&ss, "", E131Node::Options()); E131Node node(&ss, "", E131Node::Options());
if (!node.Start()) if (!node.Start()) {
return -1; return -1;
}


ss.AddReadDescriptor(node.GetSocket()); ss.AddReadDescriptor(node.GetSocket());
ss.RegisterRepeatingTimeout( ss.RegisterRepeatingTimeout(
Expand Down

0 comments on commit b1f0773

Please sign in to comment.