Skip to content
Snippets Groups Projects
Commit d78c5f40 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Minor code tidy

parent 3d95a28e
No related branches found
No related tags found
No related merge requests found
Pipeline #9625 failed
/*
* Copyright 2019 Nicolas Pope
* Copyright 2019 Nicolas Pope. All rights reserved.
*
* See LICENSE.
*/
#include <glog/logging.h>
......@@ -45,18 +47,11 @@ static json config;
static bool findConfiguration(const string &file) {
ifstream i;
if (file != "") {
i.open(file);
}
if (!i.is_open()) {
i.open("./config.json");
}
if (!i.is_open()) {
i.open(FTL_LOCAL_CONFIG_ROOT "/config.json");
}
if (!i.is_open()) {
i.open(FTL_GLOBAL_CONFIG_ROOT "/config.json");
}
if (file != "") i.open(file);
if (!i.is_open()) i.open("./config.json");
if (!i.is_open()) i.open(FTL_LOCAL_CONFIG_ROOT "/config.json");
if (!i.is_open()) i.open(FTL_GLOBAL_CONFIG_ROOT "/config.json");
if (!i.is_open()) return false;
i >> config;
return true;
}
......@@ -140,7 +135,7 @@ static void run(const string &file) {
// Choose and configure disparity algorithm
auto disparity = Disparity::create(config["disparity"]);
Mat l, r, disparity32F, depth32F, lbw, rbw;
Mat l, r, disparity;
Display display(calibrate, config["display"]);
......@@ -156,10 +151,10 @@ static void run(const string &file) {
sync->get(ftl::LEFT, l);
sync->get(ftl::RIGHT, r);
disparity->compute(l, r, disparity32F);
disparity->compute(l, r, disparity);
// Send RGB+Depth images for local rendering
display.render(l, disparity32F);
display.render(l, disparity);
// streamer.send(l, disparity32F);
}
......
......@@ -49,16 +49,15 @@ using namespace std;
int Socket::rpcid__ = 0;
// TODO(nick) Move to tcp_internal.cpp
static int tcpConnect(URI &uri) {
int rc;
sockaddr_in destAddr;
//std::cerr << "TCP Connect: " << uri.getHost() << " : " << uri.getPort() << std::endl;
#ifdef WIN32
WSAData wsaData;
if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) {
//ERROR
LOG(ERROR) << "Could not initiate sockets";
return INVALID_SOCKET;
}
#endif
......@@ -67,6 +66,7 @@ static int tcpConnect(URI &uri) {
int csocket = socket(AF_INET, SOCK_STREAM, 0);
if (csocket == INVALID_SOCKET) {
LOG(ERROR) << "Unable to create TCP socket";
return INVALID_SOCKET;
}
......@@ -84,7 +84,6 @@ static int tcpConnect(URI &uri) {
#endif
LOG(ERROR) << "Address not found : " << uri.getHost() << std::endl;
return INVALID_SOCKET;
}
......@@ -120,8 +119,6 @@ static int tcpConnect(URI &uri) {
arg &= (~O_NONBLOCK);
fcntl(csocket, F_SETFL, arg) < 0)*/
// Handshake??
return csocket;
}
......@@ -386,6 +383,7 @@ void Socket::_dispatchReturn(const std::string &d) {
Dispatcher::response_t the_result;
unpacked.get().convert(the_result);
// Msgpack stipulates that 1 means return message
if (std::get<0>(the_result) != 1) {
LOG(ERROR) << "Bad RPC return message";
return;
......@@ -399,6 +397,8 @@ void Socket::_dispatchReturn(const std::string &d) {
if (callbacks_.count(id) > 0) {
LOG(INFO) << "Received return RPC value";
// Call the callback with unpacked return value
(*callbacks_[id])(res);
callbacks_.erase(id);
} else {
......@@ -428,17 +428,23 @@ int Socket::_send() {
// Create a websocket header as well.
size_t len = 0;
char buf[20]; // TODO(nick) Should not be a stack buffer.
// Calculate total size of message
for (auto v : send_vec_) {
len += v.iov_len;
}
// Pack correct websocket header into buffer
int rc = ws_prepare(wsheader_type::BINARY_FRAME, false, len, buf, 20);
if (rc == -1) return -1;
// Patch the first io vector to be ws header
send_vec_[0].iov_base = buf;
send_vec_[0].iov_len = rc;
}
#ifdef WIN32
// TODO(nick) Use WSASend instead
// TODO(nick) Use WSASend instead as equivalent to writev
int c = 0;
for (auto v : send_vec_) {
c += ftl::net::internal::send(sock_, (char*)v.iov_base, v.iov_len, 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment