BOOL CMsgPoolBuffer::ReadMsg(TRawMsg *msg, I32 buff_size) { if (m_pReadLock) m_pReadLock->Lock(); I32 len = buff_size - sizeof(TRawMsg); //read header BOOL bResult = ReadData(MSG_HEADER(msg), MSG_HEADER_LEN); if (bResult) { if (msg->len > 0) { // read parameter if (msg->len <= len) bResult = ReadData(MSG_PARAM(msg), msg->len); else { ReadData(NULL, msg->len); bResult = FALSE; } } } if (m_pReadLock) m_pReadLock->Unlock(); return bResult; }
JzMsg *jz_msg_new_restart_confirmation () { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER (self); self->id = JZ_MSG_RESTART_CONFIRMATION; MSG_ERROR_CHECK(self); return self; }
JzMsg *jz_msg_new_reset_confirmation (guint16 lcn) { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER(self); self->id = JZ_MSG_RESET_CONFIRMATION; self->lcn = lcn; MSG_ERROR_CHECK(self); return self; }
JzMsg *jz_msg_new_rnr (guint16 lcn, guint16 pr) { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER(self); self->id = JZ_MSG_RNR; self->lcn = lcn; self->pr = pr; return self; }
JzMsg * jz_msg_new_disconnect_indication () { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER(self); self->id = JZ_MSG_DISCONNECT_INDICATION; MSG_ERROR_CHECK(self); return self; }
JzMsg * jz_msg_new_disconnect () { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER(self); self->id = JZ_MSG_DISCONNECT; MSG_ERROR_CHECK(self); return self; }
JzMsg *jz_msg_new_restart_request (restart_cause_t cause, diag_t diagnostic) { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER (self); self->id = JZ_MSG_RESTART_REQUEST; self->cause = cause; self->diagnostic = diagnostic; MSG_ERROR_CHECK(self); return self; }
JzMsg *jz_msg_new_reset_request (guint16 lcn, reset_cause_t cause, diag_t diagnostic) { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER(self); self->id = JZ_MSG_RESET_REQUEST; self->lcn = lcn; self->cause = cause; self->diagnostic = diagnostic; MSG_ERROR_CHECK(self); return self; }
JzMsg * jz_msg_new_connect (gchar *calling_address, guint8 iodir) { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER(self); self->id = JZ_MSG_CONNECT; self->calling_address = g_strdup (calling_address); self->iodir = iodir; MSG_ERROR_CHECK(self); return self; }
JzMsg * jz_msg_new_diagnostic (diag_t diagnostic, guint8 version, guint8 id, guint16 lcn) { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER(self); self->id = JZ_MSG_DIAGNOSTIC; self->diagnostic = diagnostic; self->diagnostic_version = version; self->diagnostic_id = id; self->diagnostic_lcn = lcn; MSG_ERROR_CHECK(self); return self; }
JzMsg * jz_msg_new_data (guint16 lcn, guint8 q, guint16 pr, guint16 ps, guint8 *data, gsize len) { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER(self); self->id = JZ_MSG_DATA; self->lcn = lcn; self->q = q; self->pr = pr; self->ps = ps; self->data = g_byte_array_new_take (data, len); MSG_ERROR_CHECK(self); g_byte_array_ref (self->data); return self; }
JzMsg * jz_msg_new_call_accepted (guint16 lcn, gchar *calling_address, gchar *called_address, packet_t packet, guint16 window, tput_t throughput, guint8 *data, gsize len) { JzMsg *self = g_new0(JzMsg, 1); MSG_HEADER (self); self->id = JZ_MSG_CALL_ACCEPTED; self->lcn = lcn; self->calling_address = g_strdup (calling_address); self->called_address = g_strdup (called_address); self->packet = packet; self->window = window; self->throughput = throughput; self->data = g_byte_array_new_take (data, len); MSG_ERROR_CHECK(self); return self; }
BOOL CMsgPoolFile::ReadMsg(TRawMsg *msg, I32 buff_size) { if (m_fileOut == INVALID_FILE_HANDLE) return FALSE; if (m_pReadLock) m_pReadLock->Lock(); I32 len = buff_size - sizeof(TRawMsg); //read header BOOL bResult = (MSG_HEADER_LEN == OSReadFile(m_fileOut, MSG_HEADER(msg), MSG_HEADER_LEN)); if (bResult) { if (msg->len > 0) { // read parameter if (msg->len <= len) { bResult = (msg->len == OSReadFile(m_fileOut, MSG_PARAM(msg), msg->len)); } else { OSReadFile(m_fileOut, NULL, msg->len); bResult = FALSE; } } } if (m_pReadLock) m_pReadLock->Unlock(); return bResult; }