feat(phase-9.75g-0): Implement BID-FFI Day 6 - Dynamic method discovery system
- Enhanced plugin metadata API with find_method() and get_methods() - Implemented generic plugin method calling system (execute_plugin_method_generic) - Fixed TLV encoding: use Bytes tag for string data in write() - Fixed read() method: provide default size argument when called without args - Replaced hardcoded execute_plugin_file_method with dynamic system - Full end-to-end test successful: FileBox plugin write/read working 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -8,6 +8,7 @@ pub struct LoadedPlugin {
|
||||
pub library: Library,
|
||||
pub handle: PluginHandle,
|
||||
pub type_id: u32,
|
||||
pub plugin_info: NyashPluginInfo, // プラグイン情報を保存
|
||||
}
|
||||
|
||||
impl LoadedPlugin {
|
||||
@ -48,9 +49,46 @@ impl LoadedPlugin {
|
||||
handle.initialize(&host, &mut info)?;
|
||||
let type_id = info.type_id;
|
||||
|
||||
Ok(Self { library, handle, type_id })
|
||||
Ok(Self { library, handle, type_id, plugin_info: info })
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the plugin's Box type name
|
||||
pub fn get_type_name(&self) -> BidResult<&str> {
|
||||
unsafe { self.plugin_info.name() }
|
||||
}
|
||||
|
||||
/// Get all available methods for this plugin
|
||||
pub fn get_methods(&self) -> BidResult<Vec<(u32, String, u32)>> {
|
||||
let mut methods = Vec::new();
|
||||
|
||||
unsafe {
|
||||
let methods_slice = self.plugin_info.methods_slice()?;
|
||||
for method_info in methods_slice {
|
||||
let method_name = method_info.name()?.to_string();
|
||||
methods.push((
|
||||
method_info.method_id,
|
||||
method_name,
|
||||
method_info.signature_hash,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(methods)
|
||||
}
|
||||
|
||||
/// Find a method by name and return its info
|
||||
pub fn find_method(&self, method_name: &str) -> BidResult<Option<(u32, u32)>> {
|
||||
unsafe {
|
||||
let methods_slice = self.plugin_info.methods_slice()?;
|
||||
for method_info in methods_slice {
|
||||
if method_info.name()? == method_name {
|
||||
return Ok(Some((method_info.method_id, method_info.signature_hash)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a minimal host vtable for plugins
|
||||
|
||||
Reference in New Issue
Block a user