Index: code/branches/network/src/network/ConnectionManager.cc
===================================================================
--- code/branches/network/src/network/ConnectionManager.cc	(revision 173)
+++ code/branches/network/src/network/ConnectionManager.cc	(revision 173)
@@ -0,0 +1,139 @@
+//
+// C++ Interface: ConnectionManager
+//
+// Description: The Class ConnectionManager manages the servers conenctions to the clients. 
+// each connection is provided by a new process. communication between master process and 
+// connection processes is provided by ...
+//
+//
+// Author:  Dumeni, Oli
+//
+
+// enet library for networking support
+#include enet/enet.h
+// boost.thread library for multithreading support
+#include boost/thread/thread.hpp
+// headerfile
+#include "network/ConnectionManager.h"
+
+namespace network{
+  ConnectionManager::ConnectionManager(){
+    quit=false;
+    client=NULL;
+    bindAddress.host = std::ENET_HOST_ANY;
+    bindAddress.port = NETWORK_PORT;
+  }
+  
+  ConnectionManager::ConnectionManager(int port, int address){
+    quit=false;
+    client=NULL;
+    bindAddress.host = address;
+    bindAddress.port = NETWORK_PORT;
+  }
+  
+  void ConnectionManager::loop(){
+    if(!quit && !buffer.isEmpty()){
+      // to be implemented =================
+      
+    }
+  }
+  
+  bool ConnectionManager::createListener(){
+    threads.create_thread(&peerLoop);
+    return true;
+  }
+  
+  bool ConnectionManager::quitServer(){
+    quit=true;
+    threads.join_all();
+    return true;
+  }
+  
+  bool ConnectionManager::peerLoop(){
+    ENetEvent event;
+    server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
+    if(server==NULL)
+      // add some error handling here ==========================
+      quit=true;
+    
+    while(!quit){
+      if(enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT)<0){
+        // we should never reach this point
+        quit=true;
+        // add some error handling here ========================
+      }
+      switch(event.type){
+        // log handling ================
+      case std::EVENT_TYPE_CONNECT:
+        addClient(event);
+        break;
+      case std::EVENT_TYPE_RECEIVE:
+        processData(event);
+        break;
+      case std::EVENT_TYPE_DISCONNECT:
+        // add some error/log handling here
+        clientDisconnect(event.peer);
+        break;
+      }
+    }
+    // if we're finishied, destroy server
+    enet_host_destroy(server);
+  }
+  
+  ConnectionManager::processData(ENetEvent event){
+//     insert packetdecode and buffer stuff here
+    
+  }
+  
+  bool ConnectionManager::clientDisconnect(ENetPeer peer){
+    ClientList *temp=client;
+    if(temp->event.peer==peer){
+      if(temp->next==NULL){
+        client=NULL;
+      } else{
+        client=temp->next;
+      }
+      delete temp;
+      return true;
+    } else {
+      while(temp->next!=NULL){
+        if(temp->next->event.peer==peer){
+          ClientList *temp2=temp->next;
+          temp->next=temp2->next;
+          delete temp2;
+          return true;
+        } else
+          temp=temp->next;
+      }
+    }
+    return false;
+  }
+  
+  bool ConnectionManager::addClient(ENetEvent event){
+    if(client==NULL){
+      client =new ClientList;
+      client->ID=1;
+      client->next=NULL;
+      client->event = event;
+    } else {
+      ClienList *temp = client;
+      int i=1;
+      while(temp->next != NULL){
+        temp=temp->next;
+        i++;
+      }
+      temp->next=new ClientList;
+      temp=temp->next;
+      temp->ID=i+1;
+      temp->event=event;
+      temp->next=NULL;
+    }
+    return true;
+  }
+  
+  void ConnectionManager::test(){
+    while(!quit)
+    
+    
+  }
+}
Index: code/branches/network/src/network/ConnectionManager.h
===================================================================
--- code/branches/network/src/network/ConnectionManager.h	(revision 173)
+++ code/branches/network/src/network/ConnectionManager.h	(revision 173)
@@ -0,0 +1,71 @@
+//
+// C++ Interface: ConnectionManager
+//
+// Description: 
+//
+//
+// Author:  <>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef NETWORK_CONNECTIONMANAGER_H
+#define NETWORK_CONNECTIONMANAGER_H
+
+#include PacketBuffer.h
+
+namespace network{
+  //
+#define NETWORK_PORT 5555
+#define NETWORK_MAX_CONNECTIONS 50
+#define NETWORK_WAIT_TIMEOUT 5000
+  //just some defines to make life easier ;)
+#define ENetEvent std::ENetEvent
+#define ENetHost std::ENetHost
+#define ENetAddress std::ENetAddress
+#define ENetPeer std::ENetPeer
+  
+  struct ClientList{
+    ENetEvent event;
+    int ID;
+    ClientList *next;
+  };
+  
+  class ConnectionManager{
+    public:
+    ConnectionManager();
+    ~ConnectionManager();
+    void loop(); // thread1
+    bool createListener();
+    bool quitServer();
+    bool sendEvent(/*.....*/);
+    bool sendEvent(int clientID/*.....*/);
+    void test();
+    private:
+    void peerLoop(int clientNumber); //thread2
+    bool clientDisconnect(ENetPeer peer);
+    bool processData(ENetEvent event);
+    bool addClient(ENetEvent event);
+    //packetbuffer
+    PacketBuffer buffer;
+    // enet stuff
+    ENetHost *server;
+    ENetAddress bindAddress;
+    // quit-variable (communication with threads)
+    bool quit;
+    // thread group
+    boost::thread_group threads;
+    // clientlist
+    ClientList *client;
+  };
+  
+  
+  
+  
+  
+  
+  
+  
+}
+
+#endif
Index: code/branches/network/src/network/PacketBuffer.cc
===================================================================
--- code/branches/network/src/network/PacketBuffer.cc	(revision 173)
+++ code/branches/network/src/network/PacketBuffer.cc	(revision 173)
@@ -0,0 +1,82 @@
+// C++ PacketBuffer
+// 
+// Author Oliver Scheuss
+#include <iostream>
+#include "network/PacketBuffer.h"
+
+namespace network{
+
+PacketBuffer::PacketBuffer(){
+  locked=false;
+  first=NULL;
+  last=NULL;
+}
+
+bool PacketBuffer::push(PacketEnvelope pck){
+  if(!locked){
+    locked=true;
+    // also works if fifo is null (queue empty)
+    // just to be sure last is really the last element
+    while(last!=NULL && last->next!=NULL)
+      last=last->next;
+    // first element?
+    if(first==NULL){
+      first=new QueueItem;
+      last=first;
+      last->next=NULL;
+      // change this!!!!!!!
+      last->packet = new PacketEnvelope;
+      last->packet->data = pck.data;
+      last->packet->length = pck.length;
+    } else {
+      //insert a new element at the bottom
+      last->next = new QueueItem;
+      last=last->next;
+      // initialize last->next
+      last->next=NULL;
+      // save the packet to the new element
+      // change this!!!!!!!!
+      last->packet = new PacketEnvelope;
+      last->packet->data = pck.data;
+      last->packet->length = pck.length;
+    }
+    locked=false;
+    return true;
+  }
+  else
+    return false;
+}
+
+PacketEnvelope *PacketBuffer::pop(){
+  if(!locked && first!=NULL){
+    locked = true;
+    QueueItem *temp = first;
+    // get packet
+    PacketEnvelope *p = first->packet;
+    // remove first element
+    first = first->next;
+    delete temp;
+    locked=false;
+    return p;
+  } else
+    return NULL;
+}
+
+bool PacketBuffer::isEmpty(){
+  return (first==NULL);
+}
+
+bool PacketBuffer::isLocked(){
+  return locked;
+}
+
+void PacketBuffer::print(){
+  QueueItem *temp=first;
+  while(temp!=NULL){
+    std::cout << temp->packet->data << std::endl;
+    temp=temp->next;
+  }
+  
+}
+
+}// namespace network
Index: code/branches/network/src/network/PacketBuffer.h
===================================================================
--- code/branches/network/src/network/PacketBuffer.h	(revision 173)
+++ code/branches/network/src/network/PacketBuffer.h	(revision 173)
@@ -0,0 +1,48 @@
+//
+// C++ Interface: PacketBuffer
+//
+// Description: 
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef NETWORK_PACKETBUFFER_H 
+#define NETWORK_PACKETBUFFER_H
+
+#include <queue>
+#include <string>
+
+namespace network{
+
+struct PacketEnvelope{
+  int length;
+  int data;
+};
+
+struct QueueItem{
+  PacketEnvelope *packet;
+  QueueItem *next;
+};
+
+class PacketBuffer{
+public:
+  PacketBuffer();
+  bool isLocked();
+  bool isEmpty();
+  // pops a packet from the queue
+  PacketEnvelope *pop();
+  // pushs a packet to the queue
+  bool push(PacketEnvelope pck);
+  void print();
+private:
+  bool locked;
+  QueueItem *first;
+  QueueItem *last;
+};
+
+} //namespace
+#endif /* NETWORK_PACKETBUFFER_H */
Index: code/branches/network/src/network/PacketBufferTest.cc
===================================================================
--- code/branches/network/src/network/PacketBufferTest.cc	(revision 173)
+++ code/branches/network/src/network/PacketBufferTest.cc	(revision 173)
@@ -0,0 +1,25 @@
+#include "network/PacketBuffer.h"
+#include "network/PacketBuffer.cc"
+#include <iostream>
+#include <string>
+
+using namespace network;
+
+int main(int argc, char **argv[]){
+  PacketBuffer test = PacketBuffer();
+  PacketEnvelope p={8, 5};
+  if(test.isEmpty())
+    std::cout << "empty buffer" << std::endl;
+  for(int i=0; i<10; i++){
+    p.data=i*i;
+    std::cout << i << ": pushing " << p.data << std::endl;
+    test.push(p);
+  }
+  std::cout << std::endl << "queue.print()" << std::endl;
+  test.print();
+  while(!test.isEmpty()){
+    int i=test.pop()->data;
+    std::cout << "We popped the value " << i << std::endl;
+  }
+  return 0;
+}
