Skip to content

Commit

Permalink
Styling Refactor: Using astyle from new style guide to refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlJaMa committed Aug 1, 2014
1 parent 4d18e12 commit 918242b
Show file tree
Hide file tree
Showing 114 changed files with 15,983 additions and 17,453 deletions.
1,169 changes: 562 additions & 607 deletions src/clientagent/AstronClient.cpp

Large diffs are not rendered by default.

1,308 changes: 607 additions & 701 deletions src/clientagent/Client.cpp

Large diffs are not rendered by default.

318 changes: 157 additions & 161 deletions src/clientagent/Client.h

Large diffs are not rendered by default.

389 changes: 179 additions & 210 deletions src/clientagent/ClientAgent.cpp

Large diffs are not rendered by default.

82 changes: 41 additions & 41 deletions src/clientagent/ClientAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,60 @@ extern ConfigVariable<std::string> ca_client_type;
// TODO: Consider moving to util/ this class might be reusable in other roles that utilize ranges.
class ChannelTracker
{
public:
ChannelTracker(channel_t min = INVALID_CHANNEL, channel_t max = INVALID_CHANNEL);
public:
ChannelTracker(channel_t min = INVALID_CHANNEL, channel_t max = INVALID_CHANNEL);

channel_t alloc_channel();
void free_channel(channel_t channel);
channel_t alloc_channel();
void free_channel(channel_t channel);

private:
channel_t m_next;
channel_t m_max;
std::queue<channel_t> m_unused_channels;
private:
channel_t m_next;
channel_t m_max;
std::queue<channel_t> m_unused_channels;
};

class ClientAgent : public Role
{
friend class Client;
friend class Client;

public:
ClientAgent(RoleConfig rolconfig);
~ClientAgent();
public:
ClientAgent(RoleConfig rolconfig);
~ClientAgent();

// handle_tcp generates a new Client object from a raw tcp connection.
void handle_tcp(boost::asio::ip::tcp::socket *socket);
// handle_tcp generates a new Client object from a raw tcp connection.
void handle_tcp(boost::asio::ip::tcp::socket *socket);

// handle_ssl generates a new Client object from an ssl stream.
void handle_ssl(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *stream);
// handle_ssl generates a new Client object from an ssl stream.
void handle_ssl(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *stream);

// handle_datagram handles Datagrams received from the message director.
// Currently the ClientAgent does not handle any datagrams,
// and delegates everything to the Client objects.
void handle_datagram(DatagramHandle in_dg, DatagramIterator &dgi);
// handle_datagram handles Datagrams received from the message director.
// Currently the ClientAgent does not handle any datagrams,
// and delegates everything to the Client objects.
void handle_datagram(DatagramHandle in_dg, DatagramIterator &dgi);

// ssl_password_callback prompts for password on stdin if the cert/key has a password
std::string ssl_password_callback();
// ssl_password_callback prompts for password on stdin if the cert/key has a password
std::string ssl_password_callback();

const std::string& get_version() const
{
return m_server_version;
}
const std::string& get_version() const
{
return m_server_version;
}

uint32_t get_hash() const
{
return m_hash;
}
uint32_t get_hash() const
{
return m_hash;
}

private:
NetworkAcceptor *m_net_acceptor;
std::string m_client_type;
std::string m_server_version;
ChannelTracker m_ct;
ConfigNode m_clientconfig;
LogCategory *m_log;
uint32_t m_hash;
private:
NetworkAcceptor *m_net_acceptor;
std::string m_client_type;
std::string m_server_version;
ChannelTracker m_ct;
ConfigNode m_clientconfig;
LogCategory *m_log;
uint32_t m_hash;

boost::asio::ssl::context m_ssl_ctx;
std::string m_ssl_cert;
std::string m_ssl_key;
boost::asio::ssl::context m_ssl_ctx;
std::string m_ssl_cert;
std::string m_ssl_key;
};
32 changes: 15 additions & 17 deletions src/clientagent/ClientFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,43 @@ namespace ssl = boost::asio::ssl;

BaseClientType::BaseClientType(const std::string &name)
{
ClientFactory::singleton().add_client_type(name, this);
ClientFactory::singleton().add_client_type(name, this);
}


ClientFactory& ClientFactory::singleton()
{
static ClientFactory* fact = new ClientFactory();
return *fact;
static ClientFactory* fact = new ClientFactory();
return *fact;
}

// add_client_type adds a factory for client of type 'name'
// It is called automatically when instantiating a new ClientType.
void ClientFactory::add_client_type(const std::string &name, BaseClientType *factory)
{
m_factories[name] = factory;
m_factories[name] = factory;
}

