AESubprocessSystem.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "AtomicEditor.h"
  5. #include <Atomic/Core/CoreEvents.h>
  6. #include <Atomic/Core/Context.h>
  7. #include <Atomic/IO/FileSystem.h>
  8. #include "AEEvents.h"
  9. #include "AESubprocessSystem.h"
  10. namespace AtomicEditor
  11. {
  12. SubprocessSystem::SubprocessSystem(Context* context) :
  13. Object(context),
  14. updateTimer_(0.0f)
  15. {
  16. SubscribeToEvent(E_UPDATE, HANDLER(SubprocessSystem, HandleUpdate));
  17. SubscribeToEvent(E_EDITORSHUTDOWN, HANDLER(SubprocessSystem, HandleEditorShutdown));
  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. void SubprocessSystem::HandleEditorShutdown(StringHash eventType, VariantMap& eventData)
  57. {
  58. context_->RemoveSubsystem(GetType());
  59. }
  60. }