[PolyORB-users] CosEvent example

Vadim Godunko vgodunko at rostel.ru
Tue Jan 23 18:56:24 CET 2007


Hello,

 From time to time in this list someone asked about example of use of 
CosEvent services.

Attached files is an example. It split into three programs:

channel.adb - primary server which serve event channel

supplier.adb - event supplier, it get ChannelAdmin IOR, connect to proxy 
and send an event

consumer.adb - event consumer, it get ChannelAdmin IOR, connect to proxy 
and waiting for events.
-------------- next part --------------

with Ada.Text_IO;

with CORBA.Object;
with CORBA.ORB;
with CosEventChannelAdmin.EventChannel.Impl;
with PortableServer.POA.Helper;
with PortableServer.POAManager;

with PolyORB.Setup.Thread_Pool_Server;
pragma Warnings (Off, PolyORB.Setup.Thread_Pool_Server);

procedure Channel is
begin
   declare
      Argv : CORBA.ORB.Arg_List := CORBA.ORB.Command_Line_Arguments;

   begin
      CORBA.ORB.Init (CORBA.ORB.To_CORBA_String ("ORB"), Argv);
   end;

   declare
      Root_POA      : PortableServer.POA.Local_Ref;
      Event_Channel : CORBA.Object.Ref;
--      Event_Channel : CosEventChannelAdmin.EventChannel.Ref;

   begin

      --  Retrieve Root POA

      Root_POA := PortableServer.POA.Helper.To_Local_Ref
        (CORBA.ORB.Resolve_Initial_References
         (CORBA.ORB.To_CORBA_String ("RootPOA")));

      PortableServer.POAManager.Activate
        (PortableServer.POA.Get_The_POAManager (Root_POA));

      --  Creating event channel

      Event_Channel :=
         PortableServer.POA.Servant_To_Reference
         (Root_POA,
          PortableServer.Servant
          (CosEventChannelAdmin.EventChannel.Impl.Create));

      --  Output EventChannel IOR

      Ada.Text_IO.Put_Line
        ("'"
         & CORBA.To_Standard_String
         (CORBA.Object.Object_To_String (Event_Channel))
         & "'");

      CORBA.ORB.Run;
   end;

exception
   when others =>
      CORBA.ORB.Shutdown (True);
      raise;
end Channel;
-------------- next part --------------

--  with Ada.Text_IO;
with Ada.Command_Line;

with CORBA.Object;
with CORBA.ORB;
with CosEventChannelAdmin.ConsumerAdmin;
with CosEventChannelAdmin.EventChannel;
with CosEventChannelAdmin.ProxyPushSupplier;
with CosEventComm.PushConsumer.Helper;
with CosEventComm.PushConsumer.Impl;
--  with MyConsumer.Impl;
with PortableServer.POA.Helper;
with PortableServer.POAManager;

with PolyORB.Setup.Thread_Pool_Server;
pragma Warnings (Off, PolyORB.Setup.Thread_Pool_Server);

procedure Consumer is
begin
   declare
      Argv : CORBA.ORB.Arg_List := CORBA.ORB.Command_Line_Arguments;

   begin
      CORBA.ORB.Init (CORBA.ORB.To_CORBA_String ("ORB"), Argv);
   end;

   declare
      Root_POA      : PortableServer.POA.Local_Ref;
      Event_Channel : CosEventChannelAdmin.EventChannel.Ref;
      Consumer      : CosEventComm.PushConsumer.Ref;
      Admin         : CosEventChannelAdmin.ConsumerAdmin.Ref;
      Proxy         : CosEventChannelAdmin.ProxyPushSupplier.Ref;

   begin
      --  Getting EventChannel reference

      CORBA.ORB.String_To_Object
        (CORBA.To_CORBA_String (Ada.Command_Line.Argument (1)), Event_Channel);

      --  Getting supplier proxy

      Admin := CosEventChannelAdmin.EventChannel.for_consumers (Event_Channel);

      Proxy := CosEventChannelAdmin.ConsumerAdmin.obtain_push_supplier (Admin);

      --  Retrieve Root POA

      Root_POA := PortableServer.POA.Helper.To_Local_Ref
        (CORBA.ORB.Resolve_Initial_References
         (CORBA.ORB.To_CORBA_String ("RootPOA")));

      PortableServer.POAManager.Activate
        (PortableServer.POA.Get_The_POAManager (Root_POA));

      --  Creating event consumer

