Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 13, 2009, 5:05:17 PM (15 years ago)
Author:
dafrick
Message:

Hopefully merged trunk successfully into pickup branch.

Location:
code/branches/pickup
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup

  • code/branches/pickup/src/libraries/network/Client.cc

    r5781 r5935  
    4343#include <cassert>
    4444
     45#include "util/Clock.h"
    4546#include "util/Debug.h"
    46 #include "core/Clock.h"
    4747#include "synchronisable/Synchronisable.h"
    4848#include "packet/Chat.h"
    4949#include "packet/Gamestate.h"
    5050#include "FunctionCallManager.h"
     51#include "core/CoreIncludes.h"
     52#include "core/Game.h"
    5153
    5254namespace orxonox
     
    158160    return;
    159161  }
     162 
     163  void Client::connectionClosed()
     164  {
     165    ObjectList<Synchronisable>::iterator it;
     166    for(it = ObjectList<Synchronisable>::begin(); it; )
     167    {
     168      if( it->getSyncMode() != 0x0 )
     169        (it++)->destroy();
     170      else
     171      {
     172        ++it;
     173      }
     174    }
     175    Game::getInstance().popState();
     176    Game::getInstance().popState();
     177  }
    160178
    161179}
  • code/branches/pickup/src/libraries/network/Client.h

    r5781 r5935  
    4545
    4646#include <string>
     47
     48#include "util/UtilPrereqs.h"
    4749#include "ClientConnection.h"
    4850#include "GamestateClient.h"
     
    7274
    7375    void update(const Clock& time);
    74 
     76  protected:
     77    virtual void connectionClosed();
    7578  private:
    7679    Client(const Client& copy); // not used
  • code/branches/pickup/src/libraries/network/ClientConnection.cc

    r5781 r5935  
    118118          case ENET_EVENT_TYPE_DISCONNECT:
    119119            COUT(4) << "received disconnect confirmation from server" << endl;
     120            this->connectionClosed();
    120121            return true;
    121122        }
     
    123124    }
    124125    enet_peer_reset( this->server_ );
     126    this->connectionClosed();
    125127    return false;
    126128  }
     
    133135  }
    134136
    135   void ClientConnection::addClient(ENetEvent* event)
     137  void ClientConnection::addPeer(ENetEvent* event)
    136138  {
    137139    assert(0);
    138140  }
    139   void ClientConnection::disconnectPeer(ENetEvent* event)
     141  void ClientConnection::removePeer(ENetEvent* event)
    140142  {
    141143    this->established_=false;
    142144    COUT(1) << "Received disconnect Packet from Server!" << endl;
    143145        // server closed the connection
     146    this->connectionClosed();
    144147  }
    145148
  • code/branches/pickup/src/libraries/network/ClientConnection.h

    r5781 r5935  
    5353    bool addPacket(ENetPacket *packet);
    5454    inline bool isConnected(){ return this->established_; }
     55  protected:
     56    virtual void connectionClosed()=0;
    5557  private:
    56     virtual void addClient(ENetEvent* event);
    57     virtual void disconnectPeer(ENetEvent* event);
     58    virtual void addPeer(ENetEvent* event);
     59    virtual void removePeer(ENetEvent* event);
    5860   
    5961    bool disconnectConnection();
  • code/branches/pickup/src/libraries/network/ClientConnectionListener.cc

    r5781 r5935  
    3333#include "ClientInformation.h"
    3434
    35 namespace orxonox{
     35namespace orxonox
     36{
     37    ClientConnectionListener::ClientConnectionListener()
     38    {
     39        RegisterRootObject(ClientConnectionListener);
     40    }
    3641
    37   ClientConnectionListener::ClientConnectionListener()
    38   {
    39     RegisterRootObject(ClientConnectionListener);
    40   }
     42    void ClientConnectionListener::broadcastClientConnected(unsigned int clientID)
     43    {
     44        for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)
     45            it->clientConnected(clientID);
     46    }
     47   
     48    void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID)
     49    {
     50        for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)
     51            it->clientDisconnected(clientID);
     52    }
    4153
    42   void ClientConnectionListener::getConnectedClients(){
    43     if(GameMode::showsGraphics())
    44       this->clientConnected(0); //server client id
    45     ClientInformation *client = ClientInformation::getBegin();
    46     while(client){
    47       this->clientConnected(client->getID());
    48       client=client->next();
     54    void ClientConnectionListener::getConnectedClients()
     55    {
     56        ClientInformation* client = ClientInformation::getBegin();
     57        while (client)
     58        {
     59            this->clientConnected(client->getID());
     60            client = client->next();
     61        }
    4962    }
    50   }
    51 
    5263}
    5364
  • code/branches/pickup/src/libraries/network/ClientConnectionListener.h

    r5781 r5935  
    3333#include "core/OrxonoxClass.h"
    3434
    35 namespace orxonox{
     35namespace orxonox
     36{
     37    class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
     38    {
     39        public:
     40            ClientConnectionListener();
     41            virtual ~ClientConnectionListener() {}
     42           
     43            static void broadcastClientConnected(unsigned int clientID);
     44            static void broadcastClientDisconnected(unsigned int clientID);
    3645
    37   class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
    38   {
    39     friend class Server;
     46            virtual void clientConnected(unsigned int clientID) = 0;
     47            virtual void clientDisconnected(unsigned int clientID) = 0;
    4048
    41   public:
    42     ClientConnectionListener();
    43     virtual ~ClientConnectionListener() {}
    44 
    45     void getConnectedClients();
    46 
    47   protected:
    48     virtual void clientConnected(unsigned int clientID) = 0;
    49     virtual void clientDisconnected(unsigned int clientID) = 0;
    50   };
    51 
     49        protected:
     50            void getConnectedClients();
     51    };
    5252}
    5353
  • code/branches/pickup/src/libraries/network/Connection.cc

    • Property svn:eol-style set to native
    r5781 r5935  
    8383        // log handling ================
    8484        case ENET_EVENT_TYPE_CONNECT:
    85           addClient( &event );
     85          addPeer( &event );
    8686          break;
    8787        case ENET_EVENT_TYPE_DISCONNECT:
    88           disconnectPeer( &event );
     88          removePeer( &event );
    8989          break;
    9090        case ENET_EVENT_TYPE_RECEIVE:
  • code/branches/pickup/src/libraries/network/Connection.h

    • Property svn:eol-style set to native
    r5781 r5935  
    6464   
    6565    int service(ENetEvent* event);
    66     void disconnectPeer(ENetPeer *peer);
     66    virtual void disconnectPeer(ENetPeer *peer);
    6767   
    6868    void processQueue();
    69     virtual void addClient(ENetEvent* event)=0;
    70     virtual void disconnectPeer(ENetEvent* event)=0;
     69    virtual void addPeer(ENetEvent* event)=0;
     70    virtual void removePeer(ENetEvent* event)=0;
    7171    virtual bool processPacket(ENetEvent* event);
    7272   
  • code/branches/pickup/src/libraries/network/GamestateClient.cc

    r5781 r5935  
    108108    ObjectList<Synchronisable>::iterator temp=it;
    109109    ++it;
    110     delete  *temp;
     110    temp->destroy(); // or delete?
    111111  }
    112112
  • code/branches/pickup/src/libraries/network/GamestateManager.cc

    r5781 r5935  
    7777        delete (*it2).second;
    7878    }
    79     delete this->trafficControl_;
     79    this->trafficControl_->destroy();
    8080//     delete this->threadMutex_;
    8181//     delete this->threadPool_;
     
    160160      finishGamestate( cid, &clientGamestates.back(), client, reference );
    161161      //FunctorMember<GamestateManager>* functor =
    162 //       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) );
    163 //       executor->setObject(this);
     162//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) );
    164163//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
    165164//       (*static_cast<Executor*>(executor))();
  • code/branches/pickup/src/libraries/network/NetworkFunction.cc

    r5781 r5935  
    6060    std::map<std::string, NetworkFunctionBase*>::iterator it;
    6161    for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )
    62       delete it->second;
     62      it->second->destroy();
    6363  }
    6464 
  • code/branches/pickup/src/libraries/network/NetworkPrereqs.h

    r5781 r5935  
    2828
    2929/**
    30   @file
    31   @brief Contains all the necessary forward declarations for all classes and structs.
     30@file
     31@brief
     32    Shared library macros, enums, constants and forward declarations for the network library
    3233*/
    3334
     
    4041// Shared library settings
    4142//-----------------------------------------------------------------------
     43
    4244#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( NETWORK_STATIC_BUILD )
    4345#  ifdef NETWORK_SHARED_BUILD
     
    5759
    5860//-----------------------------------------------------------------------
    59 // Library global contants
     61// Constants
    6062//-----------------------------------------------------------------------
     63
    6164namespace orxonox
    6265{
    6366  static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
    6467  static const unsigned int CLIENTID_UNKNOWN    = static_cast<unsigned int>(-2);
    65   static const uint32_t     OBJECTID_UNKNOWN    = static_cast<uint32_t>(-1);
     68}
     69
     70//-----------------------------------------------------------------------
     71// Enums
     72//-----------------------------------------------------------------------
     73
     74namespace orxonox
     75{
     76  namespace packet
     77  {
     78    namespace PacketFlag
     79    {
     80      enum Value
     81      {
     82        Reliable   = 1,
     83        Unsequence = 2,
     84        NoAllocate = 4
     85      };
     86    }
     87  }
    6688}
    6789
     
    84106namespace orxonox
    85107{
     108  class ChatListener;
    86109  class Client;
    87110  class ClientConnection;
    88111  class ClientConnectionListener;
    89   class ClientFrameListener;
    90112  class ClientInformation;
    91113  class Connection;
    92114  class FunctionCallManager;
    93115  class GamestateClient;
     116  class GamestateHandler;
    94117  class GamestateManager;
    95   class GamestateHandler;
    96   class NetworkCallbackBase;
    97   template <class T> class NetworkCallback;
    98   class NetworkCallbackManager;
     118  class Host;
    99119  class NetworkFunctionBase;
     120  struct NetworkFunctionPointer;
    100121  class NetworkFunctionStatic;
     122  template <class T>
     123  class NetworkMemberFunction;
    101124  class NetworkMemberFunctionBase;
    102   template <class T> class NetworkMemeberFunction;
    103   struct NetworkFunctionPointer;
    104125  class Server;
    105126  class ServerConnection;
    106   class ServerFrameListener;
    107   class Synchronisable;
    108   class SynchronisableVariableBase;
    109   template <class T> class SynchronisableVariable;
    110   template <class T> class SynchronisableVariableBidirectional;
    111   struct ClientList;
    112   struct PacketEnvelope;
    113   struct QueueItem;
    114   struct syncData;
    115127  class TrafficControl;
    116   class obj;
    117   class objInfo;
    118128
     129  // packet
    119130  namespace packet
    120131  {
     
    122133    class Chat;
    123134    class ClassID;
     135    class DeleteObjects;
    124136    class FunctionCalls;
    125137    class FunctionIDs;
    126138    class Gamestate;
    127     class NetworkIDs;
    128139    class Packet;
    129140    class Welcome;
     141  }
    130142
    131     namespace PacketFlag
    132     {
    133       enum Value
    134       {
    135         Reliable   = 1,
    136         Unsequence = 2,
    137         NoAllocate = 4
    138       };
    139     }
    140   }
     143  // synchronisable
     144  template <class T>
     145  class NetworkCallback;
     146  class NetworkCallbackBase;
     147  class NetworkCallbackManager;
     148  class Synchronisable;
     149  class SynchronisableHeader;
     150  template <class T>
     151  class SynchronisableVariable;
     152  class SynchronisableVariableBase;
     153  template <class T>
     154  class SynchronisableVariableBidirectional;
    141155}
    142156
  • code/branches/pickup/src/libraries/network/Server.cc

    r5781 r5935  
    4646#include <string>
    4747
     48#include "util/Clock.h"
    4849#include "util/Debug.h"
    49 #include "core/Clock.h"
    5050#include "core/ObjectList.h"
    5151#include "core/Executor.h"
     
    245245    packet::DeleteObjects *del = new packet::DeleteObjects();
    246246    if(!del->fetchIDs())
     247    {
     248      delete del;
    247249      return true;  //everything ok (no deletes this tick)
     250    }
    248251//     COUT(3) << "sending DeleteObjects" << std::endl;
    249252    while(temp != NULL){
     
    267270
    268271
    269   void Server::addClient(ENetEvent *event){
     272  void Server::addPeer(ENetEvent *event){
    270273    static unsigned int newid=1;
    271274
     
    279282
    280283    // inform all the listeners
    281     ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
    282     while(listener){
    283       listener->clientConnected(newid);
    284       listener++;
    285     }
     284    ClientConnectionListener::broadcastClientConnected(newid);
    286285
    287286    ++newid;
     
    290289    createClient(temp->getID());
    291290}
     291
     292  void Server::removePeer(ENetEvent *event)
     293  {
     294    COUT(4) << "removing client from list" << std::endl;
     295    ClientInformation *client = ClientInformation::findClient(&event->peer->address);
     296    if(!client)
     297      return;
     298    else
     299    {
     300      //ServerConnection::disconnectClient( client );
     301      ClientConnectionListener::broadcastClientDisconnected( client->getID() );
     302      delete client;
     303    }
     304  }
    292305
    293306  bool Server::createClient(int clientID){
     
    329342    ServerConnection::disconnectClient( client );
    330343    GamestateManager::removeClient(client);
    331 // inform all the listeners
    332     ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
    333     while(listener){
    334       listener->clientDisconnected(client->getID());
    335       ++listener;
    336     }
    337     delete client; //remove client from list
     344    // inform all the listeners
     345    ClientConnectionListener::broadcastClientDisconnected(client->getID());
    338346  }
    339347
  • code/branches/pickup/src/libraries/network/Server.h

    r5781 r5935  
    3232#include "NetworkPrereqs.h"
    3333
     34#include "util/UtilPrereqs.h"
    3435#include "core/CorePrereqs.h"
    3536#include "Host.h"
     
    6566    unsigned int playerID(){return 0;}
    6667   
    67     void addClient(ENetEvent *event);
     68    void addPeer(ENetEvent *event);
     69    void removePeer(ENetEvent *event);
     70   
    6871    bool createClient(int clientID);
    6972    void disconnectClient( ClientInformation *client);
  • code/branches/pickup/src/libraries/network/ServerConnection.cc

    r5781 r5935  
    103103  {
    104104    Connection::disconnectPeer( client->getPeer() );
    105     delete client;
    106   }
    107  
    108   void ServerConnection::disconnectPeer( ENetEvent* event )
    109   {
    110     COUT(4) << "removing client from list" << std::endl;
    111     ClientInformation *client = ClientInformation::findClient(&event->peer->address);
    112     if(!client)
    113       return;
    114     else
    115       ServerConnection::disconnectClient( client );
    116105  }
    117106 
     
    119108    ClientInformation *client = ClientInformation::findClient(clientID);
    120109    if(client)
    121       disconnectClient(client);
     110      ServerConnection::disconnectClient(client);
    122111  }
    123112
     
    126115    ClientInformation *temp = ClientInformation::getBegin();
    127116    while(temp!=0){
    128       disconnectClient( temp );
     117      ServerConnection::disconnectClient( temp );
    129118      temp = temp->next();
    130119    }
     
    141130          break;
    142131        case ENET_EVENT_TYPE_DISCONNECT:
    143           if(ClientInformation::findClient(&(event.peer->address)))
    144             delete ClientInformation::findClient(&(event.peer->address));
     132          removePeer( &event );
    145133          temp = ClientInformation::getBegin();
    146134          break;
  • code/branches/pickup/src/libraries/network/ServerConnection.h

    • Property svn:eol-style set to native
    r5781 r5935  
    5959    static bool addPacketAll(ENetPacket *packet);
    6060    virtual void disconnectClient(ClientInformation *client);
    61     void disconnectPeer( ENetEvent* event );
    6261    void disconnectClient(int clientID);
    6362  protected:
  • code/branches/pickup/src/libraries/network/packet/CMakeLists.txt

    r5781 r5935  
    11ADD_SOURCE_FILES(NETWORK_SRC_FILES
     2COMPILATION_BEGIN PacketCompilation.cc
    23  Acknowledgement.cc
    34  Chat.cc
     
    910  Packet.cc
    1011  Welcome.cc
     12COMPILATION_END
    1113)
    1214
  • code/branches/pickup/src/libraries/network/packet/ClassID.cc

    r5781 r5935  
    4949  Identifier *id;
    5050  std::string classname;
    51   unsigned int nrOfClasses=0; 
     51  unsigned int nrOfClasses=0;
    5252  unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses
    5353  uint32_t network_id;
    5454  flags_ = flags_ | PACKET_FLAGS_CLASSID;
    5555  std::queue<std::pair<uint32_t, std::string> > tempQueue;
    56  
     56
    5757  //calculate total needed size (for all strings and integers)
    58   std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();
    59   for(;it != Factory::getFactoryMapEnd();++it){
     58  std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin();
     59  for(;it != Identifier::getStringIdentifierMapEnd();++it){
    6060    id = (*it).second;
    61     if(id == NULL)
     61    if(id == NULL || !id->hasFactory())
    6262      continue;
    6363    classname = id->getName();
    6464    network_id = id->getNetworkID();
    65     if(network_id==0)
    66       COUT(3) << "we got a null class id: " << id->getName() << std::endl;
    6765    // now push the network id and the classname to the stack
    6866    tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) );
     
    7068    packetSize += (classname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t);
    7169  }
    72  
     70
    7371  this->data_=new uint8_t[ packetSize ];
    7472  //set the appropriate packet id
    7573  assert(this->data_);
    7674  *(Type::Value *)(this->data_ + _PACKETID ) = Type::ClassID;
    77  
     75
    7876  uint8_t *temp=data_+sizeof(uint32_t);
    7977  // save the number of all classes
    8078  *(uint32_t*)temp = nrOfClasses;
    8179  temp += sizeof(uint32_t);
    82  
     80
    8381  // now save all classids and classnames
    8482  std::pair<uint32_t, std::string> tempPair;
     
    9189    temp+=2*sizeof(uint32_t)+tempPair.second.size()+1;
    9290  }
    93  
     91
    9492  COUT(5) << "classid packetSize is " << packetSize << endl;
    95  
     93
    9694}
    9795
     
    111109  temp += sizeof(uint32_t);
    112110  totalsize += sizeof(uint32_t); // storage size for nr of all classes
    113  
     111
    114112  for(unsigned int i=0; i<nrOfClasses; i++){
    115113    totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
     
    125123  uint32_t stringsize;
    126124  unsigned char *classname;
    127  
    128  
    129   //clean the map of network ids
    130   Factory::cleanNetworkIDs();
    131  
     125
     126
     127  //clear the map of network ids
     128  Identifier::clearNetworkIDs();
     129
    132130  COUT(4) << "=== processing classids: " << endl;
    133131  std::pair<uint32_t, std::string> tempPair;
     
    136134  nrOfClasses = *(uint32_t*)temp;
    137135  temp += sizeof(uint32_t);
    138  
     136
    139137  for( int i=0; i<nrOfClasses; i++){
    140138    networkID = *(uint32_t*)temp;
  • code/branches/pickup/src/libraries/network/packet/Gamestate.cc

    r5781 r5935  
    378378  rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() );
    379379  assert( memcmp( dest2, gs, dest_length) == 0 );
     380  delete dest2;
    380381#endif
    381382
  • code/branches/pickup/src/libraries/network/synchronisable/Synchronisable.cc

    r5781 r5935  
    4747  /**
    4848  * Constructor:
    49   * Initializes all Variables and sets the right objectID
     49  * Initializes all Variables and sets the right objectID_
    5050  */
    51   Synchronisable::Synchronisable(BaseObject* creator){
     51  Synchronisable::Synchronisable(BaseObject* creator ){
    5252    RegisterRootObject(Synchronisable);
    5353    static uint32_t idCounter=0;
     
    5555    if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ) )
    5656    {
    57       this->objectID = idCounter++; //this is only needed when running a server
    58     //add synchronisable to the objectMap
    59       objectMap_[this->objectID] = this;
     57      this->setObjectID( idCounter++ );
    6058    }
    6159    else
    6260    {
    63       objectID=OBJECTID_UNKNOWN;
    64       this->setObjectMode(0x0);   //make sure this object doesn't get synchronized
    65     }
    66     classID = static_cast<uint32_t>(-1);
     61      objectID_=OBJECTID_UNKNOWN;
     62    }
     63    classID_ = static_cast<uint32_t>(-1);
    6764   
    6865    // set dataSize to 0
     
    7269
    7370    // get creator id
    74     this->creatorID = OBJECTID_UNKNOWN;
    75 
    76     searchcreatorID:
     71    if( creator )
     72      this->creatorID_ = creator->getSceneID();
     73    else
     74      this->creatorID_ = OBJECTID_UNKNOWN;
     75
     76    /*searchcreatorID:
    7777    if (creator)
    7878    {
     
    8080        if (synchronisable_creator && synchronisable_creator->objectMode_)
    8181        {
    82             this->creatorID = synchronisable_creator->getObjectID();
     82            this->creatorID = synchronisable_creator->getScene()->getObjectID();
    8383        }
    8484        else if (creator != creator->getCreator())
     
    8787            goto searchcreatorID;
    8888        }
    89     }
     89    }*/
    9090  }
    9191
    9292  /**
    9393   * Destructor:
    94    * Delete all callback objects and remove objectID from the objectMap_
     94   * Delete all callback objects and remove objectID_ from the objectMap_
    9595   */
    9696  Synchronisable::~Synchronisable(){
     
    9999      // remove object from the static objectMap
    100100      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
    101         deletedObjects_.push(objectID);
     101        deletedObjects_.push(objectID_);
    102102    }
    103103    // delete all Synchronisable Variables from syncList ( which are also in stringList )
     
    107107    stringList.clear();
    108108    std::map<uint32_t, Synchronisable*>::iterator it;
    109     it = objectMap_.find(objectID);
     109    it = objectMap_.find(objectID_);
    110110    if (it != objectMap_.end())
    111111      objectMap_.erase(it);
     
    172172    Synchronisable *no = orxonox_cast<Synchronisable*>(bo);
    173173    assert(no);
    174     no->objectID=header.getObjectID();
    175     no->creatorID=header.getCreatorID(); //TODO: remove this
    176     no->classID=header.getClassID();
    177     COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
     174    assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
     175    no->setObjectID(header.getObjectID());
     176    //no->creatorID=header.getCreatorID(); //TODO: remove this
     177    no->setClassID(header.getClassID());
     178    assert(no->creatorID_ == header.getCreatorID());
     179    //assert(no->classID_ == header.getClassID());
     180    COUT(4) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << std::endl;
    178181          // update data and create object/entity...
    179     assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
    180     Synchronisable::objectMap_[header.getObjectID()] = no;
    181182    bool b = no->updateData(mem, mode, true);
    182183    assert(b);
     
    191192
    192193  /**
    193    * Finds and deletes the Synchronisable with the appropriate objectID
    194    * @param objectID objectID of the Synchronisable
     194   * Finds and deletes the Synchronisable with the appropriate objectID_
     195   * @param objectID_ objectID_ of the Synchronisable
    195196   * @return true/false
    196197   */
    197   bool Synchronisable::deleteObject(uint32_t objectID){
    198     if(!getSynchronisable(objectID))
     198  bool Synchronisable::deleteObject(uint32_t objectID_){
     199    if(!getSynchronisable(objectID_))
    199200      return false;
    200     assert(getSynchronisable(objectID)->objectID==objectID);
    201     Synchronisable *s = getSynchronisable(objectID);
     201    assert(getSynchronisable(objectID_)->objectID_==objectID_);
     202    Synchronisable *s = getSynchronisable(objectID_);
    202203    if(s)
    203       delete s;
     204      s->destroy(); // or delete?
    204205    else
    205206      return false;
     
    208209
    209210  /**
    210    * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable
    211    * @param objectID objectID of the Synchronisable
    212    * @return pointer to the Synchronisable with the objectID
    213    */
    214   Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID){
     211   * This function looks up the objectID_ in the objectMap_ and returns a pointer to the right Synchronisable
     212   * @param objectID_ objectID_ of the Synchronisable
     213   * @return pointer to the Synchronisable with the objectID_
     214   */
     215  Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){
    215216    std::map<uint32_t, Synchronisable*>::iterator it1;
    216     it1 = objectMap_.find(objectID);
     217    it1 = objectMap_.find(objectID_);
    217218    if (it1 != objectMap_.end())
    218219      return it1->second;
     
    220221//     ObjectList<Synchronisable>::iterator it;
    221222//     for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    222 //       if( it->getObjectID()==objectID ){
    223 //         objectMap_[objectID] = *it;
     223//       if( it->getObjectID()==objectID_ ){
     224//         objectMap_[objectID_] = *it;
    224225//         return *it;
    225226//       }
     
    231232
    232233  /**
    233    * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classID to the given memory
     234   * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID_ and classID_ to the given memory
    234235   * takes a pointer to already allocated memory (must have at least getSize bytes length)
    235236   * structure of the bitstream:
    236    * |totalsize,objectID,classID,var1,var2,string1_length,string1,var3,...|
     237   * |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...|
    237238   * length of varx: size saved int syncvarlist
    238239   * @param mem pointer to allocated memory with enough size
     
    252253    uint32_t tempsize = 0;
    253254#ifndef NDEBUG
    254     if (this->classID==0)
     255    if (this->classID_==0)
    255256      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
    256257#endif
    257258
    258     if (this->classID == static_cast<uint32_t>(-1))
    259         this->classID = this->getIdentifier()->getNetworkID();
    260 
    261     assert(ClassByID(this->classID));
    262     assert(this->classID==this->getIdentifier()->getNetworkID());
     259    if (this->classID_ == static_cast<uint32_t>(-1))
     260        this->classID_ = this->getIdentifier()->getNetworkID();
     261
     262    assert(ClassByID(this->classID_));
     263    assert(this->classID_==this->getIdentifier()->getNetworkID());
     264    assert(this->objectID_!=OBJECTID_UNKNOWN);
    263265    std::vector<SynchronisableVariableBase*>::iterator i;
    264266
     
    269271
    270272
    271     COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl;
     273    COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl;
    272274    // copy to location
    273275    for(i=syncList.begin(); i!=syncList.end(); ++i){
     
    277279   
    278280    tempsize += SynchronisableHeader::getSize();
    279     header.setObjectID( this->objectID );
    280     header.setCreatorID( this->creatorID );
    281     header.setClassID( this->classID );
     281    header.setObjectID( this->objectID_ );
     282    header.setCreatorID( this->creatorID_ );
     283    header.setClassID( this->classID_ );
    282284    header.setDataAvailable( true );
    283285    header.setDataSize( tempsize );
     
    311313    // start extract header
    312314    SynchronisableHeader syncHeader(mem);
    313     assert(syncHeader.getObjectID()==this->objectID);
    314     assert(syncHeader.getCreatorID()==this->creatorID);
    315     assert(syncHeader.getClassID()==this->classID);
     315    assert(syncHeader.getObjectID()==this->objectID_);
     316    assert(syncHeader.getCreatorID()==this->creatorID_);
     317    assert(syncHeader.getClassID()==this->classID_);
    316318    if(syncHeader.isDataAvailable()==false){
    317319      mem += syncHeader.getDataSize();
     
    322324    // stop extract header
    323325
    324     //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
     326    //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
    325327    for(i=syncList.begin(); i!=syncList.end(); i++)
    326328    {
     
    361363    if(mode==0x0)
    362364      mode=state_;
    363     return ( (objectMode_&mode)!=0 && (!syncList.empty() ) );
    364   }
    365 
    366   /**
    367    * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones
     365    return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) );
     366  }
     367
     368  /**
     369   * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones
    368370   * @param mem pointer to the bytestream
    369371   */
     
    371373  {
    372374    SynchronisableHeader header(mem);
    373     assert(header.getObjectID()==this->objectID);
     375    assert(header.getObjectID()==this->objectID_);
    374376    return header.isDataAvailable();
    375377  }
     
    383385   * @param mode same as in registerVar
    384386   */
    385   void Synchronisable::setObjectMode(uint8_t mode){
     387  void Synchronisable::setSyncMode(uint8_t mode){
    386388    assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3);
    387     objectMode_=mode;
     389    this->objectMode_=mode;
    388390  }
    389391
  • code/branches/pickup/src/libraries/network/synchronisable/Synchronisable.h

    r5781 r5935  
    6868   * @brief: stores information about a Synchronisable
    6969   *
    70    * This class stores the information about a Synchronisable (objectID, classID, creatorID, dataSize)
     70   * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
    7171   * in an emulated bitset.
    7272   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    7373   * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0
    74    * Byte 5 to 8: objectID
    75    * Byte 9 to 12: classID
    76    * Byte 13 to 16: creatorID
     74   * Byte 5 to 8: objectID_
     75   * Byte 9 to 12: classID_
     76   * Byte 13 to 16: creatorID_
    7777   */
    7878  class _NetworkExport SynchronisableHeader{
     
    9494      inline uint32_t getObjectID() const
    9595        { return *(uint32_t*)(data_+4); }
    96       inline void setObjectID(uint32_t objectID)
    97         { *(uint32_t*)(data_+4) = objectID; }
     96      inline void setObjectID(uint32_t objectID_)
     97        { *(uint32_t*)(data_+4) = objectID_; }
    9898      inline uint32_t getClassID() const
    9999        { return *(uint32_t*)(data_+8); }
    100       inline void setClassID(uint32_t classID)
    101         { *(uint32_t*)(data_+8) = classID; }
     100      inline void setClassID(uint32_t classID_)
     101        { *(uint32_t*)(data_+8) = classID_; }
    102102      inline uint32_t getCreatorID() const
    103103        { return *(uint32_t*)(data_+12); }
    104       inline void setCreatorID(uint32_t creatorID)
    105         { *(uint32_t*)(data_+12) = creatorID; }
     104      inline void setCreatorID(uint32_t creatorID_)
     105        { *(uint32_t*)(data_+12) = creatorID_; }
    106106      inline void operator=(SynchronisableHeader& h)
    107107        { memcpy(data_, h.data_, getSize()); }
     
    122122
    123123    static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
    124     static bool deleteObject(uint32_t objectID);
    125     static Synchronisable *getSynchronisable(uint32_t objectID);
     124    static bool deleteObject(uint32_t objectID_);
     125    static Synchronisable *getSynchronisable(uint32_t objectID_);
    126126    static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); }
    127127    static uint32_t popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
    128128
    129     inline uint32_t getObjectID() const {return objectID;}
    130     inline unsigned int getCreatorID() const {return creatorID;}
    131     inline uint32_t getClassID() const {return classID;}
    132     inline unsigned int getPriority() const { return objectFrequency_;}
     129    inline uint32_t getObjectID() const {return this->objectID_;}
     130    inline unsigned int getCreatorID() const {return this->creatorID_;}
     131    inline uint32_t getClassID() const {return this->classID_;}
     132    inline unsigned int getPriority() const { return this->objectFrequency_;}
     133    inline uint8_t getSyncMode() const { return this->objectMode_; }
     134   
     135    void setSyncMode(uint8_t mode);
    133136
    134137  protected:
     
    136139    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    137140    //template <class T> void unregisterVariable(T& var);
    138     void setObjectMode(uint8_t mode);
    139141    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
    140142
     
    146148    bool isMyData(uint8_t* mem);
    147149    bool doSync(int32_t id, uint8_t mode=0x0);
    148 
    149     uint32_t objectID;
    150     uint32_t creatorID;
    151     uint32_t classID;
     150   
     151    inline void setObjectID(uint32_t id){ this->objectID_ = id; objectMap_[this->objectID_] = this; }
     152    inline void setClassID(uint32_t id){ this->classID_ = id; }
     153
     154    uint32_t objectID_;
     155    uint32_t creatorID_;
     156    uint32_t classID_;
    152157
    153158    std::vector<SynchronisableVariableBase*> syncList;
Note: See TracChangeset for help on using the changeset viewer.