< prev index next >

src/jdk.accessibility/windows/native/libjavaaccessbridge/AccessBridgeATInstance.cpp

Print this page




  36 
  37 
  38 /**
  39  *  AccessBridgeATInstance constructor
  40  */
  41 AccessBridgeATInstance::AccessBridgeATInstance(HWND ourABWindow, HWND winABWindow,
  42                                                char *memoryFilename,
  43                                                AccessBridgeATInstance *next) {
  44     ourAccessBridgeWindow = ourABWindow;
  45     winAccessBridgeWindow = winABWindow;
  46     nextATInstance = next;
  47     javaEventMask = 0;
  48     accessibilityEventMask = 0;
  49     strncpy(memoryMappedFileName, memoryFilename, cMemoryMappedNameSize);
  50 }
  51 
  52 /**
  53  * AccessBridgeATInstance descructor
  54  */
  55 AccessBridgeATInstance::~AccessBridgeATInstance() {
  56     PrintDebugString("\r\nin AccessBridgeATInstance::~AccessBridgeATInstance");
  57 
  58     // if IPC memory mapped file view is valid, unmap it
  59     if (memoryMappedView != (char *) 0) {
  60         PrintDebugString("  unmapping memoryMappedView; view = %p", memoryMappedView);
  61         UnmapViewOfFile(memoryMappedView);
  62         memoryMappedView = (char *) 0;
  63     }
  64     // if IPC memory mapped file handle map is open, close it
  65     if (memoryMappedFileMapHandle != (HANDLE) 0) {
  66         PrintDebugString("  closing memoryMappedFileMapHandle; handle = %p", memoryMappedFileMapHandle);
  67         CloseHandle(memoryMappedFileMapHandle);
  68         memoryMappedFileMapHandle = (HANDLE) 0;
  69     }
  70 }
  71 
  72 /**
  73  * Sets up the memory-mapped file to do IPC messaging
  74  * 1 files is created: to handle requests for information
  75  * initiated from Windows AT.  The package is placed into
  76  * the memory-mapped file (char *memoryMappedView),
  77  * and then a special SendMessage() is sent.  When the
  78  * JavaDLL returns from SendMessage() processing, the
  79  * data will be in memoryMappedView.  The SendMessage()
  80  * return value tells us if all is right with the world.
  81  *
  82  * The set-up proces involves creating the memory-mapped
  83  * file, and writing a special string to it so that the
  84  * WindowsDLL so it knows about it as well.
  85  */
  86 LRESULT
  87 AccessBridgeATInstance::initiateIPC() {
  88     DWORD errorCode;
  89 
  90     PrintDebugString("\r\nIn AccessBridgeATInstance::initiateIPC()");
  91 
  92     // open Windows-initiated IPC filemap & map it to a ptr
  93 
  94     memoryMappedFileMapHandle = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,
  95                                                 FALSE, memoryMappedFileName);
  96     if (memoryMappedFileMapHandle == NULL) {
  97         errorCode = GetLastError();
  98         PrintDebugString("  Failed to CreateFileMapping for %s, error: %X", memoryMappedFileName, errorCode);
  99         return errorCode;
 100     } else {
 101         PrintDebugString("  CreateFileMapping worked - filename: %s", memoryMappedFileName);
 102     }
 103 
 104     memoryMappedView = (char *) MapViewOfFile(memoryMappedFileMapHandle,
 105                                               FILE_MAP_READ | FILE_MAP_WRITE,
 106                                               0, 0, 0);
 107     if (memoryMappedView == NULL) {
 108         errorCode = GetLastError();
 109         PrintDebugString("  Failed to MapViewOfFile for %s, error: %X", memoryMappedFileName, errorCode);
 110         return errorCode;
 111     } else {
 112         PrintDebugString("  MapViewOfFile worked - view: %p", memoryMappedView);
 113     }
 114 
 115 
 116     // look for the JavaDLL's answer to see if it could read the file
 117     if (strcmp(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_QUERY) != 0) {
 118         PrintDebugString("  JavaVM failed to write to memory mapped file %s",
 119                          memoryMappedFileName);
 120         return -1;
 121     } else {
 122         PrintDebugString("  JavaVM successfully wrote to file!");
 123     }
 124 
 125 
 126     // write some data to the memory mapped file for WindowsDLL to verify
 127     strcpy(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_ANSWER);
 128 
 129 
 130     return 0;
 131 }
 132 
 133 
 134 typedef struct EVENT_STRUCT
 135 {
 136     char *buffer;
 137     int bufsize;
 138     ABHWND64 winAccessBridgeWindow;
 139     ABHWND64 ourAccessBridgeWindow;
 140 }EVENT_STRUCT;
 141 
 142 


 196     event_struct->ourAccessBridgeWindow = ABHandleToLong(ourAccessBridgeWindow);
 197     event_struct->winAccessBridgeWindow = ABHandleToLong(winAccessBridgeWindow);
 198     if(!JavaBridgeThreadId)
 199         {
 200             HANDLE JavaBridgeThreadHandle = BeginThread(JavaBridgeThread,&JavaBridgeThreadId,(DWORD)event_struct);
 201             CloseHandle(JavaBridgeThreadHandle);
 202         }
 203     PostThreadMessage(JavaBridgeThreadId,WM_USER,(WPARAM)event_struct,0);
 204 }
 205 
 206 
 207 /**
 208  * sendJavaEventPackage - uses SendMessage(WM_COPYDATA) to do
 209  *                        IPC messaging with the Java AccessBridge DLL
 210  *                        to propogate events to those ATs that want 'em
 211  *
 212  */
 213 LRESULT
 214 AccessBridgeATInstance::sendJavaEventPackage(char *buffer, int bufsize, long eventID) {
 215 
 216     PrintDebugString("AccessBridgeATInstance::sendJavaEventPackage() eventID = %X", eventID);
 217     PrintDebugString("AccessBridgeATInstance::sendJavaEventPackage() (using PostMessage) eventID = %X", eventID);
 218 
 219     if (eventID & javaEventMask) {
 220         do_event(buffer,bufsize,ourAccessBridgeWindow,winAccessBridgeWindow);
 221         return(0);
 222     } else {
 223         return -1;
 224     }
 225 }
 226 
 227 
 228 /**
 229  * uses SendMessage(WM_COPYDATA) to do
 230  * IPC messaging with the Java AccessBridge DLL
 231  * to propogate events to those ATs that want 'em
 232  *
 233  */
 234 LRESULT
 235 AccessBridgeATInstance::sendAccessibilityEventPackage(char *buffer, int bufsize, long eventID) {
 236 
 237     PrintDebugString("AccessBridgeATInstance::sendAccessibilityEventPackage() eventID = %X", eventID);
 238 
 239     if (eventID & accessibilityEventMask) {
 240         do_event(buffer,bufsize,ourAccessBridgeWindow,winAccessBridgeWindow);
 241         return(0);
 242     } else {
 243         return -1;
 244     }
 245 }
 246 
 247 
 248 /**
 249  * findABATInstanceFromATHWND - walk through linked list from
 250  *                              where we are.  Return the
 251  *                              AccessBridgeATInstance
 252  *                              of the ABATInstance that
 253  *                              matches the passed in vmID;
 254  *                              no match: return 0
 255  */
 256 AccessBridgeATInstance *
 257 AccessBridgeATInstance::findABATInstanceFromATHWND(HWND window) {


  36 
  37 
  38 /**
  39  *  AccessBridgeATInstance constructor
  40  */
  41 AccessBridgeATInstance::AccessBridgeATInstance(HWND ourABWindow, HWND winABWindow,
  42                                                char *memoryFilename,
  43                                                AccessBridgeATInstance *next) {
  44     ourAccessBridgeWindow = ourABWindow;
  45     winAccessBridgeWindow = winABWindow;
  46     nextATInstance = next;
  47     javaEventMask = 0;
  48     accessibilityEventMask = 0;
  49     strncpy(memoryMappedFileName, memoryFilename, cMemoryMappedNameSize);
  50 }
  51 
  52 /**
  53  * AccessBridgeATInstance descructor
  54  */
  55 AccessBridgeATInstance::~AccessBridgeATInstance() {
  56     PrintDebugString("[INFO]: in AccessBridgeATInstance::~AccessBridgeATInstance");
  57 
  58     // if IPC memory mapped file view is valid, unmap it
  59     if (memoryMappedView != (char *) 0) {
  60         PrintDebugString("[INFO]:   unmapping memoryMappedView; view = %p", memoryMappedView);
  61         UnmapViewOfFile(memoryMappedView);
  62         memoryMappedView = (char *) 0;
  63     }
  64     // if IPC memory mapped file handle map is open, close it
  65     if (memoryMappedFileMapHandle != (HANDLE) 0) {
  66         PrintDebugString("[INFO]:   closing memoryMappedFileMapHandle; handle = %p", memoryMappedFileMapHandle);
  67         CloseHandle(memoryMappedFileMapHandle);
  68         memoryMappedFileMapHandle = (HANDLE) 0;
  69     }
  70 }
  71 
  72 /**
  73  * Sets up the memory-mapped file to do IPC messaging
  74  * 1 files is created: to handle requests for information
  75  * initiated from Windows AT.  The package is placed into
  76  * the memory-mapped file (char *memoryMappedView),
  77  * and then a special SendMessage() is sent.  When the
  78  * JavaDLL returns from SendMessage() processing, the
  79  * data will be in memoryMappedView.  The SendMessage()
  80  * return value tells us if all is right with the world.
  81  *
  82  * The set-up proces involves creating the memory-mapped
  83  * file, and writing a special string to it so that the
  84  * WindowsDLL so it knows about it as well.
  85  */
  86 LRESULT
  87 AccessBridgeATInstance::initiateIPC() {
  88     DWORD errorCode;
  89 
  90     PrintDebugString("[INFO]: In AccessBridgeATInstance::initiateIPC()");
  91 
  92     // open Windows-initiated IPC filemap & map it to a ptr
  93 
  94     memoryMappedFileMapHandle = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,
  95                                                 FALSE, memoryMappedFileName);
  96     if (memoryMappedFileMapHandle == NULL) {
  97         errorCode = GetLastError();
  98         PrintDebugString("[ERROR]:   Failed to CreateFileMapping for %s, error: %X", memoryMappedFileName, errorCode);
  99         return errorCode;
 100     } else {
 101         PrintDebugString("[INFO]:   CreateFileMapping worked - filename: %s", memoryMappedFileName);
 102     }
 103 
 104     memoryMappedView = (char *) MapViewOfFile(memoryMappedFileMapHandle,
 105                                               FILE_MAP_READ | FILE_MAP_WRITE,
 106                                               0, 0, 0);
 107     if (memoryMappedView == NULL) {
 108         errorCode = GetLastError();
 109         PrintDebugString("[ERROR]:   Failed to MapViewOfFile for %s, error: %X", memoryMappedFileName, errorCode);
 110         return errorCode;
 111     } else {
 112         PrintDebugString("[INFO]:   MapViewOfFile worked - view: %p", memoryMappedView);
 113     }
 114 
 115 
 116     // look for the JavaDLL's answer to see if it could read the file
 117     if (strcmp(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_QUERY) != 0) {
 118         PrintDebugString("[ERROR]:   JavaVM failed to write to memory mapped file %s",
 119                          memoryMappedFileName);
 120         return -1;
 121     } else {
 122         PrintDebugString("[INFO]:   JavaVM successfully wrote to file!");
 123     }
 124 
 125 
 126     // write some data to the memory mapped file for WindowsDLL to verify
 127     strcpy(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_ANSWER);
 128 
 129 
 130     return 0;
 131 }
 132 
 133 
 134 typedef struct EVENT_STRUCT
 135 {
 136     char *buffer;
 137     int bufsize;
 138     ABHWND64 winAccessBridgeWindow;
 139     ABHWND64 ourAccessBridgeWindow;
 140 }EVENT_STRUCT;
 141 
 142 


 196     event_struct->ourAccessBridgeWindow = ABHandleToLong(ourAccessBridgeWindow);
 197     event_struct->winAccessBridgeWindow = ABHandleToLong(winAccessBridgeWindow);
 198     if(!JavaBridgeThreadId)
 199         {
 200             HANDLE JavaBridgeThreadHandle = BeginThread(JavaBridgeThread,&JavaBridgeThreadId,(DWORD)event_struct);
 201             CloseHandle(JavaBridgeThreadHandle);
 202         }
 203     PostThreadMessage(JavaBridgeThreadId,WM_USER,(WPARAM)event_struct,0);
 204 }
 205 
 206 
 207 /**
 208  * sendJavaEventPackage - uses SendMessage(WM_COPYDATA) to do
 209  *                        IPC messaging with the Java AccessBridge DLL
 210  *                        to propogate events to those ATs that want 'em
 211  *
 212  */
 213 LRESULT
 214 AccessBridgeATInstance::sendJavaEventPackage(char *buffer, int bufsize, long eventID) {
 215 
 216     PrintDebugString("[INFO]: AccessBridgeATInstance::sendJavaEventPackage() eventID = %X", eventID);
 217     PrintDebugString("[INFO]: AccessBridgeATInstance::sendJavaEventPackage() (using PostMessage) eventID = %X", eventID);
 218 
 219     if (eventID & javaEventMask) {
 220         do_event(buffer,bufsize,ourAccessBridgeWindow,winAccessBridgeWindow);
 221         return(0);
 222     } else {
 223         return -1;
 224     }
 225 }
 226 
 227 
 228 /**
 229  * uses SendMessage(WM_COPYDATA) to do
 230  * IPC messaging with the Java AccessBridge DLL
 231  * to propogate events to those ATs that want 'em
 232  *
 233  */
 234 LRESULT
 235 AccessBridgeATInstance::sendAccessibilityEventPackage(char *buffer, int bufsize, long eventID) {
 236 
 237     PrintDebugString("[INFO]: AccessBridgeATInstance::sendAccessibilityEventPackage() eventID = %X", eventID);
 238 
 239     if (eventID & accessibilityEventMask) {
 240         do_event(buffer,bufsize,ourAccessBridgeWindow,winAccessBridgeWindow);
 241         return(0);
 242     } else {
 243         return -1;
 244     }
 245 }
 246 
 247 
 248 /**
 249  * findABATInstanceFromATHWND - walk through linked list from
 250  *                              where we are.  Return the
 251  *                              AccessBridgeATInstance
 252  *                              of the ABATInstance that
 253  *                              matches the passed in vmID;
 254  *                              no match: return 0
 255  */
 256 AccessBridgeATInstance *
 257 AccessBridgeATInstance::findABATInstanceFromATHWND(HWND window) {
< prev index next >