On 16 Jun 2009, at 23:49, Stefan Bidigaray wrote:

I'll try to be to the point... I'm need to be able to find some bundles that conform to a particular protocol so that I can load them and maybe use them. I've been reading the Apple docs and I already know how to search the bundle directories and use - conformWithProtocol:. What I'm having a hard time grasping is, how do I find out if the bundle I'm looking at actually meets my criterias before loading it? Is this even possible? Since NSBundle doesn't support unloading (at least according to Apple) I don't want to load every single bundle in the system just to then find out they are just going to take up space. I've read the Apple Plug-in docs and NSBundle Programming Guide, but I still don't know how to do what I'm trying to.

I'm not at all sure you can.

It's true to say that you can't unload bundle code ... the gnu runtime doesn't support it, and while I think I read somewhere that Apple's new 64bit runtime would support it, the standard one definitely didn't last time I looked.

As far as I'm aware, there's no convention for storing the protocols supported by a bundle's principal class in its info.plist, so I don't see how you can check what a bundle does without loading the code.

I think the normal way that an application determines which bundles to load is by using its own directory/filename conventions, so you just search the bundle directories for bundles with the correct names or bundles in subdirectories with the correct names.

> FYI: this is for the NSSound reimplementation effort... I'm trying to support multiple "plug-ins".

Well, as NSSound is a gui class, presumably bundles for it should count as gui library resources. In GNUstep we do have a standard location for gui library resources, and the GNUstep extension [NSBundle +bundleForLibrary:version:] returns the bundle for that location. The problem is, that only returns the bundle in the first domain found (assumed to be the one associated with the library being used), and I guess with plugins you would want to allow bundles to be provided by something other than the standard gui library.

So, I think you are going to have to define your own conventions for this. I would suggest using NSSerarchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask,YES) to get a list of library directories, then look for specific naming patterns in those library directories.
eg.

Assuming your bundles are those with an 'nssound' extension located in the 'Bundles' subdirectory ...

{
  NSString      *path;
  NSArray       *paths;
  NSBundle      *bundle;
  NSEnumerator  *enumerator;
  NSMutableArray *all;

  /* Gather up the paths */
  paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
                                              NSAllDomainsMask, YES);

  enumerator = [paths objectEnumerator];
  all = [NSMutable array arrayWithCapacity: 10];
  while ((path = [enumerator nextObject]) != nil)
    {
      bundle = [self bundleWithPath: path];
paths = [bundle pathsForResourcesOfType: @"nssound" inDirectory: @"Bundles"];
      [all addObjectsFromArray: paths];
    }

  return all;
}



_______________________________________________
Discuss-gnustep mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to