Recent

Author Topic: How can I get names of CORBA-interfaces via rtti?  (Read 1455 times)

TheKeeper

  • New member
  • *
  • Posts: 8
How can I get names of CORBA-interfaces via rtti?
« on: July 20, 2026, 12:52:03 pm »
I have some class and I should know all corba and com interfaces, which are implemented by this class.

With COM-interfaces I have no problem:

Code: Pascal  [Select][+][-]
  1. InterfaceTablePtr := RttiType.AsInstance.MetaClassType.GetInterfaceTable();
  2. {$R-}
  3. for i := 0 to InterfaceTablePtr^.EntryCount - 1 do
  4.   if Assigned(InterfaceTablePtr^.Entries[i].IIDRef) then
  5.     Debug := InterfaceTablePtr^.Entries[i].IIDStrRef^^;
  6. {$R+}

But that's how TInterfaceEntry looks like:

Code: Pascal  [Select][+][-]
  1. tinterfaceentry = record
  2. private
  3.   function GetIID: pguid; inline;
  4.   function GetIIDStr: pshortstring; inline;
  5. public
  6.   property IID: pguid read GetIID;
  7.   property IIDStr: pshortstring read GetIIDStr;
  8. public
  9.   IIDRef      : ^pguid; { if assigned(IID) then Com else Corba}
  10.   VTable      : Pointer;
  11.   case integer of
  12.     1 : (
  13.       IOffset: sizeuint;
  14.     );
  15.     2 : (
  16.       IOffsetAsCodePtr: CodePointer;
  17.       IIDStrRef   : ^pshortstring; { never nil. Com: upper(GuidToString(IID^)) }
  18.       IType       : tinterfaceentrytype;
  19.     );
  20. end;

If I try to get IIDStr, I'll got GUID. But GUID for CORBA is useless because CORBA-interfaces are defined by their name.
How can I get name of corba interface by its enrty?
« Last Edit: July 20, 2026, 12:54:30 pm by TheKeeper »

cdbc

  • Hero Member
  • *****
  • Posts: 2921
    • http://www.cdbc.dk
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #1 on: July 20, 2026, 01:46:30 pm »
Hi
Hmm, I do it like this:
Code: Pascal  [Select][+][-]
  1. generic function TFactoryGen.GetSvc<T>(const aName: string = ''): T;
  2. var ti: PTypeInfo;
  3. begin { we check if said plugin-service exist in repo, before returning it, else nil }
  4.   ti:= TypeInfo(T);
  5.   if aName = '' then begin { empty means we want the /default/ svc of this type }
  6.     if PluginMgr.QueryPliServiceDefault(ti.Name) then
  7.       pointer(Result):= PluginMgr.GetPliSvcDefaultWeak(ti.Name)
  8.     else Result:= T(nil);
  9.   end else begin { ok, we have to try and fetch the named svc of this type }
  10.     if PluginMgr.QueryPliService(ti.Name,aName) then
  11.       pointer(Result):= PluginMgr.GetPliSvcWeak(ti.Name,aName)
  12.     else Result:= T(nil);
  13.   end;
  14. end; { GetSvc<T> }
the above works for everything I throw at it...
Regards Benny

edit: well, maybe I misunderstood the problem a bit, sorry mate
« Last Edit: July 20, 2026, 01:49:51 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

TheKeeper

  • New member
  • *
  • Posts: 8
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #2 on: July 20, 2026, 02:15:21 pm »
Yes, problem is not how to get name by typeinfo of certain corba-interface, problem is how to get names of all corba-interfaces which are implemented by certain class.
But nevertheless, thanks for answer.

sh17

  • New Member
  • *
  • Posts: 11
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #3 on: July 20, 2026, 02:38:53 pm »
Just out of curiosity, who still uses CORBA these days? I wrote my diploma thesis on it back in 2002.

