Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5800 was 5800, checked in by patrick, 18 years ago

network: included more comments to make it easier to debug

File size: 2.2 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()
31  : Synchronizeable()
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(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  /* copy the data localy */
69  for( int i = 0; i < length; i++)
70  {
71    this->inData[i] = data[i];
72  }
73  /* and debug output */
74  this->writeDebug();
75}
76
77
78/**
79 *  read data from Synchronizeable
80 */
81int SimpleSync::readBytes(byte* data)
82{
83  PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);
84  /* write the test message */
85  data = this->outData;
86  /* debug msg */
87  this->readDebug();
88  /* return the length of the test */
89  return this->outLength;
90}
91
92
93void SimpleSync::writeDebug()
94{
95  PRINTF(0)("Write in: |");
96  for(int i = 0; i < this->recLength; i++)
97  {
98    PRINT(0)(" %i ",this->inData[i]);
99  }
100  PRINT(0)("|\n");
101}
102
103
104void SimpleSync::readDebug()
105{
106  PRINTF(0)("Read out: |");
107  for(int i = 0; i < this->outLength; i++)
108  {
109    PRINT(0)(" %c ",this->outData[i]);
110  }
111  PRINT(0)("|\n");
112}
Note: See TracBrowser for help on using the repository browser.