|
Lines 88-100
Link Here
|
| 88 |
jclass jClass_appInfo = NULL; |
88 |
jclass jClass_appInfo = NULL; |
| 89 |
jobject jObject_appInfo = NULL; |
89 |
jobject jObject_appInfo = NULL; |
| 90 |
jmethodID jMethod_appInfo = NULL; |
90 |
jmethodID jMethod_appInfo = NULL; |
| 91 |
jbyte * pBuffer = NULL; |
91 |
pi_buffer_t* pBuffer = NULL; |
| 92 |
int bProceed = 1; |
92 |
int bProceed = 1; |
| 93 |
int iNumBytesRead = 0; |
93 |
int iNumBytesRead = 0; |
| 94 |
|
94 |
|
| 95 |
if (bProceed) { |
95 |
if (bProceed) { |
| 96 |
/* Allocate memory for maximum data size */ |
96 |
/* Allocate memory for maximum data size */ |
| 97 |
pBuffer = (jbyte *)malloc(MAX_RESOURCE_SIZE); |
97 |
pBuffer = pi_buffer_new(MAX_RESOURCE_SIZE); |
| 98 |
if (pBuffer == NULL) { |
98 |
if (pBuffer == NULL) { |
| 99 |
postJavaException(env, |
99 |
postJavaException(env, |
| 100 |
"org/gnu/pilotlink/PilotLinkException", |
100 |
"org/gnu/pilotlink/PilotLinkException", |
|
Lines 104-110
Link Here
|
| 104 |
} |
104 |
} |
| 105 |
if (bProceed) { |
105 |
if (bProceed) { |
| 106 |
/* Read app-info block && verify successful read */ |
106 |
/* Read app-info block && verify successful read */ |
| 107 |
iNumBytesRead = dlp_ReadAppBlock(handle, db, 0, pBuffer, MAX_RESOURCE_SIZE); |
107 |
iNumBytesRead = dlp_ReadAppBlock(handle, db, 0, MAX_RESOURCE_SIZE, pBuffer); |
| 108 |
if (iNumBytesRead < 0) { |
108 |
if (iNumBytesRead < 0) { |
| 109 |
/* Throw Java exception, iNumBytesRead is actually an error code */ |
109 |
/* Throw Java exception, iNumBytesRead is actually an error code */ |
| 110 |
postPilotLinkException(env, "Unable to read app-block", iNumBytesRead, errno); |
110 |
postPilotLinkException(env, "Unable to read app-block", iNumBytesRead, errno); |
|
Lines 129-139
Link Here
|
| 129 |
} |
129 |
} |
| 130 |
if (bProceed) { |
130 |
if (bProceed) { |
| 131 |
jbyteArray jArray_buffer = env->NewByteArray(iNumBytesRead); |
131 |
jbyteArray jArray_buffer = env->NewByteArray(iNumBytesRead); |
| 132 |
env->SetByteArrayRegion(jArray_buffer, 0, (jint)iNumBytesRead, pBuffer); |
132 |
env->SetByteArrayRegion(jArray_buffer, 0, (jint)iNumBytesRead, (jbyte *)pBuffer->data); |
| 133 |
jObject_appInfo = env->NewObject(jClass_appInfo, jMethod_appInfo, jArray_buffer); |
133 |
jObject_appInfo = env->NewObject(jClass_appInfo, jMethod_appInfo, jArray_buffer); |
| 134 |
} |
134 |
} |
| 135 |
|
135 |
|
| 136 |
if (pBuffer != NULL) free(pBuffer); |
136 |
if (pBuffer != NULL) pi_buffer_free(pBuffer); |
| 137 |
return jObject_appInfo; |
137 |
return jObject_appInfo; |
| 138 |
} |
138 |
} |
| 139 |
/* |
139 |
/* |
|
Lines 561-571
Link Here
|
| 561 |
env->ReleaseStringUTFChars(jdbname, dbname); |
561 |
env->ReleaseStringUTFChars(jdbname, dbname); |
| 562 |
if (dlp_OpenDB(handle,0,0x80|0x40,dbn,&db)<0) { |
562 |
if (dlp_OpenDB(handle,0,0x80|0x40,dbn,&db)<0) { |
| 563 |
|
563 |
|
| 564 |
printf("Fehler!"); |
564 |
printf("Fehler!\n"); |
| 565 |
return NULL; |
565 |
return NULL; |
| 566 |
} |
566 |
} |
| 567 |
jbyte buff[0xffff]; |
567 |
jbyte buff[0xffff]; |
| 568 |
int l=dlp_ReadAppBlock(handle,db,0,&buff,0xffff); |
568 |
pi_buffer_t pbuff = {(unsigned char *) buff, 0xfff, 0}; |
|
|
569 |
int l=dlp_ReadAppBlock(handle,db,0,0xffff,&pbuff); |
| 569 |
printf("read app-Block of size %d\n",l); |
570 |
printf("read app-Block of size %d\n",l); |
| 570 |
fflush(stdout); |
571 |
fflush(stdout); |
| 571 |
|
572 |
|
|
Lines 659-671
Link Here
|
| 659 |
(JNIEnv *env, jobject obj, jint handle , jint db , jint idx) { |
660 |
(JNIEnv *env, jobject obj, jint handle , jint db , jint idx) { |
| 660 |
|
661 |
|
| 661 |
jbyte buffer[MAX_RESOURCE_SIZE]; |
662 |
jbyte buffer[MAX_RESOURCE_SIZE]; |
|
|
663 |
pi_buffer_t pbuff = {(unsigned char *) buffer, MAX_RESOURCE_SIZE, 0}; |
| 662 |
recordid_t id; |
664 |
recordid_t id; |
| 663 |
jint size, attr, category; |
665 |
jint attr, category; |
| 664 |
//printf("Getting record..\n"); |
666 |
//printf("Getting record..\n"); |
| 665 |
int ret = dlp_ReadRecordByIndex(handle, db, idx, buffer, |
667 |
int size = dlp_ReadRecordByIndex(handle, db, idx, &pbuff, |
| 666 |
&id, &size, &attr, &category); |
668 |
&id, &attr, &category); |
| 667 |
if (ret<0) { |
669 |
if (size<0) { |
| 668 |
postPilotLinkException(env,"Error reading database by index",ret,errno); |
670 |
postPilotLinkException(env,"Error reading database by index",size,errno); |
| 669 |
return NULL; |
671 |
return NULL; |
| 670 |
} |
672 |
} |
| 671 |
//printf("getting class!\n"); |
673 |
//printf("getting class!\n"); |
|
Lines 810-816
Link Here
|
| 810 |
int parent_sd = -1, /* Client socket, formerly sd */ |
812 |
int parent_sd = -1, /* Client socket, formerly sd */ |
| 811 |
client_sd = -1, /* Parent socket, formerly sd2 */ |
813 |
client_sd = -1, /* Parent socket, formerly sd2 */ |
| 812 |
result; |
814 |
result; |
| 813 |
struct pi_sockaddr addr; |
|
|
| 814 |
struct stat attr; |
815 |
struct stat attr; |
| 815 |
struct SysInfo sys_info; |
816 |
struct SysInfo sys_info; |
| 816 |
const char *defport = "/dev/pilot"; |
817 |
const char *defport = "/dev/pilot"; |
|
Lines 875-884
Link Here
|
| 875 |
/* |
876 |
/* |
| 876 |
if (port != NULL) { |
877 |
if (port != NULL) { |
| 877 |
*/ |
878 |
*/ |
| 878 |
addr.pi_family = PI_AF_PILOT; |
879 |
result = pi_bind(parent_sd, port); |
| 879 |
strncpy(addr.pi_device, port, sizeof(addr.pi_device)); |
|
|
| 880 |
result = |
| 881 |
pi_bind(parent_sd, (struct sockaddr *) &addr, sizeof(addr)); |
| 882 |
/* |
880 |
/* |
| 883 |
} else { |
881 |
} else { |
| 884 |
result = pi_bind(parent_sd, NULL, 0); |
882 |
result = pi_bind(parent_sd, NULL, 0); |
|
Lines 999-1005
Link Here
|
| 999 |
bProceed = 0; |
997 |
bProceed = 0; |
| 1000 |
} else { |
998 |
} else { |
| 1001 |
int so_timeout = 16; |
999 |
int so_timeout = 16; |
| 1002 |
int sizeof_so_timeout = sizeof(so_timeout); |
1000 |
size_t sizeof_so_timeout = sizeof(so_timeout); |
| 1003 |
|
1001 |
|
| 1004 |
pi_setsockopt(client_sd, PI_LEVEL_DEV, PI_DEV_TIMEOUT, |
1002 |
pi_setsockopt(client_sd, PI_LEVEL_DEV, PI_DEV_TIMEOUT, |
| 1005 |
&so_timeout, &sizeof_so_timeout); |
1003 |
&so_timeout, &sizeof_so_timeout); |
|
Lines 1046-1062
Link Here
|
| 1046 |
unsigned long iRsrcType; /* Resource type */ |
1044 |
unsigned long iRsrcType; /* Resource type */ |
| 1047 |
int iRsrcID; /* Resource ID */ |
1045 |
int iRsrcID; /* Resource ID */ |
| 1048 |
int iRsrcSize; /* Actual resource size */ |
1046 |
int iRsrcSize; /* Actual resource size */ |
| 1049 |
jbyte * pRsrcData; /* Buffer for resource data */ |
1047 |
pi_buffer_t *pRsrcData; /* Buffer for resource data */ |
| 1050 |
int iResult; /* Result of library call */ |
|
|
| 1051 |
jobject pRecordObject = NULL; |
1048 |
jobject pRecordObject = NULL; |
| 1052 |
|
1049 |
|
| 1053 |
/* Get "enough" memory for incoming resource data */ |
1050 |
/* Get "enough" memory for incoming resource data */ |
| 1054 |
if ((pRsrcData = (jbyte *)malloc(MAX_RESOURCE_SIZE * sizeof(jbyte))) != NULL) { |
1051 |
if ((pRsrcData = pi_buffer_new(MAX_RESOURCE_SIZE * sizeof(jbyte))) != NULL) { |
| 1055 |
|
1052 |
|
| 1056 |
/* Invoke C library function */ |
1053 |
/* Invoke C library function */ |
| 1057 |
iResult = dlp_ReadResourceByIndex(iSockHandle, iDBHandle, iRsrcIndex, |
1054 |
iRsrcSize = dlp_ReadResourceByIndex(iSockHandle, iDBHandle, iRsrcIndex, |
| 1058 |
pRsrcData, &iRsrcType, &iRsrcID, &iRsrcSize); |
1055 |
pRsrcData, &iRsrcType, &iRsrcID); |
| 1059 |
if (iResult >= 0) { |
1056 |
if (iRsrcSize >= 0) { |
| 1060 |
jclass pRecordClass; |
1057 |
jclass pRecordClass; |
| 1061 |
jmethodID pRecordConstructor; |
1058 |
jmethodID pRecordConstructor; |
| 1062 |
|
1059 |
|
|
Lines 1067-1080
Link Here
|
| 1067 |
|
1064 |
|
| 1068 |
/* Fill a Java array with resource data && invoke constructor */ |
1065 |
/* Fill a Java array with resource data && invoke constructor */ |
| 1069 |
jbyteArray pJavaArray = env->NewByteArray(iRsrcSize); |
1066 |
jbyteArray pJavaArray = env->NewByteArray(iRsrcSize); |
| 1070 |
env->SetByteArrayRegion(pJavaArray, 0, iRsrcSize, pRsrcData); |
1067 |
env->SetByteArrayRegion(pJavaArray, 0, iRsrcSize, (jbyte *)pRsrcData->data); |
| 1071 |
pRecordObject = env->NewObject(pRecordClass, pRecordConstructor, |
1068 |
pRecordObject = env->NewObject(pRecordClass, pRecordConstructor, |
| 1072 |
pJavaArray, (jlong)iRsrcID, (jint)iRsrcSize, (jint)0, (jint)iRsrcType); |
1069 |
pJavaArray, (jlong)iRsrcID, (jint)iRsrcSize, (jint)0, (jint)iRsrcType); |
| 1073 |
} |
1070 |
} |
| 1074 |
} else { |
1071 |
} else { |
| 1075 |
postPilotLinkException(env, "Unable to read resource by index", iResult, errno); |
1072 |
postPilotLinkException(env, "Unable to read resource by index", iRsrcSize, errno); |
| 1076 |
} |
1073 |
} |
| 1077 |
free(pRsrcData); |
1074 |
pi_buffer_free(pRsrcData); |
| 1078 |
} else { |
1075 |
} else { |
| 1079 |
postJavaException(env, |
1076 |
postJavaException(env, |
| 1080 |
"org/gnu/pilotlink/PilotLinkException", |
1077 |
"org/gnu/pilotlink/PilotLinkException", |
|
Lines 1175-1184
Link Here
|
| 1175 |
{ |
1172 |
{ |
| 1176 |
int iResult = 0; |
1173 |
int iResult = 0; |
| 1177 |
struct DBInfo rInfoDB; |
1174 |
struct DBInfo rInfoDB; |
|
|
1175 |
pi_buffer_t pi_bufInfoDB = {(unsigned char *) &rInfoDB, sizeof(struct DBInfo), 0}; |
| 1178 |
jobject pDBInfoObject = NULL; |
1176 |
jobject pDBInfoObject = NULL; |
| 1179 |
|
1177 |
|
| 1180 |
/* Execute low-level library call... */ |
1178 |
/* Execute low-level library call... */ |
| 1181 |
iResult = dlp_ReadDBList(iSockHandle, cardno, flags, start, &rInfoDB); |
1179 |
iResult = dlp_ReadDBList(iSockHandle, cardno, flags, start, &pi_bufInfoDB); |
| 1182 |
if (iResult >= 0) { |
1180 |
if (iResult >= 0) { |
| 1183 |
jclass pDBInfoClass = NULL; |
1181 |
jclass pDBInfoClass = NULL; |
| 1184 |
jmethodID pDBInfoMethod = NULL; |
1182 |
jmethodID pDBInfoMethod = NULL; |