Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtaining a sub-interface from an interface

Tags:

People also ask

What is a sub interface?

A subinterface is a virtual interface created by dividing one physical interface into multiple logical interfaces. Subinterfaces use the parent physical interface for sending and receiving data. Supported features.

How do I create a sub interface on a Cisco router?

To create a VLAN subinterface, use the interface command in XR Config mode. To delete a subinterface, use the no form of this command. Physical interface or virtual interface followed by the subinterface path ID.

How many subinterfaces can be configured on an interface Cisco?

You can partition one physical interface into up to 4094 different subinterfaces, one for each VLAN.


This is a bit of special case of interfaces, where a class implements multiple versions of the same interface, ie. something like the following

IBase = interface
   procedure Foo;
end;

ISub = interface (IBase)
   procedure Bar;
end;

ISpecialBase = interface (IBase) end;

ISpecialSub = interface (ISub) end;

TMyClass = class(TInterfacedObject, ISpecialBase, ISpecialSub)

   procedure SpecialFoo1;
   procedure SpecialFoo2;
   procedure SpecialBar;

   procedure ISpecialBase.Foo = SpecialFoo1;

   procedure ISpecialSub.Foo = SpecialFoo2;
   procedure ISpecialSub.Bar = SpecialBar;

   function GetTheRightOne(parameters) : IBase;

end;

...

function TMyClass.GetTheRightOne(parameters) : IBase;
begin
   if (something complex depending on parameters) then
      Result := ISpecialBase(Self)
   else Result := ISpecialSub(Self)
end;

of course there are about a dozen ISpecialXxxx in the real case.

There is a very important need to have only one instance, ie. I want to avoid having to create adapters or dummy instances just to defer the ISpecialXxxx implementations, as the sole purpose of the previous design is precisely to have a single instance handle many outstanding interfaces (ie. the RefCount of the TMyClass can get in the thousandths).

Now the problem is that GetTheRightOne() returns an IBase, yet at some point I want to check if that IBase can be cast to an ISub.

Is there a way to do it with the above declaration form?

One way could be add a

function GetSub : ISub;

to IBase, but that really makes the design a lot heavier, as it would have to be implemented for each ISpecialXxxx, and would be redundant with the ISpecialXxxx "inheritence", so I'm looking for a more elegant solution (assuming it exists).

(I have other "bloat" solutions, so I'm really want to emphasize I'm looking for a non-bloat solution)

edit : some more details

  • GUIDs are there in the original code (but their lack isn't what's causing the difficulty)
  • Supports & QueryInterface don't work, because of the ISpecialXxx needed to have multiple version of the interface per class, ISub isn't listed explitly, and so isn't found. Both works however when using an adapter/dummy class to defer the interface (as then ISub can be listed explicitly)

edit2 : if you want the gory details

Check https://code.google.com/p/dwscript/source/browse/trunk/Source/dwsJSONConnector.pas (r2492), the TdwsJSONConnectorType class, and the IJSONLow interface, the goal is to have the IConnectorFastCall detected from it when it's passed as an IConnectorCall, and thus be able to have LowFastCall invoked rather than LowCall.

The detection has to occur in TConnectorCallExpr.AssignConnectorSym, line 294, where there is currently a QueryInterface.

Note that the QueryInterface works in the case of TdwsJSONIndexReadCall & TdwsJSONIndexWriteCall as they implement the IConnectorCall & IConnectorFastCall from distinct classes & instances. But that's what I'd like to avoid.

Of course ideally, the goal would be to fold back everything into the ConnectorType class (single class, single instance), and for each interface, a particular ConnectorType class should be free to implement either IConnectorCall or IConnectorFastCall.