// IDL schema definition for Stock Quoter service.
module Stock
{
exception Invalid_Stock {};
exception Invalid_Quoter {};
/**
* @class Quoter
*
* @brief Access Stock information.
*/
interface Quoter {
/// Returns the current stock value or throws an exception.
long get_quote (in string stock_name)
raises (Invalid_Stock);
};
/**
* @class Quoter
*
* @brief Factory that creates Quoter objects.
*/
interface Quoter_Factory {
/// Returns an object reference to a new Quoter selected
/// by name e.g., "Dow Jones," "Reuters," etc.
Quoter create_quoter (in string name)
raises (Invalid_Quoter);
};
};
You will use the TAO CORBA IDL compiler to translate this
specification into client-side stubs and server-side
skeletons. The client application (which you must write)
will use the stubs as a proxy to access the Stock Quoter
service implemented by the server. In addition, you must also write
the server, which implements the
Quoter_Factory::create_quoter() and
Quoter::get_quote() operations that provide the Stock
Quoter service.
// Servant that implements the Quoter interface.
class Quoter_i : public virtual POA_Stock::Quoter,
public virtual PortableServer::RefCountServantBase
{
public:
// ...
CORBA::Long get_quote (const char *stock_name);
};
class Quoter_Factory_i : public virtual POA_Stock::Quoter_Factory,
public virtual PortableServer::RefCountServantBase
{
public:
// ...
Quoter::Quoter_ptr create_quoter (const char *name);
};
To implement the Quoter_Factory_i::create_quoter() method
you'll need to use explicit activiation with user-defined IDs, i.e.,
POA::activiate_object_with_id(). You'll need to use an
STL std::map that maps names of the stock quoters (i.e.,
"Dow Jones" and "Reuters") to object references to Quoter
instances. To implement the Quoter_i::get_quote() method
you'll need to use an STL std::map that maps stock names
(i.e., "BEAS," "IBM," and "MSFT") to stock quotes.
In addition, you'll need to implement a main() function
that dynamically creates an instance of Quoter_Factory_i,
obtains and activates the RootPOA, and then calls
CORBA::ORB::run() method to run the server's event loop.
To make your life easy, the server should write its IOR to a file
before it calls the ORB's run() method (later, we'll use
more advanced techniques, such as a Naming Service). Thus, when your
server is started, you should create a file that contains something
like the following
if you use the
IOR:000000000000001649444c3a43756269745...
-ORBObjRefStyle IOR IOR format or
if you use the
iioploc://1.1@tango.dre.vanderbilt.edu:10015/P35ad159600081a38/\0\1server
-ORBObjRefStyle URL IOR format. For more
information on these options, please see the TAO online
options documentation.
CORBA::string_to_object() method to convert the string
into an object reference. This object reference will then be downcast
via _narrow() to an object reference for the
Quoter::Quoter_Factory interface. At this point, the
client should call the
Quoter::Quoter_Factory::create_quoter() factory method
via the object reference to obtain an object reference to the
appropriate Quoter::Quoter_ptr from the server. After
the client application has bound to an object reference for the
Quoter::Quoter interface, it can call the
get_quote() method via the object reference.
For the purposes of the assignment, you can make the client-side
driver program very simple. The client can read a command from its
standard input and send it to the server. For example, you could type
the following commands to the client:
% ./client tango.dre.vanderbilt.edu
> create "Dow Jones"
> get "MSFT"
Current value of MSFT is $100
If anything fails to work properly the client should simply print out
the appropriate exception and exit with a return status of 1. If
everything works correctly, the program should exit with a return
status of 0.
Back to CS 396 home page.