<commit_before>/**
 * @file
 * @author <NAME>
 * @date 2012.02.04
 * @brief Implementation of NetworkConnection class
 */

#include <iostream>
#include <cstdlib>
#include <cassert>

#include <SDL.h>

#include "network_connection.hxx"
#include "network_assembly.hxx"
#include "network_geraet.hxx"
#include "antenna.hxx"
#include "io.hxx"

#include "src/sim/game_field.hxx"
#include "src/sim/game_object.hxx"
#include "src/exit_conditions.hxx"

using namespace std;

NetworkConnection::geraetNumMap_t* NetworkConnection::geraetNumMap;

NetworkConnection::NetworkConnection(NetworkAssembly* assembly_,
                                     const Antenna::endpoint& endpoint_,
                                     bool incomming)
: field(assembly_->field->width, assembly_->field->height),
  nextOutSeq(0),
  greatestSeq(0),
  latency(0),
  lastIncommingTime(SDL_GetTicks()),
  status(incomming? Established : Connecting),
  endpoint(endpoint_),
  parent(assembly_),
  scg(NULL) //TODO: replace with actual object later
{
  //TODO: put SCG in channel map
}

NetworkConnection::~NetworkConnection() {
  //scg is stored within the channel map, so we don't have to explicitly
  //delete it.
  for (inchannels_t::const_iterator it = inchannels.begin();
       it != inchannels.end(); ++it)
    delete it->second;
  for (outchannels_t::const_iterator it = outchannels.begin();
       it != outchannels.end(); ++it)
    delete it->second;
}

void NetworkConnection::update(unsigned et) noth {
  //TODO: do something
}

void NetworkConnection::process(const Antenna::endpoint& source,
                                Antenna* antenna, Tuner* tuner,
                                const byte* data, unsigned datlen)
noth {
  if (datlen < 4) {
    //Packet does not even have a header
    #ifdef DEBUG
    cerr << "Warning: Dropping packet of length " << datlen
         << " from source " << source << endl;
    #endif
    return;
  }

  channel chan;
  seq_t seq;<commit_msg>Add Synchronous Control Gerät logic to NetworkConnection.<commit_after>/**
 * @file
 * @author <NAME>
 * @date 2012.02.04
 * @brief Implementation of NetworkConnection class
 */

#include <iostream>
#include <cstdlib>
#include <cassert>

#include <SDL.h>

#include "network_connection.hxx"
#include "network_assembly.hxx"
#include "network_geraet.hxx"
#include "antenna.hxx"
#include "io.hxx"
#include "synchronous_control_geraet.hxx"

#include "src/sim/game_field.hxx"
#include "src/sim/game_object.hxx"
#include "src/exit_conditions.hxx"

using namespace std;

NetworkConnection::geraetNumMap_t* NetworkConnection::geraetNumMap;

NetworkConnection::NetworkConnection(NetworkAssembly* assembly_,
                                     const Antenna::endpoint& endpoint_,
                                     bool incomming)
: field(assembly_->field->width, assembly_->field->height),
  nextOutSeq(0),
  greatestSeq(0),
  latency(0),
  lastIncommingTime(SDL_GetTicks()),
  status(incomming? Established : Connecting),
  endpoint(endpoint_),
  parent(assembly_),
  scg(new SynchronousControlGeraet(this, incomming))
{
  inchannels[0] = scg;
  outchannels[0] = scg;
}

NetworkConnection::~NetworkConnection() {
  //Other Geräte depend on the SCG in deletion, so delete it
  //at the end and ignore it within the loops
  for (inchannels_t::const_iterator it = inchannels.begin();
       it != inchannels.end(); ++it)
    if (it->second != scg) delete it->second;
  for (outchannels_t::const_iterator it = outchannels.begin();
       it != outchannels.end(); ++it)
    if (it->second != scg) delete it->second;
  delete scg;
}

void NetworkConnection::update(unsigned et) noth {
  //TODO: do something
}

void NetworkConnection::process(const Antenna::endpoint& source,
                                Antenna* antenna, Tuner* tuner,
                                const byte* data, unsigned datlen)
noth {
  if (datlen < 4) {
    //Packet does not even have a header
    #ifdef DEBUG
    cerr << "Warning: Dropping packet of length " << datlen
         << " from source " << source << endl;
    #endif
    return;
  }

  channel chan;
  seq_t seq;
{'fraction_non_alphanumeric': 0.12247382517652788, 'fraction_numerical': 0.006330654979303628, 'mean_word_length': 3.310598111227702, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805773', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1281, 'n_words': 324}