Advertisement
Guest User

xbmc-server.cpp

a guest
Oct 8th, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2005-2008 Team XBMC
  3. * http://www.xbmc.org
  4. *
  5. * This Program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This Program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with XBMC; see the file COPYING. If not, write to
  17. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. */
  21.  
  22. #include "system.h"
  23. #include "settings/AppParamParser.h"
  24. #include "settings/AdvancedSettings.h"
  25. #include "GUIInfoManager.h"
  26. #include "FileItem.h"
  27. #include "Application.h"
  28. #include "PlayListPlayer.h"
  29. #include "utils/log.h"
  30. #include "xbmc.h"
  31. #ifdef _LINUX
  32. #include <sys/resource.h>
  33. #include <signal.h>
  34. #endif
  35. #if defined(TARGET_DARWIN_OSX)
  36. #include "Util.h"
  37. // SDL redefines main as SDL_main
  38. #ifdef HAS_SDL
  39. #include <SDL/SDL.h>
  40. #endif
  41. #endif
  42. #ifdef HAS_LIRC
  43. #include "input/linux/LIRC.h"
  44. #endif
  45. #include "XbmcContext.h"
  46.  
  47. int main(int argc, char* argv[])
  48. {
  49. BYTE processExceptionCount = 0;
  50.  
  51. const BYTE MAX_EXCEPTION_COUNT = 10;
  52.  
  53. // set up some xbmc specific relationships
  54. XBMC::Context context;
  55.  
  56. //this can't be set from CAdvancedSettings::Initialize() because it will overwrite
  57. //the loglevel set with the --debug flag
  58. g_advancedSettings.m_logLevel = LOG_LEVEL_NORMAL;
  59. g_advancedSettings.m_logLevelHint = LOG_LEVEL_NORMAL;
  60. CLog::SetLogLevel(g_advancedSettings.m_logLevel);
  61.  
  62. CLog::Log(LOGNOTICE, "Starting XBMC Server..." );
  63.  
  64. printf("XBMC Media Center %s\n", g_infoManager.GetVersion().c_str());
  65. printf("Copyright (C) 2005-2011 Team XBMC - http://www.xbmc.org\n\n");
  66. printf("Starting XBMC Server\n\n");
  67.  
  68. #ifdef _LINUX
  69. // Prevent child processes from becoming zombies on exit if not waited upon. See also Util::Command
  70. struct sigaction sa;
  71. memset(&sa, 0, sizeof(sa));
  72.  
  73. sa.sa_flags = SA_NOCLDWAIT;
  74. sa.sa_handler = SIG_IGN;
  75. sigaction(SIGCHLD, &sa, NULL);
  76. #endif
  77. setlocale(LC_NUMERIC, "C");
  78. g_advancedSettings.Initialize();
  79.  
  80. if (!g_advancedSettings.Initialized())
  81. g_advancedSettings.Initialize();
  82.  
  83. #ifndef _WIN32
  84. CAppParamParser appParamParser;
  85. appParamParser.Parse((const char **)argv, argc);
  86. #endif
  87. if (!g_application.Create())
  88. {
  89. fprintf(stderr, "ERROR: Unable to create application. Exiting\n");
  90. return -1;
  91. }
  92. if (!g_application.Initialize())
  93. {
  94. fprintf(stderr, "ERROR: Unable to Initialize. Exiting\n");
  95. return -1;
  96. }
  97.  
  98. // Start scanning the Video Library for changes...
  99. // g_application.StartVideoScan("");
  100.  
  101. // Run xbmc
  102. while (!g_application.m_bStop)
  103. {
  104. //-----------------------------------------
  105. // Animate and render a frame
  106. //-----------------------------------------
  107. try
  108. {
  109. g_application.Process();
  110. //reset exception count
  111. processExceptionCount = 0;
  112.  
  113. }
  114. catch (...)
  115. {
  116. CLog::Log(LOGERROR, "exception in CApplication::Process()");
  117. processExceptionCount++;
  118. //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
  119. if (processExceptionCount > MAX_EXCEPTION_COUNT)
  120. {
  121. CLog::Log(LOGERROR, "CApplication::Process(), too many exceptions");
  122. throw;
  123. }
  124. }
  125.  
  126. // If scanning the Video Library has finished then ask XBMC to quit...
  127. // if (!g_application.IsVideoScanning()) g_application.getApplicationMessenger().Quit();
  128.  
  129. // Sleep for a little bit so we don't hog the CPU...
  130.  
  131. Sleep(50);
  132. // printf(".");
  133. } // !g_application.m_bStop
  134.  
  135. g_application.Destroy();
  136.  
  137. printf("\n\nExiting XBMC Server...\n");
  138.  
  139. CLog::Log(LOGNOTICE, "Exiting XBMC Server..." );
  140.  
  141. return g_application.m_ExitCode;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement