Make your own free website on Tripod.com
// C++
#include <CosEvent.h>
...
class PushConsumer_i:
{
 public:
  void push (const CORBA::Any& a,
    CORBA::Environment&);
                void disconnect_push_consumer
    (CORBA::Environment&);
 private:
         CORBA::Boolean m_disconnected;

};

void PushConsumer_i::push(const CORBA::Any& a,
           CORBA::Environment&)
{
        if (!m_disconnected) {
                        CORBA::String_var msg;
        if (a >>= msg)
                ;
        else
                cout << "Bad TypeCode: expected a string" << endl;
        } else throw CosEventComm::Disconnected;

}
void PushConsumerClass::disconnect_push_consumer(
                                        CORBA::Environment&)
{
        m_disconnected = 1;
        cout << "Disconnecting push consumer ..." << endl;
}

int main() {

        CosEventChannelAdmin::EventChannel  channel;
        CosEventChannelAdmin::ConsumerAdmin
     consumerAdmin;
        CosEventChannelAdmin::ProxyPushSupplier
            proxyPushSupplier;

        PushConsumer_i  pushConsumer = new PushConsumer_i;
        CORBA::String_var eventChannelName = "otrmp//clock";
        try {
  // Initialize ....
                // Obtain a reference to the event channel:
                channel = CosEventChannelAdmin::EventChannel::
                                _bind(eventChannelName, 0);
                // Obtain a reference to a proxy push supplier
                consumerAdmin = eventChannel->for_consumers();
                proxyPushSupplier =
                                consumerAdmin->obtain_push_supplier();
                // Connect the push consumer to the proxy supplier:
                proxyPushSupplier->connect_push_consumer(
         pushConsumer);

                // Wait for incoming push() invocations from
                // the event channel:
                CORBA::App.processEvents(1000*60);
        } catch ... // Handle exceptions here.
                ...
}