Index: code/branches/network/src/network/ConnectionManager.cc
===================================================================
--- code/branches/network/src/network/ConnectionManager.cc	(revision 195)
+++ code/branches/network/src/network/ConnectionManager.cc	(revision 196)
@@ -7,19 +7,21 @@
 //
 //
-// Author:  Dumeni, Oli
+// Author:  Oliver Scheuss
 //
 
-// 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{
+  
+  boost::thread_group network_threads;
+  
+  void test(){
+    return;
+  }
+  
   ConnectionManager::ConnectionManager(){
     quit=false;
     client=NULL;
-    bindAddress.host = std::ENET_HOST_ANY;
+    bindAddress.host = ENET_HOST_ANY;
     bindAddress.port = NETWORK_PORT;
   }
@@ -32,23 +34,79 @@
   }
   
-  void ConnectionManager::loop(){
-    if(!quit && !buffer.isEmpty()){
-      // to be implemented =================
-      
-    }
-  }
-  
-  bool ConnectionManager::createListener(){
-    threads.create_thread(&peerLoop);
-    return true;
-  }
-  
-  bool ConnectionManager::quitServer(){
+  
+  ENetPacket *ConnectionManager::getPacket(){
+    if(!buffer.isEmpty())
+      return buffer.pop();
+    else
+        return NULL;
+  }
+  
+  bool ConnectionManager::queueEmpty(){
+    return buffer.isEmpty();
+  }
+  
+  void ConnectionManager::createListener(){
+    network_threads.create_thread(boost::bind(boost::mem_fn(&ConnectionManager::receiverThread), this));
+//     boost::thread thr(boost::bind(boost::mem_fn(&ConnectionManager::receiverThread), this));
+    return;
+  }
+  
+  bool ConnectionManager::quitListener(){
     quit=true;
-    threads.join_all();
-    return true;
-  }
-  
-  bool ConnectionManager::peerLoop(){
+    network_threads.join_all();
+    return true;
+  }
+  
+  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer){
+    if(client=NULL)
+      return false;
+    ClientList *temp=client;
+    while(peer->host != temp->event->peer->host){
+      temp=temp->next;
+      if(temp==NULL)
+        return false;
+    }
+    if(enet_peer_send(temp->event->peer, temp->ID, packet)!=0)
+      return false;
+    return true;
+  }
+  
+  bool ConnectionManager::addPacket(ENetPacket *packet, int ID){
+    if(client=NULL)
+      return false;
+    ClientList *temp=client;
+    while(ID != temp->ID){
+      temp=temp->next;
+      if(temp==NULL)
+        return false;
+    }
+    if(enet_peer_send(temp->event->peer, temp->ID, packet)!=0)
+      return false;
+    else
+      return true;
+  }
+  
+  bool ConnectionManager::addPacketAll(ENetPacket *packet){
+    ClientList *temp=client;
+    while(temp!=NULL){
+      if(enet_peer_send(temp->event->peer, temp->ID, packet)!=0)
+         return false;
+    }
+    return true;
+  }
+  
+  bool ConnectionManager::sendPackets(ENetEvent *event){
+    if(server==NULL)
+      return false;
+    if(enet_host_service(server, event, NETWORK_SEND_WAIT)>=0)
+      return true;
+    else 
+      return false;
+  }
+  
+  void ConnectionManager::receiverThread(){
+    // what about some error-handling here ?
+    enet_initialize();
+    atexit(enet_deinitialize);
     ENetEvent event;
     server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
@@ -65,11 +123,12 @@
       switch(event.type){
         // log handling ================
-      case std::EVENT_TYPE_CONNECT:
-        addClient(event);
+        case ENET_EVENT_TYPE_CONNECT:
+        addClient(&event);
         break;
-      case std::EVENT_TYPE_RECEIVE:
-        processData(event);
+      case ENET_EVENT_TYPE_RECEIVE:
+        std::cout << event.packet->data << std::endl;
+        processData(&event);
         break;
-      case std::EVENT_TYPE_DISCONNECT:
+      case ENET_EVENT_TYPE_DISCONNECT:
         // add some error/log handling here
         clientDisconnect(event.peer);
@@ -81,12 +140,14 @@
   }
   
-  ConnectionManager::processData(ENetEvent event){
-//     insert packetdecode and buffer stuff here
-    
-  }
-  
-  bool ConnectionManager::clientDisconnect(ENetPeer peer){
-    ClientList *temp=client;
-    if(temp->event.peer==peer){
+  bool ConnectionManager::processData(ENetEvent *event){
+    // just add packet to the buffer
+    // this can be extended with some preprocessing
+    return buffer.push(event->packet);
+  }
+  
+  bool ConnectionManager::clientDisconnect(ENetPeer *peer){
+    ClientList *temp=client;
+    // do we have to remove the first item ?
+    if(temp->event->peer->host==peer->host){
       if(temp->next==NULL){
         client=NULL;
@@ -98,5 +159,6 @@
     } else {
       while(temp->next!=NULL){
-        if(temp->next->event.peer==peer){
+        if(temp->next->event->peer->host==peer->host){
+          // do a correct relink and delete the disconnected client
           ClientList *temp2=temp->next;
           temp->next=temp2->next;
@@ -104,4 +166,5 @@
           return true;
         } else
+          //otherwise keep on searching ;)
           temp=temp->next;
       }
@@ -110,5 +173,7 @@
   }
   
-  bool ConnectionManager::addClient(ENetEvent event){
+  bool ConnectionManager::addClient(ENetEvent *event){
+    
+    // first client?
     if(client==NULL){
       client =new ClientList;
@@ -117,5 +182,6 @@
       client->event = event;
     } else {
-      ClienList *temp = client;
+      // otherwise add a new element to clientlist
+      ClientList *temp = client;
       int i=1;
       while(temp->next != NULL){
@@ -132,8 +198,4 @@
   }
   
-  void ConnectionManager::test(){
-    while(!quit)
-    
-    
-  }
+  
 }
Index: code/branches/network/src/network/ConnectionManager.h
===================================================================
--- code/branches/network/src/network/ConnectionManager.h	(revision 195)
+++ code/branches/network/src/network/ConnectionManager.h	(revision 196)
@@ -5,5 +5,5 @@
 //
 //
-// Author:  <>, (C) 2007
+// Author:  Oliver Scheuss, (C) 2007
 //
 // Copyright: See COPYING file that comes with this distribution
@@ -13,5 +13,13 @@
 #define NETWORK_CONNECTIONMANAGER_H
 
-#include PacketBuffer.h
+#include <iostream>
+// enet library for networking support
+#include <enet/enet.h>
+// boost.thread library for multithreading support
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+// headerfile
+#include "network/ConnectionManager.h"
+#include "network/PacketBuffer.h"
 
 namespace network{
@@ -20,12 +28,13 @@
 #define NETWORK_MAX_CONNECTIONS 50
 #define NETWORK_WAIT_TIMEOUT 5000
+#define NETWORK_SEND_WAIT 5
   //just some defines to make life easier ;)
-#define ENetEvent std::ENetEvent
-#define ENetHost std::ENetHost
-#define ENetAddress std::ENetAddress
-#define ENetPeer std::ENetPeer
+// #define ENetEvent std::ENetEvent
+// #define ENetHost std::ENetHost
+// #define ENetAddress std::ENetAddress
+// #define ENetPeer std::ENetPeer
   
   struct ClientList{
-    ENetEvent event;
+    ENetEvent *event;
     int ID;
     ClientList *next;
@@ -35,16 +44,25 @@
     public:
     ConnectionManager();
-    ~ConnectionManager();
-    void loop(); // thread1
-    bool createListener();
-    bool quitServer();
-    bool sendEventAll(/*.....*/);
-    bool sendEvent(int clientID/*.....*/);
-    void test();
+    ConnectionManager(int port, int address);
+    ENetPacket *getPacket(); // thread1
+    // check wheter the packet queue is empty
+    bool queueEmpty();
+    // create a new listener thread
+    void createListener();
+    bool quitListener();
+    // add a packet to queue for a specific client peer
+    bool addPacket(ENetPacket *packet, ENetPeer *peer);
+    // add ad packet to queue for a specific client ID
+    bool addPacket(ENetPacket *packet, int ID);
+    // add a packet to queue for all clients
+    bool addPacketAll(ENetPacket *packet);
+    // send out all queued packets
+    bool sendPackets(ENetEvent *event);
     private:
-    void peerLoop(int clientNumber); //thread2
-    bool clientDisconnect(ENetPeer peer);
-    bool processData(ENetEvent event);
-    bool addClient(ENetEvent event);
+    bool clientDisconnect(ENetPeer *peer);
+    bool processData(ENetEvent *event);
+    bool addClient(ENetEvent *event);
+    // implementation of the listener
+    void receiverThread(); //thread2
     //packetbuffer
     PacketBuffer buffer;
@@ -54,8 +72,8 @@
     // quit-variable (communication with threads)
     bool quit;
-    // thread group
-    boost::thread_group threads;
     // clientlist
     ClientList *client;
+//     thread group
+//     boost::thread_group threads;
   };
   
Index: code/branches/network/src/network/Makefile
===================================================================
--- code/branches/network/src/network/Makefile	(revision 196)
+++ code/branches/network/src/network/Makefile	(revision 196)
@@ -0,0 +1,20 @@
+all: server client
+
+# Link command:
+server: clean PacketBuffer.o ConnectionManager.o dummyserver.o
+	g++ ConnectionManager.o dummyserver.o PacketBuffer.o -o server -lenet -lboost_thread -g
+
+dummyserver.o:
+	g++ -c dummyserver.cc -o dummyserver.o -g
+# Compilation commands:
+ConnectionManager.o:
+	g++ -c ConnectionManager.cc -o ConnectionManager.o -g
+
+PacketBuffer.o: 
+	g++ -c PacketBuffer.cc -o PacketBuffer.o -g
+
+clean:
+	rm -rf *.o
+
+client:
+	g++ dummyclient.cc -o client -lenet
Index: code/branches/network/src/network/PacketBuffer.cc
===================================================================
--- code/branches/network/src/network/PacketBuffer.cc	(revision 195)
+++ code/branches/network/src/network/PacketBuffer.cc	(revision 196)
@@ -1,10 +1,16 @@
 // C++ PacketBuffer
-// 
+// d
 // Author Oliver Scheuss
+
+#ifndef NETWORK_PACKETBUFFER_CC
+#define NETWORK_PACKETBUFFER_CC
+
 #include <iostream>
 #include "network/PacketBuffer.h"
 
 namespace network{
-
+  
+   boost::mutex networkPacketBufferMutex;
+  
 PacketBuffer::PacketBuffer(){
   closed=false;
@@ -12,4 +18,6 @@
   last=NULL;
 }
+    //this is needed in order to make the packetbuffer threadsafe
+  
 
 bool PacketBuffer::push(ENetPacket *pck){
@@ -79,2 +87,4 @@
 
 }// namespace network
+
+#endif
Index: code/branches/network/src/network/PacketBuffer.h
===================================================================
--- code/branches/network/src/network/PacketBuffer.h	(revision 195)
+++ code/branches/network/src/network/PacketBuffer.h	(revision 196)
@@ -19,10 +19,8 @@
 #include <boost/bind.hpp>
 #include <boost/thread/mutex.hpp>
-#include <boost/thread/mutex.hpp>
 
-//this is needed in order to make the packetbuffer threadsafe
-boost::mutex networkPacketBufferMutex;
 
 namespace network{
+
 
 struct PacketEnvelope{
@@ -47,4 +45,5 @@
   // pushs a packet to the queue
   bool push(ENetPacket *pck);
+  
 private:
   QueueItem *first;
@@ -52,6 +51,4 @@
   bool closed;
   
-  //make it threadsafe
-//   boost::mutex mutex;
 };
 
Index: code/branches/network/src/network/dummyclient.cc
===================================================================
--- code/branches/network/src/network/dummyclient.cc	(revision 196)
+++ code/branches/network/src/network/dummyclient.cc	(revision 196)
@@ -0,0 +1,78 @@
+//
+// Dummy client to test ConnectionManager and PacketBuffer classes
+//
+// Author: Oliver Scheuss
+
+#include <iostream>
+#include "enet/enet.h"
+
+using namespace std;
+
+int main(){
+  ENetHost * client;
+  ENetAddress address;
+  ENetEvent event;
+  ENetPeer *peer;
+
+  enet_initialize();
+  atexit(enet_deinitialize);
+  
+  enet_address_set_host(&address, "127.0.0.1");
+  address.port = 5555;
+
+        // create client object
+  client = enet_host_create(NULL, 2, 0, 0);
+
+  if(client==NULL){
+    fprintf(stderr, "An error occured");
+    exit(EXIT_FAILURE);
+  }
+        // connect peer
+  peer = enet_host_connect(client, &address, 2);
+  if(peer==NULL){
+    fprintf(stderr, "Peer establishing error");
+    exit(EXIT_FAILURE);
+  }
+        // wait 5 seconds for the connection attempt to succeed
+  if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){
+    puts("Connection to localhost:5555 succeeded.");
+  }else{
+    enet_peer_reset(peer);
+    puts("Connection to localhost:5555 failed.");
+  }
+
+  for(int i=0; i<10; i++){
+        // weihnachtsmann bringt packete
+    ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);
+        // extend the packet and append the string foo to it
+        // send packet to peer on channel id 0
+    enet_peer_send(peer, 1, packet);
+        // keep the timeout very small for low delay
+    if(enet_host_service(client, &event, 1)==0){
+      cout << "successfully sent: " << event.type << endl;
+    }else{
+      cout << "failed sending" << endl;
+    }
+  }
+
+        // now disconnect
+  enet_peer_disconnect (peer, 0);
+        // 3 seconds timeout
+  while(enet_host_service(client, &event, 3000) > 0){
+    switch (event.type)
+    {
+      case ENET_EVENT_TYPE_RECEIVE:
+        enet_packet_destroy(event.packet);
+        break;
+      case ENET_EVENT_TYPE_DISCONNECT:
+        puts("Disconnection succeeded.");
+        return 0;
+    }
+  }
+        // if disconnect failed
+  enet_peer_reset(peer);
+
+  
+  
+  return 0;
+}
Index: code/branches/network/src/network/dummyserver.cc
===================================================================
--- code/branches/network/src/network/dummyserver.cc	(revision 196)
+++ code/branches/network/src/network/dummyserver.cc	(revision 196)
@@ -0,0 +1,34 @@
+//
+// Dummy server to test ConnectionManager and PacketBuffer classes
+//
+// Author: Oliver Scheuss
+
+
+#include <iostream>
+#include "enet/enet.h"
+#include "network/ConnectionManager.h"
+
+using namespace network;
+
+int main(){
+  ConnectionManager server = ConnectionManager();
+  bool quit=false;
+  ENetPacket *packet;
+  server.createListener();
+  while(!quit){
+    if(server.queueEmpty())
+      usleep(100);
+    else{
+      packet=server.getPacket();
+      if(packet==NULL){
+        // there was some error
+        //std::cout << "null pointer" << std::endl;
+        quit=true;
+      }
+      else
+        std::cout << "We received: " << packet->data << std::endl;
+    }
+  }
+  server.quitListener();
+  return 0;
+}
