AtomicNETService.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <Atomic/IO/Log.h>
  23. #include <Atomic/IO/FileSystem.h>
  24. #include <Atomic/IPC/IPC.h>
  25. #include <Atomic/IPC/IPCEvents.h>
  26. #include <Atomic/IPC/IPCBroker.h>
  27. #include <Atomic/Core/CoreEvents.h>
  28. #include <ToolCore/ToolEnvironment.h>
  29. #include <ToolCore/ToolSystem.h>
  30. #include "../Command/NETCmd.h"
  31. #include "AtomicNETService.h"
  32. namespace ToolCore
  33. {
  34. AtomicNETService::AtomicNETService(Context* context) :
  35. IPCServer(context)
  36. {
  37. }
  38. AtomicNETService::~AtomicNETService()
  39. {
  40. }
  41. bool AtomicNETService::GetServiceExecutable(String& execPath, Vector<String>& args) const
  42. {
  43. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  44. execPath = String::EMPTY;
  45. args.Clear();
  46. #ifdef ATOMIC_DEBUG
  47. String config = "Debug";
  48. #else
  49. String config = "Release";
  50. #endif
  51. String netServiceFilename = tenv->GetAtomicNETRootDir() + config + "/AtomicNETService/AtomicNETService.exe";
  52. #ifdef ATOMIC_PLATFORM_WINDOWS
  53. execPath = netServiceFilename;
  54. #elif defined ATOMIC_PLATFORM_OSX
  55. execPath = tenv->GetMonoExecutableDir() + "mono64";
  56. args.Push(netServiceFilename);
  57. #elif defined ATOMIC_PLATFORM_LINUX
  58. execPath = "/usr/bin/mono";
  59. args.Push(netServiceFilename);
  60. #endif
  61. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  62. if (!fileSystem->FileExists(execPath))
  63. {
  64. ATOMIC_LOGERRORF("AtomicNETService binary not found: %s", execPath.CString());
  65. return false;
  66. }
  67. return true;
  68. }
  69. bool AtomicNETService::Start()
  70. {
  71. String exec;
  72. Vector<String> args;
  73. if (!GetServiceExecutable(exec, args))
  74. return false;
  75. if (!IPCServer::StartInternal(exec, args))
  76. {
  77. return false;
  78. }
  79. return true;
  80. }
  81. }