/** * copies a user supplied event message to a queue of messages * * @param binaryBuffer a pointer to binary event buffer to send * The platform should make a private copy of this buffer as * access to it is not allowed after the function call. * @param binaryBufferLen size of binary event buffer to send * @return <tt>JAVACALL_OK</tt> if an event successfully sent, * <tt>JAVACALL_FAIL</tt> or negative value if failed */ javacall_result javacall_event_send(unsigned char* binaryBuffer, int binaryBufferLen){ javacall_bool ok; if (!event_initialized) { javacall_events_init(); } ok=(binaryBuffer!=NULL) && (binaryBufferLen>0); if (ok) { ok=WaitForSingleObject(events_mutex, 500)==WAIT_OBJECT_0; } if (ok) { ok=(binaryBuffer!=NULL) && (binaryBufferLen>0); } if (ok) { enqueueEventMessage(binaryBuffer,binaryBufferLen); ok=ReleaseMutex(events_mutex); } if (ok) { ok=SetEvent(events_handle); } return ok?JAVACALL_OK:JAVACALL_FAIL; }
/** * Waits for an incoming event message and copies it to user supplied * data buffer * @param waitForever indicate if the function should block forever * @param timeTowaitInMillisec max number of seconds to wait * if waitForever is false * @param binaryBuffer user-supplied buffer to copy event to * @param binaryBufferMaxLen maximum buffer size that an event can be * copied to. * If an event exceeds the binaryBufferMaxLen, then the first * binaryBufferMaxLen bytes of the events will be copied * to user-supplied binaryBuffer, and JAVACALL_OUT_OF_MEMORY will * be returned * @param outEventLen user-supplied pointer to variable that will hold actual * event size received * Platform is responsible to set this value on success to the * size of the event received, or 0 on failure. * If outEventLen is NULL, the event size is not returned. * @return <tt>JAVACALL_OK</tt> if an event successfully received, * <tt>JAVACALL_FAIL</tt> or if failed or no messages are avaialable */ javacall_result javacall_event_receive( long timeTowaitInMillisec, /*OUT*/ unsigned char* binaryBuffer, /*IN*/ int binaryBufferMaxLen, /*OUT*/ int* outEventLen) { javacall_bool ok; int totalRead=0; if (!event_initialized) { javacall_events_init(); } ok=(binaryBuffer!=NULL) && (binaryBufferMaxLen>0); if (ok) { ok = WaitForSingleObject(events_mutex, 0)==WAIT_OBJECT_0; } if (ok) { totalRead = dequeueEventMessage(binaryBuffer,binaryBufferMaxLen); if (head == NULL) { ResetEvent(events_handle); } ok = ReleaseMutex(events_mutex); } ok= ok && (totalRead!=0); if (outEventLen!=NULL) { *outEventLen = ok ? totalRead : 0; } return ok ? JAVACALL_OK : JAVACALL_FAIL; }