SubprocessSystem.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include <Atomic/Core/CoreEvents.h>
  5. #include <Atomic/Core/Context.h>
  6. #include <Atomic/IO/FileSystem.h>
  7. #include "SubprocessSystem.h"
  8. namespace ToolCore
  9. {
  10. SubprocessSystem::SubprocessSystem(Context* context) :
  11. Object(context),
  12. updateTimer_(0.0f)
  13. {
  14. SubscribeToEvent(E_UPDATE, HANDLER(SubprocessSystem, HandleUpdate));
  15. }
  16. SubprocessSystem::~SubprocessSystem()
  17. {
  18. for (unsigned i = 0; i < processes_.Size(); i++)
  19. processes_[i]->Stop();
  20. processes_.Clear();
  21. }
  22. Subprocess* SubprocessSystem::Launch(const String& command, const Vector<String>& args, const String& initialDirectory)
  23. {
  24. Poco::Process::Env env;
  25. return Launch(command, args, initialDirectory, env);
  26. }
  27. Subprocess* SubprocessSystem::Launch(const String& command, const Vector<String>& args, const String& initialDirectory, const Poco::Process::Env& env)
  28. {
  29. SharedPtr<Subprocess> process(new Subprocess(context_));
  30. if (process->Launch(GetNativePath(command), args, GetNativePath(initialDirectory), env))
  31. {
  32. processes_.Push(process);
  33. return process;
  34. }
  35. return 0;
  36. }
  37. void SubprocessSystem::HandleUpdate(StringHash eventType, VariantMap& eventData)
  38. {
  39. Vector<Subprocess*> remove;
  40. for (unsigned i = 0; i < processes_.Size(); i++)
  41. {
  42. Subprocess* process = processes_[i];
  43. if (!process->Update(this))
  44. {
  45. remove.Push(process);
  46. }
  47. }
  48. for (unsigned i = 0; i < remove.Size(); i++)
  49. {
  50. processes_.Remove(SharedPtr<Subprocess>(remove[i]));
  51. }
  52. }
  53. }