Index: src/OFPlugin.h ================================================================== --- src/OFPlugin.h +++ src/OFPlugin.h @@ -15,24 +15,15 @@ * The OFPlugin class provides a system for loading plugins at runtime. */ @interface OFPlugin: OFObject { void *handle; - id plugin; } /** * Loads an OFPlugin from a file. * * \param path Path to the OFPlugin file. The suffix is appended automatically. * \return A new autoreleased OFPlugin */ + pluginFromFile: (const char*)path; - -/** - * Initializes an already allocated OFPlugin from a file. - * - * \param path Path to the OFPlugin file. The suffix is appended automatically. - * \return An initialized OFPlugin - */ -- initFromFile: (const char*)path; @end Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -19,18 +19,15 @@ #import "OFExceptions.h" @implementation OFPlugin + pluginFromFile: (const char*)path { - return [[[OFPlugin alloc] initFromFile: path] autorelease]; -} - -- initFromFile: (const char*)path -{ char *file; size_t pathlen, suffixlen; - id (*init_plugin)(); + void *handle; + OFPlugin *(*init_plugin)(); + OFPlugin *plugin; Class c; if ((self = [super init])) { pathlen = strlen(path); suffixlen = strlen(PLUGIN_SUFFIX); @@ -61,38 +58,20 @@ c = [self class]; [super free]; @throw [OFInitializationFailedException newWithClass: c]; } + + plugin->handle = handle; + return plugin; } return self; } - free { - [plugin free]; dlclose(handle); return [super free]; } - -#ifdef __objc_INCLUDE_GNU -- (retval_t)forward: (SEL)selector - : (arglist_t)args -#else -- (id)forward: (SEL)selector - : (marg_list)args -#endif -{ - return [plugin performv: selector - : args]; -} - -- (IMP)methodFor: (SEL)selector -{ - if ([self respondsTo: selector]) - return [self methodFor: selector]; - else - return [plugin methodFor: selector]; -} @end Index: tests/OFPlugin/OFPlugin.m ================================================================== --- tests/OFPlugin/OFPlugin.m +++ tests/OFPlugin/OFPlugin.m @@ -15,12 +15,12 @@ #import "TestPlugin/TestPlugin.h" int main() { - OFPlugin *plugin; + TestPlugin *plugin; plugin = [OFPlugin pluginFromFile: "TestPlugin/TestPlugin"]; [plugin test]; return 0; } Index: tests/OFPlugin/TestPlugin/TestPlugin.h ================================================================== --- tests/OFPlugin/TestPlugin/TestPlugin.h +++ tests/OFPlugin/TestPlugin/TestPlugin.h @@ -7,13 +7,10 @@ * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ -#import "OFObject.h" +#import "OFPlugin.h" -@protocol TestPlugin +@interface TestPlugin: OFPlugin - (void)test; @end - -@interface TestPlugin: OFObject -@end