## IDL Definitions for the Stock Quoter Publisher/Subscriber Real-time CORBA Service

Note: All the IDL definitions are included in the Stock module:

    // IDL schema definition for the Stock Quoter Publisher/Subscriber Real-time CORBA Service.
    module Stock
    {
      ...
    };

### Common

This IDL file (Common.idl) contains all the exception(s), struct(s), value type(s) and common interface(s) used by the Stock Quoter Publisher/Subscriber Real-time CORBA Service. The generated lib of this idl file will be linked by all the other projects in the system.

- #### Defining the IDL exception

    exception Invalid_Stock {};

This exception is used when the needed stock does not exist in the stock database.

- #### Defining the IDL struct

    struct StockInfo
    {
      string name;
      long high;
      long low;
      long last;
    };

This struct contains the information about a stock. The items in this struct denote the name, highest value, lowest value and last value of the stock respectively.

- #### Defining the IDL value types

Unlike CORBA Objects (which are passed by reference), instances of CORBA valuetype are always passed by value. Like CORBA structs, they can contain state in the form of fields. Unlike structs, however, they can have user-defined operations and support inheritance.

    valuetype StockName
    {
      public string name;
    };

This value type is used in the communication between stock distributor server and stock broker client to handle the callback from distributor server whenever the value of a stock the stock broker client interested in changes.

    valuetype Cookie
    {
      public string cookie_id;
    };

This value type is used to record the subscription relationship between stock distributor server and stock broker client. It can also be used to unsubscribe the stock broker clien from the stock distributor server.

- #### Defining the common IDL interfaces

    interface Trigger
    {
      void start ();
      void stop ();
    }

This interface is inherited by the stock distributor interface because it need to be run as a daemon that can be started and stopped by a system administrator.

    interface StockNameConsumer
    {
      void push_StockName (in StockName the_stockname);

      attribute Cookie cookie;
    };

This interface is used as a callback interface used by the distributor to notify brokers of updates.

    interface StockQuoter
    {
      StockInfo get_stock_info (in string stock_name) raises Invalid_Stock;
    };

This interface is used by brokers to get detailed stock information.

### Distributor

This IDL file (Distributor.idl) contains IDL definitions for the Stock Distributor in the Publish/Subscribe Real-time CORBA Stock Quoter Service.

- #### Defining the IDL exception

    exception Invalid_Subscription {};

This exception is used when the needed cookie does not exist in the stock subscribers list.

- #### Defining the IDL interfaces

    interface StockDistributor : Trigger
    {
      /// Event source operation to establish connectivity.
      Cookie subscribe_notifier (in Stock::StockNameConsumer c, in RTCORBA::Priority priority);

      /// Event source operation to discontinue connectivity.
      Stock::StockNameConsumer unsubscribe_notifier (in Cookie ck)
        raises (Invalid_Subscription);;

      /// Factory operation to return StockQuoter object reference.
      StockQuoter provide_quoter_info ()
        raises (Invalid_Subscription);;

      /// Shutdown the object and terminate the application.
      oneway void shutdown ();

      /// Controls rate of updates.
      attribute long notification_rate;
    };

This is the interface definition for Stock Distributor servers.

The subscribe_notifier() and unsubscribe_notifier() operations are to subscribe/unsubscribe Stock Broker clients with the Stock Distributor servers.

The provide_quoter_info() factory operation returns StockQuoter object references that Stock Broker clients can use to get more information about a particular stock.

The shutdown() operation is a oneway operation which shuts down the object and terminates the application.

The notification_rate attribute stands for the notification frequency that the Stock Distributor servers used to communicate with the Stock Broker clients.

    interface StockDistributorHome
    {
      StockDistributor create ();
    };

This is the interface definition for Stock Distributor Home. This factory reduces the bookkeeping that CORBA applications must do to create and manage their objects.

### Broker

This IDL file (Broker.idl) contains IDL definitions for the Stock Broker in the Publish/Subscribe Real-time CORBA Stock Quoter Service.

- #### Defining the IDL interfaces

    interface StockBroker
    {
      /// Factory operation to return StockNameConsumer object reference.
      StockNameConsumer get_consumer_notifier ();

      /// Connects the broker to a supplied Quoter object reference.
      void connect_quoter_info  (in StockQuoter c);

      /// Disconnects a the quoter connection.
      StockQuoter disconnect_quoter_info ();

      /// Gets the current quoter connection.
      StockQuoter get_connection_quoter_info ();

      /// Shutdown the object and terminate the application.
      oneway void shutdown ();
    };

This is the interface definition for Stock Broker clients.

The get_consumer_notifier() operation returns an object reference of the StockNameConsumer interface shown earlier. When the stock quoter system is initialized, this factory operation will be used to return the StockNameConsumer object that belongs to the StockBroker object.

The connect_quoter_info() and disconnect_quoter_info() operations are used to connect/disconnect the StockBroker object with the StockQuoter object that's provided by the StockDistributor interface described next.

The get_connection_quoter_info() operation is used to get the current connected StockQuoter object.

The shutdown() operation is a oneway operation which shuts down the object and terminates the application.

    interface StockBrokerHome
    {
      /// Create a StockBroker object.
      StockBroker create (in StockDistributor dist, in string stock_name);
    };

This is the interface definition for Stock Broker Home. This factory reduces the bookkeeping that CORBA applications must do to create and manage their objects.

### Compiling the IDL files and generating the stub, skeleton and implementation files

To generate the helper files you need to invoke the IDL compiler, like this:

    tao_idl Common.idl
    tao_idl -GI Broker.idl
    tao_idl -GI Distributor.idl

The "-GI" flag is used to generate the frames for the implmentation files (*I.h and *I.cpp). You can change the names of the files into *_i.h and *_i.cpp because the next time you run the IDL compiler, these implemention files (*I.h and *I.cpp) will be overwritten by the newly generated implemention files (with the same file names).

However, you don't need to do this often, in fact you rarely have to do it at all because this can be handled by writing and using a mpc file.

Email: shanshan.jiang@vanderbilt.edu