Code cleanup

This commit is contained in:
Alex Yatskov 2012-02-19 09:55:16 -08:00
parent 75ab0b2c99
commit c9a663c03c
16 changed files with 298 additions and 297 deletions

View File

@ -32,8 +32,8 @@ namespace metacall {
template <typename R> template <typename R>
bool Binding::bind(const Token& token, R(*function)()) { bool Binding::bind(const Token& token, R(*function)()) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor0p<R>(function); m_functors[token] = new Functor0p<R>(function);
return true; return true;
} }
@ -42,8 +42,8 @@ bool Binding::bind(const Token& token, R(*function)()) {
template <typename R, typename P1> template <typename R, typename P1>
bool Binding::bind(const Token& token, R(*function)(P1)) { bool Binding::bind(const Token& token, R(*function)(P1)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor1p<R, P1>(function); m_functors[token] = new Functor1p<R, P1>(function);
return true; return true;
} }
@ -52,8 +52,8 @@ bool Binding::bind(const Token& token, R(*function)(P1)) {
template <typename R, typename P1, typename P2> template <typename R, typename P1, typename P2>
bool Binding::bind(const Token& token, R(*function)(P1, P2)) { bool Binding::bind(const Token& token, R(*function)(P1, P2)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor2p<R, P1, P2>(function); m_functors[token] = new Functor2p<R, P1, P2>(function);
return true; return true;
} }
@ -62,8 +62,8 @@ bool Binding::bind(const Token& token, R(*function)(P1, P2)) {
template <typename R, typename P1, typename P2, typename P3> template <typename R, typename P1, typename P2, typename P3>
bool Binding::bind(const Token& token, R(*function)(P1, P2, P3)) { bool Binding::bind(const Token& token, R(*function)(P1, P2, P3)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor3p<R, P1, P2, P3>(function); m_functors[token] = new Functor3p<R, P1, P2, P3>(function);
return true; return true;
} }
@ -72,8 +72,8 @@ bool Binding::bind(const Token& token, R(*function)(P1, P2, P3)) {
template <typename R, typename P1, typename P2, typename P3, typename P4> template <typename R, typename P1, typename P2, typename P3, typename P4>
bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4)) { bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor4p<R, P1, P2, P3, P4>(function); m_functors[token] = new Functor4p<R, P1, P2, P3, P4>(function);
return true; return true;
} }
@ -82,8 +82,8 @@ bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4)) {
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5> template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5)) { bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor5p<R, P1, P2, P3, P4, P5>(function); m_functors[token] = new Functor5p<R, P1, P2, P3, P4, P5>(function);
return true; return true;
} }
@ -92,8 +92,8 @@ bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5)) {
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6)) { bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor6p<R, P1, P2, P3, P4, P5, P6>(function); m_functors[token] = new Functor6p<R, P1, P2, P3, P4, P5, P6>(function);
return true; return true;
} }
@ -102,8 +102,8 @@ bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6)) {
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6, P7)) { bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6, P7)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor7p<R, P1, P2, P3, P4, P5, P6, P7>(function); m_functors[token] = new Functor7p<R, P1, P2, P3, P4, P5, P6, P7>(function);
return true; return true;
} }
@ -112,8 +112,8 @@ bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6, P7))
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8> template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6, P7, P8)) { bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6, P7, P8)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor8p<R, P1, P2, P3, P4, P5, P6, P7, P8>(function); m_functors[token] = new Functor8p<R, P1, P2, P3, P4, P5, P6, P7, P8>(function);
return true; return true;
} }
@ -122,8 +122,8 @@ bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6, P7,
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9> template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6, P7, P8, P9)) { bool Binding::bind(const Token& token, R(*function)(P1, P2, P3, P4, P5, P6, P7, P8, P9)) {
if (functors_.find(token) == functors_.end()) { if (m_functors.find(token) == m_functors.end()) {
functors_[token] = new Functor9p<R, P1, P2, P3, P4, P5, P6, P7, P8, P9>(function); m_functors[token] = new Functor9p<R, P1, P2, P3, P4, P5, P6, P7, P8, P9>(function);
return true; return true;
} }

View File

@ -37,9 +37,9 @@ Binding::~Binding() {
} }
Binding::CallResult Binding::call(const Token& token, Deserializer* args, Serializer* ret) const { Binding::CallResult Binding::call(const Token& token, Deserializer* args, Serializer* ret) const {
const FunctorMap::const_iterator iter = functors_.find(token); const FunctorMap::const_iterator iter = m_functors.find(token);
if (iter == functors_.end()) { if (iter == m_functors.end()) {
return CALL_RESULT_UNBOUND_FUNC; return CALL_RESULT_UNBOUND_FUNC;
} }
if (!iter->second->call(args, ret)) { if (!iter->second->call(args, ret)) {
@ -50,19 +50,19 @@ Binding::CallResult Binding::call(const Token& token, Deserializer* args, Serial
} }
void Binding::unbind(const Token& token) { void Binding::unbind(const Token& token) {
FunctorMap::iterator iter = functors_.find(token); FunctorMap::iterator iter = m_functors.find(token);
if (iter != functors_.end()) { if (iter != m_functors.end()) {
delete iter->second; delete iter->second;
functors_.erase(iter); m_functors.erase(iter);
} }
} }
void Binding::unbindAll() { void Binding::unbindAll() {
for (FunctorMap::iterator iter = functors_.begin(); iter != functors_.end(); ++iter) { for (FunctorMap::iterator iter = m_functors.begin(); iter != m_functors.end(); ++iter) {
delete iter->second; delete iter->second;
} }
functors_.clear(); m_functors.clear();
} }

View File

@ -69,7 +69,7 @@ public:
private: private:
typedef std::map<unsigned, IFunctor*> FunctorMap; typedef std::map<unsigned, IFunctor*> FunctorMap;
FunctorMap functors_; FunctorMap m_functors;
}; };

View File

@ -42,60 +42,62 @@ Buffer::Buffer() {
} }
void Buffer::addToBack(const void* data, int bytes) { void Buffer::addToBack(const void* data, int bytes) {
data_.insert( m_data.insert(
data_.end(), m_data.end(),
static_cast<const byte*>(data), static_cast<const byte*>(data),
static_cast<const byte*>(data) + bytes static_cast<const byte*>(data) + bytes
); );
} }
void Buffer::addToFront(const void* data, int bytes) { void Buffer::addToFront(const void* data, int bytes) {
data_.insert( m_data.insert(
data_.begin(), m_data.begin(),
static_cast<const byte*>(data), static_cast<const byte*>(data),
static_cast<const byte*>(data) + bytes static_cast<const byte*>(data) + bytes
); );
} }
int Buffer::removeFromFront(void* data, int bytes) { int Buffer::removeFromFront(void* data, int bytes) {
bytes = std::min(static_cast<size_t>(bytes), data_.size()); bytes = std::min(static_cast<size_t>(bytes), m_data.size());
if (data != NULL) { if (data != NULL) {
memcpy(data, &data_[0], bytes); memcpy(data, &m_data[0], bytes);
} }
data_.erase(data_.begin(), data_.begin() + bytes);
m_data.erase(m_data.begin(), m_data.begin() + bytes);
return bytes; return bytes;
} }
int Buffer::removeFromBack(void* data, int bytes) { int Buffer::removeFromBack(void* data, int bytes) {
bytes = std::min(static_cast<size_t>(bytes), data_.size()); bytes = std::min(static_cast<size_t>(bytes), m_data.size());
if (data != NULL) { if (data != NULL) {
memcpy(data, &data_[data_.size() - bytes], bytes); memcpy(data, &m_data[m_data.size() - bytes], bytes);
} }
data_.erase(data_.end() - bytes, data_.end());
m_data.erase(m_data.end() - bytes, m_data.end());
return bytes; return bytes;
} }
void Buffer::clear() { void Buffer::clear() {
data_.clear(); m_data.clear();
} }
void Buffer::setData(const void* data, int bytes) { void Buffer::setData(const void* data, int bytes) {
data_.assign( m_data.assign(
static_cast<const byte*>(data), static_cast<const byte*>(data),
static_cast<const byte*>(data) + bytes static_cast<const byte*>(data) + bytes
); );
} }
const void* Buffer::data() const { const void* Buffer::data() const {
return bytes() == 0 ? NULL : &data_[0]; return bytes() == 0 ? NULL : &m_data[0];
} }
void* Buffer::data() { void* Buffer::data() {
return bytes() == 0 ? NULL : &data_[0]; return bytes() == 0 ? NULL : &m_data[0];
} }
int Buffer::bytes() const { int Buffer::bytes() const {
return data_.size(); return m_data.size();
} }
bool Buffer::serialize(Serializer* serializer) const { bool Buffer::serialize(Serializer* serializer) const {

View File

@ -52,7 +52,7 @@ public:
bool deserialize(Deserializer* deserializer); bool deserialize(Deserializer* deserializer);
private: private:
std::vector<byte> data_; std::vector<byte> m_data;
}; };

View File

@ -34,18 +34,18 @@ namespace metacall {
// //
Client::Client() : Client::Client() :
stream_(&socket_), m_stream(&m_socket),
protocol_(&stream_, &binding_) m_protocol(&m_stream, &m_binding)
{ {
} }
void Client::advance() { void Client::advance() {
if (!socket_.opened()) { if (!m_socket.opened()) {
return; return;
} }
if (socket_.connected()) { if (m_socket.connected()) {
protocol_.advance(); m_protocol.advance();
} }
else { else {
disconnect(); disconnect();
@ -55,42 +55,42 @@ void Client::advance() {
bool Client::connect(const char name[], int port) { bool Client::connect(const char name[], int port) {
disconnect(); disconnect();
socket_.open(); m_socket.open();
socket_.setNagle(false); m_socket.setNagle(false);
if (!socket_.connect(name, port)) { if (!m_socket.connect(name, port)) {
disconnect(); disconnect();
return false; return false;
} }
socket_.setBlocking(false); m_socket.setBlocking(false);
return true; return true;
} }
void Client::disconnect() { void Client::disconnect() {
protocol_.clearHandlers(); m_protocol.clearHandlers();
stream_.reset(); m_stream.reset();
socket_.close(); m_socket.close();
} }
bool Client::connected() const { bool Client::connected() const {
return socket_.connected(); return m_socket.connected();
} }
const Protocol* Client::protocol() const { const Protocol* Client::protocol() const {
return &protocol_; return &m_protocol;
} }
Protocol* Client::protocol() { Protocol* Client::protocol() {
return &protocol_; return &m_protocol;
} }
const Binding* Client::binding() const { const Binding* Client::binding() const {
return &binding_; return &m_binding;
} }
Binding* Client::binding() { Binding* Client::binding() {
return &binding_; return &m_binding;
} }

View File

@ -37,7 +37,6 @@ public:
Client(); Client();
void advance(); void advance();
bool connect(const char name[], int port); bool connect(const char name[], int port);
void disconnect(); void disconnect();
bool connected() const; bool connected() const;
@ -48,10 +47,10 @@ public:
Binding* binding(); Binding* binding();
private: private:
Socket socket_; Socket m_socket;
Stream stream_; Stream m_stream;
Binding binding_; Binding m_binding;
Protocol protocol_; Protocol m_protocol;
}; };

View File

@ -49,17 +49,17 @@ public:
typedef R(*F)(); typedef R(*F)();
Functor0p(F function) : Functor0p(F function) :
function_(function) m_function(function)
{ {
} }
bool call(Deserializer*, Serializer* ret) const { bool call(Deserializer*, Serializer* ret) const {
ret->write(function_()); ret->write(m_function());
return true; return true;
} }
private: private:
F function_; F m_function;
}; };
template <> template <>
@ -68,17 +68,17 @@ public:
typedef void(*F)(); typedef void(*F)();
Functor0p(F function) : Functor0p(F function) :
function_(function) m_function(function)
{ {
} }
bool call(Deserializer*, Serializer*) const { bool call(Deserializer*, Serializer*) const {
function_(); m_function();
return true; return true;
} }
private: private:
F function_; F m_function;
}; };
@ -92,7 +92,7 @@ public:
typedef R (*F)(P1); typedef R (*F)(P1);
Functor1p(F function) : Functor1p(F function) :
function_(function) m_function(function)
{ {
} }
@ -101,14 +101,14 @@ public:
const bool success = args->read(&p1); const bool success = args->read(&p1);
if (success) { if (success) {
ret->write(function_(p1)); ret->write(m_function(p1));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1> template <typename P1>
@ -117,7 +117,7 @@ public:
typedef void (*F)(P1); typedef void (*F)(P1);
Functor1p(F function) : Functor1p(F function) :
function_(function) m_function(function)
{ {
} }
@ -126,14 +126,14 @@ public:
const bool success = args->read(&p1); const bool success = args->read(&p1);
if (success) { if (success) {
function_(p1); m_function(p1);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
@ -147,7 +147,7 @@ public:
typedef R (*F)(P1, P2); typedef R (*F)(P1, P2);
Functor2p(F function) : Functor2p(F function) :
function_(function) m_function(function)
{ {
} }
@ -160,14 +160,14 @@ public:
args->read(&p2); args->read(&p2);
if (success) { if (success) {
ret->write(function_(p1, p2)); ret->write(m_function(p1, p2));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1, typename P2> template <typename P1, typename P2>
@ -176,7 +176,7 @@ public:
typedef void (*F)(P1, P2); typedef void (*F)(P1, P2);
Functor2p(F function) : Functor2p(F function) :
function_(function) m_function(function)
{ {
} }
@ -189,14 +189,14 @@ public:
args->read(&p2); args->read(&p2);
if (success) { if (success) {
function_(p1, p2); m_function(p1, p2);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
@ -210,7 +210,7 @@ public:
typedef R (*F)(P1, P2, P3); typedef R (*F)(P1, P2, P3);
Functor3p(F function) : Functor3p(F function) :
function_(function) m_function(function)
{ {
} }
@ -225,14 +225,14 @@ public:
args->read(&p3); args->read(&p3);
if (success) { if (success) {
ret->write(function_(p1, p2, p3)); ret->write(m_function(p1, p2, p3));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1, typename P2, typename P3> template <typename P1, typename P2, typename P3>
@ -241,7 +241,7 @@ public:
typedef void (*F)(P1, P2, P3); typedef void (*F)(P1, P2, P3);
Functor3p(F function) : Functor3p(F function) :
function_(function) m_function(function)
{ {
} }
@ -256,14 +256,14 @@ public:
args->read(&p3); args->read(&p3);
if (success) { if (success) {
function_(p1, p2, p3); m_function(p1, p2, p3);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
@ -277,7 +277,7 @@ public:
typedef R (*F)(P1, P2, P3, P4); typedef R (*F)(P1, P2, P3, P4);
Functor4p(F function) : Functor4p(F function) :
function_(function) m_function(function)
{ {
} }
@ -294,14 +294,14 @@ public:
args->read(&p4); args->read(&p4);
if (success) { if (success) {
ret->write(function_(p1, p2, p3, p4)); ret->write(m_function(p1, p2, p3, p4));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1, typename P2, typename P3, typename P4> template <typename P1, typename P2, typename P3, typename P4>
@ -310,7 +310,7 @@ public:
typedef void (*F)(P1, P2, P3, P4); typedef void (*F)(P1, P2, P3, P4);
Functor4p(F function) : Functor4p(F function) :
function_(function) m_function(function)
{ {
} }
@ -327,14 +327,14 @@ public:
args->read(&p4); args->read(&p4);
if (success) { if (success) {
function_(p1, p2, p3, p4); m_function(p1, p2, p3, p4);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
@ -348,7 +348,7 @@ public:
typedef R (*F)(P1, P2, P3, P4, P5); typedef R (*F)(P1, P2, P3, P4, P5);
Functor5p(F function) : Functor5p(F function) :
function_(function) m_function(function)
{ {
} }
@ -367,14 +367,14 @@ public:
args->read(&p5); args->read(&p5);
if (success) { if (success) {
ret->write(function_(p1, p2, p3, p4, p5)); ret->write(m_function(p1, p2, p3, p4, p5));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1, typename P2, typename P3, typename P4, typename P5> template <typename P1, typename P2, typename P3, typename P4, typename P5>
@ -383,7 +383,7 @@ public:
typedef void (*F)(P1, P2, P3, P4, P5); typedef void (*F)(P1, P2, P3, P4, P5);
Functor5p(F function) : Functor5p(F function) :
function_(function) m_function(function)
{ {
} }
@ -402,14 +402,14 @@ public:
args->read(&p5); args->read(&p5);
if (success) { if (success) {
function_(p1, p2, p3, p4, p5); m_function(p1, p2, p3, p4, p5);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
@ -423,7 +423,7 @@ public:
typedef R (*F)(P1, P2, P3, P4, P5, P6); typedef R (*F)(P1, P2, P3, P4, P5, P6);
Functor6p(F function) : Functor6p(F function) :
function_(function) m_function(function)
{ {
} }
@ -444,14 +444,14 @@ public:
args->read(&p6); args->read(&p6);
if (success) { if (success) {
ret->write(function_(p1, p2, p3, p4, p5, p6)); ret->write(m_function(p1, p2, p3, p4, p5, p6));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
@ -460,7 +460,7 @@ public:
typedef void (*F)(P1, P2, P3, P4, P5, P6); typedef void (*F)(P1, P2, P3, P4, P5, P6);
Functor6p(F function) : Functor6p(F function) :
function_(function) m_function(function)
{ {
} }
@ -481,14 +481,14 @@ public:
args->read(&p6); args->read(&p6);
if (success) { if (success) {
function_(p1, p2, p3, p4, p5, p6); m_function(p1, p2, p3, p4, p5, p6);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
@ -502,7 +502,7 @@ public:
typedef R (*F)(P1, P2, P3, P4, P5, P6, P7); typedef R (*F)(P1, P2, P3, P4, P5, P6, P7);
Functor7p(F function) : Functor7p(F function) :
function_(function) m_function(function)
{ {
} }
@ -525,14 +525,14 @@ public:
args->read(&p7); args->read(&p7);
if (success) { if (success) {
ret->write(function_(p1, p2, p3, p4, p5, p6, p7)); ret->write(m_function(p1, p2, p3, p4, p5, p6, p7));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
@ -541,7 +541,7 @@ public:
typedef void (*F)(P1, P2, P3, P4, P5, P6, P7); typedef void (*F)(P1, P2, P3, P4, P5, P6, P7);
Functor7p(F function) : Functor7p(F function) :
function_(function) m_function(function)
{ {
} }
@ -564,14 +564,14 @@ public:
args->read(&p7); args->read(&p7);
if (success) { if (success) {
function_(p1, p2, p3, p4, p5, p6, p7); m_function(p1, p2, p3, p4, p5, p6, p7);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
@ -585,7 +585,7 @@ public:
typedef R (*F)(P1, P2, P3, P4, P5, P6, P7, P8); typedef R (*F)(P1, P2, P3, P4, P5, P6, P7, P8);
Functor8p(F function) : Functor8p(F function) :
function_(function) m_function(function)
{ {
} }
@ -610,14 +610,14 @@ public:
args->read(&p8); args->read(&p8);
if (success) { if (success) {
ret->write(function_(p1, p2, p3, p4, p5, p6, p7, p8)); ret->write(m_function(p1, p2, p3, p4, p5, p6, p7, p8));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8> template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
@ -626,7 +626,7 @@ public:
typedef void (*F)(P1, P2, P3, P4, P5, P6, P7, P8); typedef void (*F)(P1, P2, P3, P4, P5, P6, P7, P8);
Functor8p(F function) : Functor8p(F function) :
function_(function) m_function(function)
{ {
} }
@ -651,14 +651,14 @@ public:
args->read(&p8); args->read(&p8);
if (success) { if (success) {
function_(p1, p2, p3, p4, p5, p6, p7, p8); m_function(p1, p2, p3, p4, p5, p6, p7, p8);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
@ -672,7 +672,7 @@ public:
typedef R (*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9); typedef R (*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9);
Functor9p(F function) : Functor9p(F function) :
function_(function) m_function(function)
{ {
} }
@ -699,14 +699,14 @@ public:
args->read(&p9); args->read(&p9);
if (success) { if (success) {
ret->write(function_(p1, p2, p3, p4, p5, p6, p7, p8, p9)); ret->write(m_function(p1, p2, p3, p4, p5, p6, p7, p8, p9));
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };
template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9> template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
@ -715,7 +715,7 @@ public:
typedef void (*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9); typedef void (*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9);
Functor9p(F function) : Functor9p(F function) :
function_(function) m_function(function)
{ {
} }
@ -742,14 +742,14 @@ public:
args->read(&p9); args->read(&p9);
if (success) { if (success) {
function_(p1, p2, p3, p4, p5, p6, p7, p8, p9); m_function(p1, p2, p3, p4, p5, p6, p7, p8, p9);
} }
return success; return success;
} }
private: private:
F function_; F m_function;
}; };

View File

@ -154,8 +154,8 @@ Protocol::TaskId Protocol::invoke(const Token& token, const P1& p1, const P2& p2
template <typename R> template <typename R>
Protocol::TaskState Protocol::queryResult(TaskId id, R* result) { Protocol::TaskState Protocol::queryResult(TaskId id, R* result) {
TaskMap::const_iterator iter = taskMap_.find(id); TaskMap::const_iterator iter = m_taskMap.find(id);
if (iter == taskMap_.end()) { if (iter == m_taskMap.end()) {
return TASK_STATE_UNDEFINED; return TASK_STATE_UNDEFINED;
} }

View File

@ -34,25 +34,25 @@ namespace metacall {
// //
Protocol::Protocol(Stream* stream, Binding* binding) : Protocol::Protocol(Stream* stream, Binding* binding) :
stream_(stream), m_stream(stream),
binding_(binding), m_binding(binding),
rate_(64) m_rate(64)
{ {
} }
void Protocol::advance() { void Protocol::advance() {
if (!stream_->socket()->connected()) { if (!m_stream->socket()->connected()) {
return; return;
} }
for (int i = 0; i < rate_; ++i) { for (int i = 0; i < m_rate; ++i) {
if (advanceStream() != Stream::STATE_READY) { if (advanceStream() != Stream::STATE_READY) {
break; break;
} }
} }
std::vector<TaskMap::iterator> processed; std::vector<TaskMap::iterator> processed;
for (TaskMap::iterator iter = taskMap_.begin(); iter != taskMap_.end(); ++iter) { for (TaskMap::iterator iter = m_taskMap.begin(); iter != m_taskMap.end(); ++iter) {
TaskEntry& entry = iter->second; TaskEntry& entry = iter->second;
switch (entry.state) { switch (entry.state) {
case TASK_STATE_READY: case TASK_STATE_READY:
@ -69,21 +69,21 @@ void Protocol::advance() {
} }
for (size_t i = 0; i < processed.size(); ++i) { for (size_t i = 0; i < processed.size(); ++i) {
taskMap_.erase(processed[i]); m_taskMap.erase(processed[i]);
} }
} }
void Protocol::setRate(int rate) { void Protocol::setRate(int rate) {
rate_ = rate; m_rate = rate;
} }
bool Protocol::pendingTasks() const { bool Protocol::pendingTasks() const {
return taskMap_.size() > 0; return m_taskMap.size() > 0;
} }
bool Protocol::setHandler(TaskId id, HandlerProc handler, void* userPtr) { bool Protocol::setHandler(TaskId id, HandlerProc handler, void* userPtr) {
const TaskMap::iterator iter = taskMap_.find(id); const TaskMap::iterator iter = m_taskMap.find(id);
if (iter == taskMap_.end() || iter->second.state != TASK_STATE_PENDING) { if (iter == m_taskMap.end() || iter->second.state != TASK_STATE_PENDING) {
return false; return false;
} }
@ -92,25 +92,25 @@ bool Protocol::setHandler(TaskId id, HandlerProc handler, void* userPtr) {
} }
void Protocol::clearHandler(TaskId id) { void Protocol::clearHandler(TaskId id) {
const TaskMap::iterator iter = taskMap_.find(id); const TaskMap::iterator iter = m_taskMap.find(id);
if (iter != taskMap_.end()) { if (iter != m_taskMap.end()) {
taskMap_.erase(iter); m_taskMap.erase(iter);
} }
} }
void Protocol::clearHandlers() { void Protocol::clearHandlers() {
for (TaskMap::iterator iter = taskMap_.begin(); iter != taskMap_.end(); ++iter) { for (TaskMap::iterator iter = m_taskMap.begin(); iter != m_taskMap.end(); ++iter) {
iter->second.handlers.clear(); iter->second.handlers.clear();
} }
} }
Stream::State Protocol::advanceStream() { Stream::State Protocol::advanceStream() {
stream_->advance(); m_stream->advance();
PacketHeader header; PacketHeader header;
int headerSize = 0; int headerSize = 0;
Stream::State state = stream_->peek(&header, &headerSize); Stream::State state = m_stream->peek(&header, &headerSize);
if (state == Stream::STATE_READY) { if (state == Stream::STATE_READY) {
switch (header.id) { switch (header.id) {
case PACKET_ID_FUNCTION_CALL_REQUEST: case PACKET_ID_FUNCTION_CALL_REQUEST:
@ -132,10 +132,10 @@ Stream::State Protocol::advanceInvokeReply() {
PacketInvokeReply packetReply; PacketInvokeReply packetReply;
Deserializer deserializer(&packetReply.data); Deserializer deserializer(&packetReply.data);
Stream::State state = stream_->receive(&packetReply); Stream::State state = m_stream->receive(&packetReply);
if (state == Stream::STATE_READY) { if (state == Stream::STATE_READY) {
const TaskMap::iterator iter = taskMap_.find(static_cast<TaskId>(packetReply.taskId)); const TaskMap::iterator iter = m_taskMap.find(static_cast<TaskId>(packetReply.taskId));
if (iter == taskMap_.end()) { if (iter == m_taskMap.end()) {
state = Stream::STATE_ERROR_PROTOCOL; state = Stream::STATE_ERROR_PROTOCOL;
} }
else { else {
@ -155,13 +155,13 @@ Stream::State Protocol::advanceInvokeRequest() {
PacketInvokeRequest packetRequest; PacketInvokeRequest packetRequest;
Deserializer deserializer(&packetRequest.data); Deserializer deserializer(&packetRequest.data);
const Stream::State state = stream_->receive(&packetRequest); const Stream::State state = m_stream->receive(&packetRequest);
if (state == Stream::STATE_READY) { if (state == Stream::STATE_READY) {
PacketInvokeReply packetReply; PacketInvokeReply packetReply;
packetReply.taskId = packetRequest.taskId; packetReply.taskId = packetRequest.taskId;
Serializer serializer(&packetReply.data); Serializer serializer(&packetReply.data);
switch (binding_->call(packetRequest.function, &deserializer, &serializer)) { switch (m_binding->call(packetRequest.function, &deserializer, &serializer)) {
case Binding::CALL_RESULT_INVALID_ARGS: case Binding::CALL_RESULT_INVALID_ARGS:
packetReply.flags |= PacketInvokeReply::FLAG_INVALID_ARGS; packetReply.flags |= PacketInvokeReply::FLAG_INVALID_ARGS;
break; break;
@ -172,7 +172,7 @@ Stream::State Protocol::advanceInvokeRequest() {
break; break;
} }
stream_->send(packetReply); m_stream->send(packetReply);
} }
return state; return state;
@ -189,18 +189,18 @@ Protocol::TaskId Protocol::invokeExec(const Token& token, PacketInvokeRequest* p
packetRequest->function = token; packetRequest->function = token;
packetRequest->taskId = taskId; packetRequest->taskId = taskId;
if (stream_->send(*packetRequest) != Stream::STATE_READY) { if (m_stream->send(*packetRequest) != Stream::STATE_READY) {
return TASK_ID_INVALID; return TASK_ID_INVALID;
} }
taskMap_[taskId] = TaskEntry(); m_taskMap[taskId] = TaskEntry();
return taskId; return taskId;
} }
Protocol::TaskId Protocol::registerTaskId() { Protocol::TaskId Protocol::registerTaskId() {
static int id = TASK_ID_INVALID; static int s_id = TASK_ID_INVALID;
while (++id == TASK_ID_INVALID); while (++s_id == TASK_ID_INVALID);
return static_cast<TaskId>(id); return static_cast<TaskId>(s_id);
} }

View File

@ -117,10 +117,10 @@ private:
static TaskId registerTaskId(); static TaskId registerTaskId();
typedef std::map<TaskId, TaskEntry> TaskMap; typedef std::map<TaskId, TaskEntry> TaskMap;
TaskMap taskMap_; TaskMap m_taskMap;
Stream* stream_; Stream* m_stream;
Binding* binding_; Binding* m_binding;
int rate_; int m_rate;
}; };

View File

@ -34,31 +34,31 @@ namespace metacall {
// //
Deserializer::Deserializer(const Buffer* data) : Deserializer::Deserializer(const Buffer* data) :
data_(data), m_data(data),
offset_(0) m_offset(0)
{ {
} }
const byte* Deserializer::readRaw(int size) { const byte* Deserializer::readRaw(int size) {
if (data_ == NULL || size > data_->bytes() - offset_) { if (m_data == NULL || size > m_data->bytes() - m_offset) {
return NULL; return NULL;
} }
const byte* data = static_cast<const byte*>(data_->data()) + offset_; const byte* data = static_cast<const byte*>(m_data->data()) + m_offset;
offset_ += size; m_offset += size;
return data; return data;
} }
int Deserializer::offset() const { int Deserializer::offset() const {
return offset_; return m_offset;
} }
bool Deserializer::setOffset(int offset, bool relative) { bool Deserializer::setOffset(int offset, bool relative) {
const int offsetNew = relative ? offset_ + offset : offset; const int offsetNew = relative ? m_offset + offset : offset;
if (offsetNew >= 0 && offsetNew <= data_->bytes()) { if (offsetNew >= 0 && offsetNew <= m_data->bytes()) {
offset_ = offsetNew; m_offset = offsetNew;
return true; return true;
} }
@ -71,25 +71,25 @@ bool Deserializer::setOffset(int offset, bool relative) {
// //
Serializer::Serializer(Buffer* data) : Serializer::Serializer(Buffer* data) :
data_(data), m_data(data),
offset_(0) m_offset(0)
{ {
} }
bool Serializer::writeRaw(const void* data, int size) { bool Serializer::writeRaw(const void* data, int size) {
if (data_ != NULL) { if (m_data != NULL) {
data_->addToBack(static_cast<const byte*>(data), size); m_data->addToBack(static_cast<const byte*>(data), size);
offset_ += size; m_offset += size;
} }
return true; return true;
} }
bool Serializer::setOffset(int offset, bool relative) { bool Serializer::setOffset(int offset, bool relative) {
const int offsetNew = relative ? offset_ + offset : offset; const int offsetNew = relative ? m_offset + offset : offset;
if (offsetNew >= 0 && offsetNew <= data_->bytes()) { if (offsetNew >= 0 && offsetNew <= m_data->bytes()) {
offset_ = offsetNew; m_offset = offsetNew;
return true; return true;
} }
@ -97,7 +97,7 @@ bool Serializer::setOffset(int offset, bool relative) {
} }
int Serializer::offset() const { int Serializer::offset() const {
return offset_; return m_offset;
} }

View File

@ -43,8 +43,8 @@ public:
int offset() const; int offset() const;
private: private:
const Buffer* data_; const Buffer* m_data;
int offset_; int m_offset;
}; };
@ -63,8 +63,8 @@ public:
int offset() const; int offset() const;
private: private:
Buffer* data_; Buffer* m_data;
int offset_; int m_offset;
}; };

View File

@ -34,8 +34,8 @@ namespace metacall {
// //
Server::Server() : Server::Server() :
clientMax_(1), m_clientMax(1),
clientActive_(CLIENT_ID_INVALID) m_clientActive(CLIENT_ID_INVALID)
{ {
} }
@ -50,20 +50,20 @@ void Server::advance() {
} }
const Binding* Server::binding() const { const Binding* Server::binding() const {
return &binding_; return &m_binding;
} }
Binding* Server::binding() { Binding* Server::binding() {
return &binding_; return &m_binding;
} }
bool Server::start(int serverPort, int clientsMax) { bool Server::start(int serverPort, int clientsMax) {
stop(); stop();
if (server_.open() && server_.bind(serverPort) && server_.listen()) { if (m_server.open() && m_server.bind(serverPort) && m_server.listen()) {
server_.setBlocking(false); m_server.setBlocking(false);
server_.setNagle(false); m_server.setNagle(false);
clientMax_ = clientsMax; m_clientMax = clientsMax;
return true; return true;
} }
@ -73,18 +73,18 @@ bool Server::start(int serverPort, int clientsMax) {
void Server::stop() { void Server::stop() {
disconnectAll(); disconnectAll();
clientMax_ = 0; m_clientMax = 0;
} }
void Server::getClients(std::vector<ClientId>* clients) const { void Server::clients(std::vector<ClientId>* clients) const {
for (ClientMap::const_iterator iter = clients_.begin(); iter != clients_.end(); ++iter) { for (ClientMap::const_iterator iter = m_clients.begin(); iter != m_clients.end(); ++iter) {
clients->push_back(iter->first); clients->push_back(iter->first);
} }
} }
bool Server::getClient(ClientId id, ClientData* data) const { bool Server::clients(ClientId id, ClientData* data) const {
const ClientMap::const_iterator iter = clients_.find(id); const ClientMap::const_iterator iter = m_clients.find(id);
if (iter == clients_.end()) { if (iter == m_clients.end()) {
return false; return false;
} }
@ -96,45 +96,45 @@ bool Server::getClient(ClientId id, ClientData* data) const {
} }
void Server::disconnect(ClientId id) { void Server::disconnect(ClientId id) {
const ClientMap::iterator iter = clients_.find(id); const ClientMap::iterator iter = m_clients.find(id);
if (iter != clients_.end()) { if (iter != m_clients.end()) {
delete iter->second; delete iter->second;
clients_.erase(iter); m_clients.erase(iter);
} }
} }
void Server::disconnectAll() { void Server::disconnectAll() {
for (ClientMap::iterator iter = clients_.begin(); iter != clients_.end(); ++iter) { for (ClientMap::iterator iter = m_clients.begin(); iter != m_clients.end(); ++iter) {
delete iter->second; delete iter->second;
} }
clients_.clear(); m_clients.clear();
} }
int Server::clientCount() const { int Server::clientCount() const {
return clients_.size(); return m_clients.size();
} }
Server::ClientId Server::clientActive() const { Server::ClientId Server::clientActive() const {
return clientActive_; return m_clientActive;
} }
void Server::advanceConnecting() { void Server::advanceConnecting() {
if (clientMax_ == 0 || !server_.opened()) { if (m_clientMax == 0 || !m_server.opened()) {
return; return;
} }
Socket client; Socket client;
if (!server_.accept(&client)) { if (!m_server.accept(&client)) {
return; return;
} }
const std::pair<ClientId, ClientEntry*> entry( const std::pair<ClientId, ClientEntry*> entry(
registerClientId(), registerClientId(),
new ClientEntry(&binding_) new ClientEntry(&m_binding)
); );
const ClientMap::iterator iter = clients_.insert(entry).first; const ClientMap::iterator iter = m_clients.insert(entry).first;
iter->second->socket.set(client.release()); iter->second->socket.set(client.release());
iter->second->socket.setNagle(false); iter->second->socket.setNagle(false);
iter->second->socket.setBlocking(false); iter->second->socket.setBlocking(false);
@ -142,7 +142,7 @@ void Server::advanceConnecting() {
void Server::advanceDisconnecting() { void Server::advanceDisconnecting() {
std::vector<ClientMap::iterator> clients; std::vector<ClientMap::iterator> clients;
for (ClientMap::iterator iter = clients_.begin(); iter != clients_.end(); ++iter) { for (ClientMap::iterator iter = m_clients.begin(); iter != m_clients.end(); ++iter) {
if (!iter->second->socket.connected()) { if (!iter->second->socket.connected()) {
clients.push_back(iter); clients.push_back(iter);
} }
@ -154,20 +154,20 @@ void Server::advanceDisconnecting() {
} }
void Server::advanceConnected() { void Server::advanceConnected() {
ASSERT(clientActive_ == CLIENT_ID_INVALID); ASSERT(m_clientActive == CLIENT_ID_INVALID);
for (ClientMap::iterator iter = clients_.begin(); iter != clients_.end(); ++iter) { for (ClientMap::iterator iter = m_clients.begin(); iter != m_clients.end(); ++iter) {
clientActive_ = iter->first; m_clientActive = iter->first;
iter->second->protocol.advance(); iter->second->protocol.advance();
} }
clientActive_ = CLIENT_ID_INVALID; m_clientActive = CLIENT_ID_INVALID;
} }
Server::ClientId Server::registerClientId() { Server::ClientId Server::registerClientId() {
static int id = CLIENT_ID_INVALID; static int s_id = CLIENT_ID_INVALID;
while (++id == CLIENT_ID_INVALID); while (++s_id == CLIENT_ID_INVALID);
return static_cast<ClientId>(id); return static_cast<ClientId>(s_id);
} }

View File

@ -59,8 +59,8 @@ public:
void disconnect(ClientId id); void disconnect(ClientId id);
void disconnectAll(); void disconnectAll();
void getClients (std::vector<ClientId>* clients) const; void clients(std::vector<ClientId>* clients) const;
bool getClient (ClientId id, ClientData* data) const; bool clients(ClientId id, ClientData* data) const;
ClientId clientActive() const; ClientId clientActive() const;
int clientCount() const; int clientCount() const;
const Binding* binding() const; const Binding* binding() const;
@ -85,11 +85,11 @@ private:
static ClientId registerClientId(); static ClientId registerClientId();
typedef std::map<ClientId, ClientEntry*> ClientMap; typedef std::map<ClientId, ClientEntry*> ClientMap;
ClientMap clients_; ClientMap m_clients;
int clientMax_; int m_clientMax;
ClientId clientActive_; ClientId m_clientActive;
Socket server_; Socket m_server;
Binding binding_; Binding m_binding;
}; };

View File

@ -46,7 +46,7 @@ static struct Winsock {
~Winsock() { ~Winsock() {
WSACleanup(); WSACleanup();
} }
} winsock; } s_winsock;
#endif #endif