[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coldsync-hackers] USB on OS X



On Tue, Oct 23, 2001 at 07:10:15PM -0400, Matthew C Weigel wrote:
> A stumbling block is that I'm not sure about the overall structure, and
> I'm not sure what role some of the io_* functions play (like io_select,
> which doesn't seem to be used in the program source).

	A PConnection is an object (yes, you can write object-oriented
code in C). The caller should only access it through

	PConnection *new_PConnection(char *fname,
			    const pconn_listen_t listenType,
			    const pconn_proto_t protocol,
			    int prompt_for_hotsync);
	int PConnClose(PConnection *pconn);
	int PConn_bind(PConnection *pconn,
		      const void *addr,
		      const int addrlen);

which are documented in their own man pages, and the io_*() functions.
The io_*() functions, in turn, are mostly inspired by socket-related
functions. Not all of them are used for all connection types (e.g,
usb_drain() is just "return 0").

	When you create a new PConnection with new_PConnection(), you
need to specify both the "listen type" and the software protocol. The
listen type specifies the physical connection to the Palm (serial,
USB, TCP, etc.)[1].

[1] The one exception to this is USB under Linux: Linux allows you to
access a USB device as if it were a serial device. Thus, you have to
lie to new_PConnection() and tell it that it's a serial device. The
listen type really specifies whether it makes sense to use functions
like tcsetattr() and suchlike.

	The 'protocol' argument specifies the protocol stack to use in
communications with the Palm. Communication over a serial line uses
DLP/PADP/SLP, whereas USB and network Hotsync use DLP over what I've
called "netsync", for lack of a better term. The 'protocol' argument
determines how pconn->dlp.read and pconn->dlp.write will be
initialized.

	Once you've created a new PConnection with new_PConnection(),
you can use the various io_*() functions. Unfortunately, the only
sample code showing how to use io_bind, io_connect, and io_accept is
ColdSync itself, but if you're familiar with bind(), connect() and
accept(), it'll make a bit more sense.
	io_read and io_write are directly modeled after read() and
write(). They allow you to read/write a stream of bytes from/to the
Palm, without worrying about the listen type. (The software protocols
are a different matter.)

	If you want to define a new "OSX" listen type, start by
creating libpconn/PConnection_osx.c, modeled after one of the other
libpconn/PConnection_<protocol>.c files. You'll need to define
	pconn_osx_open()
	osx_bind()
	osx_read()
	osx_write()
	osx_accept()
	osx_connect()
	osx_drain()
	osx_close()
	osx_select()
then modify libpconn/PConnection.c accordingly.
	If any of the osx_*() functions don't really apply, you can
just have them trivially return successfully(see usb_drain()).

	You'll also need to check which software protocol you're using
(see the various "switch (pconn->protocol)" statements in
PConnection_*.c).

> Another stumbling block is the use of select() in the program source -
> is this ever used to assume you can select() across all connections
> with Palms?

	(*io_select)() really only performs a subset of what select()
does: it waits for the PConnection to become readable/writable. It
doesn't allow you to select() on multiple file descriptors.

	Does this answer your questions?

-- 
Andrew Arensburger                      This message *does* represent the
arensb@ooblick.com                      views of ooblick.com
		Abandon hope early and avoid the rush.
This message was sent through the coldsync-hackers mailing list.  To remove
yourself from this mailing list, send a message to majordomo@thedotin.net
with the words "unsubscribe coldsync-hackers" in the message body.  For more
information on Coldsync, send mail to coldsync-hackers-owner@thedotin.net.