[2] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 4 | // %flair:license}
|
---|
| 5 | // created: 2011/05/01
|
---|
| 6 | // filename: ui_com.h
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: classe permettant la lecture et l'ecriture RT sur socket UDT
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #ifndef UI_COM_H
|
---|
| 19 | #define UI_COM_H
|
---|
| 20 |
|
---|
| 21 | #include "Thread.h"
|
---|
| 22 | #include <udt.h>
|
---|
| 23 | #ifdef __XENO__
|
---|
| 24 | #include <native/pipe.h>
|
---|
| 25 | #endif
|
---|
| 26 |
|
---|
[15] | 27 | namespace flair {
|
---|
| 28 | namespace core {
|
---|
| 29 | class Mutex;
|
---|
| 30 | class Object;
|
---|
[2] | 31 | }
|
---|
[15] | 32 | namespace gui {
|
---|
| 33 | class SendData;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
[2] | 36 |
|
---|
[15] | 37 | class ui_com : public flair::core::Thread {
|
---|
| 38 | public:
|
---|
| 39 | ui_com(const flair::core::Object *parent, UDTSOCKET sock);
|
---|
| 40 | ~ui_com();
|
---|
[439] | 41 | //Send, public part
|
---|
| 42 | void Send(char *buf, ssize_t size,int ttl = -1);//ttl in ms, -1 for infinite
|
---|
[15] | 43 | ssize_t Receive(char *buf, ssize_t buf_size);
|
---|
| 44 | void AddSendData(const flair::gui::SendData *obj);
|
---|
[441] | 45 | void UpdateSendData(const flair::gui::SendData *obj);//must be called with mutex locked
|
---|
[15] | 46 | void RemoveSendData(const flair::gui::SendData *obj);
|
---|
[442] | 47 | void UpdateDataToSendBufferSize(const flair::gui::SendData *obj);
|
---|
[15] | 48 | void Block(void);
|
---|
| 49 | void UnBlock(void);
|
---|
| 50 | bool ConnectionLost(void);
|
---|
[234] | 51 | void CheckConnection(void);
|
---|
[15] | 52 | private:
|
---|
[456] | 53 | //datasToSend and resumeTimes are pushed/pop together
|
---|
[441] | 54 | std::vector<const flair::gui::SendData *> datasToSend;
|
---|
| 55 | std::vector<flair::core::Time> resumeTimes;
|
---|
[15] | 56 | flair::core::Mutex *send_mutex;
|
---|
| 57 | UDTSOCKET socket_fd;
|
---|
| 58 | bool connection_lost;
|
---|
| 59 | void Run(void);
|
---|
| 60 | void SendDatas(void);
|
---|
[439] | 61 | //private part, called to effectively send to udt
|
---|
| 62 | void SendNRT(char *buf, ssize_t size,int ttl);
|
---|
[441] | 63 | void PushDatasToSend(const flair::gui::SendData *dataToSend);
|
---|
[456] | 64 | void UpdateResumeTime(const flair::gui::SendData *obj);//must be called with mutex locked
|
---|
[440] | 65 | typedef struct {
|
---|
| 66 | char* buf;
|
---|
[441] | 67 | size_t actual_size;
|
---|
| 68 | size_t final_size;
|
---|
[440] | 69 | uint16_t period;
|
---|
| 70 | uint16_t nb_buffering;
|
---|
| 71 | } PushedData_t;
|
---|
[441] | 72 | std::vector<PushedData_t> pushedDatas;
|
---|
[456] | 73 | size_t CalcBufferSize(const PushedData_t* ptr) const;//must be called with mutex locked
|
---|
| 74 | PushedData_t* GetCorrespondingPushedData(const flair::gui::SendData *dataToSend);//returns null if no corresponding buffer
|
---|
| 75 | void AddPushedData(const flair::gui::SendData *obj);
|
---|
[439] | 76 |
|
---|
[456] | 77 |
|
---|
[15] | 78 | static int compressBuffer(char *in, ssize_t in_size, char **out,
|
---|
| 79 | ssize_t *out_size, int level);
|
---|
| 80 | static int uncompressBuffer(unsigned char *in, ssize_t in_size,
|
---|
| 81 | unsigned char **out, ssize_t *out_size);
|
---|
[2] | 82 | #ifdef __XENO__
|
---|
[15] | 83 | bool is_running;
|
---|
| 84 | static void *user_thread(void *arg);
|
---|
| 85 | pthread_t thread;
|
---|
| 86 | RT_PIPE pipe;
|
---|
[2] | 87 | #endif
|
---|
| 88 | };
|
---|
| 89 |
|
---|
| 90 | #endif // UI_COM_H
|
---|