IPCWindows.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifdef ATOMIC_PLATFORM_WINDOWS
  2. #pragma once
  3. #include "../Core/Object.h"
  4. #include "IPCTypes.h"
  5. namespace Atomic
  6. {
  7. class PipePair {
  8. public:
  9. PipePair();
  10. IPCHandle serverRead() const { return srvRead_; }
  11. IPCHandle serverWrite() const { return srvWrite_; }
  12. IPCHandle clientRead() const { return clnRead_; }
  13. IPCHandle clientWrite() const { return clnWrite_; }
  14. static IPCHandle OpenPipeServer(const wchar_t* name, bool read);
  15. static IPCHandle OpenPipeClient(const wchar_t* name, bool read);
  16. private:
  17. IPCHandle srvRead_;
  18. IPCHandle srvWrite_;
  19. IPCHandle clnRead_;
  20. IPCHandle clnWrite_;
  21. };
  22. class PipeWin {
  23. public:
  24. PipeWin();
  25. ~PipeWin();
  26. bool OpenClient(IPCHandle pipeRead, IPCHandle pipeWrite);
  27. bool OpenServer(IPCHandle pipeRead, IPCHandle pipeWrite);
  28. bool Write(const void* buf, size_t sz);
  29. bool Read(void* buf, size_t* sz);
  30. bool IsConnected() const { return pipeRead_ != INVALID_IPCHANDLE_VALUE && pipeWrite_ != INVALID_IPCHANDLE_VALUE; }
  31. private:
  32. IPCHandle pipeRead_;
  33. IPCHandle pipeWrite_;
  34. };
  35. class PipeTransport : public PipeWin {
  36. public:
  37. static const size_t kBufferSz = 4096;
  38. bool Send(const void* buf, size_t sz) {
  39. return Write(buf, sz);
  40. }
  41. char* Receive(size_t* size);
  42. private:
  43. PODVector<char> buf_;
  44. };
  45. class IPCProcess : public Object
  46. {
  47. OBJECT(IPCProcess)
  48. public:
  49. IPCProcess(Context* context, IPCHandle clientRead, IPCHandle clientWrite, IPCHandle pid = INVALID_IPCHANDLE_VALUE);
  50. virtual ~IPCProcess();
  51. bool IsRunning();
  52. IPCHandle clientRead() const { return clientRead_; }
  53. IPCHandle clientWrite() const { return clientWrite_; }
  54. bool Launch(const String& command, const Vector<String>& args, const String& initialDirectory);
  55. private:
  56. IPCHandle pid_;
  57. IPCHandle clientRead_;
  58. IPCHandle clientWrite_;
  59. };
  60. }
  61. #endif