Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7678 in orxonox.OLD for branches/network


Ignore:
Timestamp:
May 18, 2006, 12:58:08 PM (19 years ago)
Author:
rennerc
Message:

finished MessageManager implementation

Location:
branches/network/src/lib/network
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/message_manager.cc

    r7671 r7678  
    130130  int nAcks;
    131131 
     132  assert( i + INTSIZE <= length );
    132133  n = Converter::byteArrayToInt( data + i, &nAcks );
    133134  assert( n == INTSIZE );
     
    140141  for ( int j = 0; j < nAcks; j++ )
    141142  {
     143    assert( i + INTSIZE <= length );
    142144    n = Converter::byteArrayToInt( data + i, &number );
    143145    assert( n == INTSIZE );
     
    149151  int nMessages;
    150152 
     153  assert( i + INTSIZE <= length );
    151154  n = Converter::byteArrayToInt( data + i, &nMessages );
    152155  assert( n == INTSIZE );
    153156  i += n;
     157
     158  int messageLength, messageId;
    154159 
    155160  for ( int j = 0; j < nMessages; j++ )
    156161  {
    157   }
     162    assert( i + INTSIZE <= length );
     163    n = Converter::byteArrayToInt( data + i, &messageLength );
     164    assert( n == INTSIZE );
     165    i += n;
     166   
     167    assert( i + INTSIZE <= length );
     168    n = Converter::byteArrayToInt( data + i, &number );
     169    assert( n == INTSIZE );
     170    i += n;
     171 
     172    assert( i + INTSIZE <= length );
     173    n = Converter::byteArrayToInt( data + i, &messageId );
     174    assert( n == INTSIZE );
     175    i += n;
     176   
     177    if ( number > 0 )
     178      messageQueue[userId].toAck.push_back( number );
     179   
     180    assert( i + messageLength <= length );
     181    assert( messageHandlerMap.find( (MessageId)messageId ) != messageHandlerMap.end() );
     182    (*(messageHandlerMap[(MessageId)messageId].cb))( (MessageId)messageId, data + i, messageLength, messageHandlerMap[(MessageId)messageId].someData, userId );
     183    i += messageLength;
     184  }
     185
     186  return i;
    158187}
    159188
     
    164193void MessageManager::cleanUpUser( int userId )
    165194{
     195  if ( messageQueue.find( userId ) == messageQueue.end() )
     196    return;
     197   
     198  for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ )
     199  {
     200    if ( it->data )
     201      delete it->data;
     202    it->data = NULL;
     203  }
     204 
     205  messageQueue[userId].toAck.clear();
     206 
     207  messageQueue.erase( userId );
    166208}
    167209
     
    175217bool MessageManager::registerMessageHandler( MessageId messageId, MessageCallback cb, void * someData )
    176218{
     219  MessageHandler messageHandler;
     220 
     221  messageHandler.cb = cb;
     222  messageHandler.messageId = messageId;
     223  messageHandler.someData = someData;
     224 
     225  messageHandlerMap[messageId] = messageHandler;
     226 
     227  return true;
    177228}
    178229
     
    183234void MessageManager::initUser( int userId )
    184235{
    185 }
     236  // just do something so map creates a new entry
     237  messageQueue[userId].toAck.clear();
     238  assert( messageQueue[userId].messages.size() == 0 );
     239}
  • branches/network/src/lib/network/message_manager.h

    r7671 r7678  
    2020      int length
    2121      int number
    22       byte MessageId
     22      int MessageId
    2323      byte * data
    2424    )[1..nmsg]
    2525*/
    26 
    27 typedef void (*MessageCallback)( byte * data, int dataLength, void * someData, int userId );
    2826
    2927
     
    3129{
    3230};
     31
     32typedef void (*MessageCallback)( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    3333
    3434enum RecieverType
     
    5959  MessageCallback cb;
    6060  MessageId       messageId;
     61  void *          someData;
    6162};
    6263
  • branches/network/src/lib/network/synchronizeable.cc

    r7631 r7678  
    174174    if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
    175175    {
    176       (*it)->debug();
     176      //(*it)->debug();
    177177      n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );
    178178      stateTo->sizeList.push_back( n );
     
    183183      for ( int j = 0; j < (*it)->getSize(); j++ )
    184184      {
     185        //TODO this should be called!!!!!!!!!!1
    185186        assert(false);
    186187        stateTo->data[i] = 0;
     
    310311    else
    311312    {
    312       PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId );
     313//      PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId );
    313314      i += (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i );
    314315    }
Note: See TracChangeset for help on using the changeset viewer.