AEPlayerMode.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <Atomic/IO/Log.h>
  2. #include <Atomic/Core/ProcessUtils.h>
  3. #include <Atomic/IPC/IPC.h>
  4. #include <Atomic/IPC/IPCEvents.h>
  5. #include <Atomic/IPC/IPCWorker.h>
  6. #include "AEPlayerMode.h"
  7. namespace AtomicEditor
  8. {
  9. PlayerMode::PlayerMode(Context* context) :
  10. Object(context)
  11. {
  12. fd_[0] = INVALID_IPCHANDLE_VALUE;
  13. fd_[1] = INVALID_IPCHANDLE_VALUE;
  14. }
  15. void PlayerMode::HandleHelloFromBroker(StringHash eventType, VariantMap& eventData)
  16. {
  17. assert(eventData[HelloFromBroker::P_HELLO].GetString() == "Hello");
  18. assert(eventData[HelloFromBroker::P_LIFETHEUNIVERSEANDEVERYTHING].GetInt() == 42);
  19. LOGERROR("Passed Test!");
  20. }
  21. void PlayerMode::ProcessArguments() {
  22. const Vector<String>& arguments = GetArguments();
  23. for (unsigned i = 0; i < arguments.Size(); ++i)
  24. {
  25. if (arguments[i].Length() > 1)
  26. {
  27. String argument = arguments[i].ToLower();
  28. String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
  29. if (argument.StartsWith("--ipc-server=") || argument.StartsWith("--ipc-client="))
  30. {
  31. LOGINFOF("Starting IPCWorker %s", argument.CString());
  32. Vector<String> ipc = argument.Split(argument.CString(), '=');
  33. if (ipc.Size() == 2)
  34. {
  35. if (argument.StartsWith("--ipc-server="))
  36. {
  37. #ifdef ATOMIC_PLATFORM_WINDOWS
  38. WString wipc(ipc[1]);
  39. HANDLE pipe = reinterpret_cast<HANDLE>(_wtoi64(wipc.CString()));
  40. fd_[0] = pipe;
  41. #else
  42. int fd = ToInt(ipc[1].CString());
  43. fd_[0] = fd;
  44. #endif
  45. }
  46. else
  47. {
  48. #ifdef ATOMIC_PLATFORM_WINDOWS
  49. WString wipc(ipc[1]);
  50. HANDLE pipe = reinterpret_cast<HANDLE>(_wtoi64(wipc.CString()));
  51. fd_[1] = pipe;
  52. #else
  53. int fd = ToInt(ipc[1].CString());
  54. fd_[1] = fd;
  55. #endif
  56. }
  57. }
  58. }
  59. }
  60. }
  61. #ifdef ATOMIC_PLATFORM_WINDOWS
  62. if (fd_[0] != INVALID_IPCHANDLE_VALUE)
  63. {
  64. //::CloseHandle(fd_[0]);
  65. fd_[0] = INVALID_IPCHANDLE_VALUE;
  66. }
  67. if (fd_[1] != INVALID_IPCHANDLE_VALUE)
  68. {
  69. IPC* ipc = new IPC(context_);
  70. context_->RegisterSubsystem(ipc);
  71. //ipc->InitWorker(fd_[0], fd_[1]);
  72. }
  73. #else
  74. if (fd_[0] != INVALID_IPCHANDLE_VALUE && fd_[1] != INVALID_IPCHANDLE_VALUE)
  75. {
  76. IPC* ipc = GetSubsystem<IPC>();
  77. SubscribeToEvent(E_IPCHELLOFROMBROKER, HANDLER(PlayerMode, HandleHelloFromBroker));
  78. ipc->InitWorker(fd_[0], fd_[1]);
  79. }
  80. #endif
  81. }
  82. PlayerMode::~PlayerMode()
  83. {
  84. }
  85. }