Browse Source

Windows IPC linking with stub methods

Josh Engebretson 10 years ago
parent
commit
7fa7938c41

+ 4 - 1
Source/Atomic/IPC/IPC.cpp

@@ -33,10 +33,13 @@ IPC::~IPC()
     worker_ = 0;
 }
 
-bool IPC::InitWorker(int fd1, int fd2)
+bool IPC::InitWorker(IPCHandle fd1, IPCHandle fd2)
 {
     // close server fd
+
+#ifndef ATOMIC_PLATFORM_WINDOWS
     close(fd1);
+#endif
 
     worker_ = new IPCWorker(fd2, context_);
     worker_->Run();

+ 3 - 2
Source/Atomic/IPC/IPC.h

@@ -2,9 +2,10 @@
 
 #include "../Core/Object.h"
 #include "../Core/Mutex.h"
-
 #include "../Container/List.h"
 
+#include "IPCTypes.h"
+
 namespace Atomic
 {
 
@@ -32,7 +33,7 @@ public:
     void QueueEvent(StringHash eventType, VariantMap& eventData);
 
     // for a child worker process
-    bool InitWorker(int fd1, int fd2);
+    bool InitWorker(IPCHandle fd1, IPCHandle fd2);
 
     // spawn a worker process
     IPCBroker* SpawnWorker(const String& command, const Vector<String>& args, const String& initialDirectory = "");

+ 6 - 0
Source/Atomic/IPC/IPCBroker.cpp

@@ -1,5 +1,7 @@
 
+#ifndef ATOMIC_PLATFORM_WINDOWS
 #include <unistd.h>
+#endif
 
 #include "../Core/StringUtils.h"
 #include "../IO/Log.h"
@@ -49,7 +51,9 @@ bool IPCBroker::Update()
     if (!shouldRun_)
     {
         Stop();
+#ifndef ATOMIC_PLATFORM_WINDOWS
         close(pp_.fd1());
+#endif
         return false;
     }
 
@@ -83,7 +87,9 @@ bool IPCBroker::SpawnWorker(const String& command, const Vector<String>& args, c
     if (!otherProcess_->Launch(command, pargs, initialDirectory))
         return false;
 
+#ifndef ATOMIC_PLATFORM_WINDOWS
     close(pp_.fd2());
+#endif
 
     return Run();
 

+ 7 - 0
Source/Atomic/IPC/IPCChannel.h

@@ -10,6 +10,13 @@
 #include "IPCMessage.h"
 #include "IPCUnix.h"
 
+#ifdef ATOMIC_PLATFORM_WINDOWS
+
+// Windows defines PostMessage as PostMessgeA/W
+#undef PostMessage
+
+#endif
+
 namespace Atomic
 {
 

+ 4 - 0
Source/Atomic/IPC/IPCMessage.h

@@ -5,7 +5,11 @@
 #include "../IO/VectorBuffer.h"
 #include "../IO/MemoryBuffer.h"
 
+#ifndef ATOMIC_PLATFORM_WINDOWS
 #include "IPCUnix.h"
+#else
+#include "IPCWindows.h"
+#endif
 
 namespace Atomic
 {

+ 25 - 0
Source/Atomic/IPC/IPCTypes.h

@@ -0,0 +1,25 @@
+
+#pragma once
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+
+namespace Atomic
+{
+
+// avoid needing to include <windows.h>
+
+// Windows handle type
+
+//#define INVALID_HANDLE_VALUE -1
+
+#define INVALID_IPCHANDLE_VALUE (void *)(-1)
+typedef void* IPCHandle;
+
+#else
+
+typedef int IPCHandle;
+
+#endif
+
+
+}

+ 19 - 19
Source/Atomic/IPC/IPCUnix.h

@@ -10,54 +10,54 @@ namespace Atomic
 
 class PipePair {
 public:
-  PipePair();
+    PipePair();
 
-  int fd1() const { return fd_[0]; }
-  int fd2() const { return fd_[1]; }
+    int fd1() const { return fd_[0]; }
+    int fd2() const { return fd_[1]; }
 
 private:
-  int fd_[2];
+    int fd_[2];
 };
 
 
 class PipeUnix {
 public:
-  PipeUnix();
+    PipeUnix();
 
-  bool OpenClient(int fd);
-  bool OpenServer(int fd);
+    bool OpenClient(int fd);
+    bool OpenServer(int fd);
 
-  bool Write(const void* buf, size_t sz);
-  bool Read(void* buf, size_t* sz);
+    bool Write(const void* buf, size_t sz);
+    bool Read(void* buf, size_t* sz);
 
-  bool IsConnected() const { return fd_ != -1; }
+    bool IsConnected() const { return fd_ != -1; }
 
 private:
-  int fd_;
+    int fd_;
 };
 
 
 class PipeTransport : public PipeUnix {
 public:
-  static const size_t kBufferSz = 4096;
+    static const size_t kBufferSz = 4096;
 
-  bool Send(const void* buf, size_t sz) {
-    return Write(buf, sz);
-  }
+    bool Send(const void* buf, size_t sz) {
+        return Write(buf, sz);
+    }
 
-  char* Receive(size_t* size);
+    char* Receive(size_t* size);
 
 private:
-  PODVector<char> buf_;
+    PODVector<char> buf_;
 };
 
 class IPCProcess : public Object
 {
     OBJECT(IPCProcess)
 
-public:
+    public:
 
-    IPCProcess(Context* context, int fd1, int fd2, int pid = -1);
+        IPCProcess(Context* context, int fd1, int fd2, int pid = -1);
 
     virtual ~IPCProcess();
 

+ 80 - 0
Source/Atomic/IPC/IPCWindows.cpp

@@ -0,0 +1,80 @@
+#ifdef ATOMIC_PLATFORM_WINDOWS
+
+#include "IPCWindows.h"
+
+namespace Atomic
+{
+
+PipePair::PipePair(bool inherit_fd2)
+{
+    srv_ = INVALID_IPCHANDLE_VALUE;
+    cln_ = INVALID_IPCHANDLE_VALUE;
+
+}
+
+PipeWin::PipeWin() : pipe_(INVALID_IPCHANDLE_VALUE) {
+}
+
+PipeWin::~PipeWin()
+{
+
+}
+
+bool PipeWin::OpenClient(IPCHandle pipe) {
+    return true;
+}
+
+bool PipeWin::OpenServer(IPCHandle pipe, bool connect) {
+    return true;
+}
+
+
+bool PipeWin::Write(const void* buf, size_t sz)
+{
+    return true;
+}
+
+bool PipeWin::Read(void* buf, size_t* sz) {
+    return true;
+}
+
+
+char* PipeTransport::Receive(size_t* size) {
+    if (buf_.Size() < kBufferSz) {
+        buf_.Resize(kBufferSz);
+    }
+
+    *size = kBufferSz;
+    if (!Read(&buf_[0], size)) {
+        return NULL;
+    }
+    return &buf_[0];
+}
+
+
+IPCProcess::IPCProcess(Context* context, IPCHandle fd1, IPCHandle fd2, IPCHandle pid) : Object(context),
+    pid_(pid),
+    fd1_(fd1),
+    fd2_(fd2)
+{
+}
+
+IPCProcess::~IPCProcess()
+{
+
+}
+
+bool IPCProcess::IsRunning()
+{
+    return false;
+
+}
+
+bool IPCProcess::Launch(const String& command, const Vector<String>& args, const String& initialDirectory)
+{
+    return false;
+}
+
+}
+
+#endif

+ 85 - 0
Source/Atomic/IPC/IPCWindows.h

@@ -0,0 +1,85 @@
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+
+#pragma once
+
+#include "../Core/Object.h"
+#include "IPCTypes.h"
+
+namespace Atomic
+{
+
+class PipePair {
+
+public:
+    PipePair(bool inherit_fd2 = false);
+    IPCHandle fd1() const { return srv_; }
+    IPCHandle fd2() const { return cln_; }
+
+    static IPCHandle OpenPipeServer(const wchar_t* name, bool low_integrity = true);
+    static IPCHandle OpenPipeClient(const wchar_t* name, bool inherit, bool impersonate);
+
+private:
+    IPCHandle srv_;
+    IPCHandle cln_;
+};
+
+class PipeWin {
+public:
+    PipeWin();
+    ~PipeWin();
+
+    bool OpenClient(IPCHandle pipe);
+    bool OpenServer(IPCHandle pipe, bool connect = false);
+
+    bool Write(const void* buf, size_t sz);
+    bool Read(void* buf, size_t* sz);
+
+    bool IsConnected() const { return pipe_ != INVALID_IPCHANDLE_VALUE; }
+
+private:
+    IPCHandle pipe_;
+};
+
+
+class PipeTransport : public PipeWin {
+public:
+    static const size_t kBufferSz = 4096;
+
+    bool Send(const void* buf, size_t sz) {
+        return Write(buf, sz);
+    }
+
+    char* Receive(size_t* size);
+
+private:
+    PODVector<char> buf_;
+};
+
+class IPCProcess : public Object
+{
+    OBJECT(IPCProcess)
+
+    public:
+
+    IPCProcess(Context* context, IPCHandle fd1, IPCHandle fd2, IPCHandle pid = INVALID_IPCHANDLE_VALUE);
+
+    virtual ~IPCProcess();
+
+    bool IsRunning();
+
+    IPCHandle fd1() const { return fd1_; }
+    IPCHandle fd2() const { return fd2_; }
+
+    bool Launch(const String& command, const Vector<String>& args, const String& initialDirectory);
+
+private:
+
+    IPCHandle pid_;
+    IPCHandle fd1_;
+    IPCHandle fd2_;
+};
+
+}
+
+#endif

+ 7 - 3
Source/Atomic/IPC/IPCWorker.cpp

@@ -3,21 +3,25 @@
 
 #include "IPCWorker.h"
 #include "IPCMessage.h"
-#include "IPCUnix.h"
+
 
 #ifdef ATOMIC_PLATFORM_WINDOWS
+#include "IPCWindows.h"
 #else
-    #include <unistd.h>
+#include "IPCUnix.h"
+#include <unistd.h>
 #endif
 
 namespace Atomic
 {
 
-IPCWorker::IPCWorker(int fd, Context* context) : IPCChannel(context),
+IPCWorker::IPCWorker(IPCHandle fd, Context* context) : IPCChannel(context),
     fd_(fd)
 {
 
+#ifndef ATOMIC_PLATFORM_WINDOWS
     otherProcess_ = new IPCProcess(context_, -1, fd, getppid());
+#endif
 
     if (!transport_.OpenClient(fd_))
     {

+ 3 - 2
Source/Atomic/IPC/IPCWorker.h

@@ -1,6 +1,7 @@
 
 #pragma once
 
+#include "IPCTypes.h"
 #include "IPC.h"
 #include "IPCChannel.h"
 
@@ -13,7 +14,7 @@ class IPCWorker : public IPCChannel
 
 public:
     /// Construct.
-    IPCWorker(int fd, Context* context);
+    IPCWorker(IPCHandle fd, Context* context);
     /// Destruct.
     virtual ~IPCWorker();
 
@@ -23,7 +24,7 @@ public:
 
 private:
 
-    int fd_;
+    IPCHandle fd_;
 
 };
 

+ 1 - 1
Source/AtomicEditor/Source/Main.cpp

@@ -38,7 +38,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, in
 {
     _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
     Atomic::ParseArguments(GetCommandLineW());
-    return function;
+    return RunEditorApplication();
 }
 // MSVC release mode: write minidump on crash
 #elif defined(_MSC_VER) && defined(ATOMIC_MINIDUMPS) && !defined(ATOMIC_WIN32_CONSOLE)

+ 1 - 1
Source/AtomicEditor/Source/Player/AEPlayerApplication.cpp

@@ -156,7 +156,7 @@ void AEPlayerApplication::Start()
     {
         IPC* ipc = new IPC(context_);
         context_->RegisterSubsystem(ipc);
-        ipc->InitWorker(fd_[0], fd_[1]);
+        //ipc->InitWorker(fd_[0], fd_[1]);
     }
 
     // Instantiate and register the Javascript subsystem