AESubprocessSystem.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/IO/FileSystem.h>
  7. #include "AtomicEditor.h"
  8. #include "AESubprocessSystem.h"
  9. namespace AtomicEditor
  10. {
  11. SubprocessSystem::SubprocessSystem(Context* context) :
  12. Object(context),
  13. updateTimer_(0.0f)
  14. {
  15. SubscribeToEvent(E_UPDATE, HANDLER(SubprocessSystem, HandleUpdate));
  16. }
  17. SubprocessSystem::~SubprocessSystem()
  18. {
  19. for (unsigned i = 0; i < processes_.Size(); i++)
  20. processes_[i]->Stop();
  21. processes_.Clear();
  22. }
  23. Subprocess* SubprocessSystem::Launch(const String& command, const Vector<String>& args, const String& initialDirectory)
  24. {
  25. SharedPtr<Subprocess> process(new Subprocess(context_));
  26. if (process->Launch(GetNativePath(command), args, GetNativePath(initialDirectory)))
  27. {
  28. processes_.Push(process);
  29. return process;
  30. }
  31. return 0;
  32. }
  33. void SubprocessSystem::HandleUpdate(StringHash eventType, VariantMap& eventData)
  34. {
  35. Vector<Subprocess*> remove;
  36. for (unsigned i = 0; i < processes_.Size(); i++)
  37. {
  38. Subprocess* process = processes_[i];
  39. if (!process->Update(this))
  40. {
  41. remove.Push(process);
  42. }
  43. }
  44. for (unsigned i = 0; i < remove.Size(); i++)
  45. {
  46. processes_.Remove(SharedPtr<Subprocess>(remove[i]));
  47. }
  48. }
  49. }