static void CALLBACK midi_callback(HMIDIIN handle, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { int len; int i; switch (uMsg) { case MIM_DATA: #ifdef DEBUG log_message(mididrv_log, "MIDI callback got %08x", dwParam1); #endif len = message_len((BYTE)(dwParam1 & 0xff)); for (i = 0; i < len; i++) { write_fifo((BYTE)(dwParam1 & 0xff)); dwParam1 >>= 8; } break; case MIM_LONGDATA: break; case MIM_OPEN: case MIM_CLOSE: case MIM_ERROR: case MIM_LONGERROR: case MIM_MOREDATA: break; default: break; } }
/* sends a byte to MIDI-Out */ void mididrv_out(BYTE b) { MMRESULT ret; int thres; #ifdef DEBUG log_message(mididrv_log, "out %02x", b); #endif out_buf[out_index] = b; out_index++; if (out_index > OUT_BUF_LEN) { out_index = 0; log_error(mididrv_log, "MIDI-Out overrun."); } thres = message_len(out_buf[0]); /* flush when enough bytes have been queued */ if (out_index >= thres) { DWORD data; out_index = 0; data = out_buf[0] | (out_buf[1] << 8) | (out_buf[2] << 16); #ifdef DEBUG log_message(mididrv_log, "flushing out %06x", data); #endif ret = midiOutShortMsg(handle_out, data); if (ret != MMSYSERR_NOERROR) { log_error(mididrv_log, "Failed to output data on MIDI-Out device."); } } return; }
int clSocketBase::ReadMessage(wxString& message, int timeout) throw (clSocketException) { size_t message_len(0); size_t bytesRead(0); int rc = Read( (char*)&message_len, sizeof(message_len), bytesRead, timeout); if ( rc != kSuccess ) { // timeout return rc; } bytesRead = 0; char *buff = new char[message_len+1]; memset(buff, 0, message_len+1); rc = Read(buff, message_len, bytesRead, timeout); if ( rc != kSuccess ) { wxDELETEA( buff ); return rc; } if ( bytesRead == 0 ) { // session was closed wxDELETEA( buff ); throw clSocketException("connection closed by peer"); } else if ( bytesRead != message_len ) { wxDELETEA( buff ); throw clSocketException("Wrong message length received"); } buff[message_len] = '\0'; message = buff; return kSuccess; }
/** * Function to send a message to the destination queue. * @param source_queue The enum for the message source (The enum matches with * the integer value). * @param dest_queue The enum for the message destination (The enum matches * with the integer value). * @param message_string The string message to be sent. * @return Returns an error code according to ipc_definitions.h. */ int send(enum MESSAGE_QUEUES source_queue, enum MESSAGE_QUEUES dest_queue, char* message_string){ if (source_queue == dest_queue) { return ERROR_SEND_TO_SELF; } if (message_len(message_string) == ERROR_MAX_STRING_LENGTH){ return ERROR_MAX_STRING_LENGTH; } /*Returns queue full, source/destination queue not exist*/ return enqueue(source_queue, dest_queue, message_string); }
int clSocketBase::ReadMessage(wxString& message, int timeout) throw(clSocketException) { // send the length in string form to avoid binary / arch differences between remote and local machine char msglen[11]; memset(msglen, 0, sizeof(msglen)); size_t message_len(0); size_t bytesRead(0); int rc = Read((char*)msglen, sizeof(msglen) - 1, bytesRead, timeout); if(rc != kSuccess) { // timeout return rc; } // convert the string to int message_len = ::atoi(msglen); bytesRead = 0; char* buff = new char[message_len + 1]; memset(buff, 0, message_len + 1); // read the entire amount we need int bytesLeft = message_len; int totalRead = 0; while(bytesLeft > 0) { rc = Read(buff + totalRead, bytesLeft, bytesRead, timeout); if(rc != kSuccess) { wxDELETEA(buff); return rc; } else if(rc == 0) { // session was closed wxDELETEA(buff); throw clSocketException("connection closed by peer"); } else { bytesLeft -= bytesRead; totalRead += bytesRead; bytesRead = 0; } } buff[message_len] = '\0'; message = buff; return kSuccess; }
int clSocketBase::ReadMessage(wxString& message, int timeout) { // send the length in string form to avoid binary / arch differences between remote and local machine char msglen[11]; memset(msglen, 0, sizeof(msglen)); size_t message_len(0); size_t bytesRead(0); int rc = Read((char*)msglen, sizeof(msglen) - 1, bytesRead, timeout); if(rc != kSuccess) { // timeout return rc; } // convert the string to int message_len = ::atoi(msglen); bytesRead = 0; std::unique_ptr<char> pBuff(new char[message_len]); // read the entire amount we need int bytesLeft = message_len; int totalRead = 0; while(bytesLeft > 0) { rc = Read(pBuff.get() + totalRead, bytesLeft, bytesRead, timeout); if(rc != kSuccess) { return rc; } else { bytesLeft -= bytesRead; totalRead += bytesRead; bytesRead = 0; } } message.assign(pBuff.get(), message_len); return kSuccess; }