Re: COM on mac
Re: COM on mac
- Subject: Re: COM on mac
- From: Sheehan Olver <email@hidden>
- Date: Tue, 14 Jan 2003 18:30:18 -0600
You are wrong about this being difficult. Since you have access to
both the server code and the client code, the easiest way to do this is
Distributed Objects. Look at the cocoa documentation in project
builder. I assume you are familiar with Objective-C. The key class is
NSConnection. Basically, you create a class that acts as the interface,
for example lets say it contains a method called
- (NSArray *)bookList;
Now on the server end, say on a host called "book.foo.com", you just
register your object with NSConnection:
[[NSConnection defaultConnection] setRootObject:serverObject];
if([[NSConnection defaultConnection] registerName:@"bookserver"] == NO)
{
/* handle Error */
}
Now the client just needs a reference to the server object. This is
done again with NSConnection:
id serverObject = [[NSConnection
rootProxyForConnectionWithRegisteredName:@"bookserver"]
host:@"book.foo.com];
NSArray *books = [serverObject bookList];
As you can see, what you want to do is very easy. The main concept is
that you need to think in terms of objects and methods rather than
functions. Of course, things are several caveats. For example on the
client side, serverObject of course isn't a reference to the actual
object. It is merely a "proxy" which forwards the method calls. I would
suggest reading through the different topics in the Project Builder
Cocoa help, or better yet get a Cocoa book and read through it.
Generally, the motto of cocoa is if something is hard to do, you are
doing it wrong.
Sheehan Olver
On Tuesday, January 14, 2003, at 02:02 PM,
email@hidden wrote:
Let's say for example, I have a server business object, or application,
called, 'CAB'. It's running over there on the machine called
'AppServ'.
Let's say that Hypothetical application exposes a method called
'GetVendorList' that takes the parameters 'ProductType' and returns a
recordset of Vendors that offer the products meeting the producttype
criteria. Now, just for the sake of compatability, we'll just say
that both
machines are Mac machines, let's not introduce the Windows <-> Mac COM
mess
into this.
In the Windows world, you would use that remote object via COM/DCOM
with the
following code: (I'm using VB for simplicity of the example, it's true
in
any language, the syntax and complexity varies greatly)
Dim obj as CAB
Dim RS as ADODB.RecordSet
Set CAB = CreateObject("CAB", "AppServer")
Set RS = CAB.GetVendorList("books")
Now, the same methodology applies locally for objects and applications
as
well, but let's just use the remote methodology for giggles.
From what I can tell, using Cocoa, and Objective C, the NSMutableArray
of
NSDictionary elements is as close to the recordset as you'll get. No
biggie, I get that. What I don't get is a real world example of the
'I want
to create an instance of an application or framework for use in my
application on a remote machine and call it's methods'.
Now, I've used AppleScript to do a limited amount of this on the local
machine, using Mail, iCal, AddressBook, and Entourage to accomplish
some of
these tasks via AppleScript isn't very difficult (if some of the syntax
isn't a little confusing, I still can't figure out how to determine if
a
Todo item from iCal is 'completed' since "if completion date of aTodo
is not
null then" doesn't work). That's dandy, but how do I know take that
concept
and apply it to the Objective C environment and distribute it across a
pair
of machines?
I might add that Apple Events probably come second nature to an old Mac
programmer that came from the Toolbox, through Carbon to Cocoa, but
coming
to Cocoa, from Win32 introduces wrinkles that you probably are
overlooking.
One of those is that we are apparently spoiled to having a lot of the
boilerplate code of remoting objects and applications hidden for us by
some
smart if inelegant tools. Please don't get me wrong, I love my Mac,
but
there are paradigm shifts in the development methodology that are
painful,
and that's coming from someone who is comfortable with both Unix and
IPC, as
well as doing low level Win32 stuff. I can do all of the remoting in
C++
too, but I don't see any clear documentation of how to take the COM
concepts
and apply them here. The closest I've found is to forego a native
method
and use CORBA with all of it's overhead, or build a Cocoa Java layer
and use
the Java remoting tools.
Perhaps I'm barking up the wrong tree. Ultimately I suspect the
Rendezvous
is going to help this situation, but as far as I can tell, it helps
with the
discovery process, but doesn't provide any tools for abstracting away
from
having to write a full client and server TCP implementation using BSD
sockets, and making the decisions that that kind of design entails.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.