Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/subprojects/network/simple_sync.cc @ 6260

Last change on this file since 6260 was 6139, checked in by patrick, 19 years ago

trunk: merged branche network with trunk using command: svn merge -r5999:HEAD, conflicts resolved in favor of the trunk bla

File size: 2.5 KB
RevLine 
[5650]1/*
2  orxonox - the future of 3D-vertical-scrollers
[5800]3
[5650]4  Copyright (C) 2004 orx
[5800]5
[5650]6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8      the Free Software Foundation; either version 2, or (at your option)
9      any later version.
[5800]10
[5650]11### File Specific:
12    main-programmer: Patrick Boenzli
[5800]13    co-programmer:
[5650]14*/
15
16
17/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
18          For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
19*/
20#define DEBUG_MODULE_NETWORK
21
22#include "simple_sync.h"
23
24#include "debug.h"
25
[5800]26
[5650]27/**
28 *  default constructor
29 */
[5804]30SimpleSync::SimpleSync(const char* name)
31  : Synchronizeable(name)
[5650]32{
[5808]33  /* define the local buffer size */
[5650]34  this->outLength = 10;
[5800]35  this->recLength = 0;
[5798]36  this->inLength = 40;
[5650]37  this->outData = new byte[this->outLength];
[5798]38  this->inData = new byte[this->inLength];
[5800]39
[5808]40  /* init the buffer data */
[5650]41  for( int i = 0; i < this->outLength; i++)
42  {
43    this->outData[i] = i;
44  }
[5800]45  for( int i = 0; i < this->inLength; i++)
46  {
47    this->inData[i] = 0;
48  }
49
[5650]50}
51
[5800]52
[5650]53/**
54 *  default destructor deletes all unneded stuff
55 */
56SimpleSync::~SimpleSync()
57{
[5808]58  if( this->outData)
59    delete[] this->outData;
60  if( this->inData)
61    delete[] this->inData;
[5650]62}
63
[5800]64
[5650]65/**
[5798]66 *  write data to Synchronizeable
[5650]67 */
[5806]68void SimpleSync::writeBytes(const byte* data, int length)
[5650]69{
[5800]70  PRINTF(0)("SimpleSync: got %i bytes of data\n", length);
71  this->recLength = length;
[5798]72  if(this->inLength < length)
73    PRINTF(0)("ERROR: local buffer is smaller than the data to receive.\n");
[5805]74
[5650]75  /* copy the data localy */
[5800]76  for( int i = 0; i < length; i++)
[5650]77  {
78    this->inData[i] = data[i];
79  }
80  /* and debug output */
81  this->writeDebug();
82}
83
84
85/**
[5798]86 *  read data from Synchronizeable
[5650]87 */
[6139]88int SimpleSync::readBytes(byte* data, int maxLength, int * reciever)
[5650]89{
[5800]90  PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);
[5805]91
[5806]92  /* debug msg */
93  this->readDebug();
94
[5650]95  /* write the test message */
[5805]96  for( int i = 0; i < this->outLength; i++)
97    data[i] = this->outData[i];
98
[5650]99  /* return the length of the test */
100  return this->outLength;
101}
102
[5800]103
[5806]104void SimpleSync::writeDebug() const
[5650]105{
[5805]106  PRINTF(0)("Write in bytes: \t(0 <-) |");
[5800]107  for(int i = 0; i < this->recLength; i++)
[5650]108  {
[5802]109    PRINT(0)(" [%u] ",this->inData[i]);
[5650]110  }
111  PRINT(0)("|\n");
112}
113
[5800]114
[5806]115void SimpleSync::readDebug() const
[5650]116{
[5805]117  PRINTF(0)("Read out bytes: \t(0 ->) |");
[5798]118  for(int i = 0; i < this->outLength; i++)
[5650]119  {
[5802]120    PRINT(0)(" [%u] ",this->outData[i]);
[5650]121  }
122  PRINT(0)("|\n");
123}
Note: See TracBrowser for help on using the repository browser.