--      Obj := CosEventChannelAdmin.EventChannel.Impl.Create;
      Consumer :=
--         PortableServer.POA.Servant_To_Reference
--         (Root_POA,
--          PortableServer.Servant
--          (MyConsumer.Impl.Create));
         CosEventComm.PushConsumer.Helper.Unchecked_To_Ref
         (PortableServer.POA.Servant_To_Reference
          (Root_POA,
           PortableServer.Servant
           (CosEventComm.PushConsumer.Impl.Create)));

      CosEventChannelAdmin.ProxyPushSupplier.connect_push_consumer
        (Proxy, Consumer);

      --  Output EventChannel IOR

--      Ada.Text_IO.Put_Line
--        ("'"
--         & CORBA.To_Standard_String
--         (CORBA.Object.Object_To_String (Event_Channel))
--         & "'");

      CORBA.ORB.Run;
   end;

exception
   when others =>
      CORBA.ORB.Shutdown (True);
      raise;
end Consumer;
-------------- next part --------------

--  with Ada.Text_IO;
with Ada.Command_Line;

with CORBA.Object;
with CORBA.ORB;
with CosEventChannelAdmin.SupplierAdmin;
with CosEventChannelAdmin.EventChannel;
with CosEventChannelAdmin.ProxyPushConsumer;
with CosEventComm.PushConsumer;
with CosEventComm.PushSupplier.Helper;
with CosEventComm.PushSupplier.Impl;
with PortableServer.POA.Helper;
with PortableServer.POAManager;

with PolyORB.Setup.Thread_Pool_Server;
pragma Warnings (Off, PolyORB.Setup.Thread_Pool_Server);

procedure Supplier is
begin
   declare
      Argv : CORBA.ORB.Arg_List := CORBA.ORB.Command_Line_Arguments;

   begin
      CORBA.ORB.Init (CORBA.ORB.To_CORBA_String ("ORB"), Argv);
   end;

   declare
      Root_POA      : PortableServer.POA.Local_Ref;
      Event_Channel : CosEventChannelAdmin.EventChannel.Ref;
      Supplier      : CosEventComm.PushSupplier.Ref;
      Admin         : CosEventChannelAdmin.SupplierAdmin.Ref;
      Proxy         : CosEventChannelAdmin.ProxyPushConsumer.Ref;

   begin
      --  Getting EventChannel reference

      CORBA.ORB.String_To_Object
        (CORBA.To_CORBA_String (Ada.Command_Line.Argument (1)), Event_Channel);

      --  Getting supplier proxy

      Admin := CosEventChannelAdmin.EventChannel.for_suppliers (Event_Channel);

      Proxy := CosEventChannelAdmin.SupplierAdmin.obtain_push_consumer (Admin);

      --  Retrieve Root POA

      Root_POA := PortableServer.POA.Helper.To_Local_Ref
        (CORBA.ORB.Resolve_Initial_References
         (CORBA.ORB.To_CORBA_String ("RootPOA")));

      PortableServer.POAManager.Activate
        (PortableServer.POA.Get_The_POAManager (Root_POA));

      --  Creating event consumer

      Supplier :=
         CosEventComm.PushSupplier.Helper.Unchecked_To_Ref
         (PortableServer.POA.Servant_To_Reference
          (Root_POA,
           PortableServer.Servant
           (CosEventComm.PushSupplier.Impl.Create)));

      --  Output EventChannel IOR

--      Ada.Text_IO.Put_Line
--        ("'"
--         & CORBA.To_Standard_String
--         (CORBA.Object.Object_To_String (Event_Channel))
--         & "'");

      CosEventChannelAdmin.ProxyPushConsumer.connect_push_supplier
        (Proxy, Supplier);

--      CosEventComm.PushConsumer.push (Proxy, CORBA.To_Any (CORBA.Long (1)));
      CosEventChannelAdmin.ProxyPushConsumer.push
        (Proxy, CORBA.To_Any (CORBA.Long (1)));
   end;

   CORBA.ORB.Shutdown (True);

exception
   when others =>
      CORBA.ORB.Shutdown (True);
      raise;
end Supplier;


More information about the PolyORB-users mailing list