Permalink
Browse files

Merge pull request #1532 from peternewman/protobuf-3.6

Various tidying up/improvements
  • Loading branch information...
peternewman committed Jan 8, 2019
2 parents cb021b4 + 458fbb9 commit b1f0773f3113a60a1c7b2b082e092bca1eb131ca
@@ -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),
// 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
import java.nio.ByteOrder;
byte[] header = ByteBuffer.allocate(4).order(ByteOrder.nativeOrder()).putInt(headerContent).array();
int headerValue = ByteBuffer.wrap(header).order(ByteOrder.nativeOrder()).getInt();
@@ -271,6 +271,7 @@ cache:
- $HOME/.cache/pip # pip cache
- $HOME/.npm # npm cache
- $HOME/.ccache # ccache cache
- $HOME/.m2 # maven cache

before_cache:
- rm -f $HOME/.cache/pip/log/debug.log # erase log
@@ -358,8 +358,15 @@ void FlagRegistry::GenManPage() {
str << " <" << flag->arg_type() << ">";
}
if (flag->short_opt()) {
short_flag_lines.push_back(
OptionPair(str.str(), iter->second->help()));
if (flag->name() == FLAGS_version.name()) {
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 {
long_flag_lines.push_back(
OptionPair(str.str(), iter->second->help()));
@@ -399,7 +399,7 @@ uint16_t AdvancedTCPConnectorTest::ReservePort() {
void AdvancedTCPConnectorTest::AcceptedConnection(TCPSocket *new_socket) {
OLA_ASSERT_NOT_NULL(new_socket);
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;

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

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());

m_connected_socket = socket;
@@ -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 &&
ip_address == other.ip_address &&
bcast_address == other.bcast_address &&
subnet_mask == other.subnet_mask &&
hw_address == other.hw_address &&
loopback == other.loopback &&
index == other.index &&
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
*/
@@ -228,8 +244,9 @@ Interface InterfaceBuilder::Construct() {
bool InterfaceBuilder::SetAddress(const string &str,
IPV4Address *target) {
IPV4Address tmp_address;
if (!IPV4Address::FromString(str, &tmp_address))
if (!IPV4Address::FromString(str, &tmp_address)) {
return false;
}
*target = tmp_address;
return true;
}
@@ -44,7 +44,7 @@ using std::vector;
* @param iface, the interface to populate
* @param ip_or_name the IP address or interface name 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
*/
// TODO(Simon): Change these to callback based code to reduce duplication.
@@ -84,13 +84,15 @@ bool InterfacePicker::ChooseInterface(
}
}

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

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

@@ -99,7 +101,7 @@ bool InterfacePicker::ChooseInterface(
* Select an interface to use by index
* @param iface, the interface to populate
* @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
*/
// TODO(Simon): Change these to callback based code to reduce duplication.
@@ -125,13 +127,15 @@ bool InterfacePicker::ChooseInterface(
}
}

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

if (!found)
if (!found) {
*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;
}

@@ -75,13 +75,7 @@ void InterfacePickerTest::testGetInterfaces() {
vector<Interface>::iterator iter;
cout << endl;
for (iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
cout << iter->name << 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 << iter->ToString("\n ") << endl;
cout << endl;
cout << "---------------" << endl;
}
@@ -133,7 +127,7 @@ void InterfacePickerTest::testChooseInterface() {

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

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

FakeInterfacePicker picker3(interfaces);
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
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(iface2 == iface);
OLA_ASSERT_EQ(iface2, iface);

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

// now check by iface index
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
OLA_ASSERT_TRUE(picker3.ChooseInterface(&iface, 3));
OLA_ASSERT_TRUE(iface1 == iface);
OLA_ASSERT_EQ(iface1, iface);
}
@@ -112,7 +112,7 @@ void InterfaceTest::testBuilder() {
// now build from IPV4Address and MACAddress objects
IPV4Address ip_address, netmask, broadcast_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);
MACAddress mac_address;
MACAddress::FromString("ba:98:76:54:32:10", &mac_address);
@@ -129,4 +129,20 @@ void InterfaceTest::testBuilder() {
OLA_ASSERT_EQ(broadcast_address, interface.bcast_address);
OLA_ASSERT_EQ(netmask, interface.subnet_mask);
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());
}
@@ -343,7 +343,7 @@ void SocketTest::ReceiveSendAndClose(ConnectedDescriptor *socket) {
void SocketTest::NewConnectionSend(TCPSocket *new_socket) {
OLA_ASSERT_TRUE(new_socket);
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;
ssize_t bytes_sent = new_socket->Send(
static_cast<const uint8_t*>(test_cstring),
@@ -361,7 +361,7 @@ void SocketTest::NewConnectionSend(TCPSocket *new_socket) {
void SocketTest::NewConnectionSendAndClose(TCPSocket *new_socket) {
OLA_ASSERT_NOT_NULL(new_socket);
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;
ssize_t bytes_sent = new_socket->Send(
static_cast<const uint8_t*>(test_cstring),
@@ -279,7 +279,7 @@ void TCPConnectorTest::testEarlyDestruction() {
void TCPConnectorTest::AcceptedConnection(TCPSocket *new_socket) {
OLA_ASSERT_NOT_NULL(new_socket);
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;

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

/**
@@ -153,7 +153,7 @@ class IPV4Address {
* @brief Write the string representation of this IPV4Address to an
* ostream.
* @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,
const IPV4Address &address) {
@@ -47,7 +47,25 @@ class Interface {
uint16_t type = ARP_VOID_TYPE);
Interface(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;
IPV4Address ip_address;
@@ -168,7 +168,7 @@ inline void _FailIf(const SourceLine &source_line,
ola::testing::ASSERT_DATA_EQUALS(OLA_SOURCELINE(), \
(expected.GetRaw()), (expected.Size()), \
(actual.GetRaw()), (actual.Size())); \
OLA_ASSERT_TRUE(expected == actual)
OLA_ASSERT_EQ(expected, actual)

#define OLA_ASSERT_NULL(value) \
CPPUNIT_NS::Asserter::failIf( \
@@ -96,7 +96,7 @@ class PluginAdaptor: public ola::io::SelectServerInterface {
* @brief Return the instance name for the OLA server
* @return a string which is the instance name
*/
const std::string InstanceName();
const std::string InstanceName() const;

ExportMap *GetExportMap() const {
return m_export_map;
@@ -171,12 +171,14 @@ bool E131Node::Start() {
return false;
}

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

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

m_socket.SetTos(m_options.dscp);
m_socket.SetMulticastInterface(m_interface.ip_address);
@@ -52,8 +52,9 @@ bool SendFrames(E131Node *node, DmxBuffer *buffer,
int main(int argc, char* argv[]) {
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;
}

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

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

ss.AddReadDescriptor(node.GetSocket());
ss.RegisterRepeatingTimeout(
Oops, something went wrong.

0 comments on commit b1f0773

Please sign in to comment.