Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/synchronizeable_var/synchronizeable_ip.cc @ 10209

Last change on this file since 10209 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

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