Skip to content

Commit

Permalink
Move various implementations from .h to .cpp files
Browse files Browse the repository at this point in the history
  • Loading branch information
DDuarte committed Jul 8, 2012
1 parent 743da90 commit e4ce395
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 209 deletions.
2 changes: 2 additions & 0 deletions src/LeClient/LeClient.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<ItemGroup>
<ClCompile Include="Application.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="NetworkTask.cpp" />
<ClCompile Include="OpenGLTest.cpp" />
<ClCompile Include="TcpClient.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Application.h" />
Expand Down
6 changes: 6 additions & 0 deletions src/LeClient/LeClient.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<ClCompile Include="OpenGLTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NetworkTask.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TcpClient.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Application.h">
Expand Down
29 changes: 29 additions & 0 deletions src/LeClient/NetworkTask.cpp
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;
}
31 changes: 4 additions & 27 deletions src/LeClient/NetworkTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "ITask.h"
#include "TcpClient.h"
#include "SettingsManager.h"

class NetworkTask : public ITask
{
Expand All @@ -12,32 +11,10 @@ class NetworkTask : public ITask
TcpConnection* _connection;

public:
NetworkTask()
{
_hive = new Hive();
}

bool Start()
{
_connection = new TcpConnection(_hive);
_connection->Connect(GetConfig("connection.host", std::string), GetConfig("connection.port", int));
return true;
}

void Update()
{
_hive->Poll();
Sleep(1);
}

void Stop()
{
_hive->Stop();
_connection->Disconnect();

delete _hive;
delete _connection;
}
NetworkTask();
bool Start();
void Update();
void Stop();
};

#endif // NETWORKTASK_H
65 changes: 65 additions & 0 deletions src/LeClient/TcpClient.cpp
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;
}
71 changes: 6 additions & 65 deletions src/LeClient/TcpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,15 @@
class TcpConnection : public Connection
{
private:

private:
void OnAccept(const std::string& host, uint16 port)
{
std::cout << "[" << __FUNCTION__ << "] " << host << ":" << port << std::endl;

// Start the next receive
Recv();
}

void 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 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 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 OnTimer(const boost::posix_time::time_duration& delta)
{
std::cout << "[" << __FUNCTION__ << "] " << delta << std::endl;
}

void OnError(const boost::system::error_code& error)
{
std::cout << "[" << __FUNCTION__ << "] " << error << std::endl;
}
void OnAccept(const std::string& host, uint16 port);
void OnConnect(const std::string& host, uint16 port);
void OnSend(const std::vector<uint8>& buffer);
void OnRecv(std::vector<uint8>& buffer);
void OnTimer(const boost::posix_time::time_duration& delta);
void OnError(const boost::system::error_code& error);

public:
TcpConnection(Hive* hive) : Connection(hive) {}

~TcpConnection() {}
};

Expand Down
2 changes: 2 additions & 0 deletions src/LeServer/LeServer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="NetworkTask.cpp" />
<ClCompile Include="ServerApplication.cpp" />
<ClCompile Include="TcpServer.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="NetworkTask.h" />
Expand Down
6 changes: 6 additions & 0 deletions src/LeServer/LeServer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<ClCompile Include="ServerApplication.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TcpServer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NetworkTask.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="TcpServer.h">
Expand Down
30 changes: 30 additions & 0 deletions src/LeServer/NetworkTask.cpp
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;
}
32 changes: 4 additions & 28 deletions src/LeServer/NetworkTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,10 @@ class NetworkTask : public ITask
TcpAcceptor* _acceptor;

public:
NetworkTask()
{
_hive = new Hive();
_acceptor = new TcpAcceptor(_hive);
}

bool Start()
{
// accept one connection; next one will be accepted in TcpAcceptor::OnAccept
TcpConnection* connection = new TcpConnection(_hive);
_acceptor->Accept(connection);
return true;
}

void Update()
{
_hive->Poll();
Sleep(1);
}

void Stop()
{
_hive->Stop();
_acceptor->Stop();

delete _acceptor;
delete _hive;
}
NetworkTask();
bool Start();
void Update();
void Stop();
};

#endif // NETWORKTASK_H
Loading

0 comments on commit e4ce395

Please sign in to comment.