diff --git a/.cproject b/.cproject deleted file mode 100644 index 445d1ce..0000000 --- a/.cproject +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore index 920f6a8..d612436 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ Debug Release *.pyc +*.user diff --git a/.project b/.project deleted file mode 100644 index 1f942f3..0000000 --- a/.project +++ /dev/null @@ -1,89 +0,0 @@ - - - metacall - - - - - - org.python.pydev.PyDevBuilder - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.autoBuildTarget - all - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.buildCommand - make - - - org.eclipse.cdt.make.core.buildLocation - ${workspace_loc:/metacall/Debug} - - - org.eclipse.cdt.make.core.cleanBuildTarget - clean - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.fullBuildTarget - all - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - org.python.pydev.pythonNature - - diff --git a/.pydevproject b/.pydevproject deleted file mode 100644 index a9cca03..0000000 --- a/.pydevproject +++ /dev/null @@ -1,7 +0,0 @@ - - - - -Default -python 2.7 - diff --git a/main.cpp b/main.cpp index 2cde54a..56b1566 100644 --- a/main.cpp +++ b/main.cpp @@ -67,7 +67,7 @@ static void serverTest1(const char str[], int num) { // Program entry // -int main(int argc, char *argv[]) { +int main(int, char *[]) { const int port = 1234; Server server; diff --git a/mc_socket.cpp b/mc_socket.cpp index d6fbe22..66e51ae 100644 --- a/mc_socket.cpp +++ b/mc_socket.cpp @@ -140,7 +140,7 @@ bool Socket::connect(const char name[], int port) { return false; } - sockaddr_in host = { 0 }; + sockaddr_in host; host.sin_port = htons(static_cast(port)); host.sin_family = AF_INET; host.sin_addr.s_addr = address; @@ -156,7 +156,7 @@ bool Socket::connect(const char name[], int port) { bool Socket::bind(int port) { ASSERT(opened()); - sockaddr_in host = { 0 }; + sockaddr_in host; host.sin_family = AF_INET; host.sin_addr.s_addr = INADDR_ANY; host.sin_port = htons(static_cast(port)); @@ -262,8 +262,9 @@ bool Socket::wait(unsigned mask, int seconds) const { #pragma warning(pop) #endif - timeval timeoutVal = { 0 }; + timeval timeoutVal; timeoutVal.tv_sec = seconds; + timeoutVal.tv_usec = 0; timeval* const timeoutPtr = seconds < 0 ? NULL : &timeoutVal; const int result = select( @@ -303,7 +304,7 @@ const char* Socket::hostname() const { return NULL; } - sockaddr_in host = { 0 }; + sockaddr_in host; socklen_t hostSize = sizeof(host); sockaddr* const hostPtr = reinterpret_cast(&host); diff --git a/mc_stream-inl.hpp b/mc_stream-inl.hpp index 3de83fb..4307483 100644 --- a/mc_stream-inl.hpp +++ b/mc_stream-inl.hpp @@ -28,7 +28,7 @@ namespace metacall { template Stream::State Stream::send(const T& packet) { - if (!socket_->connected()) { + if (!m_socket->connected()) { return STATE_ERROR_CONNECTION; } @@ -42,7 +42,7 @@ Stream::State Stream::send(const T& packet) { serializerTemp.offset() ); - Serializer serializerSend(&buffSend_); + Serializer serializerSend(&m_buffSend); serializerSend.write(header); serializerSend.writeRaw(buffTemp.data(), buffTemp.bytes()); @@ -51,7 +51,7 @@ Stream::State Stream::send(const T& packet) { template Stream::State Stream::receive(T* packet) { - if (!socket_->connected()) { + if (!m_socket->connected()) { return STATE_ERROR_CONNECTION; } @@ -63,14 +63,14 @@ Stream::State Stream::receive(T* packet) { return state; } - buffRecv_.removeFromFront(NULL, headerSize); + m_buffRecv.removeFromFront(NULL, headerSize); - Deserializer deserializer(&buffRecv_); + Deserializer deserializer(&m_buffRecv); const bool success = deserializer.read(packet) && deserializer.offset() == static_cast(header.size); - buffRecv_.removeFromFront(NULL, header.size); + m_buffRecv.removeFromFront(NULL, header.size); return success ? STATE_READY : STATE_ERROR_PROTOCOL; } diff --git a/mc_stream.cpp b/mc_stream.cpp index 494a2d4..e6938e1 100644 --- a/mc_stream.cpp +++ b/mc_stream.cpp @@ -43,31 +43,31 @@ enum { // Stream::Stream(Socket* socket) : - socket_(socket) + m_socket(socket) { } Stream::State Stream::advance() { - if (!socket_->connected()) { + if (!m_socket->connected()) { return STATE_ERROR_CONNECTION; } - if (buffSend_.bytes() > 0 && socket_->wait(Socket::MASK_WRITE, 0)) { - const int bytesSent = socket_->send( - buffSend_.data(), - buffSend_.bytes() + if (m_buffSend.bytes() > 0 && m_socket->wait(Socket::MASK_WRITE, 0)) { + const int bytesSent = m_socket->send( + m_buffSend.data(), + m_buffSend.bytes() ); if (bytesSent <= 0) { return STATE_ERROR_CONNECTION; } - buffSend_.removeFromFront(NULL, bytesSent); + m_buffSend.removeFromFront(NULL, bytesSent); } - if (socket_->wait(Socket::MASK_READ, 0)) { + if (m_socket->wait(Socket::MASK_READ, 0)) { byte buffRecv[SOCKET_BUFFER_SIZE]; - const int bytesRecv = socket_->receive( + const int bytesRecv = m_socket->receive( buffRecv, sizeof(buffRecv) ); @@ -76,23 +76,23 @@ Stream::State Stream::advance() { return STATE_ERROR_CONNECTION; } - buffRecv_.addToBack(buffRecv, bytesRecv); + m_buffRecv.addToBack(buffRecv, bytesRecv); } return STATE_READY; } void Stream::reset() { - buffSend_.clear(); - buffRecv_.clear(); + m_buffSend.clear(); + m_buffRecv.clear(); } Stream::State Stream::peek(PacketHeader* header, int* headerSize) { - if (!socket_->connected()) { + if (!m_socket->connected()) { return STATE_ERROR_CONNECTION; } - Deserializer deserializer(&buffRecv_); + Deserializer deserializer(&m_buffRecv); if (!deserializer.read(header)) { return STATE_PENDING_PACKET_HEADER; } @@ -104,7 +104,7 @@ Stream::State Stream::peek(PacketHeader* header, int* headerSize) { *headerSize = deserializer.offset(); const int packetSize = static_cast(header->size) + *headerSize; - if (buffRecv_.bytes() < packetSize) { + if (m_buffRecv.bytes() < packetSize) { return STATE_PENDING_PACKET_BODY; } @@ -112,11 +112,11 @@ Stream::State Stream::peek(PacketHeader* header, int* headerSize) { } const Socket* Stream::socket() const { - return socket_; + return m_socket; } Socket* Stream::socket() { - return socket_; + return m_socket; } diff --git a/mc_stream.hpp b/mc_stream.hpp index 30afb75..d9a7d1b 100644 --- a/mc_stream.hpp +++ b/mc_stream.hpp @@ -44,22 +44,22 @@ class Stream { Stream(Socket* socket); - State advance (); - void reset (); + State advance(); + void reset(); template - State send (const T& packet); + State send(const T& packet); template - State receive (T* packet); - State peek (PacketHeader* header, int* headerSize); + State receive(T* packet); + State peek(PacketHeader* header, int* headerSize); - const Socket* socket () const; - Socket* socket (); + const Socket* socket() const; + Socket* socket(); private: - Socket* socket_; - Buffer buffRecv_; - Buffer buffSend_; + Socket* m_socket; + Buffer m_buffRecv; + Buffer m_buffSend; }; diff --git a/mc_token.cpp b/mc_token.cpp index 805ef08..1f942ad 100644 --- a/mc_token.cpp +++ b/mc_token.cpp @@ -34,25 +34,27 @@ namespace metacall { // Token::Token(const char value[]) : - value_(hash(value)) + m_value(hash(value)) { } -Token::Token(unsigned value) : - value_(value) +Token::Token(const unsigned value) : + m_value(value) { } Token::operator unsigned() const { - return value_; + return m_value; } unsigned Token::hash(const char str[]) { - // djb2 string hash, see http://www.cse.yorku.ca/~oz/hash.html + // metacall uses the djb2 string hash, see + // http://www.cse.yorku.ca/~oz/hash.html unsigned hash = 5381; for (const char* ptr = str; *ptr != 0; ++ptr) { hash = (hash << 5) + hash + *ptr; } + return hash; } diff --git a/mc_token.hpp b/mc_token.hpp index 276140e..1aa44c8 100644 --- a/mc_token.hpp +++ b/mc_token.hpp @@ -42,7 +42,7 @@ public: private: static unsigned hash(const char str[]); - unsigned value_; + unsigned m_value; }; diff --git a/metacall.pro b/metacall.pro new file mode 100644 index 0000000..48f5431 --- /dev/null +++ b/metacall.pro @@ -0,0 +1,39 @@ +TEMPLATE = app +CONFIG += console +CONFIG -= qt + +SOURCES += main.cpp \ + mc_token.cpp \ + mc_stream.cpp \ + mc_socket.cpp \ + mc_server.cpp \ + mc_serial.cpp \ + mc_protocol.cpp \ + mc_client.cpp \ + mc_buffer.cpp \ + mc_binding.cpp + +OTHER_FILES += \ + metacall.py \ + metacall.pro.user + +HEADERS += \ + metacall.hpp \ + mc_token.hpp \ + mc_stream.hpp \ + mc_stream-inl.hpp \ + mc_socket.hpp \ + mc_server.hpp \ + mc_serial.hpp \ + mc_serial-inl.hpp \ + mc_protocol.hpp \ + mc_protocol-inl.hpp \ + mc_packet.hpp \ + mc_meta.hpp \ + mc_functor.hpp \ + mc_common.hpp \ + mc_client.hpp \ + mc_buffer.hpp \ + mc_binding.hpp \ + mc_binding-inl.hpp +