Changeset 445 in flair-src


Ignore:
Timestamp:
Sep 10, 2021, 3:14:17 PM (3 months ago)
Author:
Sanahuja Guillaume
Message:

update buffering

Location:
trunk/lib/FlairCore/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/SendData.cpp

    r442 r445  
    122122
    123123  if (getUiCom() != NULL) {
    124       getUiCom()->UpdateDataToSendSize();
    125         getUiCom()->UpdateDataToSendBufferSize(this);
     124    getUiCom()->UpdateDataToSendBufferSize(this);
    126125  }
    127126}
  • trunk/lib/FlairCore/src/SendData.h

    r437 r445  
    5858protected:
    5959  /*!
    60   * \brief Notify that SenData's datas have changed
     60  * \brief Notify that SendData's datas have changed
    6161  *
    6262  * This method must be called when the datas have changed. \n
  • trunk/lib/FlairCore/src/ui_com.cpp

    r444 r445  
    3939using namespace flair::gui;
    4040
    41 ui_com::ui_com(const Object *parent, UDTSOCKET sock)
    42     : Thread(parent, "send", 2,16384*2) {
    43   // buffer envoi
    44   send_buffer = (char *)malloc(3);
    45   send_size = 3; // id(1)+period(2)
    46 
     41ui_com::ui_com(const Object *parent, UDTSOCKET sock) : Thread(parent, "send", 2,16384*2) {
    4742  // mutex
    48   send_mutex = NULL;
    4943  send_mutex = new Mutex(this, ObjectName());
    5044
     
    150144  Send(&buf,1);
    151145 
    152   if (send_buffer != NULL)
    153     free(send_buffer);
    154   send_buffer = NULL;
    155 
     146    for (size_t i = 0; i < pushedDatas.size(); i++) {
     147      free(pushedDatas.at(i).buf);
     148    }
    156149  //Printf("destruction ui_com ok\n");
    157150}
     
    264257//-> enelver l'alloc du buffer au startup (UpdateDataToSendSize)
    265258void ui_com::Run(void) {
    266   // check endianness
    267   char header;
    268   if (IsBigEndian()) {
    269     header = DATA_BIG_ENDIAN;
    270     Printf("System is big endian\n");
    271   } else {
    272     header = DATA_LITTLE_ENDIAN;
    273     Printf("System is little endian\n");
    274   }
    275 
    276259#ifdef __XENO__
    277260  WarnUponSwitches(true);
     
    305288
    306289      // envoi des donnees
    307       int offset = 3;
    308       send_buffer[0] = header;
    309290      send_mutex->GetMutex();
    310291
    311       for (size_t i = 0; i < datasToSend.size(); i++) {
    312         if (datasToSend.at(i)->SendPeriod() == resume_period && datasToSend.at(i)->IsEnabled() == true) {
    313           datasToSend.at(i)->CopyDatas(send_buffer + offset);
    314           offset += datasToSend.at(i)->SendSize();
    315         }
    316       }
    317       if (offset != 3) {
    318         memcpy(&send_buffer[1], &resume_period, sizeof(uint16_t));
    319         //printf("send %i %i %i %x %x\n",resume_period,offset,sizeof(uint16_t),send_buffer,&send_buffer[1]);
    320         // for(int i=0;i<offset;i++) printf("%x ",send_buffer[i]);
    321         // printf("\n");
    322         //Send(send_buffer, offset,resume_period);
    323       }
    324 
    325       //test to push datas
     292      //mulit buffering
    326293      for (size_t i = 0; i < datasToSend.size(); i++) {
    327294        if (datasToSend.at(i)->SendPeriod() == resume_period && datasToSend.at(i)->IsEnabled() == true) {
     
    329296        }
    330297      }
    331       //end test
    332298     
    333299      // on planifie la prochaine execution
     
    375341 
    376342  if(ptr->actual_size==0) {
    377       if (IsBigEndian()) {
    378         ptr->buf[0] = MULTIPLE_DATA_BIG_ENDIAN;
     343      if(ptr->nb_buffering>1) {
     344          if (IsBigEndian()) {
     345            ptr->buf[0] = MULTIPLE_DATA_BIG_ENDIAN;
     346          } else {
     347            ptr->buf[0]  = MULTIPLE_DATA_LITTLE_ENDIAN;
     348          }
     349          ptr->actual_size+=sizeof(char);
     350          memcpy(ptr->buf+ptr->actual_size,&(ptr->period),sizeof(uint16_t));
     351          ptr->actual_size+=sizeof(uint16_t);
     352          memcpy(ptr->buf+ptr->actual_size,&(ptr->nb_buffering),sizeof(uint16_t));
     353          ptr->actual_size+=sizeof(uint16_t);
    379354      } else {
    380         ptr->buf[0]  = MULTIPLE_DATA_LITTLE_ENDIAN;
     355          if (IsBigEndian()) {
     356            ptr->buf[0] = DATA_BIG_ENDIAN;
     357          } else {
     358            ptr->buf[0]  = DATA_LITTLE_ENDIAN;
     359          }
     360          ptr->actual_size+=sizeof(char);
     361          memcpy(ptr->buf+ptr->actual_size,&(ptr->period),sizeof(uint16_t));
     362          ptr->actual_size+=sizeof(uint16_t);
    381363      }
    382       ptr->actual_size+=sizeof(char);
    383       memcpy(ptr->buf+ptr->actual_size,&(ptr->period),sizeof(uint16_t));
    384       ptr->actual_size+=sizeof(uint16_t);
    385       memcpy(ptr->buf+ptr->actual_size,&(ptr->nb_buffering),sizeof(uint16_t));
    386       ptr->actual_size+=sizeof(uint16_t);
    387364  }
    388365 
     
    613590        }
    614591        bufSize*=(*pushedDatasIterator).nb_buffering;
    615         if(bufSize!=0) bufSize+=sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t);//header+period+nb_buffering
     592        if(bufSize!=0) {
     593            bufSize+=sizeof(char)+sizeof(uint16_t);//header+period
     594            if((*pushedDatasIterator).nb_buffering>1) bufSize+=sizeof(uint16_t);//+nb_buffering
     595        }   
    616596        if(bufSize!=(*pushedDatasIterator).final_size && bufSize!=0) {
    617597            //Printf("change buf size %i->%i\n",(*pushedDatasIterator).final_size,bufSize);
     
    655635        }
    656636        tmp.final_size*=obj->NbBuffering();
    657         tmp.final_size+=sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t);//header+period+nb_buffering
     637        tmp.final_size+=sizeof(char)+sizeof(uint16_t);//header+period
     638        if(tmp.nb_buffering>1) tmp.final_size+=sizeof(uint16_t);//+nb_buffering
    658639        //printf("final size %i\n",tmp.final_size);
    659640        tmp.buf=(char*)malloc(tmp.final_size);
     
    667648  //Printf("nb buf %i\n",pushedDatas.size());
    668649  return;
    669 }
    670 
    671 //allocate a buffer at startup for the worst case
    672 //(every data send with same pedriod)
    673 //TODO: dynamic size depending on what gcs asks?
    674 void ui_com::UpdateDataToSendSize(void) {
    675   send_mutex->GetMutex();
    676   send_size = 3; // id(1)+period(2)
    677   for (size_t i = 0; i < datasToSend.size(); i++) {
    678     if (datasToSend[i] != NULL)
    679       send_size += datasToSend[i]->SendSize();
    680   }
    681 
    682   // send_buffer=(char*)realloc((void*)send_buffer,send_size*sizeof(char));
    683   if (send_buffer != NULL)
    684     free(send_buffer);
    685   send_buffer = (char *)malloc(send_size * sizeof(char));
    686   send_mutex->ReleaseMutex();
    687650}
    688651
     
    704667    }
    705668   
    706     ptr->final_size=sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t);//header+period+nb_buffering
     669    ptr->final_size=sizeof(char)+sizeof(uint16_t);//header+period
     670    if(ptr->nb_buffering>1) ptr->final_size+=sizeof(uint16_t);//+nb_buffering
    707671    ptr->final_size+=obj->SendSize()*obj->NbBuffering();
    708     Printf("final %i\n",ptr->final_size);
     672    //Printf("final %i\n",ptr->final_size);
    709673    free(ptr->buf);
    710674    ptr->buf=(char*)malloc(ptr->final_size);
  • trunk/lib/FlairCore/src/unexported/ui_com.h

    r442 r445  
    4646  void RemoveSendData(const flair::gui::SendData *obj);
    4747  void UpdateDataToSendBufferSize(const flair::gui::SendData *obj);
    48   void UpdateDataToSendSize(void);
    4948  void Block(void);
    5049  void UnBlock(void);
     
    5251  void CheckConnection(void);
    5352private:
    54   ssize_t send_size;
    55   char *send_buffer;
    5653  std::vector<const flair::gui::SendData *> datasToSend;
    5754  std::vector<flair::core::Time> resumeTimes;
Note: See TracChangeset for help on using the changeset viewer.