SubprocessSystem.cpp 1.8 KB

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