5.2 KiB
Interface Proxy Implementation
Proxy generation for interfaces to enable inheritance in Workflow scripts.
VlppReflection provides interface proxy macros that generate proxy implementations for interfaces, enabling them to be inherited and implemented in Workflow scripts. The proxy system handles the bridge between C++ interfaces and dynamic Workflow script implementations.
Proxy Declaration Patterns
Interfaces Without Base Interfaces
- Use
BEGIN_INTERFACE_PROXY_NOPARENT_RAWPTRfor interfaces without base interfaces using raw pointers - Use
BEGIN_INTERFACE_PROXY_NOPARENT_SHAREDPTRfor interfaces without base interfaces usingPtr<T> - Choose based on the memory management strategy for interface implementations
Interfaces With Base Interfaces
- Use
BEGIN_INTERFACE_PROXY_RAWPTRfor interfaces with base interfaces using raw pointers - Use
BEGIN_INTERFACE_PROXY_SHAREDPTRfor interfaces with base interfaces usingPtr<T> - All reflectable base interfaces must be listed (
IDescriptabledoesn't count)
Proxy Completion
- Use
END_INTERFACE_PROXYto complete proxy definition - Must be used regardless of which BEGIN macro was used
Method Implementation Patterns
Void Methods Without Parameters
- Use
INVOKE_INTERFACE_PROXY_NOPARAMSfor void methods without parameters - Handles method calls that don't return values and don't take arguments
Return Value Methods Without Parameters
- Use
INVOKEGET_INTERFACE_PROXY_NOPARAMSfor return value methods without parameters - Automatically handles return value retrieval and type conversion
Void Methods With Parameters
- Use
INVOKE_INTERFACE_PROXYfor void methods with parameters - Pass all method arguments to the macro
Return Value Methods With Parameters
- Use
INVOKEGET_INTERFACE_PROXYfor return value methods with parameters - Automatically handles both parameter passing and return value retrieval
Implementation Structure
Proxy Pattern
An interface proxy begins with the appropriate BEGIN macro and ends with END_INTERFACE_PROXY(name):
BEGIN_INTERFACE_PROXY_NOPARENT_SHAREDPTR(IMyInterface)
void VoidMethodNoParams() override
{
INVOKE_INTERFACE_PROXY_NOPARAMS(VoidMethodNoParams);
}
int GetValueNoParams() override
{
INVOKEGET_INTERFACE_PROXY_NOPARAMS(GetValueNoParams);
}
void VoidMethodWithParams(int a, const WString& b) override
{
INVOKE_INTERFACE_PROXY(VoidMethodWithParams, a, b);
}
int GetValueWithParams(int a, const WString& b) override
{
INVOKEGET_INTERFACE_PROXY(GetValueWithParams, a, b);
}
END_INTERFACE_PROXY(IMyInterface)
Method Implementation Rules
Inside the proxy, there are functions that implement the interface. In each function implementation there will be only one line of code from the appropriate INVOKE macro.
The return keyword is not necessary as INVOKEGET_INTERFACE_PROXY_NOPARAMS and INVOKEGET_INTERFACE_PROXY already handle return values automatically.
Proxy Categories
Raw or Shared Pointer Proxies
This is decided by the natural usage of the interface. If an instance of the interface is usually stored in Ptr<T>, use the shared pointer version.
Interface Inheritance Hierarchy
Base Interface Considerations
When registering interfaces with inheritance:
- Register base interfaces first
- List all reflectable base interfaces in the proxy declaration
IDescriptableis handled automatically and should not be listed- Ensure proper virtual inheritance in C++ interface definitions
Extra Content
Advanced Proxy Scenarios
Multiple Inheritance
For interfaces that inherit from multiple base interfaces:
BEGIN_INTERFACE_PROXY_SHAREDPTR(IDerivedInterface, IBaseInterface1, IBaseInterface2)
// Implement all methods from all interfaces
END_INTERFACE_PROXY(IDerivedInterface)
Complex Parameter Types
Proxy methods can handle complex parameter types:
- Custom struct types (must be registered)
- Collection types
- Other interface types
- Enum types
- Nullable types
Error Handling
Proxy implementations automatically handle:
- Type conversion errors
- Method invocation failures
- Parameter validation
- Return value conversion
Performance Considerations
- Proxy Overhead: Proxy calls have additional overhead compared to direct calls
- Type Conversion: Parameter and return value conversion can impact performance
- Caching: Consider caching proxy instances for frequently used interfaces
- Memory Management: Choose appropriate pointer type based on usage patterns
Integration with Workflow Scripts
Interface proxies enable Workflow scripts to:
- Implement C++ interfaces directly
- Override virtual methods
- Participate in callback scenarios
- Integrate with event systems
- Provide custom business logic implementations
Best Practices
- Choose Appropriate Pointer Type: Use shared pointers for reference-counted scenarios
- Complete Implementation: Implement all interface methods in the proxy
- Error Handling: Consider error scenarios in proxy implementations
- Documentation: Document the purpose and usage of each proxy
- Testing: Thoroughly test proxy implementations with Workflow scripts