Brian Silverman | 4acae81 | 2016-03-14 13:16:19 -0400 | [diff] [blame] | 1 | #ifndef AOS_VISION_IMAGE_UDP_H_ |
| 2 | #define AOS_VISION_IMAGE_UDP_H_ |
| 3 | |
| 4 | #include <arpa/inet.h> |
| 5 | #include <sys/socket.h> |
| 6 | #include <math.h> |
| 7 | #include <unistd.h> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "aos/common/macros.h" |
| 11 | #include "aos/common/scoped_fd.h" |
| 12 | |
| 13 | namespace aos { |
| 14 | namespace vision { |
| 15 | |
| 16 | // Simple wrapper around a transmitting UDP socket. |
| 17 | // |
| 18 | // LOG(FATAL)s for all errors, including from Send. |
| 19 | class TXUdpSocket { |
| 20 | public: |
| 21 | TXUdpSocket(const char *ip_addr, int port); |
| 22 | |
| 23 | // Returns the number of bytes actually sent. |
| 24 | int Send(const void *data, int size); |
| 25 | |
| 26 | private: |
| 27 | ScopedFD fd_; |
| 28 | |
| 29 | DISALLOW_COPY_AND_ASSIGN(TXUdpSocket); |
| 30 | }; |
| 31 | |
| 32 | // Simple wrapper around a receiving UDP socket. |
| 33 | // |
| 34 | // LOG(FATAL)s for all errors, including from Recv. |
| 35 | class RXUdpSocket { |
| 36 | public: |
| 37 | RXUdpSocket(int port); |
| 38 | |
| 39 | // Returns the number of bytes received. |
| 40 | int Recv(void *data, int size); |
| 41 | |
| 42 | private: |
| 43 | ScopedFD fd_; |
| 44 | |
| 45 | DISALLOW_COPY_AND_ASSIGN(RXUdpSocket); |
| 46 | }; |
| 47 | |
| 48 | } // namespace vision |
| 49 | } // namespace aos |
| 50 | |
| 51 | #endif // AOS_VISION_IMAGE_UDP_H_ |