Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7954 in orxonox.OLD for trunk/src/subprojects/network/simple_sync.cc


Ignore:
Timestamp:
May 29, 2006, 3:28:41 PM (18 years ago)
Author:
patrick
Message:

trunk: merged the network branche back to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/subprojects/network/simple_sync.cc

    r6634 r7954  
    2222#include "simple_sync.h"
    2323
     24#include "class_id.h"
     25#include "fast_factory.h"
     26#include "lib/util/loading/factory.h"
     27
    2428#include "debug.h"
     29
     30CREATE_FACTORY(SimpleSync, CL_SIMPLE_SYNC);
    2531
    2632
     
    2834 *  default constructor
    2935 */
    30 SimpleSync::SimpleSync(const char* name)
    31   : Synchronizeable()
     36SimpleSync::SimpleSync( std::string name )
    3237{
    33   /* define the local buffer size */
    34   this->outLength = 10;
    35   this->recLength = 0;
    36   this->inLength = 40;
    37   this->outData = new byte[this->outLength];
    38   this->inData = new byte[this->inLength];
    39 
    40   /* init the buffer data */
    41   for( int i = 0; i < this->outLength; i++)
    42   {
    43     this->outData[i] = i;
    44   }
    45   for( int i = 0; i < this->inLength; i++)
    46   {
    47     this->inData[i] = 0;
    48   }
    49 
     38  setName( name );
     39  this->setClassID( CL_SIMPLE_SYNC, "SimpleSync" );
     40  in = 0;
     41  out = 1;
     42  syncStr = "hallo test test";
     43  id = this->registerVarId( new SynchronizeableInt( &in, &out, "var", PERMISSION_ALL ) );
     44  registerVar( new SynchronizeableString( &syncStr, &syncStr, "syncStr" ) );
    5045}
    5146
     
    5651SimpleSync::~SimpleSync()
    5752{
    58   if( this->outData)
    59     delete[] this->outData;
    60   if( this->inData)
    61     delete[] this->inData;
     53}
     54
     55void SimpleSync::debug( )
     56{
     57  printf("IN: %d OUT: %d\n", in, out);
     58  printf("str: %s\n", syncStr.c_str());
     59}
     60
     61SimpleSync::SimpleSync( const TiXmlElement * root )
     62{
     63  setName( "" );
     64  this->setClassID( CL_SIMPLE_SYNC, "SimpleSync" );
     65  in = 0;
     66  out = 1;
     67  syncStr = "hallo test test";
     68  id = this->registerVarId( new SynchronizeableInt( &in, &out, "var", PERMISSION_ALL ) );
     69  registerVar( new SynchronizeableString( &syncStr, &syncStr, "syncStr" ) );
    6270}
    6371
    6472
    65 /**
    66  *  write data to Synchronizeable
    67  */
    68 int SimpleSync::writeBytes(const byte* data, int length, int sender)
    69 {
    70   PRINTF(0)("SimpleSync: got %i bytes of data\n", length);
    71   this->recLength = length;
    72   if(this->inLength < length)
    73     PRINTF(0)("ERROR: local buffer is smaller than the data to receive.\n");
    74 
    75   /* copy the data localy */
    76   for( int i = 0; i < length; i++)
    77   {
    78     this->inData[i] = data[i];
    79   }
    80   /* and debug output */
    81   this->writeDebug();
    82 }
    8373
    8474
    85 /**
    86  *  read data from Synchronizeable
    87  */
    88 int SimpleSync::readBytes(byte* data, int maxLength, int * reciever)
    89 {
    90   PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);
    91 
    92   /* debug msg */
    93   this->readDebug();
    94 
    95   /* write the test message */
    96   for( int i = 0; i < this->outLength; i++)
    97     data[i] = this->outData[i];
    98 
    99   /* return the length of the test */
    100   return this->outLength;
    101 }
    102 
    103 
    104 void SimpleSync::writeDebug() const
    105 {
    106   PRINTF(0)("Write in bytes: \t(0 <-) |");
    107   for(int i = 0; i < this->recLength; i++)
    108   {
    109     PRINT(0)(" [%u] ",this->inData[i]);
    110   }
    111   PRINT(0)("|\n");
    112 }
    113 
    114 
    115 void SimpleSync::readDebug() const
    116 {
    117   PRINTF(0)("Read out bytes: \t(0 ->) |");
    118   for(int i = 0; i < this->outLength; i++)
    119   {
    120     PRINT(0)(" [%u] ",this->outData[i]);
    121   }
    122   PRINT(0)("|\n");
    123 }
Note: See TracChangeset for help on using the changeset viewer.