Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/synchronizeable.cc @ 6678

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

network: sys better now, got less errors and removed the pnode link sync alg, replacing

File size: 3.4 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
12### File Specific:
13   main-programmer: Silvan Nellen
14   co-programmer: Benjamin Wuest
15*/
16
17#define DEBUG_MODULE_NETWORK
18
19#include "shared_network_data.h"
20#include "network_stream.h"
21#include "netdefs.h"
22
23#include "assert.h"
24
25#include "synchronizeable.h"
26
27
28
29/**
30 *  default constructor
31 */
32Synchronizeable::Synchronizeable()
33{
34  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
35  this->owner = 0;
36  this->state = 0;
37  this->hostID = SharedNetworkData::getInstance()->getHostID();
38  this->setIsServer(this->hostID == 0);
39  this->uniqueID = -1;
40  this->networkStream = NULL;
41  this->setRequestedSync( false );
42  this->setIsOutOfSync( !(this->isServer()) );
43  this->bSynchronize = false;
44
45  NetworkStream* nd = SharedNetworkData::getInstance()->getDefaultSyncStream();
46  assert(nd != NULL);
47  nd->connectSynchronizeable(*this);
48  this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID());
49}
50
51
52
53/**
54 *  default destructor deletes all unneded stuff
55 */
56Synchronizeable::~Synchronizeable()
57{
58  if ( this->networkStream )
59    this->networkStream->disconnectSynchronizeable(*this);
60}
61
62
63/**
64 *  write data to NetworkStream
65 */
66int Synchronizeable::writeBytes(const byte* data, int length, int sender)
67{
68  PRINTF(5)("Synchronizeable::writeBytes was called\n");
69}
70
71
72/**
73 *  read data from NetworkStream
74 */
75int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever)
76{
77  PRINTF(5)("Synchronizeable::readBytes was called\n");
78}
79
80
81void Synchronizeable::writeDebug() const
82{}
83
84
85void Synchronizeable::readDebug() const
86{}
87
88
89/**
90 * Sets the server flag to a given value
91 * @param isServer: the boolean value which the server flag is to set to
92 */
93void Synchronizeable::setIsServer(bool isServer)
94{
95  if( isServer )
96    this->state = this->state | STATE_SERVER;
97  else
98    this->state = this->state & (~STATE_SERVER);
99}
100
101
102/**
103 * Sets the outofsync flag to a given value
104 * @param outOfSync: the boolean value which the outofsync flag is to set to
105 */
106void Synchronizeable::setIsOutOfSync(bool outOfSync)
107{
108  if( outOfSync )
109    this->state = this->state | STATE_OUTOFSYNC;
110  else
111    this->state = this->state & (~STATE_OUTOFSYNC);
112  //PRINTF(0)("isoutofsync %s %d\n", this->getClassName(), state);
113}
114
115
116/**
117 * Determines if the server flag is set
118 * @return true, if the server flag is true, false else
119 */
120bool Synchronizeable::isServer()
121{
122  return (this->state & STATE_SERVER) >0;
123}
124
125
126/**
127 * Determines if the outofsync flag is set
128 * @return true, if the outofsync flag is true, false else
129 */
130bool Synchronizeable::isOutOfSync()
131{
132  return (this->state & STATE_OUTOFSYNC) >0;
133}
134
135
136/**
137 * Determines if the requestedSync flag is set
138 * @return true, if the requestedSync flag is true, false else
139 */
140bool Synchronizeable::requestedSync()
141{
142  return (this->state & STATE_REQUESTEDSYNC) >0;
143}
144
145
146/**
147 * Sets the requestedsync flag to a given value
148 * @param requestedSync: the boolean value which the requestedsync flag is to set to
149 */
150void Synchronizeable::setRequestedSync( bool requestedSync )
151{
152  if( requestedSync )
153    this->state = this->state | STATE_REQUESTEDSYNC;
154  else
155    this->state = this->state & (~STATE_REQUESTEDSYNC);
156}
157
158
159
Note: See TracBrowser for help on using the repository browser.