//============================================================================ // handleMessageRecieved //============================================================================ public void handleMessageRecieved(string messageID, object objData) { //THIS SHOULD BE BACK ON THE UI THREAD! PacketWrapper packet = (PacketWrapper)objData; IEnumerable <IDockContent> documents = dockPanel.Documents; foreach (DockContent c in documents) { if (c is ITcpServerListener) { ((ITcpServerListener)c).onMessageRecieved(packet); } } }
//============================================================================ // onMessageRecieved //============================================================================ public void onMessageRecieved(PacketWrapper packet) { ThreadSafeCallbackList.MessagePacket pak = new ThreadSafeCallbackList.MessagePacket(); pak.mCallback = this.handleMessageRecieved; pak.mDataObject = packet; pak.mMessageID = "packet"; if (GlobalSettings.PlaybackSpeed != GlobalSettings.ePlaybackSpeeds.eASAP) { //spinloop here while we're waiting for commands to be processed.. while (mMessageCallbackList.Count() > 1024) { if (!AllocLogStream.isProcessing()) { break; } // Thread.Sleep(1000); } } mMessageCallbackList.enqueueMessage(pak); }
//============================================================================ // addListener //============================================================================ private static void recieveProcessPacket(byte[] header, byte packetType, int packetSize, ref byte[] packetData) { PacketWrapper pkt = new PacketWrapper(); pkt.mPacketType = packetType; pkt.mPacketSize = packetSize; pkt.mPacketData = null; if (packetSize != 0) { pkt.mPacketData = new byte[packetSize]; packetData.CopyTo(pkt.mPacketData, 0); } if (((HaloWarsMem.eALPacketType)packetType) == HaloWarsMem.eALPacketType.cALEOF) { stopProcessing(); } for (int i = 0; i < mListeners.Count; i++) { mListeners[i].onMessageRecieved(pkt); } //whatever the stream is, log it out so we can use the 'save' commands properly. mBinaryWriter.Write(header, 0, 4); if (packetData != null) { mBinaryWriter.Write(packetData, 0, packetSize); } }
//============================================================================ // onMessageRecieved //============================================================================ public void onMessageRecieved(PacketWrapper packet) { HaloWarsMem.eALPacketType type = (HaloWarsMem.eALPacketType)packet.mPacketType; switch (type) { //================================================ case HaloWarsMem.eALPacketType.cALNew: { HaloWarsMem.BALPacketNew pkt = new HaloWarsMem.BALPacketNew(packet.mPacketSize, packet.mPacketData); HeapAlloc pHeap = AllocStats.getHeapFromBasePtr(pkt.mpHeap); if (pHeap == null) { return; } pHeap.allocMem(pkt.mSize, pkt.mpBlock, pkt.mBlockSize, pkt.mContext); //pass on mFileGroupings.onNew(pkt.mpHeap, pkt.mSize, pkt.mpBlock, pkt.mBlockSize, pkt.mContext); break; } //================================================ case HaloWarsMem.eALPacketType.cALResize: { HaloWarsMem.BALPacketResize pkt = new HaloWarsMem.BALPacketResize(packet.mPacketSize, packet.mPacketData); HeapAlloc pHeap = AllocStats.getHeapFromBasePtr(pkt.mpHeap); if (pHeap == null) { return; } //pass on mFileGroupings.onResize(pkt.mpHeap, pkt.mpOrigBlock, pkt.mNewSize, pkt.mpNewBlock, pkt.mContext); //this needs to be done last pHeap.resizeMem(pkt.mpOrigBlock, pkt.mNewSize, pkt.mpNewBlock, pkt.mContext); break; } //================================================ case HaloWarsMem.eALPacketType.cALDelete: { HaloWarsMem.BALPacketDelete pkt = new HaloWarsMem.BALPacketDelete(packet.mPacketSize, packet.mPacketData); HeapAlloc pHeap = AllocStats.getHeapFromBasePtr(pkt.mpHeap); if (pHeap == null) { return; } //pass on mFileGroupings.onDelete(pkt.mpHeap, pkt.mpBlock, pkt.mContext); //need to pass on before deletion to ensure any queries occur pHeap.deleteMem(pkt.mpBlock, pkt.mContext); break; } //================================================ case HaloWarsMem.eALPacketType.cALRegisterHeap: { HaloWarsMem.BALPacketRegisterHeap pkt = new HaloWarsMem.BALPacketRegisterHeap(packet.mPacketSize, packet.mPacketData); AllocStats.registerHeap(pkt); //propagate to those that care.. heapLines.onHeapRegister(pkt.mPtr, pkt.mFlags, pkt.mName); heapFileView.onHeapRegister(pkt.mPtr, pkt.mFlags, pkt.mName); break; } //================================================ case HaloWarsMem.eALPacketType.cALIgnoreLeaf: { HaloWarsMem.BALPacketIgnoreLeaf pkt = new HaloWarsMem.BALPacketIgnoreLeaf(packet.mPacketSize, packet.mPacketData); HaloWarsMem.getSymbolInfo().addIgnoreSymbol(pkt.mSymbolName); break; } case HaloWarsMem.eALPacketType.cALEOF: { heapLines.onDisconnect(); heapKey.onDisconnect(); topAllocs.onDisconnect(); heapFileView.onDisconnect(); mFileTimelines.onDisconnect(); mFileGroupings.onDisconnect(); break; } } ; }