ipcs.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <precomp.h>
  2. #ifdef WASABI_API_COMPONENT
  3. #include <api/wac/main.h> //CUT!!!
  4. #endif
  5. #include "ipcs.h"
  6. #ifdef LINUX
  7. #include <api/linux/linuxapi.h>
  8. #endif
  9. using namespace IpcsCommand;
  10. #ifdef WIN32
  11. IpcsPtr::IpcsPtr(HWND h) {
  12. hwnd = h;
  13. }
  14. #else
  15. IpcsPtr::IpcsPtr(int q) {
  16. qid = q;
  17. }
  18. #endif
  19. void IpcsPtr::moveToForeground() {
  20. #ifdef WIN32
  21. if (IsIconic(hwnd)) ShowWindow(hwnd, SW_RESTORE);
  22. // ShowWindow(hwnd,SW_SHOW); //FG> SW_RESTORE should take care of it and is trapped for taskbar button hiding. Explicitly showing the window will make an iconless button reapear if studio is set to not have a taskbar button
  23. SetForegroundWindow(hwnd);
  24. #else
  25. DebugString( "portme -- IpcsPtr::moveToForeground\n" );
  26. #endif
  27. }
  28. void IpcsPtr::sendWasabiCommand(int command, void *param, int paramlen) {
  29. #ifdef WIN32
  30. COPYDATASTRUCT cd;
  31. cd.dwData=command;
  32. cd.cbData=paramlen;
  33. cd.lpData=param;
  34. SendMessage(hwnd, WM_COPYDATA, NULL, (long)&cd);
  35. #else
  36. wa_msgbuf msg;
  37. msg.mtype = command;
  38. ASSERT( paramlen < IPC_MSGMAX - 4 );
  39. msg.paramlen = paramlen;
  40. MEMCPY( msg.param, param, paramlen );
  41. if ( msgsnd( qid , &msg, IPC_MSGMAX, 0 ) == 1 ) {
  42. perror( "msgsnd" );
  43. }
  44. #endif
  45. }
  46. void IpcsPtr::sendWasabiCommand(int command, const char *param) {
  47. sendWasabiCommand(command, (void *)param, STRLEN(param)+1);
  48. }
  49. IpcsPtr *Ipcs::getOtherWasabiInstance() {
  50. extern String ipcWindowClassName;
  51. #ifdef WIN32
  52. HWND hwnd_instance=FindWindow(ipcWindowClassName,NULL);
  53. if(!hwnd_instance) return NULL;
  54. return(new IpcsPtr(hwnd_instance));
  55. #else
  56. int key = ftok( ".", 'w' );
  57. int qid = msgget( key, 0 );
  58. if ( qid == -1 && errno == ENOENT ) {
  59. qid = msgget( key, IPC_CREAT | IPC_EXCL | 0660 );
  60. LinuxAPI::setIPCId( qid );
  61. return NULL;
  62. } else if ( qid == -1 ) {
  63. return NULL;
  64. } else {
  65. return new IpcsPtr( qid );
  66. }
  67. #endif
  68. }
  69. #pragma warning(push)
  70. #pragma warning(disable: 4060)
  71. int Ipcs::onIpcsMessage(int command, void *param, int paramlen) {
  72. switch(command) {
  73. #ifdef WASABI_API_COMPONENT
  74. case IPC_COMMANDLINE:
  75. Main::processCommandLine((const char *)param);
  76. return 0;
  77. #endif
  78. }
  79. return 0;
  80. }
  81. #pragma warning(pop)