/* Restore the app's timer */ (void)setitimer(ITIMER_REAL, &apptimer, NULL); timerflag = FALSE; } /* stop_read_timer */ #endif /* __linux__ */ int cygDeviceInputStream_readDeviceOneByteNC (JNIEnv *jenv, jobject jobj) { jclass jc; jclass ec; jfieldID jf; jint fd = -1; int rc; int dc; char buf[1]; jfieldID tmof; int tmo; int serrno; // Get the exception class. ec = (*jenv)->FindClass(jenv, "java/io/IOException"); assert(ec); // Get the file descriptor. jc = (*jenv)->GetObjectClass(jenv, jobj); assertexc(jc); jf = (*jenv)->GetFieldID(jenv, jc, "fd", "I"); assertexc(jf); fd = (*jenv)->GetIntField(jenv, jobj, jf); if (fd == -1) { (*jenv)->ThrowNew(jenv, ec, ""); } tmof = (*jenv)->GetFieldID(jenv, jc, "tmo", "I"); assert(tmof); tmo = (*jenv)->GetIntField(jenv, jobj, tmof); #ifdef QNX // Read data - QNX with timeout if (tmo <100 & tmo>0) { tmo=100; } dc=readcond(fd, buf, 1, 1, 0, tmo/100); //10th of a second instead of microSecs if (dc<1) { //dc=-1; //return fake error } #endif /* QNX */ #if defined(__linux__) || defined(__osx__) // Start the timer. timeoutOccurred = FALSE; if (tmo > 0) start_read_timer(tmo); // Read data. buf[0] = 0; dc = read(fd, buf, 1); serrno = errno; // Stop the timer. if (tmo > 0) stop_read_timer(); if (dc < 0 && !(serrno == EINTR || serrno == EAGAIN)) { (*jenv)->ThrowNew(jenv, ec, ""); } #endif /* __linux__ */ // If timeout had occurred, or if nil data was received, return -1. if (dc <= 0) return -1; return (int)(unsigned char)buf[0]; } /* cygDeviceInputStream_readDeviceOneByteNC */
/* Restore the app's timer */ (void)setitimer(ITIMER_REAL, &apptimer, NULL); timerflag = FALSE; } /* stop_read_timer */ #endif /* __linux__ */ int cygDeviceInputStream_readDeviceOneByteNC (JNIEnv *jenv, jobject jobj) { jclass jc; jclass ec; jfieldID jf; jint fd = -1; int rc; int dc; char buf[1]; jfieldID tmof; int tmo; int serrno; // Get the exception class. ec = (*jenv)->FindClass(jenv, "java/io/IOException"); assert(ec); // Get the file descriptor. jc = (*jenv)->GetObjectClass(jenv, jobj); assertexc(jc); jf = (*jenv)->GetFieldID(jenv, jc, "fd", "I"); assertexc(jf); fd = (*jenv)->GetIntField(jenv, jobj, jf); if (fd == -1) { (*jenv)->ThrowNew(jenv, ec, ""); } tmof = (*jenv)->GetFieldID(jenv, jc, "tmo", "I"); assert(tmof); tmo = (*jenv)->GetIntField(jenv, jobj, tmof); #ifdef QNX // Read data - QNX with timeout if (tmo <100 & tmo>0) { tmo=100; } dc=readcond(fd, buf, 1, 1, 0, tmo/100); //10th of a second instead of microSecs if (dc<1) { //dc=-1; //return fake error } #endif /* QNX */ #if defined(__linux__) || defined(__osx__) // Start the timer. timeoutOccurred = FALSE; if (tmo > 0) start_read_timer(tmo); // Read data. buf[0] = 0; dc = read(fd, buf, 1); serrno = errno; // Stop the timer. if (tmo > 0) stop_read_timer(); if (dc < 0 && !(serrno == EINTR || serrno == EAGAIN)) { (*jenv)->ThrowNew(jenv, ec, ""); } #endif /* __linux__ */ // If timeout had occurred, or if nil data was received, return -1. if (dc <= 0) return -1; return (int)(unsigned char)buf[0]; } /* cygDeviceInputStream_readDeviceOneByteNC */ int cygDeviceInputStream_readDeviceNC (JNIEnv *jenv, jobject jobj, jbyteArray jba, jint off, jint len) { jclass jc; jfieldID jf; jint fd = -1; int rc; int dc = 0; char *cbuf; jfieldID tmof; int tmo; jfieldID tmoDonef; cbuf = malloc(len); assert(cbuf); // Get the file descriptor. jc = (*jenv)->GetObjectClass(jenv, jobj); assert(jc); jf = (*jenv)->GetFieldID(jenv, jc, "fd", "I"); assert(jf); fd = (*jenv)->GetIntField(jenv, jobj, jf); if (fd == -1) { return -1; } tmof = (*jenv)->GetFieldID(jenv, jc, "tmo", "I"); assert(tmof); tmoDonef = (*jenv)->GetFieldID(jenv, jc, "tmoDone", "Z"); assert(tmoDonef); tmo = (*jenv)->GetIntField(jenv, jobj, tmof); #ifdef QNX // Read data - QNX with timeout if (tmo <100 & tmo>0) { tmo=100; } dc=readcond(fd, cbuf, len, len, tmo/100, tmo/100); //10th of a second instead of microSecs if (dc<len) { (*jenv)->SetBooleanField(jenv, jobj, tmoDonef, (jboolean)JNI_TRUE); //dc=-1; //return fake error } #endif /* QNX */ #if defined(__linux__) || defined(__osx__) // Start the timer. timeoutOccurred = FALSE; if (tmo > 0) start_read_timer(tmo); //Read data dc = read(fd, cbuf, len); // If the timer had already expired, set the field tmoDone. // Else, stop the timer. if (timeoutOccurred) { dc = 0; // Bug fix for PR#117959 (*jenv)->SetBooleanField(jenv, jobj, tmoDonef, (jboolean)JNI_TRUE); } if (tmo > 0) stop_read_timer(); #endif /*__linux__*/ // Copy back the data into the java buffer. if (dc > 0) (*jenv)->SetByteArrayRegion(jenv, jba, off, dc, (jbyte*)cbuf); free(cbuf); return dc; } /* cygDeviceInputStream_readDeviceNC */ int cygDeviceInputStream_getReadCountNC (JNIEnv *jenv, jobject jobj) { jclass jc; jclass ec; jfieldID jf; jint fd = -1; int rc; int dc = 0; // Get the exception class. ec = (*jenv)->FindClass(jenv, "java/io/IOException"); assert(ec); // Get the file descriptor. jc = (*jenv)->GetObjectClass(jenv, jobj); assertexc(jc); jf = (*jenv)->GetFieldID(jenv, jc, "fd", "I"); assertexc(jf); fd = (*jenv)->GetIntField(jenv, jobj, jf); if (fd == -1) { (*jenv)->ThrowNew(jenv, ec, ""); } // Now query the device stream for any data to be read. if ((rc = ioctl(fd, FIONREAD, &dc)) == -1) (*jenv)->ThrowNew(jenv, ec, ""); return dc; } /* cygDeviceInputStream_getReadCountNC */
/* * Function: w32DeviceInputStream_getReadCountNC * Purpose: Check serial port device event * Signature: ()I * Return: 0 - Fail * none zero - succeeds */ int w32DeviceInputStream_getReadCountNC(JNIEnv *jenv, jobject jobj) { DWORD dwCommEvent = 0; HANDLE osHandle; jclass jc; jclass ec; jfieldID jf; jint fd = -1; int dc = 0; // Get the exception class. ec = (*jenv)->FindClass(jenv, "java/io/IOException"); assert(ec); // Get the file descriptor. jc = (*jenv)->GetObjectClass(jenv, jobj); assertexc(jc); jf = (*jenv)->GetFieldID(jenv, jc, "fd", "I"); assertexc(jf); fd = (*jenv)->GetIntField(jenv, jobj, jf); if (fd == -1) { (*jenv)->ThrowNew(jenv, ec, ""); } osHandle = (HANDLE)fd; if(!GetCommMask( osHandle, &dwCommEvent )) return GetLastError(); dwCommEvent |= EV_RXCHAR; if( !SetCommMask( osHandle, dwCommEvent )) return GetLastError(); if( !WaitCommEvent( osHandle, &dwCommEvent, NULL )) return GetLastError(); return (dwCommEvent&EV_RXCHAR); } /* w32DeviceInputStream_getReadCountNC() */
/* * Function: w32DeviceInputStream_readDeviceOneByteNC * Purpose: Read one byte from serial port device * Signature: ()I * Return: 0 - Fail * none zero - succeeds */ int w32DeviceInputStream_readDeviceOneByteNC(JNIEnv *jenv, jobject jobj) { HANDLE osHandle; BOOL success; OVERLAPPED overlap; DWORD lastRc; DWORD actualBytes = 0; jclass jc; jclass ec; jfieldID jf; jint fd = -1; char buf[1]; #ifdef DEBUG printf("w32DeviceOutputStream_writeDeviceNC() entered\n"); #endif /* DEBUG */ /* Get the exception class. */ ec = (*jenv)->FindClass(jenv, "java/io/IOException"); assert(ec); /* Get the file descriptor. */ jc = (*jenv)->GetObjectClass(jenv, jobj); assertexc(jc); jf = (*jenv)->GetFieldID(jenv, jc, "fd", "I"); assertexc(jf); fd = (*jenv)->GetIntField(jenv, jobj, jf); if (fd == -1) return -1; osHandle = (HANDLE) fd; iveSerClearCommErrors(osHandle); memset(&overlap,0,sizeof(overlap)); overlap.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL); if (NULL == overlap.hEvent) { lastRc = GetLastError(); iveSerThrowWin(jenv,"Error creating event semaphore",lastRc); return 0; } success = ReadFile(osHandle, buf, 1, &actualBytes, &overlap); if(success) { CloseHandle(overlap.hEvent); return (int)(unsigned char)buf[0]; } else { lastRc = GetLastError(); if (ERROR_IO_PENDING != lastRc) { CloseHandle(overlap.hEvent); iveSerThrowWin(jenv,"Error reading data",lastRc); return 0; } } buf[0] = 0; actualBytes = 0; #ifndef _WIN32_WCE success = GetOverlappedResult(osHandle,&overlap,&actualBytes,TRUE); #endif if ( success && actualBytes ) { lastRc = (int)(unsigned char)(buf[0]); } else { lastRc = GetLastError(); } CloseHandle(overlap.hEvent); return lastRc; } /* w32DeviceInputStream_readDeviceOneByteNC */
/* * Class: org_eclipse_soda_dk_comm_SerialStatusEventThread * Method: monitorSerialStatusNC * Signature: (I)V */ void w32SerialStatusEventThread_monitorSerialStatusNC (JNIEnv *jenv, jobject jobj, jint jfd) { int pollingTime; /* seconds */ HANDLE osHandle = (HANDLE)jfd; DWORD oldStatus, newStatus; jfieldID notifyOnCDID, notifyOnCTSID; jfieldID notifyOnDSRID, notifyOnRIID; jboolean notifyOnCDFlag = JNI_FALSE; jboolean notifyOnCTSFlag = JNI_FALSE; jboolean notifyOnDSRFlag = JNI_FALSE; jboolean notifyOnRIFlag = JNI_FALSE; jclass jc; jmethodID jm; jclass jspc; jfieldID spID; jobject jsp; jboolean isInterruptedReturn; jclass jspec; /* serial port event class */ jfieldID speCDID,speCTSID, speDSRID, speRIID ; /* field ID */ jint speCD, speCTS, speDSR, speRI; /* field value */ jmethodID jintMethod; jclass jthreadClass; pollingTime = getPollingTime(jenv); /* Get the const values for all the serial port event types.*/ jspec = (*jenv)->FindClass(jenv, "javax/comm/SerialPortEvent"); assertexc(jspec); speCDID = (*jenv)->GetStaticFieldID(jenv, jspec, "CD", "I"); assertexc(speCDID); speCD = (*jenv)->GetStaticIntField(jenv, jspec, speCDID); speCTSID = (*jenv)->GetStaticFieldID(jenv, jspec, "CTS", "I"); assertexc(speCTSID); speCTS = (*jenv)->GetStaticIntField(jenv, jspec, speCTSID); speDSRID = (*jenv)->GetStaticFieldID(jenv, jspec, "DSR", "I"); assertexc(speDSRID); speDSR = (*jenv)->GetStaticIntField(jenv, jspec, speDSRID); speRIID = (*jenv)->GetStaticFieldID(jenv, jspec, "RI", "I"); assertexc(speRIID); speRI = (*jenv)->GetStaticIntField(jenv, jspec, speRIID); /* Get the serial port object.*/ jc = (*jenv)->GetObjectClass(jenv, jobj); assertexc(jc); spID = (*jenv)->GetFieldID(jenv, jc, "serialPort", "Lorg/eclipse/soda/dk/comm/NSSerialPort;"); assertexc(spID); jsp = (*jenv)->GetObjectField(jenv, jobj, spID); assertexc(jsp); /* Get the class ID of the serial port object.*/ jspc = (*jenv)->GetObjectClass(jenv, jsp); assertexc(jspc); notifyOnCDID = (*jenv)->GetFieldID(jenv, jspc, "notifyOnCDFlag", "Z"); assertexc(notifyOnCDID); notifyOnCTSID = (*jenv)->GetFieldID(jenv, jspc, "notifyOnCTSFlag", "Z"); assertexc(notifyOnCTSID); notifyOnDSRID = (*jenv)->GetFieldID(jenv, jspc, "notifyOnDSRFlag", "Z"); assertexc(notifyOnDSRID); notifyOnRIID = (*jenv)->GetFieldID(jenv, jspc, "notifyOnRIFlag", "Z"); assertexc(notifyOnRIID); /* Get access to the method to add a port.*/ jm = (*jenv)->GetMethodID(jenv, jspc, "reportSerialEvent", "(IZZ)V"); assertexc(jm); /* Get access to the interrupted method.*/ jthreadClass = (*jenv)->FindClass(jenv, "java/lang/Thread"); assertexc(jthreadClass); jintMethod = (*jenv)->GetMethodID(jenv, jthreadClass, "isInterrupted", "()Z"); assertexc(jintMethod); // if (ioctl(jfd, TIOCMGET, &oldStatus) < 0) { // (void)fprintf(stderr, "Java_org_eclipse_soda_dk_comm_SerialStatusEventThread_monitorSerialStatusNC: ioctl error %d!\n", errno); // return; //t.j } #ifndef _WIN32_WCE if (GetCommModemStatus(osHandle, &oldStatus) < 0) { errno = GetLastError(); (void)fprintf(stderr, "w32SerialStatusEventThread_monitorSerialStatusNC: GetCommModemStatus() error %d!\n", errno); return; } #endif //_WIN32_WCE while(1) { Sleep(pollingTime); /* check to see if this thread has been interrupted */ isInterruptedReturn = (*jenv)->CallBooleanMethod(jenv,jobj,jintMethod); if(isInterruptedReturn == JNI_TRUE) break; notifyOnCDFlag = (*jenv)->GetBooleanField(jenv, jsp, notifyOnCDID); notifyOnCTSFlag = (*jenv)->GetBooleanField(jenv, jsp, notifyOnCTSID); notifyOnDSRFlag = (*jenv)->GetBooleanField(jenv, jsp, notifyOnDSRID); notifyOnRIFlag = (*jenv)->GetBooleanField(jenv, jsp, notifyOnRIID); #ifndef _WIN32_WCE if (GetCommModemStatus(osHandle, &newStatus) < 0) { errno = GetLastError(); (void)fprintf(stderr, "w32SerialStatusEventThread_monitorSerialStatusNC: ioctl error %d!\n", errno); return; } #endif //_WIN32_WCE if (newStatus == oldStatus) continue; if((newStatus & MS_RLSD_ON) != (oldStatus & MS_RLSD_ON)) { if(notifyOnCDFlag) /* need to use jsp to access this field */ (*jenv)->CallVoidMethod(jenv, jsp, jm, speCD, (oldStatus & MS_RLSD_ON)? JNI_TRUE:JNI_FALSE,(newStatus & MS_RLSD_ON)? JNI_TRUE:JNI_FALSE); } if((newStatus & MS_CTS_ON) != (oldStatus & MS_CTS_ON)) { if(notifyOnCTSFlag) (*jenv)->CallVoidMethod(jenv, jsp, jm, speCTS, (oldStatus & MS_CTS_ON)? JNI_TRUE:JNI_FALSE,(newStatus & MS_CTS_ON)? JNI_TRUE:JNI_FALSE); } if((newStatus & MS_DSR_ON) != (oldStatus & MS_DSR_ON)) { if(notifyOnDSRFlag) (*jenv)->CallVoidMethod(jenv, jsp, jm, speDSR, (oldStatus & MS_DSR_ON)? JNI_TRUE:JNI_FALSE,(newStatus & MS_DSR_ON)? JNI_TRUE:JNI_FALSE); } if((newStatus & MS_RING_ON) != (oldStatus & MS_RING_ON)) { if(notifyOnRIFlag) (*jenv)->CallVoidMethod(jenv, jsp, jm, speRI, (oldStatus & MS_RING_ON)? JNI_TRUE:JNI_FALSE,(newStatus & MS_RING_ON)? JNI_TRUE:JNI_FALSE); } oldStatus = newStatus; } /* end of while() */ } /* w32SerialStatusEventThread_monitorSerialStatusNC */
/* * Class: org_eclipse_soda_dk_comm_SerialDataEventThread * Method: monitorSerialDataNC * Signature: (I)V */ void w32SerialDataEventThread_monitorSerialDataNC (JNIEnv *jenv, jobject jobj, jint jfd) { jclass jspec; /* serial port event class */ fd_set r_mask; jfieldID data_available_id; /* field ID */ jint data_available_event; /* field value */ jclass jc; jmethodID jm; jfieldID spID; jobject jsp; jclass jspc; jfieldID notifyOnDataAvailableID; jboolean notifyOnDataAvailableFlag = JNI_FALSE; int result; int pollingTime; /* seconds */ struct timeval tv; jboolean isInterruptedReturn; jclass jthreadClass; jmethodID jintMethod; #if _WIN32_WCE>=400 jint stopThreadFlag; #endif pollingTime = getPollingTime(jenv); jspec = (*jenv)->FindClass(jenv, "javax/comm/SerialPortEvent"); assertexc(jspec); data_available_id = (*jenv)->GetStaticFieldID(jenv, jspec, "DATA_AVAILABLE", "I"); assertexc(data_available_id); data_available_event = (*jenv)->GetStaticIntField(jenv, jspec, data_available_id); /* Get the serial port object.*/ jc = (*jenv)->GetObjectClass(jenv, jobj); assertexc(jc); spID = (*jenv)->GetFieldID(jenv, jc, "serialPort", "Lorg/eclipse/soda/dk/comm/NSSerialPort;"); assertexc(spID); jsp = (*jenv)->GetObjectField(jenv, jobj, spID); assertexc(jsp); /* Get the class ID of the serial port object.*/ jspc = (*jenv)->GetObjectClass(jenv, jsp); assertexc(jspc); /* Get access to the method to add a port.*/ jm = (*jenv)->GetMethodID(jenv, jspc, "reportSerialEvent", "(IZZ)V"); assertexc(jm); notifyOnDataAvailableID = (*jenv)->GetFieldID(jenv, jspc, "notifyOnDataFlag", "Z"); assertexc(notifyOnDataAvailableID); /* Get access to the interrupted method.*/ jthreadClass = (*jenv)->FindClass(jenv, "java/lang/Thread"); assertexc(jthreadClass); jintMethod = (*jenv)->GetMethodID(jenv, jthreadClass, "isInterrupted", "()Z"); assertexc(jintMethod); while(1) { #if _WIN32_WCE>=400 stopThreadFlag = getStopThreadFlag(jenv, jobj); if (stopThreadFlag) break; #endif /* check to see if this thread has been interrupted */ isInterruptedReturn = (*jenv)->CallBooleanMethod(jenv,jobj,jintMethod); if(isInterruptedReturn == JNI_TRUE) break; memset(&tv, 0, sizeof(tv)); tv.tv_sec = pollingTime; FD_ZERO(&r_mask); FD_SET(jfd, &r_mask); result = select(jfd + 1, &r_mask, NULL, NULL, &tv); #ifndef _WIN32_WCE if (result == -1 && errno != EINTR) break; #endif if (!result) continue; if (FD_ISSET(jfd, &r_mask)) { notifyOnDataAvailableFlag = (*jenv)->GetBooleanField(jenv, jsp, notifyOnDataAvailableID); if(notifyOnDataAvailableFlag) (*jenv)->CallVoidMethod(jenv, jsp, jm, data_available_event, JNI_TRUE, JNI_TRUE); } } } /* w32SerialDataEventThread_monitorSerialDataNC */
/* * Class: javax_comm_CommPortIdentifier * Method: monitorInterJVMDeviceAccessNC * Signature: (Ljava/lang/Thread;)I * * Currenty not Supported on Posix Devices */ int cygCommPortIdentifier_monitorInterJVMDeviceAccessNC (JNIEnv *jenv, jobject jobj, jobject jtho) { int pollingTime; /* seconds */ int oldVal, newVal; jclass jc; jmethodID jm; jfieldID pnameID; jstring pname; const char *pnamec; jboolean isInterruptedReturn; jclass jcpoc; /* CommPortOwnershipListener interf */ jfieldID cpoPOID; /* PORT_OWNED ID */ jfieldID cpoPUID; /* PORT_UNOWNED ID */ jfieldID cpoPRID; /* PORT_OWNERSHIP_REQUESTED ID */ jint cpoPO; /* PORT_OWNED value */ jint cpoPU; /* PORT_UNOWNED value */ jint cpoPR; /* PORT_OWNERSHIP_REQUESTED value */ jmethodID jintMethod; jclass jthreadClass; int semID; union semuni scarg; int mypid = getpid(); int scpid; pollingTime = getPollingTime(jenv); /* Get the class ID of the CommPortIdentifier object.*/ jc = (*jenv)->GetObjectClass(jenv, jobj); assertexc(jc); /* Get the id of the method to report a change-ownership event. */ jm = (*jenv)->GetMethodID(jenv, jc, "fireOwnershipEvent", "(I)V"); assertexc(jm); /* Get the const values for the CommPortOwnershipListener events.*/ jcpoc = (*jenv)->FindClass(jenv, "javax/comm/CommPortOwnershipListener"); assertexc(jcpoc); cpoPOID = (*jenv)->GetStaticFieldID(jenv, jcpoc, "PORT_OWNED", "I"); assertexc(cpoPOID); cpoPO = (*jenv)->GetStaticIntField(jenv, jcpoc, cpoPOID); cpoPUID = (*jenv)->GetStaticFieldID(jenv, jcpoc, "PORT_UNOWNED", "I"); assertexc(cpoPUID); cpoPU = (*jenv)->GetStaticIntField(jenv, jcpoc, cpoPUID); cpoPRID = (*jenv)->GetStaticFieldID(jenv, jcpoc, "PORT_OWNERSHIP_REQUESTED", "I"); assertexc(cpoPRID); cpoPR = (*jenv)->GetStaticIntField(jenv, jcpoc, cpoPRID); /* Get the port name. */ pnameID = (*jenv)->GetFieldID(jenv, jc, "name", "Ljava/lang/String;"); assertexc(pnameID); pname = (*jenv)->GetObjectField(jenv, jobj, pnameID); assertexc(pname); pnamec = (*jenv)->GetStringUTFChars(jenv, pname, 0); /* Get the corresponding semaphore ID for the port name. */ semID = GetSemID(pnamec); (*jenv)->ReleaseStringUTFChars(jenv, pname, pnamec); if (semID == -1) return -1; /* Get access to the interrupted method. */ jthreadClass = (*jenv)->FindClass(jenv, "java/lang/Thread"); assertexc(jthreadClass); jintMethod = (*jenv)->GetMethodID(jenv, jthreadClass, "isInterrupted", "()Z"); assertexc(jintMethod); (void)memset(&scarg, 0, sizeof(scarg)); /* what is this for? */ /* Get the current value of the semaphore. */ #ifdef _POSIX_SEMAPHORES if ((sem_getvalue(sem_lookup(semID), &oldVal)) < 0) { #else if ((oldVal = semctl(semID, 0, GETVAL, scarg)) < 0) { #endif (void)fprintf(stderr, "Java_javax_comm_CommPortIdentifier_monitorInterJVMDeviceAccessNC: semctl error %d!\n", errno); return -1; } /* !!!!!!!!!!!!!! */ while(1) { /* Check to see if this thread has been interrupted. */ isInterruptedReturn = (*jenv)->CallBooleanMethod(jenv, jtho, jintMethod); if(isInterruptedReturn == JNI_TRUE) break; /* If the semaphore was locked the last time, wait until it gets unlocked. Else, catch some breath. */ #ifdef NCI if (oldVal) { #ifdef _POSIX_SEMAPHORES if(sem_wait(sem_lookup(semID)) <0){ #else if (semop(semID, dev_wait, NOOF_ELEMS(dev_wait)) < 0) { #endif (void)fprintf(stderr, "Java_javax_comm_CommPortIdentifier_monitorInterJVMDeviceAccessNC: semop error %d!\n", errno); return -1; } } else #endif /* NCI */ sleep(pollingTime); /* Get the new value of the semaphore. */ /* Get the current value of the semaphore. */ #ifdef _POSIX_SEMAPHORES if ((sem_getvalue(sem_lookup(semID), &oldVal)) < 0) { #else if ((oldVal = semctl(semID, 0, GETVAL, scarg)) < 0) { #endif (void)fprintf(stderr, "Java_javax_comm_CommPortIdentifier_monitorInterJVMDeviceAccessNC: semctl error %d!\n", errno); return -1; } if (newVal == oldVal) continue; /* Get PID of the last process that changed the semaphore. If it is the same JVM, ignore this change. */ /* Get the current value of the semaphore. */ #ifndef _POSIX_SEMAPHORES /* DLS HACK needs to be changed */ if ((scpid = semctl(semID, 0, GETPID, scarg)) < 0) { (void)fprintf(stderr, "Java_javax_comm_CommPortIdentifier_monitorInterJVMDeviceAccessNC: semctl error %d!\n", errno); return -1; } if (scpid != mypid) { /* If locked, send a PORT_OWNED event. Else, send a PORT_UNOWNED event. */ (*jenv)->CallVoidMethod(jenv, jobj, jm, newVal ? cpoPO : cpoPU); } #endif oldVal = newVal; } /* end of while() */ } /* Java_javax_comm_CommPortIdentifier_monitorInterJVMDeviceAccessNC */