Browse Source

poprawka laczenia + test polaczenia miedzy wezlami

master
Piotr Dergun 7 years ago
parent
commit
65b42fd646
3 changed files with 24 additions and 8 deletions
  1. +12
    -0
      Main.cpp
  2. +11
    -7
      Node.cpp
  3. +1
    -1
      Node.h

+ 12
- 0
Main.cpp View File

@ -6,8 +6,20 @@
*/ */
#include "common.h" #include "common.h"
#include "Node.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cout << "Obiekt PC1" << endl;
Node pc1;
cout << "Obiekt PC2" << endl;
Node pc2;
cout << "Lacze PC1 z PC2" << endl;
cout << pc1.connectNode(&pc2) << endl;
cout << "Lacze PC1 z PC2 (ponownie)" << endl;
cout << pc1.connectNode(&pc2) << endl;
return 0; return 0;
} }

+ 11
- 7
Node.cpp View File

@ -22,17 +22,21 @@ Node::~Node()
* funkcja symuluje typową sytuację: mamy kartę sieciową, a funkcja connectNode jest podłączeniem wtyczki * funkcja symuluje typową sytuację: mamy kartę sieciową, a funkcja connectNode jest podłączeniem wtyczki
* z jednej strony * z jednej strony
*/ */
bool Node::connectNode(Node *node)
bool Node::connectNode(Node *node, bool firstConnected)
{ {
vector<Node*>::iterator it = this->connectedNodes.begin();
for (; it != this->connectedNodes.end(); ++it) //sprawdzamy, czy połączenia już przypadkiem nie ma
if (!firstConnected)
{ {
if (*it == node)
return false;
vector<Node*>::iterator it = this->connectedNodes.begin();
for (; it != this->connectedNodes.end(); ++it) //sprawdzamy, czy połączenia już przypadkiem nie ma
{
if (*it == node)
return false;
}
} }
this->connectedNodes.push_back(node); // podłączamy drugi węzeł this->connectedNodes.push_back(node); // podłączamy drugi węzeł
node->connectNode(this); // podłączamy drugą stronę
if (!firstConnected)
node->connectNode(this, true); // to samo w drugą stronę
return true; return true;
} }

+ 1
- 1
Node.h View File

@ -25,7 +25,7 @@ class Node
public: public:
Node(); Node();
virtual ~Node(); virtual ~Node();
bool connectNode(Node *node);
bool connectNode(Node *node, bool firstConnected = false);
void send(Packet packet); void send(Packet packet);
Packet recv(); Packet recv();

Loading…
Cancel
Save