-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathitransport_layer.h
More file actions
47 lines (37 loc) · 1.95 KB
/
itransport_layer.h
File metadata and controls
47 lines (37 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include "types.h"
/*
* This class provides an interfaces for generic Transportlayers that can be used by the ROSBridge.
* Since this library has been developed for different plattforms,
* we abstract from the actual transport layer, since this varies from plattforms (and frameworks) a lot.
*
* Please see client/socket_tcp_connection.h for an example implementation that uses UNIX Sockets
* to connect to a ROSBridge server
*/
namespace rosbridge2cpp {
class ITransportLayer {
public:
enum TransportMode { JSON, BSON };
// Initialize the TransportLayer by connecting to the given IP and port
// The implementing class should have an active connection to IP:port
// when the method has been executed completly.
// Returns true if the connection has been successfully.
virtual bool Init(std::string ip_addr, int port) = 0;
// Send a string over the underlying transport mechanism to the rosbridge server
virtual bool SendMessage(std::string data) = 0;
// Send a string over the underlying transport mechanism to the rosbridge server
virtual bool SendMessage(const uint8_t *data, unsigned int length) = 0;
// Register a std::function that will be called whenever a new data packet has been received by this TransportLayer.
virtual void RegisterIncomingMessageCallback(std::function<void(json&)>) = 0;
// Register a std::function that will be called whenever a new data packet has been received by this TransportLayer.
virtual void RegisterIncomingMessageCallback(std::function<void(bson_t&)>) = 0;
// Register a std::function that will be called when errors occur.
virtual void RegisterErrorCallback(std::function<void(TransportError)>) = 0;
// Report an error to the registered ErrorCallback (see RegisterErrorCallback)
virtual void ReportError(TransportError) = 0;
// Report an error to the registered ErrorCallback (see RegisterErrorCallback)
virtual void SetTransportMode(TransportMode) = 0;
private:
/* data */
};
}