Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 31, 2007, 7:40:23 PM (16 years ago)
Author:
rgrieder
Message:
  • added dll support to the network library
  • improved header file dependency in network
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/network/PacketBuffer.cc

    r632 r777  
    11/*
    2  *   ORXONOX - the hottest 3D action shooter ever to exist
    3  *
    4  *
    5  *   License notice:
    6  *
    7  *   This program is free software; you can redistribute it and/or
    8  *   modify it under the terms of the GNU General Public License
    9  *   as published by the Free Software Foundation; either version 2
    10  *   of the License, or (at your option) any later version.
    11  *
    12  *   This program is distributed in the hope that it will be useful,
    13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  *   GNU General Public License for more details.
    16  *
    17  *   You should have received a copy of the GNU General Public License
    18  *   along with this program; if not, write to the Free Software
    19  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20  *
    21  *   Author:
    22  *      Oliver Scheuss, (C) 2007
    23  *   Co-authors:
    24  *      ...
    25  *
    26  */
     2*   ORXONOX - the hottest 3D action shooter ever to exist
     3*
     4*
     5*   License notice:
     6*
     7*   This program is free software; you can redistribute it and/or
     8*   modify it under the terms of the GNU General Public License
     9*   as published by the Free Software Foundation; either version 2
     10*   of the License, or (at your option) any later version.
     11*
     12*   This program is distributed in the hope that it will be useful,
     13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15*   GNU General Public License for more details.
     16*
     17*   You should have received a copy of the GNU General Public License
     18*   along with this program; if not, write to the Free Software
     19*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     20*
     21*   Author:
     22*      Oliver Scheuss, (C) 2007
     23*   Co-authors:
     24*      ...
     25*
     26*/
    2727
    2828// C++ PacketBuffer
     
    3030// Author Oliver Scheuss
    3131
    32 #ifndef NETWORK_PACKETBUFFER_CC
    33 #define NETWORK_PACKETBUFFER_CC
     32#include <iostream>
     33#include <queue>
     34#include <string>
     35#include <boost/bind.hpp>
     36#include <boost/thread/mutex.hpp>
    3437
    35 #include <iostream>
    3638#include "PacketBuffer.h"
    3739
    38 namespace network{
     40namespace network
     41{
     42  boost::mutex networkPacketBufferMutex;
    3943
    40    boost::mutex networkPacketBufferMutex;
    41 
    42 PacketBuffer::PacketBuffer(){
    43   closed=false;
    44   first=NULL;
    45   last=NULL;
    46 }
    47     //this is needed in order to make the packetbuffer threadsafe
     44  PacketBuffer::PacketBuffer() {
     45    closed=false;
     46    first=NULL;
     47    last=NULL;
     48  }
     49  //this is needed in order to make the packetbuffer threadsafe
    4850
    4951
    50 bool PacketBuffer::push(ENetEvent *ev){
    51   boost::mutex::scoped_lock lock(networkPacketBufferMutex);
    52   //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl;
    53 //   if(closed)
    54 //     return false;
    55   // first element?
    56   if(first==NULL){
    57     first=new QueueItem;
    58     last=first;
    59     last->next=NULL;
    60     // change this!!!!!!!
    61     last->packet = ev->packet;
    62     last->address = ev->peer->address;
     52  bool PacketBuffer::push(ENetEvent *ev) {
     53    boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     54    //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl;
     55    //   if(closed)
     56    //     return false;
     57    // first element?
     58    if(first==NULL){
     59      first=new QueueItem;
     60      last=first;
     61      last->next=NULL;
     62      // change this!!!!!!!
     63      last->packet = ev->packet;
     64      last->address = ev->peer->address;
    6365    } else {
    64     //insert a new element at the bottom
    65     last->next = new QueueItem;
    66     last=last->next;
    67     // initialize last->next
    68     last->next=NULL;
    69     // save the packet to the new element
    70     last->packet = ev->packet;
    71     last->address = ev->peer->address;
    72   }
    73   return true;
    74 }
    75 
    76 ENetPacket *PacketBuffer::pop(){
    77   boost::mutex::scoped_lock lock(networkPacketBufferMutex);
    78   //std::cout << "packetbuffer pop" << std::endl;
    79   if(first!=NULL /*&& !closed*/){
    80     QueueItem *temp = first;
    81     // get packet
    82     ENetPacket *pck=first->packet;
    83     // remove first element
    84     first = first->next;
    85     delete temp;
    86     //std::cout << "pop size of packet " << pck->dataLength << std::endl;
    87     return pck;
    88   } else{
    89     //std::cout << "nothing to return" << std::endl;
    90     return NULL;
    91   }
    92 }
    93 
    94 ENetPacket *PacketBuffer::pop(ENetAddress &address){
    95   boost::mutex::scoped_lock lock(networkPacketBufferMutex);
    96   //std::cout << "packetbuffer pop(address)" << std::endl;
    97   if(first!=NULL /*&& !closed*/){
    98     QueueItem *temp = first;
    99     // get packet
    100     ENetPacket *pck=first->packet;
    101     address = first->address;
    102     // remove first element
    103     first = first->next;
    104     delete temp;
    105     //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
    106     return pck;
    107   } else{
    108     return NULL;
    109   }
    110 }
    111 
    112 bool PacketBuffer::isEmpty(){
    113   return (first==NULL);
    114 }
    115 
    116 void PacketBuffer::print(){
    117   QueueItem *temp=first;
    118   while(temp!=NULL){
    119 //    std::cout << temp->packet->data << std::endl;
    120     temp=temp->next;
     66      //insert a new element at the bottom
     67      last->next = new QueueItem;
     68      last=last->next;
     69      // initialize last->next
     70      last->next=NULL;
     71      // save the packet to the new element
     72      last->packet = ev->packet;
     73      last->address = ev->peer->address;
     74    }
     75    return true;
    12176  }
    12277
    123 }
     78  ENetPacket *PacketBuffer::pop() {
     79    boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     80    //std::cout << "packetbuffer pop" << std::endl;
     81    if(first!=NULL /*&& !closed*/){
     82      QueueItem *temp = first;
     83      // get packet
     84      ENetPacket *pck=first->packet;
     85      // remove first element
     86      first = first->next;
     87      delete temp;
     88      //std::cout << "pop size of packet " << pck->dataLength << std::endl;
     89      return pck;
     90    } else{
     91      //std::cout << "nothing to return" << std::endl;
     92      return NULL;
     93    }
     94  }
    12495
    125 bool PacketBuffer::isClosed(){
    126   return closed;
    127 }
     96  ENetPacket *PacketBuffer::pop(ENetAddress &address) {
     97    boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     98    //std::cout << "packetbuffer pop(address)" << std::endl;
     99    if(first!=NULL /*&& !closed*/){
     100      QueueItem *temp = first;
     101      // get packet
     102      ENetPacket *pck=first->packet;
     103      address = first->address;
     104      // remove first element
     105      first = first->next;
     106      delete temp;
     107      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
     108      return pck;
     109    } else{
     110      return NULL;
     111    }
     112  }
    128113
    129 void PacketBuffer::setClosed(bool value){
    130   closed=value;
    131   return;
    132 }
     114  bool PacketBuffer::isEmpty() {
     115    return (first==NULL);
     116  }
    133117
    134 }// namespace network
     118  void PacketBuffer::print() {
     119    QueueItem *temp=first;
     120    while(temp!=NULL){
     121      //    std::cout << temp->packet->data << std::endl;
     122      temp=temp->next;
     123    }
    135124
    136 #endif
     125  }
     126
     127  bool PacketBuffer::isClosed() {
     128    return closed;
     129  }
     130
     131  void PacketBuffer::setClosed(bool value){
     132    closed=value;
     133    return;
     134  }
     135
     136} // namespace network
Note: See TracChangeset for help on using the changeset viewer.