summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TAO/ChangeLog-98c11
-rw-r--r--TAO/orbsvcs/bin/Logger/Makefile9
-rw-r--r--TAO/orbsvcs/bin/Logger/clnt.cpp163
-rw-r--r--TAO/orbsvcs/bin/Logger/clnt.h1
-rw-r--r--TAO/orbsvcs/bin/Logger/ior_multicast.cpp83
-rw-r--r--TAO/orbsvcs/bin/Logger/ior_multicast.h61
-rw-r--r--TAO/orbsvcs/bin/Logger/svr.cpp44
-rw-r--r--TAO/tao/orbconf.h23
-rw-r--r--TAO/tao/orbobj.cpp50
9 files changed, 336 insertions, 109 deletions
diff --git a/TAO/ChangeLog-98c b/TAO/ChangeLog-98c
index 528317a3b92..49830080d6a 100644
--- a/TAO/ChangeLog-98c
+++ b/TAO/ChangeLog-98c
@@ -1,3 +1,14 @@
+Tue Nov 11 00:36:39 1997 Sergio Flores <sergio@macarena.cs.wustl.edu>
+
+ * tao/orbobj.cpp (resolve_name_service): changed macro for default
+ multicast port.
+ - Added support for multicast mechanism to resolve the name
+ service.
+
+ * tao/orbconf.h: Added some definitions for TAO's default
+ multicast and reply port, and the default timeout value.
+
+
Tue Nov 11 00:06:57 1997 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
* tao/orbconf.h: Started putting a more sane way of automatically
diff --git a/TAO/orbsvcs/bin/Logger/Makefile b/TAO/orbsvcs/bin/Logger/Makefile
index 4aae3bbcc53..bc2c3765f38 100644
--- a/TAO/orbsvcs/bin/Logger/Makefile
+++ b/TAO/orbsvcs/bin/Logger/Makefile
@@ -11,12 +11,12 @@
LDLIBS = -lTAO
-IDL_SRC = loggerC.cpp loggerS.cpp
-PROG_SRCS = $(IDL_SRC) logger_i.cpp
+IDL_SRC = loggerC.cpp loggerS.cpp CosNamingC.cpp
+PROG_SRCS = $(IDL_SRC) logger_i.cpp ior_multicast.cpp
LSRC = $(PROG_SRCS)
-logger_SVR_OBJS = loggerC.o loggerS.o svr.o logger_i.o
+logger_SVR_OBJS = loggerC.o loggerS.o svr.o logger_i.o CosNamingC.o ior_multicast.o
logger_CLT_OBJS = loggerC.o clnt.o
BIN = svr clnt
@@ -42,8 +42,9 @@ DCFLAGS = -g
LDFLAGS += -L$(TAO_ROOT)/tao
CPPFLAGS += -I$(TAO_ROOT) -I$(TAO_ROOT)/tao/compat $(TSS_ORB_FLAG)#-H
-$(IDL_SRC): logger.idl
+$(IDL_SRC): logger.idl CosNaming.idl
$(TAO_ROOT)/TAO_IDL/tao_idl logger.idl
+ $(TAO_ROOT)/TAO_IDL/tao_idl CosNaming.idl
svr: $(addprefix $(VDIR),$(logger_SVR_OBJS))
$(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS)
diff --git a/TAO/orbsvcs/bin/Logger/clnt.cpp b/TAO/orbsvcs/bin/Logger/clnt.cpp
index faa05f2b18d..415cadc73a4 100644
--- a/TAO/orbsvcs/bin/Logger/clnt.cpp
+++ b/TAO/orbsvcs/bin/Logger/clnt.cpp
@@ -20,8 +20,11 @@
// ============================================================================
#include <iostream.h>
+#include "ace/INET_Addr.h"
+#include "ace/SOCK_Dgram_Mcast.h"
#include "loggerC.h"
#include "clnt.h"
+#include "ior_multicast.h"
// constructor
@@ -88,7 +91,8 @@ Logger_Client::run (void)
if (this->exit_later_)
{
- // this->logger_1_->please_exit (this->env_);
+ //Not supported yet.
+ //this->logger_1_->please_exit (this->env_);
//this->logger_2_->please_exit (this->env_);
dexc (this->env_, "server, please ACE_OS::exit");
}
@@ -119,7 +123,7 @@ Logger_Client::init (int argc, char **argv)
// retrieve the ORB
this->orb_ptr_ = CORBA::ORB_init (this->argc_,
this->argv_,
- "logger",
+ "internet",
this->env_);
if (this->env_.exception () != 0)
@@ -128,6 +132,9 @@ Logger_Client::init (int argc, char **argv)
return 1;
}
+#if !defined (ACE_HAS_IP_MULTICAST)
+ ACE_DEBUG ((LM_ERROR, "IP multicast not supported.\n"));
+
// Retrieve a factory objref.
this->objref_ = Logger_Factory::_bind (this->hostname_,
this->portnum_,
@@ -159,7 +166,66 @@ Logger_Client::init (int argc, char **argv)
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to narrow object reference to a Logger_Factory_ptr.\n"),
1);
+#else
+ char buf[BUFSIZ];
+
+ ACE_SOCK_Dgram_Mcast logger;
+ ACE_INET_Addr server, remote_addr;
+
+ // This starts out initialized to all zeros!
+ server = ACE_INET_Addr(DEFAULT_LOGGER_SERVER_REQUEST_PORT,
+ DEFAULT_LOGGER_SERVER_MULTICAST_ADDR);
+
+ if (logger.subscribe (server) == -1)
+ perror("can't subscribe to multicast group");
+
+ ACE_INET_Addr response_addr (DEFAULT_LOGGER_SERVER_REPLY_PORT);
+ ACE_SOCK_Dgram response (response_addr);
+
+ ssize_t retcode = logger.send (buf, 1);
+ if (retcode == -1)
+ return -1;
+
+ ACE_DEBUG ((LM_ERROR, "@@ Sent multicast @@\n"));
+
+ ACE_Time_Value timeout (DEFAULT_LOGGER_SERVER_TIMEOUT);
+
+ if ((retcode = response.recv (buf,
+ BUFSIZ,
+ remote_addr,
+ 0,
+ &timeout)) == -1)
+ ACE_ERROR ((LM_ERROR, "%p\n", "ACE_SOCK_Dgram::recv"));
+
+ buf[retcode] = 0; // null terminate message
+
+ ACE_DEBUG ((LM_ERROR, "server returned '%s'\n", buf));
+
+ this->objref_ = this->orb_ptr_->string_to_object ((CORBA::String) buf,
+ this->env_);
+
+ if (this->env_.exception () != 0)
+ {
+ this->env_.print_exception ("string2object");
+ return 1;
+ }
+
+ if (CORBA::is_nil (this->objref_) == CORBA::B_TRUE)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s: must identify non-null target objref\n",
+ this->argv_ [0]),
+ -1);
+
+ // Narrow the CORBA::Object reference to the stub object, checking
+ // the type along the way using _is_a.
+ this->factory_ = Logger_Factory::_narrow (this->objref_);
+
+ if (this->factory_ == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Unable to narrow object reference to a Logger_ptr.\n"),
+ -1);
+#endif
// Now retrieve the Logger obj ref corresponding to key1 and key2
this->logger_1_ = this->factory_->make_logger ("key1", this->env_);
this->logger_2_ = this->factory_->make_logger ("key2", this->env_);
@@ -199,96 +265,3 @@ main (int argc, char **argv)
cout << "....the end" << endl;
return rc;
}
-
-
-
-
-#if 0
-
-
-
-
-
-
-
-
-
-
-
-
-
-int
-main (int argc, char ** argv)
-{
- CORBA::Environment env;
- // Environment variable
-
- CORBA::Object_ptr objref;
- // storage of the factory objref
-
- Logger_Factory_ptr factory;
- // factory pointer for logger
-
- const char *logger_factory_key = "factory";
- // Key of factory obj ref.
-
- char * hostname = "macarena";
-
- CORBA::ULong portnum = 10026;
-
- // retrieve the ORB
- CORBA::ORB_init (argc,
- argv,
- "logger",
- env);
-
- if (env.exception () != 0)
- {
- env.print_exception ("ORB initialization");
- return 1;
- }
-
- // Retrieve a factory objref.
- objref = Logger_Factory::_bind (hostname,
- portnum,
- logger_factory_key,
- env);
-
- if (env.exception () != 0)
- {
- env.print_exception ("Logger_Factory::_bind");
- return 1;
- }
-
- if (CORBA::is_nil (objref) == CORBA::B_TRUE)
- ACE_ERROR_RETURN ((LM_ERROR,
- " _bind returned null object for key (%s), host (%s), port (%d)\n",
- logger_factory_key,
- hostname,
- portnum),
- 1);
-
- // Narrow the CORBA::Object reference to the stub object, checking
- // the type along the way using _is_a. There is really no need to
- // narrow <objref> because <_bind> will return us the
- // <LoggerFactory> pointer. However, we do it so that we can
- // explicitly test the _narrow function.
- factory = Logger_Factory::_narrow (objref);
-
- if (factory == 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- " (%P|%t) Unable to narrow object reference to a Logger_Factory_ptr.\n"),
- 1);
-
- // Create several logger objects (name specifies the level in the tree
- // where the logger will be bound)
- Logger_var l1 = factory->make_logger ("key1", env);
- Logger_var l2 = factory->make_logger ("key2", env);
-
- l1->log ("Logging at logger 1", env);
- l2->log ("Logging at logger 2", env);
-
- cout << "....the end" << endl;
- return 0;
-}
-#endif
diff --git a/TAO/orbsvcs/bin/Logger/clnt.h b/TAO/orbsvcs/bin/Logger/clnt.h
index e5a0263ed3d..0f7e9111f2b 100644
--- a/TAO/orbsvcs/bin/Logger/clnt.h
+++ b/TAO/orbsvcs/bin/Logger/clnt.h
@@ -1,3 +1,4 @@
+/* -*- C++ -*- */
// $Id$
// ============================================================================
diff --git a/TAO/orbsvcs/bin/Logger/ior_multicast.cpp b/TAO/orbsvcs/bin/Logger/ior_multicast.cpp
new file mode 100644
index 00000000000..e931c5f74a3
--- /dev/null
+++ b/TAO/orbsvcs/bin/Logger/ior_multicast.cpp
@@ -0,0 +1,83 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/bin/Logger
+//
+// = FILENAME
+// ior_multicast.cpp
+//
+// = DESCRIPTION
+// Listens to multicast address for client requests for ior's.
+//
+// = AUTHORS
+// Sergio Flores-Gaitan
+//
+// ============================================================================
+
+#include "ior_multicast.h"
+
+ACE_HANDLE
+IOR_Multicast::get_handle (void) const
+{
+ return this->mcast_dgram_.get_handle ();
+}
+
+IOR_Multicast::IOR_Multicast (char * ior,
+ u_short port,
+ const char *mcast_addr,
+ u_short response_port)
+ : ior_ (ior),
+ mcast_addr_ (port, mcast_addr),
+ SERVICE_RESPONSE_UDP_PORT_ (response_port),
+ response_ (response_addr_)
+{
+ // Use ACE_SOCK_Dgram_Mcast factory to subscribe to multicast group.
+ if (this->mcast_dgram_.subscribe (this->mcast_addr_) == -1)
+ ACE_ERROR ((LM_ERROR, "%p\n", "subscribe"));
+}
+
+// destructor
+
+IOR_Multicast::~IOR_Multicast (void)
+{
+ this->mcast_dgram_.unsubscribe ();
+}
+
+int
+IOR_Multicast::handle_timeout (const ACE_Time_Value &,
+ const void *arg)
+{
+ return 0;
+}
+
+int
+IOR_Multicast::handle_input (ACE_HANDLE)
+{
+ ssize_t retcode =
+ this->mcast_dgram_.recv (this->buf_,
+ BUFSIZ,
+ this->remote_addr_);
+
+ if (retcode == -1)
+ return -1;
+
+ ACE_DEBUG ((LM_ERROR, "@@ Received multicast @@\n"));
+
+ // @@ validate data string received is from a valid client here
+ // @@ Probably not needed
+
+ this->remote_addr_.set_port_number (this->SERVICE_RESPONSE_UDP_PORT_);
+ retcode = response_.send (this->ior_,
+ ACE_OS::strlen (this->ior_) + 1,
+ this->remote_addr_,
+ 0);
+
+ ACE_DEBUG ((LM_ERROR, "ior_ '%s' sent.\nretcode=%d\n", this->ior_, retcode));
+
+ if (retcode == -1)
+ return -1;
+
+ return 0;
+}
diff --git a/TAO/orbsvcs/bin/Logger/ior_multicast.h b/TAO/orbsvcs/bin/Logger/ior_multicast.h
new file mode 100644
index 00000000000..3214da36517
--- /dev/null
+++ b/TAO/orbsvcs/bin/Logger/ior_multicast.h
@@ -0,0 +1,61 @@
+/* -*- C++ -*- */
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/bin/Logger
+//
+// = FILENAME
+// ior_multicast.h
+//
+// = DESCRIPTION
+// Listens to multicast address for client requests for ior's.
+//
+// = AUTHORS
+// Sergio Flores-Gaitan
+//
+// ============================================================================
+
+#if !defined (IOR_MULTICAST_H)
+#define IOR_MULTICAST_H
+
+#include "ace/INET_Addr.h"
+#include "ace/SOCK_Dgram_Mcast.h"
+#include "ace/Reactor.h"
+
+// defines
+#define DEFAULT_LOGGER_SERVER_REQUEST_PORT 10030
+#define DEFAULT_LOGGER_SERVER_REPLY_PORT 10031
+#define DEFAULT_LOGGER_SERVER_MULTICAST_ADDR ACE_DEFAULT_MULTICAST_ADDR
+#define DEFAULT_LOGGER_SERVER_TIMEOUT 5
+
+class IOR_Multicast : public ACE_Event_Handler
+{
+public:
+ IOR_Multicast (char * ior,
+ u_short port,
+ const char *mcast_addr,
+ u_short response_port);
+ ~IOR_Multicast (void);
+
+ virtual int handle_input (ACE_HANDLE fd);
+ virtual int handle_timeout (const ACE_Time_Value &tv,
+ const void *arg);
+
+ virtual ACE_HANDLE get_handle (void) const;
+
+private:
+ char buf_[BUFSIZ];
+
+ ACE_SOCK_Dgram_Mcast mcast_dgram_;
+ ACE_INET_Addr remote_addr_;
+ ACE_INET_Addr mcast_addr_;
+ char * ior_;
+ const u_short SERVICE_RESPONSE_UDP_PORT_;
+ ACE_INET_Addr response_addr_;
+ ACE_SOCK_Dgram response_;
+
+};
+
+#endif /* IOR_MULTICAST_H */
diff --git a/TAO/orbsvcs/bin/Logger/svr.cpp b/TAO/orbsvcs/bin/Logger/svr.cpp
index 87bbea6eb88..cb25d8a3971 100644
--- a/TAO/orbsvcs/bin/Logger/svr.cpp
+++ b/TAO/orbsvcs/bin/Logger/svr.cpp
@@ -1,9 +1,27 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/bin/Logger
+//
+// = FILENAME
+// svr.cpp
+//
+// = DESCRIPTION
+// This program is an implementation of a simple logger service.
+// Whatever is sent to it through its interface is displayed on stdout.
+// It uses the Logger_Factory server to create a number of logger objects.
+//
+// = AUTHORS
+// Sergio Flores-Gaitan <sergio@cs.wustl.edu>
+//
+// ============================================================================
+
#include <iostream.h>
#include "loggerC.h"
#include "logger_i.h"
-
-// This is a a startup for a Logger_Factory server.
-// This is used for testing of the Naming Service.
+#include "ior_multicast.h"
int
main (int argc, char ** argv)
@@ -49,7 +67,26 @@ main (int argc, char ** argv)
ACE_OS::puts ((char *) str);
ACE_OS::fflush (stdout);
dmsg1 ("listening as object '%s'", str);
+
+ // Use IP multicast to advertise the service
+#if defined (ACE_HAS_IP_MULTICAST)
+ // get reactor instance from TAO
+ ACE_Reactor *reactor = TAO_ORB_Core_instance()->reactor();
+ // Instantiate a server which will receive requests for an ior
+ IOR_Multicast ior_multicast (str,
+ DEFAULT_LOGGER_SERVER_REQUEST_PORT,
+ DEFAULT_LOGGER_SERVER_MULTICAST_ADDR,
+ DEFAULT_LOGGER_SERVER_REPLY_PORT);
+
+ // register event handler for the ior multicast.
+ if (reactor->register_handler (&ior_multicast,
+ ACE_Event_Handler::READ_MASK) == -1)
+ ACE_ERROR ((LM_ERROR, "%p\n%a", "register_handler", 1));
+
+ ACE_DEBUG ((LM_DEBUG, "The multicast server setup is done.\n"));
+#endif /* ACE_HAS_IP_MULTICAST */
+
// Handle requests for this object until we're killed, or one of the
// methods asks us to exit.
if (orb_ptr->run () == -1)
@@ -58,3 +95,4 @@ main (int argc, char ** argv)
cout << "Server logger_factory is terminating" << endl;
return 0;
}
+
diff --git a/TAO/tao/orbconf.h b/TAO/tao/orbconf.h
index 739b4aa8be1..bdc45baae2d 100644
--- a/TAO/tao/orbconf.h
+++ b/TAO/tao/orbconf.h
@@ -30,14 +30,27 @@
#define TAO_DEFAULT_SERVER_OBJECT_TABLE_SIZE 64
#endif /* TAO_DEFAULT_SERVER_OBJECT_TABLE_SIZE */
-// The default multicast port number for TAO Naming Service.
-#if !defined (TAO_DEFAULT_NAME_SERVER_PORT)
-#define TAO_DEFAULT_NAME_SERVER_PORT 10013
-#endif /* TAO_DEFAULT_SERVER_PORT */
+// The default UDP multicast port number for locating the TAO Naming
+// Service.
+#if !defined (TAO_DEFAULT_NAME_SERVER_REQUEST_PORT)
+#define TAO_DEFAULT_NAME_SERVER_REQUEST_PORT 10013
+#endif /* TAO_DEFAULT_NAME_SERVER_REQUEST_PORT */
+
+// The default UDP port number for replying to a location request to
+// the TAO Naming Service.
+#if !defined (TAO_DEFAULT_NAME_SERVER_REPLY_PORT)
+#define TAO_DEFAULT_NAME_SERVER_REPLY_PORT 10014
+#endif /* TAO_DEFAULT_NAME_SERVER_REPLY_PORT */
+
+// The default timeout receiving the location request to
+// the TAO Naming Service.
+#if !defined (TAO_DEFAULT_NAME_SERVER_TIMEOUT)
+#define TAO_DEFAULT_NAME_SERVER_TIMEOUT 5
+#endif /* TAO_DEFAULT_NAME_SERVER_TIMEOUT */
// The default starting port number for TAO servers.
#if !defined (TAO_DEFAULT_SERVER_PORT)
-#define TAO_DEFAULT_SERVER_PORT 10014
+#define TAO_DEFAULT_SERVER_PORT 10015
#endif /* TAO_DEFAULT_SERVER_PORT */
// This controls the alignment for TAO structs.
diff --git a/TAO/tao/orbobj.cpp b/TAO/tao/orbobj.cpp
index 749b9778108..62cbbcd8440 100644
--- a/TAO/tao/orbobj.cpp
+++ b/TAO/tao/orbobj.cpp
@@ -12,6 +12,7 @@
#include "tao/corba.h"
#include "ace/Dynamic_Service.h"
#include "ace/Service_Repository.h"
+#include "ace/SOCK_Dgram_Mcast.h"
#include "tao/tao_internals.h"
extern void __TC_init_table (void);
@@ -386,6 +387,7 @@ CORBA_ORB::resolve_name_service (void)
// First, see if the user has given us a multicast port number
// for the name service on the command-line;
u_short port = TAO_ORB_Core_instance ()->orb_params ()->name_service_port ();
+ char buf[BUFSIZ];
if (port == 0)
{
@@ -396,10 +398,54 @@ CORBA_ORB::resolve_name_service (void)
}
if (port == 0)
- port = TAO_DEFAULT_NAME_SERVER_PORT;
+ port = TAO_DEFAULT_NAME_SERVER_REQUEST_PORT;
- // This is where the code must go to implement the multicast
+ // This is the code that implements the multicast
// Naming Service locator.
+ ACE_SOCK_Dgram_Mcast multicast;
+ ACE_INET_Addr multicast_addr, remote_addr;
+
+ // This starts out initialized to all zeros!
+ multicast_addr = ACE_INET_Addr(TAO_DEFAULT_NAME_SERVER_REQUEST_PORT,
+ ACE_DEFAULT_MULTICAST_ADDR);
+
+ // subscribe to multicast address
+ if (multicast.subscribe (multicast_addr) == -1)
+ return CORBA_Object::_nil ();
+
+ // prepare connection for the reply
+ ACE_INET_Addr response_addr (TAO_DEFAULT_NAME_SERVER_REPLY_PORT);
+ ACE_SOCK_Dgram response (response_addr);
+
+ // send multicast of one byte, enough to wake up server
+ ssize_t retcode = multicast.send (buf, 1);
+ if (retcode == -1)
+ return CORBA_Object::_nil ();
+
+ // wait for response until TAO_DEFAULT_NAME_SERVER_TIMEOUT
+ ACE_Time_Value timeout (TAO_DEFAULT_NAME_SERVER_TIMEOUT);
+ if ((retcode = response.recv (buf,
+ BUFSIZ,
+ remote_addr,
+ 0,
+ &timeout )) == -1)
+ return CORBA_Object::_nil ();
+
+ // null terminate message
+ buf[retcode] = 0;
+
+ // convert ior to an object reference
+ CORBA::Environment env;
+ this->name_service_ =
+ this->string_to_object ((CORBA::String) buf, env);
+
+ // check for errors
+ if (env.exception () != 0)
+ this->name_service_ = CORBA_Object::_nil ();
+
+ // return ior.
+ return this->name_service_;
+
ACE_NOTSUP_RETURN (CORBA_Object::_nil ());
}
}