summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@fastmq.commkdir>2009-08-30 08:18:31 +0200
committerMartin Sustrik <sustrik@fastmq.commkdir>2009-08-30 08:18:31 +0200
commit176879e5bbce6115ff5741f2426f689bda312109 (patch)
tree295d25e283b37c66497743fb33665d128ad03218
parent1d650934e477be32db9a3c64de077deed0416689 (diff)
engine virtualised; chatroom example removed
-rw-r--r--.gitignore5
-rw-r--r--Makefile.am5
-rw-r--r--configure.in3
-rw-r--r--examples/Makefile.am2
-rw-r--r--examples/chat/Makefile.am15
-rw-r--r--examples/chat/chatroom.cpp74
-rw-r--r--examples/chat/display.cpp55
-rw-r--r--examples/chat/prompt.cpp61
-rw-r--r--src/Makefile.am1
-rw-r--r--src/command.hpp2
-rw-r--r--src/i_engine.hpp43
-rw-r--r--src/object.cpp5
-rw-r--r--src/object.hpp4
-rw-r--r--src/owned.cpp2
-rw-r--r--src/owned.hpp2
-rw-r--r--src/session.cpp4
-rw-r--r--src/session.hpp4
-rw-r--r--src/zmq_engine.hpp9
18 files changed, 67 insertions, 229 deletions
diff --git a/.gitignore b/.gitignore
index cf19bd8..c1bee52 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,8 @@
+COPYING
+INSTALL
+*.m4
*.o
*.lo
+*.loT
*.la
+.*
diff --git a/Makefile.am b/Makefile.am
index 715543c..d0bee3b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,5 @@
include_HEADERS = include/zmq.h include/zmq.hpp
-
if BUILD_PYTHON
DIR_P = python
endif
@@ -9,5 +8,5 @@ if BUILD_RUBY
DIR_R = ruby
endif
-SUBDIRS = src examples $(DIR_P) $(DIR_R)
-DIST_SUBDIRS = src examples $(DIR_P) $(DIR_R)
+SUBDIRS = src $(DIR_P) $(DIR_R)
+DIST_SUBDIRS = src $(DIR_P) $(DIR_R)
diff --git a/configure.in b/configure.in
index 9691502..20beb1c 100644
--- a/configure.in
+++ b/configure.in
@@ -275,8 +275,7 @@ AC_FUNC_MALLOC
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(perror gettimeofday memset socket getifaddrs freeifaddrs)
-AC_OUTPUT(Makefile src/Makefile examples/Makefile examples/chat/Makefile python/Makefile \
-python/setup.py ruby/Makefile)
+AC_OUTPUT(Makefile src/Makefile python/Makefile python/setup.py ruby/Makefile)
AC_MSG_RESULT([])
AC_MSG_RESULT([ ******************************************************** ])
diff --git a/examples/Makefile.am b/examples/Makefile.am
deleted file mode 100644
index 5ab090f..0000000
--- a/examples/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-SUBDIRS = chat
-DIST_SUBDIRS = chat
diff --git a/examples/chat/Makefile.am b/examples/chat/Makefile.am
deleted file mode 100644
index 84dad79..0000000
--- a/examples/chat/Makefile.am
+++ /dev/null
@@ -1,15 +0,0 @@
-INCLUDES = -I$(top_builddir) -I$(top_builddir)/include
-
-noinst_PROGRAMS = chatroom display prompt
-
-chatroom_SOURCES = chatroom.cpp
-chatroom_LDADD = $(top_builddir)/src/libzmq.la
-chatroom_CXXFLAGS = -Wall -pedantic -Werror
-
-display_SOURCES = display.cpp
-display_LDADD = $(top_builddir)/src/libzmq.la
-display_CXXFLAGS = -Wall -pedantic -Werror
-
-prompt_SOURCES = prompt.cpp
-prompt_LDADD = $(top_builddir)/src/libzmq.la
-prompt_CXXFLAGS = -Wall -pedantic -Werror
diff --git a/examples/chat/chatroom.cpp b/examples/chat/chatroom.cpp
deleted file mode 100644
index 4cf123a..0000000
--- a/examples/chat/chatroom.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- Copyright (c) 2007-2009 FastMQ Inc.
-
- This file is part of 0MQ.
-
- 0MQ is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- 0MQ is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <time.h>
-#include <string.h>
-#include <iostream>
-
-using namespace std;
-
-#include <zmq.hpp>
-
-int main (int argc, const char *argv [])
-{
- // Check the command line syntax
- if (argc != 3) {
- cerr << "usage: chatroom <in-interface> <out-interface>" << endl;
- return 1;
- }
-
- // Retrieve command line arguments
- const char *in_interface = argv [1];
- const char *out_interface = argv [2];
-
- // Initialise 0MQ infrastructure
- zmq::context_t ctx (1, 1);
-
- // Create two sockets. One for receiving messages from 'propmt'
- // applications, one for sending messages to 'display' applications
- zmq::socket_t in_socket (ctx, ZMQ_SUB);
- in_socket.bind (in_interface);
- zmq::socket_t out_socket (ctx, ZMQ_PUB);
- out_socket.bind (out_interface);
-
- while (true) {
-
- // Get a message
- zmq::message_t in_message;
- in_socket.recv (&in_message);
-
- // Get the current time. Replace the newline character at the end
- // by space character.
- char timebuf [256];
- time_t current_time;
- time (&current_time);
- snprintf (timebuf, 256, "%s", ctime (&current_time));
- timebuf [strlen (timebuf) - 1] = ' ';
-
- // Create and fill in the message
- zmq::message_t out_message (strlen (timebuf) + in_message.size ());
- char *data = (char*) out_message.data ();
- memcpy (data, timebuf, strlen (timebuf));
- data += strlen (timebuf);
- memcpy (data, in_message.data (), in_message.size ());
-
- // Send the message
- out_socket.send (out_message);
- }
-}
diff --git a/examples/chat/display.cpp b/examples/chat/display.cpp
deleted file mode 100644
index eb55aa8..0000000
--- a/examples/chat/display.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- Copyright (c) 2007-2009 FastMQ Inc.
-
- This file is part of 0MQ.
-
- 0MQ is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- 0MQ is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <string.h>
-#include <string>
-#include <iostream>
-
-using namespace std;
-
-#include <zmq.hpp>
-
-int main (int argc, const char *argv [])
-{
- // Check the command line syntax.
- if (argc != 2) {
- cerr << "usage: display <chatroom-out-address>" << endl;
- return 1;
- }
-
- // Retrieve command line arguments
- const char *chatroom_out_address = argv [1];
-
- // Initialise 0MQ infrastructure, connect to the chatroom and ask for all
- // messages and gap notifications.
- zmq::context_t ctx (1, 1);
- zmq::socket_t s (ctx, ZMQ_SUB);
- s.connect (chatroom_out_address);
-
- while (true) {
-
- // Get a message and print it to the console.
- zmq::message_t message;
- s.recv (&message);
- if (message.type () == zmq::message_gap)
- cout << "Problems connecting to the chatroom..." << endl;
- else
- cout << (char*) message.data () << flush;
- }
-}
diff --git a/examples/chat/prompt.cpp b/examples/chat/prompt.cpp
deleted file mode 100644
index 66ceaf4..0000000
--- a/examples/chat/prompt.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- Copyright (c) 2007-2009 FastMQ Inc.
-
- This file is part of 0MQ.
-
- 0MQ is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- 0MQ is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <string.h>
-#include <string>
-#include <iostream>
-
-using namespace std;
-
-#include <zmq.hpp>
-
-int main (int argc, const char *argv [])
-{
- // Check the command line syntax.
- if (argc != 3) {
- cerr << "usage: prompt <chatroom-in-address> <user name>" << endl;
- return 1;
- }
-
- // Retrieve command line arguments
- const char *chatroom_in_address = argv [1];
- const char *user_name = argv [2];
-
- // Initialise 0MQ infrastructure and connect to the chatroom.
- zmq::context_t ctx (1, 1);
- zmq::socket_t s (ctx, ZMQ_PUB);
- s.connect (chatroom_in_address);
-
- while (true) {
-
- // Allow user to input the message text. Prepend it by user name.
- char textbuf [1024];
- char *rcc = fgets (textbuf, sizeof (textbuf), stdin);
- assert (rcc);
- string text (user_name);
- text = text + ": " + textbuf;
-
- // Create the message (terminating zero is part of the message)
- zmq::message_t message (text.size () + 1);
- memcpy (message.data (), text.c_str (), text.size () + 1);
-
- // Send the message
- s.send (message);
- }
-}
diff --git a/src/Makefile.am b/src/Makefile.am
index b6a4540..1dac30d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,7 @@ libzmq_la_SOURCES = \
io_thread.hpp \
ip.hpp \
i_endpoint.hpp \
+ i_engine.hpp \
i_poller.hpp \
i_poll_events.hpp \
i_signaler.hpp \
diff --git a/src/command.hpp b/src/command.hpp
index d16d4fa..9a2e5d5 100644
--- a/src/command.hpp
+++ b/src/command.hpp
@@ -65,7 +65,7 @@ namespace zmq
// Attach the engine to the session.
struct {
- class zmq_engine_t *engine;
+ struct i_engine *engine;
} attach;
// Sent from session to socket to establish pipe(s) between them.
diff --git a/src/i_engine.hpp b/src/i_engine.hpp
new file mode 100644
index 0000000..c21556f
--- /dev/null
+++ b/src/i_engine.hpp
@@ -0,0 +1,43 @@
+/*
+ Copyright (c) 2007-2009 FastMQ Inc.
+
+ This file is part of 0MQ.
+
+ 0MQ is free software; you can redistribute it and/or modify it under
+ the terms of the Lesser GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ 0MQ is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ Lesser GNU General Public License for more details.
+
+ You should have received a copy of the Lesser GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __ZMQ_I_ENGINE_HPP_INCLUDED__
+#define __ZMQ_I_ENGINE_HPP_INCLUDED__
+
+namespace zmq
+{
+
+ struct i_engine
+ {
+ virtual ~i_engine () {}
+
+ // Plug the engine to the session.
+ virtual void plug (struct i_inout *inout_) = 0;
+
+ // Unplug the engine from the session.
+ virtual void unplug () = 0;
+
+ // This method is called by the session to signalise that there
+ // are messages to send available.
+ virtual void revive () = 0;
+ };
+
+}
+
+#endif
diff --git a/src/object.cpp b/src/object.cpp
index b3cf898..c0ef21c 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -26,7 +26,6 @@
#include "owned.hpp"
#include "session.hpp"
#include "socket_base.hpp"
-#include "zmq_engine.hpp" // TODO: remove this line
zmq::object_t::object_t (dispatcher_t *dispatcher_, int thread_slot_) :
dispatcher (dispatcher_),
@@ -153,7 +152,7 @@ void zmq::object_t::send_own (socket_base_t *destination_, owned_t *object_)
send_command (cmd);
}
-void zmq::object_t::send_attach (session_t *destination_, zmq_engine_t *engine_)
+void zmq::object_t::send_attach (session_t *destination_, i_engine *engine_)
{
// The assumption here is that command sequence number of the destination
// object was already incremented in find_session function.
@@ -241,7 +240,7 @@ void zmq::object_t::process_own (owned_t *object_)
zmq_assert (false);
}
-void zmq::object_t::process_attach (zmq_engine_t *engine_)
+void zmq::object_t::process_attach (i_engine *engine_)
{
zmq_assert (false);
}
diff --git a/src/object.hpp b/src/object.hpp
index 8ce569e..250e856 100644
--- a/src/object.hpp
+++ b/src/object.hpp
@@ -60,7 +60,7 @@ namespace zmq
void send_own (class socket_base_t *destination_,
class owned_t *object_);
void send_attach (class session_t *destination_,
- class zmq_engine_t *engine_);
+ struct i_engine *engine_);
void send_bind (object_t *destination_, class owned_t *session_,
class reader_t *in_pipe_, class writer_t *out_pipe_);
void send_revive (class object_t *destination_);
@@ -76,7 +76,7 @@ namespace zmq
virtual void process_stop ();
virtual void process_plug ();
virtual void process_own (class owned_t *object_);
- virtual void process_attach (class zmq_engine_t *engine_);
+ virtual void process_attach (struct i_engine *engine_);
virtual void process_bind (class owned_t *session_,
class reader_t *in_pipe_, class writer_t *out_pipe_);
virtual void process_revive ();
diff --git a/src/owned.cpp b/src/owned.cpp
index 810bed7..a534dd3 100644
--- a/src/owned.cpp
+++ b/src/owned.cpp
@@ -47,7 +47,7 @@ void zmq::owned_t::process_plug ()
finalise_command ();
}
-void zmq::owned_t::process_attach (zmq_engine_t *engine_)
+void zmq::owned_t::process_attach (struct i_engine *engine_)
{
// Keep track of how many commands were processed so far.
processed_seqnum++;
diff --git a/src/owned.hpp b/src/owned.hpp
index 78036a3..c56ea49 100644
--- a/src/owned.hpp
+++ b/src/owned.hpp
@@ -61,7 +61,7 @@ namespace zmq
// It's vital that session invokes io_object_t::process_attach
// at the end of it's own attach handler.
- void process_attach (class zmq_engine_t *engine_);
+ void process_attach (struct i_engine *engine_);
// io_object_t defines a new handler used to disconnect the object
// from the poller object. Implement the handlen in the derived
diff --git a/src/session.cpp b/src/session.cpp
index d667851..f562bd5 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -18,7 +18,7 @@
*/
#include "session.hpp"
-#include "zmq_engine.hpp"
+#include "i_engine.hpp"
#include "err.hpp"
#include "pipe.hpp"
@@ -149,7 +149,7 @@ void zmq::session_t::process_unplug ()
}
}
-void zmq::session_t::process_attach (class zmq_engine_t *engine_)
+void zmq::session_t::process_attach (i_engine *engine_)
{
zmq_assert (engine_);
engine = engine_;
diff --git a/src/session.hpp b/src/session.hpp
index ba5bcdd..46699cf 100644
--- a/src/session.hpp
+++ b/src/session.hpp
@@ -58,7 +58,7 @@ namespace zmq
// Handlers for incoming commands.
void process_plug ();
void process_unplug ();
- void process_attach (class zmq_engine_t *engine_);
+ void process_attach (struct i_engine *engine_);
// Inbound pipe, i.e. one the session is getting messages from.
class reader_t *in_pipe;
@@ -69,7 +69,7 @@ namespace zmq
// Outbound pipe, i.e. one the socket is sending messages to.
class writer_t *out_pipe;
- class zmq_engine_t *engine;
+ struct i_engine *engine;
// The name of the session. One that is used to register it with
// socket-level repository of sessions.
diff --git a/src/zmq_engine.hpp b/src/zmq_engine.hpp
index ba25ded..8299ebf 100644
--- a/src/zmq_engine.hpp
+++ b/src/zmq_engine.hpp
@@ -20,6 +20,7 @@
#ifndef __ZMQ_ZMQ_ENGINE_HPP_INCLUDED__
#define __ZMQ_ZMQ_ENGINE_HPP_INCLUDED__
+#include "i_engine.hpp"
#include "io_object.hpp"
#include "tcp_socket.hpp"
#include "zmq_encoder.hpp"
@@ -28,24 +29,22 @@
namespace zmq
{
- class zmq_engine_t : public io_object_t
+ class zmq_engine_t : public io_object_t, public i_engine
{
public:
zmq_engine_t (class io_thread_t *parent_, fd_t fd_);
~zmq_engine_t ();
+ // i_engine interface implementation.
void plug (struct i_inout *inout_);
void unplug ();
+ void revive ();
// i_poll_events interface implementation.
void in_event ();
void out_event ();
- // This method is called by the session to signalise that there
- // are messages to send available.
- void revive ();
-
private:
// Function to handle network disconnections.