-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New routes created for UDP and TCP #20
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,72 @@ | ||
{ | ||
"files.associations": { | ||
"vector": "cpp" | ||
"vector": "cpp", | ||
"cctype": "cpp", | ||
"clocale": "cpp", | ||
"cmath": "cpp", | ||
"csignal": "cpp", | ||
"cstdarg": "cpp", | ||
"cstddef": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"cstring": "cpp", | ||
"ctime": "cpp", | ||
"cwchar": "cpp", | ||
"cwctype": "cpp", | ||
"array": "cpp", | ||
"atomic": "cpp", | ||
"hash_map": "cpp", | ||
"strstream": "cpp", | ||
"bit": "cpp", | ||
"*.tcc": "cpp", | ||
"bitset": "cpp", | ||
"chrono": "cpp", | ||
"codecvt": "cpp", | ||
"complex": "cpp", | ||
"condition_variable": "cpp", | ||
"cstdint": "cpp", | ||
"deque": "cpp", | ||
"list": "cpp", | ||
"map": "cpp", | ||
"set": "cpp", | ||
"unordered_map": "cpp", | ||
"unordered_set": "cpp", | ||
"exception": "cpp", | ||
"algorithm": "cpp", | ||
"functional": "cpp", | ||
"iterator": "cpp", | ||
"memory": "cpp", | ||
"memory_resource": "cpp", | ||
"numeric": "cpp", | ||
"optional": "cpp", | ||
"random": "cpp", | ||
"ratio": "cpp", | ||
"string": "cpp", | ||
"string_view": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"type_traits": "cpp", | ||
"utility": "cpp", | ||
"fstream": "cpp", | ||
"future": "cpp", | ||
"initializer_list": "cpp", | ||
"iomanip": "cpp", | ||
"iosfwd": "cpp", | ||
"iostream": "cpp", | ||
"istream": "cpp", | ||
"limits": "cpp", | ||
"mutex": "cpp", | ||
"new": "cpp", | ||
"ostream": "cpp", | ||
"sstream": "cpp", | ||
"stdexcept": "cpp", | ||
"streambuf": "cpp", | ||
"thread": "cpp", | ||
"cfenv": "cpp", | ||
"cinttypes": "cpp", | ||
"typeindex": "cpp", | ||
"typeinfo": "cpp", | ||
"valarray": "cpp", | ||
"variant": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef LATTICE_HUB_IO_ADAPTOR_HTTP | ||
#define LATTICE_HUB_IO_ADAPTOR_HTTP | ||
|
||
// std lib | ||
#include <string> | ||
|
||
// lib | ||
#include "crow_all.h" | ||
|
||
namespace io::adaptor { | ||
class Http; | ||
} | ||
|
||
class io::adaptor::Http { | ||
std::string api_output; | ||
crow::SimpleApp app; | ||
|
||
public: | ||
Http(); | ||
void listen(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// implementation file | ||
#include "http.h" | ||
|
||
io::adaptor::Http::Http() {} | ||
|
||
void io::adaptor::Http::listen() { | ||
CROW_ROUTE(app, "/")([]() { return "Lattice deployed"; }); | ||
|
||
CROW_ROUTE(app, "/attach").methods("PUT"_method)([&](const crow::request &req) { | ||
return api_output.c_str(); | ||
}); | ||
|
||
CROW_ROUTE(app, "/devices") | ||
.methods("GET"_method)( | ||
[&](const crow::request &req) { return api_output.c_str(); }); | ||
|
||
app.port(8080).multithreaded().run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef LATTICE_HUB_IO_ADAPTOR_UDP_INTERFACE | ||
#define LATTICE_HUB_IO_ADAPTOR_UDP_INTERFACE | ||
|
||
// libs | ||
#include <boost/array.hpp> | ||
#include <boost/asio.hpp> | ||
|
||
namespace io::adaptor::udp_interface { | ||
using boost::asio::ip::udp; | ||
|
||
class UdpServer; | ||
} // namespace io::adaptor::udp_interface | ||
|
||
class io::adaptor::udp_interface::UdpServer { | ||
udp::socket socket_; | ||
udp::endpoint remote_endpoint_; | ||
boost::array<char, 1> recv_buffer_; | ||
|
||
void start_receive(); | ||
void handle_receive(const boost::system::error_code &, std::size_t); | ||
void handle_send(boost::shared_ptr<std::string>, | ||
const boost::system::error_code &, std::size_t); | ||
|
||
public: | ||
UdpServer(boost::asio::io_service &, unsigned short); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// std lib | ||
#include <iostream> | ||
#include <thread> | ||
|
||
// lib | ||
#include <boost/bind.hpp> | ||
|
||
// implementation file | ||
#include "udp_interface.h" | ||
|
||
#define UDP_PORT 13000 | ||
|
||
io::adaptor::udp_interface::UdpServer::UdpServer( | ||
boost::asio::io_service &io_service, unsigned short port) | ||
: socket_(io_service, udp::endpoint(udp::v4(), port)) { | ||
start_receive(); | ||
} | ||
|
||
void io::adaptor::udp_interface::UdpServer::start_receive() { | ||
socket_.async_receive_from( | ||
boost::asio::buffer(recv_buffer_), remote_endpoint_, | ||
boost::bind(&io::adaptor::udp_interface::UdpServer::handle_receive, this, boost::asio::placeholders::error, | ||
boost::asio::placeholders::bytes_transferred)); | ||
} | ||
|
||
void io::adaptor::udp_interface::UdpServer::handle_receive( | ||
const boost::system::error_code &error, std::size_t bytes_transferred) { | ||
if (!error || error == boost::asio::error::message_size) { | ||
boost::shared_ptr<std::string> message(new std::string("Test string")); | ||
|
||
socket_.async_send_to( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comments. |
||
boost::asio::buffer(*message), remote_endpoint_, | ||
boost::bind(&io::adaptor::udp_interface::UdpServer::handle_send, this, message, | ||
boost::asio::placeholders::error, | ||
boost::asio::placeholders::bytes_transferred)); | ||
|
||
start_receive(); | ||
} | ||
} | ||
|
||
void io::adaptor::udp_interface::UdpServer::handle_send( | ||
boost::shared_ptr<std::string> message, | ||
const boost::system::error_code &error, std::size_t bytes_transferred) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef LATTICE_HUB_UTILS_PORT_MAP | ||
#define LATTICE_HUB_UTILS_PORT_MAP | ||
|
||
#include <string> | ||
|
||
class PortMap{ | ||
public: | ||
const static unsigned short UDP_PORT = 1300; | ||
}; | ||
|
||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comments about method above it and add meaningful parameter names.