Thaddy

  • Hero Member
  • *****
  • Posts: 19606
  • Glad to be alive.
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #4 on: July 20, 2026, 02:46:38 pm »
Add {$M+} explicitly. But CORBA interfaces are hardly useful without a broker (and FPC hasn't got a broker like Midas). There is a non-reference counted COM interface too. Use that. Very similar.
They are used in the rtl: e.g. with TStringlist and TCollection. Their interfaces are not refcounted.

What is your motivation to use CORBA? Just the non-reference count?

Using COM style is not heavier (three very lightweight methods) and gives you much more options.

Technically, in Freepascal CORBA is NOT CORBA, but CORBA style: there is no addref/release/queryinterface. It is a raw interface type.
You can not even use it with true CORBA brokers without a lot more.
« Last Edit: July 20, 2026, 03:09:02 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

TheKeeper

  • New member
  • *
  • Posts: 8
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #5 on: July 20, 2026, 03:10:39 pm »
Quote
What is your motivation to use CORBA? Just the non-reference count?
Yes, but moreover CORBA is just more lightweight. For exmaple, I can't use atomic pointer operations with COM-interfaces.
So, I use COM-interfaces in the cases when in C++ I would use shared_ptr. And I use CORBA when I need, you know, interfaces.

cdbc

  • Hero Member
  • *****
  • Posts: 2921
    • http://www.cdbc.dk
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #6 on: July 20, 2026, 03:16:20 pm »
Hi
Quote
Yes, but moreover CORBA is just more lightweight.
+1
True that!
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12980
  • FPC developer.
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #7 on: July 20, 2026, 03:20:54 pm »
Huh, shared_ptr also has lifetime management?

TheKeeper

  • New member
  • *
  • Posts: 8
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #8 on: July 20, 2026, 03:25:05 pm »
Quote
Huh, shared_ptr also has lifetime management?
I'm not very good with terms, but shared_ptr in C++ is reference counted and it is destroyed when no strong references remain.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12980
  • FPC developer.
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #9 on: July 20, 2026, 03:53:38 pm »
Quote
Huh, shared_ptr also has lifetime management?
I'm not very good with terms, but shared_ptr in C++ is reference counted and it is destroyed when no strong references remain.

Exactly my point, like COM interfaces :-)

korba812

  • Sr. Member
  • ****
  • Posts: 499
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #10 on: July 20, 2026, 04:39:58 pm »
How can I get name of corba interface by its enrty?

You should specify a GUID in the interface definition. Unlike COM interfaces, the GUID of a CORBA interface can be any string.

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$INTERFACES CORBA}
  4.  
  5. type
  6.   IFoo = interface
  7.     ['FooInterface']
  8.     procedure Foo;
  9.   end;
  10.  
  11.   IBar = interface
  12.     // ['BarInterface']
  13.     procedure Bar;
  14.   end;
  15.  
  16.   { TMyFoo }
  17.  
  18.   TMyFooBar = class(TObject, IFoo, IBar)
  19.     procedure Foo;
  20.     procedure Bar;
  21.   end;
  22.  
  23.   { TMyFoo }
  24.  
  25. procedure TMyFooBar.Foo;
  26. begin
  27.  
  28. end;
  29.  
  30. procedure TMyFooBar.Bar;
  31. begin
  32.  
  33. end;
  34.  
  35. var
  36.   I: Integer;
  37.  
  38. begin
  39.   with TMyFooBar.GetInterfaceTable^ do
  40.     for I := 0 to EntryCount - 1 do
  41.       if Entries[I].IIDRef = nil then // only CORBA interfaces
  42.       begin
  43.         Write(I, ': ');
  44.         if Entries[I].IIDStr <> nil then
  45.           WriteLn(Entries[I].IIDStr^)
  46.         else
  47.           WriteLn;
  48.       end;
  49. end.
  50.  

Thaddy

  • Hero Member
  • *****
  • Posts: 19606
  • Glad to be alive.
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #11 on: July 20, 2026, 06:31:26 pm »
That is a string, not a GUID. You can misuse a GUID string representation as a Corba style string, though. < Sigh>.
As I explained: COM is also lightweight and simply better.
Anyway, it is your choice: if you believe in fables, use it. It is only CORBA in all but name.
Better name is raw interface. Nothing to do with CORBA. Period.

Since it is a string, and not a 128 byte binary value, it is likely also slower.
It requires string handling to kick in.....When you use a identifier string....
Instead of a single binary lookup in the interface table.
« Last Edit: July 20, 2026, 06:48:00 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

TheKeeper

  • New member
  • *
  • Posts: 8
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #12 on: July 21, 2026, 08:27:09 am »
Quote
Better name is raw interface. Nothing to do with CORBA. Period.
Yeah, yeah, I call it "corba" just because "{$interfaces CORBA}".

Quote
You should specify a GUID in the interface definition. Unlike COM interfaces, the GUID of a CORBA interface can be any string.
Thanks. I get it.

korba812, Thaddy
So, I can set ANY string to CORBA (raw) interface in [] section? It's new to me.
But that is not seems right to use it that way... at least because both type of interfaces has field "GUID" in type data that returns TGUID.

Ok, guys, thanks fo answers, now I have better understanding.

So, if an interface has nothing in [] section, I can't access it via rtti (I will see there is some interface implementation, but I will not see what interface is it). So, if I want to know what interface is it, I should use [] section for CORBA just like for COM. Understood.

