Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

proxy server ip synchronizeing bug, nodes get registered

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
19
20/**
21 * standard constructor
22 * @todo this constructor is not jet implemented - do it
23*/
24SynchronizeableIP::SynchronizeableIP( IPaddress * ptrIn, IPaddress * 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  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  IPaddress oldIP = *vPtrOut;
78  IPaddress newIP;
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  newIP.host = host;
90  newIP.port = port;
91
92  setHasChanged( (newIP.host != oldIP.host || newIP.port != oldIP.port) );
93
94  assert( n == 2 * INTSIZE);
95
96  return n;
97}
98
99
100/**
101 * print out variable value
102 */
103void SynchronizeableIP::SynchronizeableIP::debug( )
104{
105  printf("SYNCHRONIZEABLE_VAR: %s IN: %i, %i OUT: %i, %i\n", name.c_str(), vPtrIn->host, vPtrIn->port, vPtrOut->host, vPtrOut->port);
106}
107
Note: See TracBrowser for help on using the repository browser.