00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #define INCL_DOSPROCESS
00013 #define INCL_DOSQUEUES
00014 #define INCL_DOSMEMMGR
00015 #define INCL_WINMESSAGEMGR
00016 #define INCL_DOSERRORS
00017 #define INCL_DOSSEMAPHORES
00018 #include <os2wrap.h>
00019
00020 #include <stdlib.h>
00021 #include <stddef.h>
00022 #include <string.h>
00023 #include <misc.h>
00024 #include <spy.h>
00025
00026 #define DBG_LOCALLOG DBG_spy
00027 #include "dbglocal.h"
00028
00029 #define Q_BUFFER_SIZE 4096
00030 #define MAX_MESSAGES (Q_BUFFER_SIZE/sizeof(Q_SPYMSG))
00031
00032 PID pidServer = 0;
00033 HQUEUE hqQueue = 0;
00034 Q_SPYMSG *pvdQMemory = 0;
00035 int msgIndex = 0;
00036
00037 BOOL InitSpyQueue()
00038 {
00039 APIRET rc;
00040
00041 if ((rc = DosOpenQueue(&pidServer, &hqQueue, "\\queues\\"Q_NAME)) != 0)
00042 {
00043 dprintf(("InitSpyQueue: couldn't open spy queue rc=%d!", rc));
00044 return FALSE;
00045 }
00046 if ((rc = DosAllocSharedMem((VOID **)&pvdQMemory,
00047 NULL,
00048 Q_BUFFER_SIZE,
00049 fALLOCSHR)) != 0)
00050 {
00051 dprintf(("InitSpyQueue: DosAllocSharedMem failed rc=%d", rc));
00052 DosCloseQueue(hqQueue);
00053 return FALSE;
00054 }
00055
00056
00057 if (DosGiveSharedMem(pvdQMemory, pidServer, PAG_READ | PAG_WRITE))
00058 {
00059 dprintf(("InitSpyQueue: DosGiveSharedMem failed"));
00060 DosCloseQueue(hqQueue);
00061 return FALSE;
00062 }
00063 return (TRUE);
00064 }
00065
00066 void CloseSpyQueue()
00067 {
00068 APIRET rc;
00069
00070 dprintf(("CloseSpyQueue"));
00071 if(hqQueue) {
00072 if(pvdQMemory) {
00073 rc = DosWriteQueue(hqQueue, Q_SPYMSG_KILLSERVER, 0, 0, 0);
00074 if(rc) {
00075 dprintf(("CloseSpyQueue: DosWriteQueue returned %d", rc));
00076 }
00077 }
00078 DosCloseQueue(hqQueue);
00079 }
00080 if(pvdQMemory)
00081 DosFreeMem(pvdQMemory);
00082 }
00083
00084 #ifdef DEBUG
00085 BOOL PostSpyMessage(HWND hwnd, ULONG Msg, ULONG wParam, ULONG lParam)
00086 {
00087 APIRET rc;
00088
00089 if (hqQueue == 0)
00090 return FALSE;
00091
00092 pvdQMemory[msgIndex].hwnd = hwnd;
00093 pvdQMemory[msgIndex].Msg = Msg;
00094 pvdQMemory[msgIndex].wParam = wParam;
00095 pvdQMemory[msgIndex].lParam = lParam;
00096
00097 if ((rc = DosWriteQueue(hqQueue,
00098 Q_SPYMSG_WNDMSG,
00099 sizeof(Q_SPYMSG),
00100 &pvdQMemory[msgIndex],
00101 0)) != 0)
00102 {
00103 hqQueue = 0;
00104 dprintf(("PostSpyMessage: DosWriteQueue returned %d", rc));
00105 return FALSE;
00106 }
00107 if(++msgIndex >= MAX_MESSAGES)
00108 {
00109 msgIndex = 0;
00110 }
00111 return TRUE;
00112 }
00113
00114 #endif