CORBA Programming/Echo/Meta Object
CORBA IDL Definition
edit #ifndef __TEST_META_ECHO_DEFINED
#define __TEST_META_ECHO_DEFINED
#include "test-echo.idl"
//
// a Test Module to test the basic PolyORB functions.
//
module Test
{
//
// The Meta Class for the echo test.
//
interface Meta_Echo
{
//
// Create a new instance of the echo object
//
Test::Echo // newly created Echo object
New_Echo ();
//
// There is only ony instance of the meta class object which
// has its own Identification.
//
const string Name_Service_Id = "Test/Meta_Echo";
};
// end interface Meta_Echo
};
// module Test
#endif
Ada Specification
edit with Test.Echo;
with PortableServer;
package Test.Meta_Echo.Impl
is
--
-- a Test Module to test the basic PolyORB functions
--
--------------------------------------------------------------------------------
--
-- The Meta Class for the echo test.
--
type Object
is new
PortableServer.Servant_Base
with private;
type Object_Ptr is access Object'Class;
--------------------------------------------------------------------------------
--
-- Create a new instance of the echo object
--
function New_Echo (
-- The Object itself
Self : access Object)
return
-- newly created Echo object
Test.Echo.Ref;
private -- -------------------------------------------------------------------
--
-- The Meta Class for the echo test.
--
type Object
is new
PortableServer.Servant_Base
with null record;
--------------------------------------------------------------------------------
end Test.Meta_Echo.Impl;
Ada Implementation
edit with CORBA.ORB;
with CORBA.Impl;
with PortableServer.POA;
with PortableServer.POA.Helper;
with PolyORB.Log;
with Test.Echo.Impl;
with Test.Echo.Helper;
with Test.Meta_Echo.Skel;
--
-- The following packages are only initialized but not used otherwise.
--
pragma Warnings (Off, Test.Meta_Echo.Skel);
--
-- initialize packages
--
pragma Elaborate (Test.Meta_Echo.Skel);
pragma Elaborate_All (Test.Echo.Impl);
package body Test.Meta_Echo.Impl
is
--
-- a Test Module to test the basic PolyORB functions
--
--------------------------------------------------------------------------------
--
-- Initialize logging from configuration file.
--
package Log is new PolyORB.Log.Facility_Log ("test.meta_echo");
--------------------------------------------------------------------------------
--
-- Log Message when Level is at least equal to the user-requested
-- level for Facility.
--
procedure Put_Line (
Message : in Standard.String;
Level : in PolyORB.Log.Log_Level := PolyORB.Log.Info)
renames
Log.Output;
--------------------------------------------------------------------------------
--
-- Create a new instance of the echo object
--
function New_Echo (
-- The Object itself
Self : access Object)
return
-- newly created Echo object
Test.Echo.Ref
is
package ORB renames CORBA.ORB;
package POA renames PortableServer.POA;
--
-- Get Reference to the portable server
--
Root_POA : POA.Ref
:= POA.Helper.To_Ref (
ORB.Resolve_Initial_References (
ORB.To_CORBA_String ("RootPOA")));
--
-- create a new Echo object
--
Echo_Object : constant CORBA.Impl.Object_Ptr
:= new Echo.Impl.Object;
--
-- create a servant for the new Echo object
--
Echo_Servant : constant PortableServer.Servant
:= PortableServer.Servant (Echo_Object);
--
-- activate the servant. Don't know what to do with the Id.
--
Echo_Id : constant PortableServer.ObjectId
:= POA.Activate_Object (
Self => Root_POA,
P_Servant => Echo_Servant);
--
-- Convert from servant type to the correct result type.
--
Result : Echo.Ref
:= Echo.Helper.To_Ref (
POA.Servant_To_Reference (
Self => Root_POA,
P_Servant => Echo_Servant));
pragma Unreferenced (Self);
pragma Unreferenced (Echo_Id);
begin
Put_Line (
"Echo = '" &
CORBA.To_Standard_String (CORBA.Object.Object_To_String (Result)) &
"'");
return Result;
end New_Echo;
--------------------------------------------------------------------------------
end Test.Meta_Echo.Impl;