bool CIrssMessage::FromBytes(char* from, int size, CIrssMessage& message) { if (!from) return false; if (size < 8) return false; //IRSS_MessageType type = (MessageType)BitConverter.ToInt32(from, 0); //IRSS_MessageFlags flags = (MessageFlags)BitConverter.ToInt32(from, 4); uint32_t type; memcpy(&type, from, 4); uint32_t flags; memcpy(&flags, from + 4, 4); message.SetType((IRSS_MessageType)type); message.SetFlags(flags); if (size > 8) { message.SetDataAsBytes(from + 8, size - 8); } return true; }
void CRemoteControl::Update() { if ((!m_bInitialized && !m_isConnecting) || (m_socket == INVALID_SOCKET)) { return; } CIrssMessage mess; if (!ReadPacket(mess)) { return; } switch (mess.GetType()) { case IRSSMT_RegisterClient: m_isConnecting = false; if ((mess.GetFlags() & IRSSMF_Success) != IRSSMF_Success) { //uh oh, it failed to register Close(); CLog::Log(LOGERROR, "IRServerSuite: failed to register XBMC as a client."); } else { m_bInitialized = true; //request info about receivers CIrssMessage mess(IRSSMT_DetectedReceivers, IRSSMF_Request); if (!SendPacket(mess)) { CLog::Log(LOGERROR, "IRServerSuite: failed to send AvailableReceivers packet."); } mess.SetType(IRSSMT_AvailableReceivers); if (!SendPacket(mess)) { CLog::Log(LOGERROR, "IRServerSuite: failed to send AvailableReceivers packet."); } mess.SetType(IRSSMT_ActiveReceivers); if (!SendPacket(mess)) { CLog::Log(LOGERROR, "IRServerSuite: failed to send AvailableReceivers packet."); } } break; case IRSSMT_RemoteEvent: HandleRemoteEvent(mess); break; case IRSSMT_Error: //I suppose the errormessage is in the packet somewhere... CLog::Log(LOGERROR, "IRServerSuite: we got an error message."); break; case IRSSMT_ServerShutdown: Close(); break; case IRSSMT_ServerSuspend: //should we do something? break; case IRSSMT_ServerResume: //should we do something? break; case IRSSMT_AvailableReceivers: { uint32_t size = mess.GetDataSize(); if (size > 0) { char* data = mess.GetData(); char* availablereceivers = new char[size + 1]; memcpy(availablereceivers, data, size); availablereceivers[size] = '\0'; CLog::Log(LOGINFO, "IRServerSuite: Available receivers: %s", availablereceivers); delete[] availablereceivers; } } break; case IRSSMT_DetectedReceivers: { uint32_t size = mess.GetDataSize(); if (size > 0) { char* data = mess.GetData(); char* detectedreceivers = new char[size + 1]; memcpy(detectedreceivers, data, size); detectedreceivers[size] = '\0'; CLog::Log(LOGINFO, "IRServerSuite: Detected receivers: %s", detectedreceivers); delete[] detectedreceivers; } } break; case IRSSMT_ActiveReceivers: { uint32_t size = mess.GetDataSize(); if (size > 0) { char* data = mess.GetData(); char* activereceivers = new char[size + 1]; memcpy(activereceivers, data, size); activereceivers[size] = '\0'; CLog::Log(LOGINFO, "IRServerSuite: Active receivers: %s", activereceivers); delete[] activereceivers; } } break; } }