Brian Silverman | 6ae77dd | 2013-03-29 22:28:08 -0700 | [diff] [blame] | 1 | #ifndef FRC971_VISION_PACKET_NOTIFIER_H_ |
| 2 | #define FRC971_VISION_PACKET_NOTIFIER_H_ |
| 3 | #include "event2/buffer.h" |
| 4 | #include "event2/event.h" |
| 5 | #include "event2/listener.h" |
| 6 | #include "event2/bufferevent.h" |
| 7 | #include "aos/common/mutex.h" |
| 8 | |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/socket.h> |
| 11 | |
| 12 | namespace frc971 { |
| 13 | namespace vision { |
| 14 | |
| 15 | /* This class lives in shared memory (using an anonomous mmap) to transfer data between |
| 16 | * the server process and the image processing process. |
| 17 | */ |
| 18 | struct PacketNotifier{ |
| 19 | aos::Mutex mutex; |
| 20 | int fd[2]; |
| 21 | //3 things can be happening: |
| 22 | //something waiting to be sent, something sending, and something getting filled (decompressed to) |
| 23 | void *buffs[3]; |
| 24 | int to_send; |
| 25 | int filling; |
| 26 | int sending; |
| 27 | bool in_flight; |
| 28 | size_t data_size; |
| 29 | void Notify(); |
| 30 | void RegisterSender(); |
| 31 | void RegisterReciever(); |
| 32 | int RecieverFD(){ return fd[1]; } |
| 33 | static PacketNotifier *MMap(size_t data_size); |
| 34 | void DataSent(const void * /*data*/, size_t /*datalen*/); |
| 35 | void *GetBuffer(); |
| 36 | static void StaticDataSent(const void *data, size_t datalen, void *self){ |
| 37 | ((PacketNotifier *)(self))->DataSent(data,datalen); |
| 38 | } |
| 39 | bool GetData(char **place_to_put,size_t *length); |
| 40 | }; |
| 41 | } // namespace vision |
| 42 | } // namespace frc971 |
| 43 | |
| 44 | |
| 45 | #endif //FRC971_VISION_PACKET_NOTIFIER_H_ |