• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

E:/PROJECTS/cvsed/mixed/VIRTUA~1/rpcdispatch/kdcomdisp.h

Go to the documentation of this file.
00001 
00007 #pragma once
00008 #include "pipesrv.h"
00009 #include "trassist.h"
00010 #include "PacketLog.h"
00011 
00012 #ifdef _DEBUG
00013 static const int KdTraceEnabled = 1;
00014 #else
00015 static const int KdTraceEnabled = 0;
00016 #endif
00017 
00019 
00024 class KdComDispatcher : public IKdComDispatcher
00025 {
00026 private:
00027         PipeServer<false, true, true> m_Pipe;
00028 
00029         unsigned KdCompNumberRetries;
00030         unsigned KdCompRetryCount;
00031 
00032         unsigned KdCompNextPacketIdToSend;
00033         unsigned KdCompPacketIdExpected;
00034 
00035         bool KD_DEBUGGER_NOT_PRESENT;
00036 
00037         enum {KdMaxBufferSize = 0xFA0};
00038 
00039         //The following members are used in synchronization bug workaround
00040         enum {KdMinPacketCountForSuccessfulLink = 5};
00041 
00042         unsigned m_PacketsSentFromLastReset;
00043         unsigned m_PacketsGotFromLastReset;
00044         
00045         unsigned m_SequentialResetCount;
00046 
00047         TraceAssistant m_TraceAssistant;
00048 
00049         PacketLogger m_PacketLogger;
00050 
00051 public:
00052         KdComDispatcher(const TCHAR *pszPipeName)
00053                 : m_Pipe(pszPipeName, 1000)
00054                 , m_PacketLogger(pszPipeName)
00055                 , KdCompNumberRetries(0)
00056                 , KdCompRetryCount(10)
00057                 , m_SequentialResetCount(0)
00058                 , m_TraceAssistant(pszPipeName)
00059         {
00060                 KdResetPacketNumbering(true);
00061                 m_TraceAssistant.ReloadParams();
00062         }
00063 
00065         void KdResetPacketNumbering(bool InitialSetting)
00066         {
00067           KdCompNextPacketIdToSend = InitialSetting ? 0x80800800 : 0x80800000;
00068       KdCompPacketIdExpected = 0x80800000;
00069           m_PacketsSentFromLastReset = m_PacketsGotFromLastReset = 0;
00070         }
00071 
00072         void SetKdDebuggerNotPresent(bool Value)
00073         {
00074                 KD_DEBUGGER_NOT_PRESENT = Value;
00075         }
00076 
00077         bool GetKdDebuggerNotPresent()
00078         {
00079                 return KD_DEBUGGER_NOT_PRESENT;
00080         }
00081 
00083         void KdpSendControlPacket(ULONG PacketType, ULONG NextPacketId);
00084 
00085         KD_RECV_CODE KdCompReceivePacketLeader(ULONG /*PacketType*/,
00086                                                                                    ULONG *pSignature,
00087                                                                                    PKD_CONTEXT pContext);
00088 
00090         unsigned KdpComputeChecksum(const void *pBuffer, unsigned Size)
00091         {
00092                 unsigned char *p = (unsigned char *)pBuffer;
00093                 unsigned sum = 0;
00094                 for (unsigned i = 0; i < Size; i++)
00095                         sum += p[i];
00096                 return sum;
00097         }
00098 
00100         KD_RECV_CODE __stdcall KdReceivePacket(ULONG PacketType,
00101                                                                                    PKD_BUFFER FirstBuffer,
00102                                                                                    PKD_BUFFER SecondBuffer,
00103                                                                                    PULONG PayloadBytes,
00104                                                                                    PKD_CONTEXT KdContext);
00105 
00107         bool __stdcall  KdSendPacket(ULONG PacketType,
00108                                                                  PKD_BUFFER FirstBuffer,
00109                                                                  PKD_BUFFER SecondBuffer,
00110                                                                  PKD_CONTEXT KdContext);
00111         
00113         virtual void ReportProtocolVersionError(int GuestVersion, int HostVersion);
00114 
00115 
00117         void SimulateWindowsTermination();
00118 
00119         ~KdComDispatcher()
00120         {
00121                 SimulateWindowsTermination();
00122         }
00123 };