Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5649 in orxonox.OLD for branches


Ignore:
Timestamp:
Nov 20, 2005, 2:48:33 AM (19 years ago)
Author:
patrick
Message:

network: added even more interface, more function to the network_manager and sync test class

Location:
branches/network/src
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/data_stream.cc

    r5648 r5649  
    2323using namespace std;
    2424
     25
     26
     27/**
     28 * This is the empty construktor
     29 */
     30DataStream::DataStream()
     31{
     32  this->setClassID(CL_DATA_STREAM, "DataStream");
     33}
     34
     35
     36
    2537/**
    2638 * This is the empty construktor
     
    2941{
    3042  this->setClassID(CL_DATA_STREAM, "DataStream");
    31   this->sync = &sync;
     43  this->synchronizeable = &sync;
    3244                       
    3345}
     
    146158}
    147159
    148 /**
    149  * This function moves the data from the downStream object to the upStream object and changes the data if necessary.
    150  * This function is virtual and therefore needs to be extended by the derived class
    151  */
    152 void DataStream::processData()
    153 {
    154 
    155 }
    156160
    157161/**
  • branches/network/src/lib/network/data_stream.h

    r5648 r5649  
    6060      DataStream* downStream;
    6161      NetworkSocket* networkSocket;
    62       Synchronizeable* sync;
     62      Synchronizeable* synchronizeable;
    6363
    6464};
  • branches/network/src/lib/network/netdefs.h

    r5624 r5649  
    2020
    2121
     22typedef enum {
     23  NET_SERVER,
     24  NET_CLIENT
     25} NodeType;
     26
    2227#endif /* _NETWORK_MANAGER */
  • branches/network/src/lib/network/network_manager.cc

    r5648 r5649  
    130130  PRINTF(0)("Establish connection...\n");
    131131  /* creating a new network stream, it will register itself automaticaly to the class list */
    132   NetworkStream* netStream = new NetworkStream(address, sync);
     132  NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT);
     133}
     134
     135/**
     136 *  creates a new NetworkStream of server type
     137 * @param sync: the listener
     138 */
     139NetworkStream& NetworkManager::createServer(Synchronizeable& sync, int port)
     140{
     141  PRINTF(0)("Create a new server socket...\n");
     142  /* creating a new network stream, it will register itself automaticaly to the class list */
     143  NetworkStream* netStream = new NetworkStream(sync, port, NET_SERVER);
    133144}
    134145
     
    152163  if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
    153164  {
    154    
     165    tIterator<BaseObject>* iterator = this->netStreamList->getIterator();
     166    NetworkStream* stream = (NetworkStream*)(iterator->firstElement());
     167    while( stream)
     168    {
     169      stream->processData();
     170      stream = (NetworkStream*)(iterator->nextElement());
     171    }
     172    delete iterator;
    155173  }
    156174
  • branches/network/src/lib/network/network_manager.h

    r5648 r5649  
    3535  NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
    3636  NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync);
     37  NetworkStream& createServer(Synchronizeable& sync, int port);
    3738  void shutdownConnection();
    3839 
  • branches/network/src/lib/network/network_stream.cc

    r5648 r5649  
    2727#include "synchronizeable.h"
    2828#include "list.h"
    29 
     29#include "debug.h"
    3030
    3131/* include your own header */
     
    3737
    3838
    39 NetworkStream::NetworkStream()
     39NetworkStream::NetworkStream()
     40  : DataStream()
    4041{
    4142  this->init();
     
    4748
    4849
    49 NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync)
     50NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type)
    5051  : DataStream(sync)
    5152{
    5253  this->init();
    53   this->networkSocket = new NetworkSocket();
     54  this->networkSocket = new NetworkSocket(/* address, type */);
     55}
     56
     57
     58NetworkStream::NetworkStream(Synchronizeable& sync, int port, NodeType type)
     59  : DataStream(sync)
     60{
     61  this->init();
     62  this->networkSocket = new NetworkSocket(/* address, type */);
    5463}
    5564
     
    6473NetworkStream::~NetworkStream()
    6574{
    66  delete networkSockets;
    67  delete synchronizeables;
     75 delete networkSocket;
     76 delete synchronizeable;
    6877 delete connectionMonitor;
    6978
     
    7281void NetworkStream::processData()
    7382{
     83  PRINTF(0)("process data\n");
    7484  byte data[10] ; // obsolete, for debugging only
    7585  byte* test = (byte *)data[0]; // obsolete, for debugging only
    7686  int ret = 0;
    77   this->synchronizeables->writeByteStream(NULL);
    78   ret = this->networkSockets->writeBytes(NULL,1);
    79   test = this->synchronizeables->readByteStream();
    80   ret = this->networkSockets->readBytes(test,1);
     87  this->synchronizeable->writeByteStream(NULL);
     88  ret = this->networkSocket->writeBytes(NULL,1);
     89  test = this->synchronizeable->readByteStream();
     90  ret = this->networkSocket->readBytes(test,1);
    8191}
    8292
  • branches/network/src/lib/network/network_stream.h

    r5648 r5649  
    1313class ConnectionMonitor;
    1414
    15 class NetworkStream : public virtual DataStream
     15class NetworkStream : public DataStream
    1616{
    1717
    1818public:
    1919  NetworkStream();
    20   NetworkStream(IPaddress& address, Synchronizeable& sync);
     20  NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
     21  NetworkStream(Synchronizeable& sync, int port, NodeType type);
    2122 
    2223  ~NetworkStream();
  • branches/network/src/subprojects/network/Makefile.am

    r5619 r5649  
    2020                  $(MAINSRCDIR)/util/loading/load_param.cc \
    2121                  $(MAINSRCDIR)/lib/util/substring.cc \
    22                   $(MAINSRCDIR)/lib/util/helper_functions.cc
     22                  $(MAINSRCDIR)/lib/util/helper_functions.cc
     23
    2324
    2425
  • branches/network/src/subprojects/network/network_unit_test.cc

    r5647 r5649  
    88#include "network_manager.h"
    99#include "network_socket.h"
     10#include "network_stream.h"
    1011#include "synchronizeable.h"
    1112
     
    124125  Synchronizeable sync;
    125126 
     127 
    126128  /* create the network manager */
    127129  NetworkManager* nm = new NetworkManager();
     
    130132  nm->initialize();
    131133
     134  /* create a server stream */
     135  nm->createServer(sync, 9999);
     136 
    132137  /* esatblish a connection */
    133138  nm->establishConnection(ip, sync);
     139
     140  /* synchronize the data 1 time (increment for longer tests) */
     141  for( int i = 0; i < 1; i++) {
     142    nm->synchronize();
     143  }
    134144 
    135145  /* delete the network manager again */
Note: See TracChangeset for help on using the changeset viewer.