Thaddy

  • Hero Member
  • *****
  • Posts: 19606
  • Glad to be alive.
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #13 on: July 21, 2026, 08:36:41 am »
Yes you can set any string in CORBA mode: it is a string, a real string, not a binary value as is a GUID in COM mode. It should probably not contain spaces, though.
You can abuse a CORBA interface identifier with the string representation of a guid, though....
Querying CORBA style interfaces by its identifier is therefor slower than COM because it involves string comparisons as opposed to COM's QueryInterface. Its only defining feature is that it is never refcounted. You could have known, because it is documented:
https://www.freepascal.org/docs-html/ref/refse50.html
https://www.freepascal.org/docs-html/prog/progsu37.html#x44-430001.2.37

Teaser:
Code: Pascal  [Select][+][-]
  1. program CorbaForDonkeys;
  2. // you can create a Corba class instance through its interface (with as)
  3. // but you can not free it
  4. // you must create Corba classes to a class instance, not the interface.
  5. {$mode objfpc}{$interfaces corba}
  6. type
  7.    ICorbaInterface = interface
  8.    ['ICorbaInterface']
  9.    procedure IAm;
  10.    end;
  11.    
  12.    TCorbaClass= class(ICorbaInterface)
  13.    procedure Iam;
  14.    end;
  15.    
  16.    procedure TCorbaClass.Iam;
  17.    begin
  18.      writeln('I am called through a Corba interface');
  19.    end;
  20.  
  21. var
  22.   Intf:ICorbaInterface;  
  23. begin
  24.   // This is allowed, but you can never free such an instance.
  25.   Intf := TCorbaClass.Create as ICorbaInterface; // slow string comparison kicks in
  26.   Intf.Iam;
  27.   // So how are you are going to free this one?
  28.   // Maybe?:
  29.   //(Intf as TCorbaClass).Free; // nope, compile time error. This works in COM
  30.   // Or:?
  31.   TCorbaClass(Intf).Free;// nope, compiles, runtime error. This also works in COM
  32. end.
  33.  

Now you know why I think Corba style interfaces are very "useful" ;) And SLOW!! This is particularly noticeable when you need to create many instances.
Better use a non-refcounted COM class, and/or (for non-ref COM as will work):
Code: Pascal  [Select][+][-]
  1. // Ok,Ok, can be done, just teasing:
  2. {$mode objfpc}{$interfaces corba}
  3. type
  4.    ICorbaInterface = interface
  5.    ['ICorbaInterface']
  6.    procedure IAm;
  7.    procedure Free;// ALWAYS add when using CORBA style.
  8.    end;
  9.    
  10.    TCorbaClass= class(ICorbaInterface)
  11.      procedure Iam;
  12.      procedure Free;// introduce this one
  13.     end;
  14.    
  15.    procedure TCorbaClass.Iam;
  16.    begin
  17.      writeln('I am called through a Corba interface');
  18.    end;
  19.    
  20.    procedure TCorbaClass.Free;
  21.    begin
  22.      Destroy;
  23.    end;
  24.  
  25. var
  26.   Intf:ICorbaInterface;  
  27. begin
  28.   Intf := TCorbaClass.Create as ICorbaInterface;// performs slow string comparison
  29.   Intf.Iam;
  30.   // explicitly add a way to free from a Corba interface instance.
  31.   Intf.Free;
  32. end.
Not my taste....
People who think CORBA style interfaces are more lightweight than COM are mistaken, they are merely defective.

This is better and faster:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$interfaces com}{$inline on}
  2. type
  3.    IComInterface = interface
  4.    ['{A44D1C83-3E1D-4222-AA55-A19F3DD4D8C1}']
  5.    procedure IAm;
  6.    end;
  7.    
  8.    TComClass= class(TNoRefCountObject,IComInterface)
  9.      procedure Iam;
  10.     end;
  11.        
  12.    procedure TComClass.Iam;
  13.    begin
  14.      writeln('I am called through a Com interface');
  15.    end;
  16.  
  17. var
  18.   Intf:IComInterface;  
  19. begin
  20.   Intf := TComClass.Create as IComInterface;
  21.   Intf.Iam;
  22.   (Intf as TComClass).Free;// because we have no refcount. LightWeight, Still faster than CORBA.
  23. end.


« Last Edit: July 21, 2026, 10:30:18 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

TheKeeper

  • New member
  • *
  • Posts: 8
Re: How can I get names of CORBA-interfaces via rtti?
« Reply #14 on: July 21, 2026, 10:23:12 am »
Quote
TCorbaClass.Create as ICorbaInterface; // slow string comparison kicks in
I very doubt about it. I never use this and always use pointer-cast (I mean ICorbaInterface(MyCorbaObject)), which is immediate, but even "as" shouldn't use string comparison.
Are you sure?
« Last Edit: July 21, 2026, 10:26:38 am by TheKeeper »

 

TinyPortal © 2005-2018