// has_client_type returns true if a client handler exists for 'name'.
bool ClientFactory::has_client_type(const std::string &name)
{
return m_factories.find(name) != m_factories.end();
return m_factories.find(name) != m_factories.end();
}

// instantiate_client creates a new Client object of type 'client_type'.
Client* ClientFactory::instantiate_client(const std::string &client_type, ConfigNode config,
ClientAgent* client_agent, tcp::socket *socket)
ClientAgent* client_agent, tcp::socket *socket)
{
if(m_factories.find(client_type) != m_factories.end())
{
return m_factories[client_type]->instantiate(config, client_agent, socket);
}
return NULL;
if(m_factories.find(client_type) != m_factories.end()) {
return m_factories[client_type]->instantiate(config, client_agent, socket);
}
return NULL;
}
Client* ClientFactory::instantiate_client(const std::string &client_type, ConfigNode config,
ClientAgent* client_agent, ssl::stream<tcp::socket> *stream)
ClientAgent* client_agent, ssl::stream<tcp::socket> *stream)
{
if(m_factories.find(client_type) != m_factories.end())
{
return m_factories[client_type]->instantiate(config, client_agent, stream);
}
return NULL;
if(m_factories.find(client_type) != m_factories.end()) {
return m_factories[client_type]->instantiate(config, client_agent, stream);
}
return NULL;
}
72 changes: 36 additions & 36 deletions src/clientagent/ClientFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,56 @@
// A BaseClientType is a common ancestor that all client factory templates inherit from.
class BaseClientType
{
public:
virtual Client* instantiate(ConfigNode config, ClientAgent* client_agent,
boost::asio::ip::tcp::socket *socket) = 0;
virtual Client* instantiate(ConfigNode config, ClientAgent* client_agent,
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *stream) = 0;
protected:
BaseClientType(const std::string &name);
public:
virtual Client* instantiate(ConfigNode config, ClientAgent* client_agent,
boost::asio::ip::tcp::socket *socket) = 0;
virtual Client* instantiate(ConfigNode config, ClientAgent* client_agent,
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *stream) = 0;
protected:
BaseClientType(const std::string &name);
};

// A ClientType is the factory for a particular client.
// Each new client should declare a ClientType<ClientClass>("ClientName");
template <class T>
class ClientType : public BaseClientType
{
public:
ClientType(const std::string &name) : BaseClientType(name)
{
}
public:
ClientType(const std::string &name) : BaseClientType(name)
{
}

virtual Client* instantiate(ConfigNode config, ClientAgent* client_agent,
boost::asio::ip::tcp::socket *socket)
{
return new T(config, client_agent, socket);
}
virtual Client* instantiate(ConfigNode config, ClientAgent* client_agent,
boost::asio::ip::tcp::socket *socket)
{
return new T(config, client_agent, socket);
}

virtual Client* instantiate(ConfigNode config, ClientAgent* client_agent,
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *stream)
{
return new T(config, client_agent, stream);
}
virtual Client* instantiate(ConfigNode config, ClientAgent* client_agent,
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *stream)
{
return new T(config, client_agent, stream);
}
};

// The ClientFactory is a singleton that instantiates clients from a client type.
class ClientFactory
{
public:
static ClientFactory& singleton();
public:
static ClientFactory& singleton();

// instantiate_client creates a new Client object of type 'client_type'.
Client* instantiate_client(const std::string &client_type, ConfigNode config,
ClientAgent* client_agent, boost::asio::ip::tcp::socket *socket);
Client* instantiate_client(const std::string &client_type, ConfigNode config,
ClientAgent* client_agent,
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *stream);
// add_client_type adds a factory for client of type 'name'
// It is called automatically when instantiating a new ClientType.
void add_client_type(const std::string &name, BaseClientType *factory);
// instantiate_client creates a new Client object of type 'client_type'.
Client* instantiate_client(const std::string &client_type, ConfigNode config,
ClientAgent* client_agent, boost::asio::ip::tcp::socket *socket);
Client* instantiate_client(const std::string &client_type, ConfigNode config,
ClientAgent* client_agent,
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *stream);
// add_client_type adds a factory for client of type 'name'
// It is called automatically when instantiating a new ClientType.
void add_client_type(const std::string &name, BaseClientType *factory);

// has_client_type returns true if a client handler exists for 'name'.
bool has_client_type(const std::string &name);
private:
std::unordered_map<std::string, BaseClientType*> m_factories;
// has_client_type returns true if a client handler exists for 'name'.
bool has_client_type(const std::string &name);
private:
std::unordered_map<std::string, BaseClientType*> m_factories;
};
Loading

0 comments on commit 918242b

Please sign in to comment.