API (extension) instance enumeration

J Jon Tara 3 years ago
0 1 0

I am struggling to understand the intended use and implementation of enumeration of API instances. In particular, I am interested in understanding it in the context of Rhodes native extensions. However, the same code structure is used in (many of) the internal APIs.

With the exception of Camera, all of the enumeration implementations seem to be dummied-up. Some will enumerate only one instance, regardless of how many there actually are. some will arbitrarily enumerate two instances.  And it is only implemented for iOS, where the enumerated values can be "back" or "front".

I'm also confused that all this really is enumerating is some strings that might symbolically identify instances.

I don't understand how/where to generate instance IDs for additional instances. Is there some assumption that you have a number at the tail of the string, and there is some base class code that will increment the number?

This seems like unfinished code, perhaps an idea that was never implemented?

FWIW, the extension I am creating is a Factory-style extension with a default instance. It's a Bonjour Browser extension. It's handy to have a default instance, but it might also be useful to have multiple instances. (For example, you might do multiple simultaneous searches for different services. Or you might not use them simultaneously, but it might be convenient to leave multiple browser objects laying around for use.)

A side-effect of enumeration might be useful to me, but is not essential. I make use of the ID value, because the extension has callbacks, and it's handy to include the ID value in each callback. That way, application code can choose to either send callbacks from each instance to a different controller URL (or lambda function) or all to the same. So, the callback code has a way of distinguishing instances in the callbacks.

I haven't actually tried creating a non-default instance yet. But, if I read the code correctly, as I have it currently written, the ID value will be nil for all but the default instance:

#import "BonjourBrowserSingleton.h"
@implementation BonjourBrowserSingleton

-(NSString*)getInitialDefaultID {
    return @"BonjourBrowser1";
}

-(void) enumerate:(id)methodResult {
    NSMutableArray* ar = [NSMutableArray arrayWithCapacity:1];
    [ar addObject:@"BonjourBrowser1"];
    [methodResult setResult:ar];
}

@end

Most of the Rhodes APIs arbitrary return an array with "SCN1" and "SCN2". That's clearly not correct.

So, I get the idea that enumerate ought to return an array with the ID strings of the instances that exist? Is application code supposed to be able to change the IDs? The ID is an API property (that we don't have to declare in our XML) so, in instance initialization, set the value of the ID property? (So that is where you would implement generation of IDs...) Then I would have to keep track of instances in some data structure (probably a hash/dictionary/etc.) in a class variable?

I checked the current master, and there doesn't seem to be any significant difference. I only find this dead-end half-implemented code.

Maybe I am misunderstanding intent, and this doesn't really apply to my scenario, as it seems oriented toward enumerating multiple hardware feature instances. (Such as cameras).

I don't really have a use for the enumeration in my code, but I do have a use for the IDs. And, perhaps that is the answer. I should generate a unique ID when an instance is created, but enumerate will "enumerate" only the default instance.

Please register or login to post a reply

1 Replies

J Jon Tara

Now even more confused...

Common API usage for Ruby is described here:

Rhomobile | Using RhoMobile Ruby API’s

Of course, the example shown is bogus, because (as of 5.0.30) the Camera API is still a 2.2 API... (I believe it is a Common API in 5.1, right?)

The implication from this is that enumerate should return an object. But, clearly, the code currently implemented for all of the common APIs enumerates the string IDs, not any kind of object. Maybe there is some magic I am missing. How do we get from those ID strings to actual Ruby/Javascript objects? The example proceeds to attempt to call a method. take_picture on the returned object. That clearly can't work if what enumerate returns is the string, "front"...

Does enumeration actually work? I mean, as documented?

I do see, at least from the Camera example, that the purpose of enumeration seems to be to enumerate hardware assets of some particular class handled by an API. And, so, probably has no role in my Bonjour Browser code. It would be strange (though perhaps of some utility) to be able to enumerate API object instances created by application code...

It seems like unfinished code/loose ends.

CONTACT
Can’t find what you’re looking for?