Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: testing env. got segfault in the code

File size: 2.0 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 *  default constructor
28 */
29SimpleSync::SimpleSync()
30  : Synchronizeable()
31{
32  this->outLength = 10;
33  this->inLength = 40;
34  this->outData = new byte[this->outLength];
35  this->inData = new byte[this->inLength];
36 
37  for( int i = 0; i < this->outLength; i++)
38  {
39    this->outData[i] = i;
40  }
41}
42
43/**
44 *  default destructor deletes all unneded stuff
45 */
46SimpleSync::~SimpleSync()
47{
48}
49
50/**
51 *  write data to Synchronizeable
52 */
53void SimpleSync::writeBytes(byte* data, int length)
54{
55  if(this->inLength < length)
56    PRINTF(0)("ERROR: local buffer is smaller than the data to receive.\n");
57  /* copy the data localy */
58  for( int i = 0; i < this->inLength; i++)
59  {
60    this->inData[i] = data[i];
61  }
62  /* and debug output */
63  this->writeDebug();
64}
65
66
67/**
68 *  read data from Synchronizeable
69 */
70int SimpleSync::readBytes(byte* data)
71{
72  /* write the test message */
73  data = this->outData;
74  /* debug msg */
75  this->readDebug();
76  /* return the length of the test */
77  return this->outLength;
78}
79
80void SimpleSync::writeDebug()
81{
82  PRINTF(0)("Write in: |");
83  for(int i = 0; i < this->inLength; i++)
84  {
85    PRINT(0)(" %i ",this->inData[i]);
86  }
87  PRINT(0)("|\n");
88}
89
90void SimpleSync::readDebug()
91{
92  PRINTF(0)("Read out: |");
93  for(int i = 0; i < this->outLength; i++)
94  {
95    PRINT(0)(" %i ",this->outData[i]);
96  }
97  PRINT(0)("|\n");
98}
Note: See TracBrowser for help on using the repository browser.