This commit is contained in:
Alex Yatskov 2012-02-19 18:47:09 -08:00
parent 2deb0a628c
commit 59ce0b59d4
9 changed files with 39 additions and 38 deletions

View File

@ -35,7 +35,7 @@ using namespace metacall;
#define TEST_UNICODE #define TEST_UNICODE
#define TEST_ANSI #define TEST_ANSI
//#define TEST_C_STRING #define TEST_C_STRING
#define TEST_BASIC_STRING #define TEST_BASIC_STRING
@ -85,20 +85,18 @@ int main(int, char *[]) {
return 1; return 1;
} }
server.binding()->bind(FPARAM(testCStrAnsi)); Binding& binding = server.binding();
server.binding()->bind(FPARAM(testCStrUnicode)); Protocol& protocol = client.protocol();
server.binding()->bind(FPARAM(testBasicStringAnsi));
server.binding()->bind(FPARAM(testBasicStringUnicode));
do { do {
Protocol* const protocol = client.protocol();
// //
// C string // C string
// //
#ifdef TEST_C_STRING #ifdef TEST_C_STRING
{ {
binding.bind(FPARAM(testCStrAnsi));
binding.bind(FPARAM(testCStrUnicode));
// //
// ANSI // ANSI
// //
@ -106,7 +104,7 @@ int main(int, char *[]) {
{ {
const char* strings[] = { "Hello world", "", NULL }; const char* strings[] = { "Hello world", "", NULL };
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
protocol->invoke("testCStrAnsi", strings[i]); protocol.invoke("testCStrAnsi", strings[i]);
} }
} }
#endif #endif
@ -117,7 +115,7 @@ int main(int, char *[]) {
{ {
const wchar_t* strings[] = { L"Hello world", L"", NULL }; const wchar_t* strings[] = { L"Hello world", L"", NULL };
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
protocol->invoke("testCStrUnicode", strings[i]); protocol.invoke("testCStrUnicode", strings[i]);
} }
} }
#endif #endif
@ -130,6 +128,9 @@ int main(int, char *[]) {
// //
#ifdef TEST_BASIC_STRING #ifdef TEST_BASIC_STRING
{ {
binding.bind(FPARAM(testBasicStringAnsi));
binding.bind(FPARAM(testBasicStringUnicode));
// //
// ANSI // ANSI
// //
@ -137,7 +138,7 @@ int main(int, char *[]) {
{ {
std::string strings[] = { std::string("Hello world"), std::string() }; std::string strings[] = { std::string("Hello world"), std::string() };
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
protocol->invoke("testBasicStringAnsi", strings[i]); protocol.invoke("testBasicStringAnsi", strings[i]);
} }
} }
#endif #endif
@ -148,7 +149,7 @@ int main(int, char *[]) {
{ {
std::wstring strings[] = { std::wstring(L"Hello world"), std::wstring() }; std::wstring strings[] = { std::wstring(L"Hello world"), std::wstring() };
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
protocol->invoke("testBasicStringUnicode", strings[i]); protocol.invoke("testBasicStringUnicode", strings[i]);
} }
} }
#endif #endif

View File

@ -76,20 +76,20 @@ bool Client::connected() const {
return m_socket.connected(); return m_socket.connected();
} }
const Protocol* Client::protocol() const { const Protocol& Client::protocol() const {
return &m_protocol; return m_protocol;
} }
Protocol* Client::protocol() { Protocol& Client::protocol() {
return &m_protocol; return m_protocol;
} }
const Binding* Client::binding() const { const Binding& Client::binding() const {
return &m_binding; return m_binding;
} }
Binding* Client::binding() { Binding& Client::binding() {
return &m_binding; return m_binding;
} }

View File

@ -41,10 +41,10 @@ public:
void disconnect(); void disconnect();
bool connected() const; bool connected() const;
const Protocol* protocol() const; const Protocol& protocol() const;
Protocol* protocol(); Protocol& protocol();
const Binding* binding() const; const Binding& binding() const;
Binding* binding(); Binding& binding();
private: private:
Socket m_socket; Socket m_socket;

View File

@ -127,7 +127,7 @@ struct PacketInvokeReply {
enum { enum {
FLAG_UNBOUND_FUNC = 1 << 0, FLAG_UNBOUND_FUNC = 1 << 0,
FLAG_INVALID_ARGS = 1 << 1, FLAG_INVALID_ARGS = 1 << 1
}; };
bool serialize(Serializer* serializer) const { bool serialize(Serializer* serializer) const {

View File

@ -40,7 +40,7 @@ Protocol::Protocol(Stream* stream, Binding* binding) :
} }
void Protocol::advance() { void Protocol::advance() {
if (!m_stream->socket()->connected()) { if (!m_stream->socket().connected()) {
return; return;
} }

View File

@ -48,12 +48,12 @@ void Server::advance() {
advanceConnected(); advanceConnected();
} }
const Binding* Server::binding() const { const Binding& Server::binding() const {
return &m_binding; return m_binding;
} }
Binding* Server::binding() { Binding& Server::binding() {
return &m_binding; return m_binding;
} }
bool Server::start(int serverPort, int clientsMax) { bool Server::start(int serverPort, int clientsMax) {

View File

@ -63,8 +63,8 @@ public:
bool clients(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;
Binding* binding(); Binding& binding();
private: private:
struct ClientEntry : public ClientData { struct ClientEntry : public ClientData {

View File

@ -110,12 +110,12 @@ Stream::State Stream::peek(PacketHeader* header, int* headerSize) {
return STATE_READY; return STATE_READY;
} }
const Socket* Stream::socket() const { const Socket& Stream::socket() const {
return m_socket; return *m_socket;
} }
Socket* Stream::socket() { Socket& Stream::socket() {
return m_socket; return *m_socket;
} }

View File

@ -53,8 +53,8 @@ class Stream {
State receive(T* packet); State receive(T* packet);
State peek(PacketHeader* header, int* headerSize); State peek(PacketHeader* header, int* headerSize);
const Socket* socket() const; const Socket& socket() const;
Socket* socket(); Socket& socket();
private: private:
Socket* m_socket; Socket* m_socket;