Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

proxy servers are synced in a better form

File size: 2.3 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->ip(), buf, maxLength );
50  assert(res > 0);
51  n += res;
52
53  res = Converter::intToByteArray( (int)vPtrIn->port(), buf, maxLength);
54  assert(res > 0);
55  n += res;
56
57  assert( 2 * INTSIZE == n);
58
59  return n;
60}
61
62/**
63 * read var data from byte buffer
64 * @param buf pointer to read from
65 * @param maxLength readFromBuf will not read more than maxLength bytes
66 * @return number bytes read
67 */
68int SynchronizeableIP::readFromBuf( byte * buf, int maxLength )
69{
70  assert( maxLength >= 2 * INTSIZE);
71
72  int host, port;
73
74  int res;
75  int n = 0;
76
77  IP oldIP = *vPtrOut;
78
79  res = Converter::byteArrayToInt( buf + n, &host);
80  assert( res > 0);
81  n += res;
82
83
84  res = Converter::byteArrayToInt( buf + n, &port);
85  assert( res > 0);
86  n += res;
87
88  *this->vPtrOut = IP(host, port);
89
90  printf(" vtrp out old: %i, %i -- new: %i, %i\n", oldIP.ip(), oldIP.port(), this->vPtrOut->ip(), this->vPtrOut->port());
91  setHasChanged( *this->vPtrOut != oldIP);
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->ip(), vPtrIn->port(), vPtrOut->ip(), vPtrOut->port());
105}
106
Note: See TracBrowser for help on using the repository browser.