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/ClientConnection.cc

    r742 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//
     
    3737//
    3838
     39#include <iostream>
     40// boost.thread library for multithreading support
     41#include <boost/thread/thread.hpp>
     42#include <boost/bind.hpp>
     43
     44#include "util/Sleep.h"
    3945#include "ClientConnection.h"
    4046
    41 #include "util/Sleep.h"
    42 
    43 namespace network{
    44 
     47namespace network
     48{
    4549  static boost::thread_group network_threads;
    4650
    47   ClientConnection::ClientConnection(int port, std::string address){
     51  ClientConnection::ClientConnection(int port, std::string address) {
    4852    quit=false;
    4953    server=NULL;
     
    5357  }
    5458
    55   ClientConnection::ClientConnection(int port, const char *address){
     59  ClientConnection::ClientConnection(int port, const char *address) {
    5660    quit=false;
    5761    server=NULL;
     
    6165  }
    6266
    63   bool ClientConnection::waitEstablished(int milisec){
     67  bool ClientConnection::waitEstablished(int milisec) {
    6468    for(int i=0; i<=milisec && !established; i++)
    6569      usleep(1000);
     
    6973
    7074
    71   ENetPacket *ClientConnection::getPacket(ENetAddress &address){
     75  ENetPacket *ClientConnection::getPacket(ENetAddress &address) {
    7276    if(!buffer.isEmpty()) {
    7377      //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl;
     
    7579    }
    7680    else{
    77         return NULL;
    78     }
    79   }
    80 
    81   ENetPacket *ClientConnection::getPacket(){
     81      return NULL;
     82    }
     83  }
     84
     85  ENetPacket *ClientConnection::getPacket() {
    8286    ENetAddress address;
    8387    return getPacket(address);
    8488  }
    8589
    86   bool ClientConnection::queueEmpty(){
     90  bool ClientConnection::queueEmpty() {
    8791    return buffer.isEmpty();
    8892  }
    8993
    90   bool ClientConnection::createConnection(){
     94  bool ClientConnection::createConnection() {
    9195    network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this));
    9296    // wait 10 seconds for the connection to be established
     
    9498  }
    9599
    96   bool ClientConnection::closeConnection(){
     100  bool ClientConnection::closeConnection() {
    97101    quit=true;
    98102    network_threads.join_all();
     
    102106
    103107
    104   bool ClientConnection::addPacket(ENetPacket *packet){
     108  bool ClientConnection::addPacket(ENetPacket *packet) {
    105109    if(server==NULL)
    106110      return false;
     
    110114  }
    111115
    112   bool ClientConnection::sendPackets(ENetEvent *event){
     116  bool ClientConnection::sendPackets(ENetEvent *event) {
    113117    if(server==NULL)
    114118      return false;
     
    119123  }
    120124
    121   bool ClientConnection::sendPackets(){
     125  bool ClientConnection::sendPackets() {
    122126    ENetEvent event;
    123127    if(server==NULL)
     
    129133  }
    130134
    131   void ClientConnection::receiverThread(){
     135  void ClientConnection::receiverThread() {
    132136    // what about some error-handling here ?
    133137    enet_initialize();
     
    170174
    171175    if(!disconnectConnection())
    172     // if disconnecting failed destroy conn.
     176      // if disconnecting failed destroy conn.
    173177      enet_peer_reset(server);
    174178    return;
    175179  }
    176180
    177   bool ClientConnection::disconnectConnection(){
     181  bool ClientConnection::disconnectConnection() {
    178182    ENetEvent event;
    179183    enet_peer_disconnect(server, 0);
     
    181185      switch (event.type)
    182186      {
    183         case ENET_EVENT_TYPE_NONE:
    184         case ENET_EVENT_TYPE_CONNECT:
    185         case ENET_EVENT_TYPE_RECEIVE:
    186           enet_packet_destroy(event.packet);
    187           break;
    188         case ENET_EVENT_TYPE_DISCONNECT:
    189           return true;
     187      case ENET_EVENT_TYPE_NONE:
     188      case ENET_EVENT_TYPE_CONNECT:
     189      case ENET_EVENT_TYPE_RECEIVE:
     190        enet_packet_destroy(event.packet);
     191        break;
     192      case ENET_EVENT_TYPE_DISCONNECT:
     193        return true;
    190194      }
    191195    }
     
    194198  }
    195199
    196   bool ClientConnection::establishConnection(){
     200  bool ClientConnection::establishConnection() {
    197201    ENetEvent event;
    198202    // connect to peer
     
    210214  }
    211215
    212   bool ClientConnection::processData(ENetEvent *event){
     216  bool ClientConnection::processData(ENetEvent *event) {
    213217    //std::cout << "got packet, pushing to queue" << std::endl;
    214218    // just add packet to the buffer
     
    217221  }
    218222
    219 
    220223}
Note: See TracChangeset for help on using the changeset viewer.