Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
Browse files Browse the repository at this point in the history
…nto libusb
  • Loading branch information
peternewman committed Dec 26, 2014
2 parents 99b2008 + 242d13b commit c476723
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 41 deletions.
36 changes: 24 additions & 12 deletions common/file/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ static string ConvertPathSeparators(const string &path) {
return result;
}

void FindMatchingFiles(const string &directory,
bool FindMatchingFiles(const string &directory,
const string &prefix,
vector<string> *files) {
vector<string> prefixes;
prefixes.push_back(prefix);
FindMatchingFiles(directory, prefixes, files);
return FindMatchingFiles(directory, prefixes, files);
}

void FindMatchingFiles(const string &directory,
bool FindMatchingFiles(const string &directory,
const vector<string> &prefixes,
vector<string> *files) {
if (directory.empty() || prefixes.empty())
return;
if (directory.empty() || prefixes.empty()) {
return true;
}

#ifdef _WIN32
WIN32_FIND_DATA find_file_data;
Expand All @@ -89,7 +90,7 @@ void FindMatchingFiles(const string &directory,
if (h_find == INVALID_HANDLE_VALUE) {
OLA_WARN << "Find first file failed: " << GetLastError() << " for "
<< search_pattern;
return;
return false;
}

do {
Expand All @@ -110,10 +111,14 @@ void FindMatchingFiles(const string &directory,
struct dirent *dir_ent_p;
if ((dp = opendir(directory.data())) == NULL) {
OLA_WARN << "Could not open " << directory << ":" << strerror(errno);
return;
return false;
}

if (readdir_r(dp, &dir_ent, &dir_ent_p)) {
OLA_WARN << "readdir_r(" << directory << "): " << strerror(errno);
return false;
}

readdir_r(dp, &dir_ent, &dir_ent_p);
while (dir_ent_p != NULL) {
vector<string>::const_iterator iter;
for (iter = prefixes.begin(); iter != prefixes.end(); ++iter) {
Expand All @@ -123,15 +128,22 @@ void FindMatchingFiles(const string &directory,
files->push_back(str.str());
}
}
readdir_r(dp, &dir_ent, &dir_ent_p);
if (readdir_r(dp, &dir_ent, &dir_ent_p)) {
OLA_WARN << "readdir_r(" << directory << "): " << strerror(errno);
return false;
}
}
if (closedir(dp)) {
OLA_WARN << "closedir(" << directory << "): " << strerror(errno);
return false;
}
closedir(dp);
#endif
return true;
}

void ListDirectory(const string& directory,
bool ListDirectory(const string& directory,
vector<string> *files) {
FindMatchingFiles(directory, "", files);
return FindMatchingFiles(directory, "", files);
}

string FilenameFromPathOrDefault(const string &path,
Expand Down
12 changes: 8 additions & 4 deletions common/io/IOStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,21 @@ void IOStack::Purge() {
* Dump this IOStack as a human readable string
*/
void IOStack::Dump(std::ostream *output) {
unsigned int length = 0;
BlockVector::const_iterator iter = m_blocks.begin();
for (; iter != m_blocks.end(); ++iter) {
length += (*iter)->Size();
}

// For now just alloc memory for the entire thing
unsigned int length = Size();
uint8_t *tmp = new uint8_t[length];

unsigned int offset = 0;
BlockVector::const_iterator iter = m_blocks.begin();
for (; iter != m_blocks.end(); ++iter) {
for (iter = m_blocks.begin(); iter != m_blocks.end(); ++iter) {
offset += (*iter)->Copy(tmp + offset, length - offset);
}

ola::FormatData(output, tmp, length);
ola::FormatData(output, tmp, offset);
delete[] tmp;
}

Expand Down
2 changes: 1 addition & 1 deletion common/io/StdinHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ StdinHandler::~StdinHandler() {


void StdinHandler::HandleData() {
char c = getchar();
int c = getchar();
if (m_callback.get())
m_callback->Run(c);
}
Expand Down
3 changes: 1 addition & 2 deletions common/rdm/PidStoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ void PidStoreTest::testPidStoreDirectoryLoad() {
GetTestDataFile("pids")));
OLA_ASSERT_NOT_NULL(root_store.get());
// check version
OLA_ASSERT_EQ(static_cast<uint64_t>(1302986774),
root_store->Version());
OLA_ASSERT_EQ(static_cast<uint64_t>(1302986774), root_store->Version());

// Check all the esta pids are there
const PidStore *esta_store = root_store->EstaStore();
Expand Down
1 change: 1 addition & 0 deletions common/rdm/SubDeviceDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ SubDeviceDispatcher::FanOutTracker::FanOutTracker(
: m_number_of_subdevices(number_of_subdevices),
m_responses_so_far(0),
m_callback(callback),
m_response_code(RDM_COMPLETED_OK),
m_response(NULL) {
}

Expand Down
5 changes: 4 additions & 1 deletion common/rpc/RpcChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,10 @@ void RpcChannel::HandleResponse(RpcMessage *msg) {
auto_ptr<OutstandingResponse> response(
STLLookupAndRemovePtr(&m_responses, msg->id()));
if (response.get()) {
response->reply->ParseFromString(msg->buffer());
if (!response->reply->ParseFromString(msg->buffer())) {
OLA_WARN << "Failed to parse response proto for "
<< response->reply->GetTypeName();
}
response->callback->Run();
}
}
Expand Down
8 changes: 6 additions & 2 deletions doxygen/examples/udp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ int main() {
IPV4SocketAddress listen_address(IPV4Address::WildCard(), PORT);

UDPSocket udp_socket;
udp_socket.Init();
udp_socket.Bind(listen_address);
if (!udp_socket.Init()) {
return -1;
}
if (!udp_socket.Bind(listen_address)) {
return -1;
}
udp_socket.SetOnData(ola::NewCallback(&ReceiveMessage, &udp_socket));

ola::io::SelectServer ss;
Expand Down
4 changes: 2 additions & 2 deletions examples/ola-uni-stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class UniverseTracker {
void ResetStats();

protected:
void Input(char c);
void Input(int c);

private:
struct UniverseStats {
Expand Down Expand Up @@ -175,7 +175,7 @@ void UniverseTracker::ResetStats() {
cout << "Reset counters" << endl;
}

void UniverseTracker::Input(char c) {
void UniverseTracker::Input(int c) {
switch (c) {
case 'q':
m_wrapper->GetSelectServer()->Terminate();
Expand Down
12 changes: 12 additions & 0 deletions include/ola/base/FlagsPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class Flag : public BaseFlag {
m_name = NewCanonicalName(name);
}

~Flag() {
delete[] m_name;
}

const char *name() const { return m_name; }
bool has_arg() const { return true; }
bool default_value() const { return m_default; }
Expand Down Expand Up @@ -206,6 +210,10 @@ class Flag<bool> : public BaseFlag {
}
}

~Flag() {
delete[] m_name;
}

const char *name() const { return m_name; }
bool has_arg() const { return m_has_arg; }
bool default_value() const { return m_default; }
Expand Down Expand Up @@ -252,6 +260,10 @@ class Flag<std::string> : public BaseFlag {
m_name = NewCanonicalName(name);
}

~Flag() {
delete[] m_name;
}

const char *name() const { return m_name; }
bool has_arg() const { return true; }
std::string default_value() const { return m_default; }
Expand Down
9 changes: 6 additions & 3 deletions include/ola/file/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ extern const char PATH_SEPARATOR;
* @param[in] prefix the prefix to match on
* @param[out] files a pointer to a vector with the absolute path of the
* matching files.
* @returns false if there was an error, true otherwise.
*/
void FindMatchingFiles(const std::string &directory,
bool FindMatchingFiles(const std::string &directory,
const std::string &prefix,
std::vector<std::string> *files);

Expand All @@ -46,8 +47,9 @@ void FindMatchingFiles(const std::string &directory,
* @param[in] prefixes the prefixes to match on
* @param[out] files a pointer to a vector with the absolute path of the
* matching files.
* @returns false if there was an error, true otherwise.
*/
void FindMatchingFiles(const std::string &directory,
bool FindMatchingFiles(const std::string &directory,
const std::vector<std::string> &prefixes,
std::vector<std::string> *files);

Expand All @@ -56,8 +58,9 @@ void FindMatchingFiles(const std::string &directory,
* the full path to the file.
* @param[in] directory the directory to list
* @param[out] files a pointer to a string vector that will receive file paths
* @returns false if there was an error, true otherwise.
*/
void ListDirectory(const std::string& directory,
bool ListDirectory(const std::string& directory,
std::vector<std::string> *files);

/**
Expand Down
2 changes: 1 addition & 1 deletion include/ola/io/StdinHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace io {

class StdinHandler {
public :
typedef ola::Callback1<void, char> InputCallback;
typedef ola::Callback1<void, int> InputCallback;

explicit StdinHandler(SelectServerInterface *ss, InputCallback *callback);
~StdinHandler();
Expand Down
8 changes: 6 additions & 2 deletions plugins/dummy/DummyPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ bool DummyPlugin::StartHook() {
&options.number_of_network_responders))
options.number_of_network_responders = DEFAULT_DEVICE_COUNT;

m_device = new DummyDevice(this, DEVICE_NAME, options);
m_device->Start();
std::auto_ptr<DummyDevice> device(
new DummyDevice(this, DEVICE_NAME, options));
if (!device->Start()) {
return false;
}
m_device = device.release();
m_plugin_adaptor->RegisterDevice(m_device);
return true;
}
Expand Down
11 changes: 8 additions & 3 deletions plugins/osc/OSCPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <stdlib.h>
#include <stdio.h>
#include <memory>
#include <string>
#include <vector>

Expand Down Expand Up @@ -97,9 +98,13 @@ bool OSCPlugin::StartHook() {
}

// Finally create the new OSCDevice, start it and register the device.
m_device = new OSCDevice(this, m_plugin_adaptor, udp_port,
port_addresses, port_configs);
m_device->Start();
std::auto_ptr<OSCDevice> device(
new OSCDevice(this, m_plugin_adaptor, udp_port, port_addresses,
port_configs));
if (!device->Start()) {
return false;
}
m_device = device.release();
m_plugin_adaptor->RegisterDevice(m_device);
return true;
}
Expand Down
11 changes: 9 additions & 2 deletions plugins/spi/SPIDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,15 @@ void SPIDevice::PopulateHardwareBackendOptions(

void SPIDevice::PopulateSoftwareBackendOptions(
SoftwareBackend::Options *options) {
StringToInt(m_preferences->GetValue(PortCountKey()), &options->outputs);
StringToInt(m_preferences->GetValue(SyncPortKey()), &options->sync_output);
if (!StringToInt(m_preferences->GetValue(PortCountKey()),
&options->outputs)) {
OLA_WARN << "Invalid integer value for " << PortCountKey();
}

if (!StringToInt(m_preferences->GetValue(SyncPortKey()),
&options->sync_output)) {
OLA_WARN << "Invalid integer value for " << SyncPortKey();
}
if (options->sync_output == -2) {
options->sync_output = options->outputs - 1;
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/spi/SPIPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ bool SPIPlugin::StartHook() {
vector<string> spi_files;
vector<string> spi_prefixes = m_preferences->GetMultipleValue(
SPI_DEVICE_PREFIX_KEY);
ola::file::FindMatchingFiles("/dev", spi_prefixes, &spi_files);
if (!ola::file::FindMatchingFiles("/dev", spi_prefixes, &spi_files)) {
return false;
}

ola::rdm::UIDAllocator uid_allocator(*base_uid);
vector<string>::const_iterator iter = spi_files.begin();
Expand Down
5 changes: 4 additions & 1 deletion plugins/usbpro/WidgetDetectorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ void WidgetDetectorThread::WaitUntilRunning() {
*/
bool WidgetDetectorThread::RunScan() {
vector<string> device_paths;
ola::file::FindMatchingFiles(m_directory, m_prefixes, &device_paths);
if (!ola::file::FindMatchingFiles(m_directory, m_prefixes, &device_paths)) {
// We want to run the scan next time in case the problem is resolved.
return true;
}

vector<string>::iterator it;
for (it = device_paths.begin(); it != device_paths.end(); ++it) {
Expand Down
2 changes: 1 addition & 1 deletion tools/e133/SimpleE133Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void SimpleE133Node::RemoveEndpoint(uint16_t endpoint_id) {
/**
* Called when there is data on stdin.
*/
void SimpleE133Node::Input(char c) {
void SimpleE133Node::Input(int c) {
switch (c) {
case 'c':
m_e133_device.CloseTCPConnection();
Expand Down
2 changes: 1 addition & 1 deletion tools/e133/SimpleE133Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SimpleE133Node {
const UID m_uid;
const IPV4Address m_ip_address;

void Input(char c);
void Input(int c);
void DumpTCPStats();
void SendUnsolicited();

Expand Down
4 changes: 2 additions & 2 deletions tools/e133/e133-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SimpleE133Monitor {
ola::e133::MessageBuilder m_message_builder;
ola::e133::DeviceManager m_device_manager;

void Input(char c);
void Input(int c);

bool EndpointRequest(
const IPV4Address &source,
Expand Down Expand Up @@ -122,7 +122,7 @@ void SimpleE133Monitor::AddIP(const IPV4Address &ip_address) {
m_device_manager.AddDevice(ip_address);
}

void SimpleE133Monitor::Input(char c) {
void SimpleE133Monitor::Input(int c) {
switch (c) {
case 'q':
m_ss.Terminate();
Expand Down

0 comments on commit c476723

Please sign in to comment.