Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_ip.cc @ 9377

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

more string switching for outcommented stuff

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*/
14
15
16#include "synchronizeable_ip.h"
17#include "converter.h"
18// #include "ip.h"
19
20/**
21 * standard constructor
22 * @todo this constructor is not jet implemented - do it
23*/
24SynchronizeableIP::SynchronizeableIP( IP * ptrIn, IP * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 2*INTSIZE, permission, priority )
25{
26  this->vPtrIn = ptrIn;
27  this->vPtrOut = ptrOut;
28}
29
30
31/**
32 * standard deconstructor
33*/
34SynchronizeableIP::~SynchronizeableIP ()
35{
36}
37
38/**
39 * write var data to byte buffer
40 * @param buf pointer to write to
41 * @param maxLength writeToBuf will not write more than maxLength bytes
42 * @return number bytes written
43 */
44int SynchronizeableIP::writeToBuf( byte * buf, int maxLength )
45{
46  int n = 0;
47  int res;
48
49  res = Converter::intToByteArray( (int)vPtrIn->host(), buf, maxLength );
50  assert(res > 0);
51  n += res;
52
53
54  res = Converter::intToByteArray( (int)vPtrIn->port(), buf + n, maxLength);
55  assert(res > 0);
56  n += res;
57
58  assert( 2 * INTSIZE == n);
59
60  return n;
61}
62
63/**
64 * read var data from byte buffer
65 * @param buf pointer to read from
66 * @param maxLength readFromBuf will not read more than maxLength bytes
67 * @return number bytes read
68 */
69int SynchronizeableIP::readFromBuf( byte * buf, int maxLength )
70{
71  assert( maxLength >= 2 * INTSIZE);
72
73  int host, port;
74
75  int res;
76  int n = 0;
77
78  IP oldVal = *vPtrOut;
79
80  res = Converter::byteArrayToInt( buf + n, &host);
81  assert( res > 0);
82  n += res;
83
84
85  res = Converter::byteArrayToInt( buf + n, &port);
86  assert( res > 0);
87  n += res;
88
89  *this->vPtrOut = IP(host, port);
90
91  this->setHasChanged( *this->vPtrOut != oldVal);
92
93  assert( n == 2 * INTSIZE);
94
95  return n;
96}
97
98
99/**
100 * print out variable value
101 */
102void SynchronizeableIP::SynchronizeableIP::debug( )
103{
104  printf("SYNCHRONIZEABLE_VAR: %s IN: %i, %i OUT: %i, %i\n", name.c_str(), vPtrIn->host(), vPtrIn->port(), vPtrOut->host(), vPtrOut->port());
105}
106
Note: See TracBrowser for help on using the repository browser.