Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/subprojects/network/simple_sync.cc @ 5806

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

network: made some functions and arguments const, since they musn't change any data.

File size: 2.4 KB
Line 
1/*
2  orxonox - the future of 3D-vertical-scrollers
3
4  Copyright (C) 2004 orx
5
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.
10
11### File Specific:
12    main-programmer: Patrick Boenzli
13    co-programmer:
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
26
27/**
28 *  default constructor
29 */
30SimpleSync::SimpleSync(const char* name)
31  : Synchronizeable(name)
32{
33  this->outLength = 10;
34  this->recLength = 0;
35  this->inLength = 40;
36  this->outData = new byte[this->outLength];
37  this->inData = new byte[this->inLength];
38
39  for( int i = 0; i < this->outLength; i++)
40  {
41    this->outData[i] = i;
42  }
43  for( int i = 0; i < this->inLength; i++)
44  {
45    this->inData[i] = 0;
46  }
47
48}
49
50
51/**
52 *  default destructor deletes all unneded stuff
53 */
54SimpleSync::~SimpleSync()
55{
56}
57
58
59/**
60 *  write data to Synchronizeable
61 */
62void SimpleSync::writeBytes(const byte* data, int length)
63{
64  PRINTF(0)("SimpleSync: got %i bytes of data\n", length);
65  this->recLength = length;
66  if(this->inLength < length)
67    PRINTF(0)("ERROR: local buffer is smaller than the data to receive.\n");
68
69  /* copy the data localy */
70  for( int i = 0; i < length; i++)
71  {
72    this->inData[i] = data[i];
73  }
74  /* and debug output */
75  this->writeDebug();
76}
77
78
79/**
80 *  read data from Synchronizeable
81 */
82int SimpleSync::readBytes(byte* data) const
83{
84  PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);
85
86  /* debug msg */
87  this->readDebug();
88
89  /* write the test message */
90  for( int i = 0; i < this->outLength; i++)
91    data[i] = this->outData[i];
92
93  /* return the length of the test */
94  return this->outLength;
95}
96
97
98void SimpleSync::writeDebug() const
99{
100  PRINTF(0)("Write in bytes: \t(0 <-) |");
101  for(int i = 0; i < this->recLength; i++)
102  {
103    PRINT(0)(" [%u] ",this->inData[i]);
104  }
105  PRINT(0)("|\n");
106}
107
108
109void SimpleSync::readDebug() const
110{
111  PRINTF(0)("Read out bytes: \t(0 ->) |");
112  for(int i = 0; i < this->outLength; i++)
113  {
114    PRINT(0)(" [%u] ",this->outData[i]);
115  }
116  PRINT(0)("|\n");
117}
Note: See TracBrowser for help on using the repository browser.