Porting gnome-pilot to pilot-link0.12 API



Carrying on from my gnome-pilot-conduits post; this is kind-of in
reverse order...

Attached is a patch to the gnome-pilot-2.0.12 tarball which
tries to port things over to the new API.  I'm sure that there are
errors in this patch (probably crashers and dataloss) but at least it
compiles against the pilot-link-0.12 pre-release 2.

I had to remove the backup conduit for now.

We really should isolate all of this buffer reading/writing into a
wrapper layer, maybe with an analogue to pi_buffer_t that can become it
when pilot-link-0.12 is released.

--- gnome-pilot-2.0.12/gpilotd/manager.c.port-to-pilot-link-0.12	2004-09-03 12:18:35.000000000 -0400
+++ gnome-pilot-2.0.12/gpilotd/manager.c	2005-03-16 18:34:33.000000000 -0500
@@ -294,25 +294,29 @@
 	GPilotPilot *pilot_info;
 	int error = 0;
 	int index = 0;
-       
+
 	pilot_info = gpilot_find_pilot_by_id (pu->userID, context->pilots);
 
 	orbed_notify_daemon_message (pilot_info->name, NULL, _("Collecting synchronization info..."));
 
-	while (1) {
-		GnomePilotDBInfo *dbinfo;
+	{
+		int i;
+		pi_buffer_t *pi_buf;
+		int result;
+
+		pi_buf = pi_buffer_new (0xffff);       
+		result = dlp_ReadDBList (pfd, 0, dlpDBListRAM, index, pi_buf);
+
+		for (i=0;i<result;i++) {
+			GnomePilotDBInfo *dbinfo;
 		
-		dbinfo = g_new0 (GnomePilotDBInfo, 1);
-		/* load next dbinfo block */
-		if (dlp_ReadDBList (pfd, 0, dlpDBListRAM, index, PI_DBINFO (dbinfo)) < 0) {
-			/* is <0, there are no more databases, break
-                           out so we can save the list */
-			break;
+			dbinfo = g_new0 (GnomePilotDBInfo, 1);
+			memcpy (dbinfo, pi_buf->data + (sizeof(struct DBInfo)*i), sizeof(struct DBInfo));
+			index = PI_DBINFO (dbinfo)->index + 1;
+			dbs = g_list_append (dbs, dbinfo);
 		}
 
-		index = PI_DBINFO (dbinfo)->index + 1;
-
-		dbs = g_list_append (dbs, dbinfo);
+		pi_buffer_free (pi_buf);
 	}
 
 	index = 1;
--- gnome-pilot-2.0.12/gpilotd/gnome-pilot-conduit-standard-abs.c.port-to-pilot-link-0.12	2004-08-26 22:02:48.000000000 -0400
+++ gnome-pilot-2.0.12/gpilotd/gnome-pilot-conduit-standard-abs.c	2005-03-16 18:34:33.000000000 -0500
@@ -31,6 +31,73 @@
 #include "gpmarshal.h"
 #include "manager.h"
 
+
+/* Compatibility routines for old API in pilot-link-0.11 */
+extern int
+gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadRecordById (int sd, int fHandle, recordid_t id, void *buffer,
+							    int *index, int *size, int *attr, int *category);
+
+extern int
+gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadRecordByIndex (int sd, int fHandle, int index, void *buffer,
+							       recordid_t * id, int *size, int *attr,
+							       int *category);
+extern int
+gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadNextModifiedRec (int sd, int fHandle, void *buffer, recordid_t * id,
+								 int *index, int *size, int *attr, int *category);
+
+
+int
+gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadRecordById (int sd, int fHandle, recordid_t id, void *buffer,
+							    int *index, int *size, int *attr, int *category)
+{
+	pi_buffer_t *pi_buf = pi_buffer_new (0xffff);
+	int result = dlp_ReadRecordById (sd, fHandle, id, 
+					 pi_buf,
+					 index, attr, category);
+	memcpy (buffer, pi_buf->data, pi_buf->used);
+	if (NULL==size) {
+		*size = pi_buf->used;
+	}
+	pi_buffer_free (pi_buf);
+
+	return result;
+}
+
+int
+gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadRecordByIndex (int sd, int fHandle, int index, void *buffer,
+							       recordid_t * id, int *size, int *attr,
+							       int *category)
+{
+	pi_buffer_t *pi_buf = pi_buffer_new (0xffff);
+	int result = dlp_ReadRecordByIndex (sd, fHandle, index, 
+					    pi_buf,
+					    id, attr, category);
+	memcpy (buffer, pi_buf->data, pi_buf->used);
+	if (NULL==size) {
+		*size = pi_buf->used;
+	}
+	pi_buffer_free (pi_buf);
+
+	return result;
+}
+
+int
+gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadNextModifiedRec (int sd, int fHandle, void *buffer, recordid_t * id,
+								 int *index, int *size, int *attr, int *category)
+{
+	pi_buffer_t *pi_buf = pi_buffer_new (0xffff);
+	int result = dlp_ReadNextModifiedRec (sd, fHandle, 
+					      pi_buf, 
+					      id, index, attr, category);
+	memcpy (buffer, pi_buf->data, pi_buf->used);
+	if (NULL==size) {
+		*size = pi_buf->used;
+	}
+	pi_buffer_free (pi_buf);
+
+	return result;
+}
+
 enum {
 	MATCH_RECORD,
 	FREE_MATCH,
@@ -433,7 +500,7 @@
 		}
 		
 		/* copy all records */
-		while (dlp_ReadRecordByIndex (dbinfo->pilot_socket,
+		while (gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadRecordByIndex (dbinfo->pilot_socket,
 					      dbinfo->db_handle,
 					      index,
 					      remote.record,
@@ -1081,7 +1148,7 @@
 		g_message("gpilotd: retrieve %ld from pilot",local->ID);
 		remote = g_new0(PilotRecord,1);
 		remote->record = malloc(0xffff);
-		dlp_ReadRecordById(handle,db,
+		gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadRecordById(handle,db,
 				   local->ID,
 				   remote->record,
 				   &index,
@@ -1438,7 +1505,7 @@
 	retval = 0;
 	remote.record = buffer;
 
-	while (dlp_ReadRecordByIndex(handle,db,
+	while (gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadRecordByIndex(handle,db,
 				     index,
 				     remote.record,
 				     &remote.ID,
@@ -1477,7 +1544,7 @@
 
 	g_message("Performing Slow Synchronization");
 
-	while (dlp_ReadRecordByIndex(handle,db,
+	while (gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadRecordByIndex(handle,db,
 				     index,
 				     remote.record,
 				     &remote.ID,
@@ -1517,7 +1584,7 @@
 
 	g_message("Performing Fast Synchronization");
 
-	while (dlp_ReadNextModifiedRec (handle, db,
+	while (gnome_pilot_compat_with_pilot_link_0_11_dlp_ReadNextModifiedRec (handle, db,
 					remote.record,
 					&remote.ID,
 					&index,
--- gnome-pilot-2.0.12/gpilotd/gpilotd.c.port-to-pilot-link-0.12	2004-09-03 12:18:35.000000000 -0400
+++ gnome-pilot-2.0.12/gpilotd/gpilotd.c	2005-03-16 18:34:33.000000000 -0500
@@ -122,7 +122,6 @@
 static int 
 pilot_connect (GPilotDevice *device,int *error) 
 {
-	struct pi_sockaddr addr;
 	int sd, listen_sd, pf;
 	int ret;
     
@@ -154,8 +153,6 @@
 		return -1;
 	}
 	
-	addr.pi_family = PI_AF_PILOT;
-
 /*
 	Most important for networking
 	. resolves inside libpisock as network
@@ -166,9 +163,7 @@
 		device->port = "net:any";
 	}
 
-	strcpy (addr.pi_device,device->port);
-
-	ret = pi_bind (listen_sd, (struct sockaddr*)&addr, sizeof (addr));
+	ret = pi_bind (listen_sd, device->port);
 	if (ret == -1) {
 		g_warning (_("Unable to bind to pilot"));
 		if (error)
--- gnome-pilot-2.0.12/utils/make-password.c.port-to-pilot-link-0.12	2005-03-16 19:23:11.000000000 -0500
+++ gnome-pilot-2.0.12/utils/make-password.c	2005-03-16 19:23:31.000000000 -0500
@@ -28,7 +28,6 @@
 
 
 int main(int argc,char *argv[]) {
-  struct pi_sockaddr addr;
   int sd,ret;
   struct PilotUser U;
   char salt[3];
@@ -42,10 +41,7 @@
     exit(1);
   }
     
-  addr.pi_family = PI_AF_PILOT;
-  strcpy(addr.pi_device,argv[1]);
-  
-  ret = pi_bind(sd, (struct sockaddr*)&addr, sizeof(addr));
+  ret = pi_bind(sd, argv[1]);
   if(ret == -1) {
     perror("pi_bind");
     exit(1);


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