-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move various implementations from .h to .cpp files
- Loading branch information
Showing
12 changed files
with
251 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "NetworkTask.h" | ||
#include "SettingsManager.h" | ||
|
||
NetworkTask::NetworkTask() | ||
{ | ||
_hive = new Hive(); | ||
} | ||
|
||
bool NetworkTask::Start() | ||
{ | ||
_connection = new TcpConnection(_hive); | ||
_connection->Connect(GetConfig("connection.host", std::string), GetConfig("connection.port", int)); | ||
return true; | ||
} | ||
|
||
void NetworkTask::Update() | ||
{ | ||
_hive->Poll(); | ||
Sleep(1); | ||
} | ||
|
||
void NetworkTask::Stop() | ||
{ | ||
_hive->Stop(); | ||
_connection->Disconnect(); | ||
|
||
delete _hive; | ||
delete _connection; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "TcpClient.h" | ||
|
||
|
||
void TcpConnection::OnAccept(const std::string& host, uint16 port) | ||
{ | ||
std::cout << "[" << __FUNCTION__ << "] " << host << ":" << port << std::endl; | ||
|
||
// Start the next receive | ||
Recv(); | ||
} | ||
|
||
void TcpConnection::OnConnect(const std::string& host, uint16 port) | ||
{ | ||
std::cout << "[" << __FUNCTION__ << "] " << host << ":" << port << std::endl; | ||
|
||
// Start the next receive | ||
Recv(); | ||
|
||
std::string str = "TEST"; | ||
|
||
std::vector<uint8> request; | ||
std::copy(str.begin(), str.end(), std::back_inserter(request)); | ||
Send(request); | ||
} | ||
|
||
void TcpConnection::OnSend(const std::vector<uint8>& buffer) | ||
{ | ||
std::cout << "[" << __FUNCTION__ << "] " << buffer.size() << " bytes" << std::endl; | ||
for(size_t x = 0; x < buffer.size(); ++x) | ||
{ | ||
std::cout << std::hex << std::setfill('0') << | ||
std::setw(2) << (int)buffer[x] << " "; | ||
if((x + 1) % 16 == 0) | ||
std::cout << std::endl; | ||
} | ||
std::cout << std::endl; | ||
} | ||
|
||
void TcpConnection::OnRecv(std::vector<uint8>& buffer) | ||
{ | ||
std::cout << "[" << __FUNCTION__ << "] " << buffer.size() << " bytes" << std::endl; | ||
for(size_t x = 0; x < buffer.size(); ++x) | ||
{ | ||
std::cout << std::hex << std::setfill('0') << | ||
std::setw(2) << (int)buffer[x] << " "; | ||
if((x + 1) % 16 == 0) | ||
{ | ||
std::cout << std::endl; | ||
} | ||
} | ||
std::cout << std::endl; | ||
|
||
// Start the next receive | ||
Recv(); | ||
} | ||
|
||
void TcpConnection::OnTimer(const boost::posix_time::time_duration& delta) | ||
{ | ||
std::cout << "[" << __FUNCTION__ << "] " << delta << std::endl; | ||
} | ||
|
||
void TcpConnection::OnError(const boost::system::error_code& error) | ||
{ | ||
std::cout << "[" << __FUNCTION__ << "] " << error << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "NetworkTask.h" | ||
|
||
NetworkTask::NetworkTask() | ||
{ | ||
_hive = new Hive(); | ||
_acceptor = new TcpAcceptor(_hive); | ||
} | ||
|
||
bool NetworkTask::Start() | ||
{ | ||
// accept one connection; next one will be accepted in TcpAcceptor::OnAccept | ||
TcpConnection* connection = new TcpConnection(_hive); | ||
_acceptor->Accept(connection); | ||
return true; | ||
} | ||
|
||
void NetworkTask::Update() | ||
{ | ||
_hive->Poll(); | ||
Sleep(1); | ||
} | ||
|
||
void NetworkTask::Stop() | ||
{ | ||
_hive->Stop(); | ||
_acceptor->Stop(); | ||
|
||
delete _acceptor; | ||
delete _hive; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.