Advertisement
Guest User

xbmc-server.cpp

a guest
Jul 10th, 2012
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.96 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.   if (!g_application.Create())
  84.   {
  85.     fprintf(stderr, "ERROR: Unable to create application. Exiting\n");
  86.     return -1;
  87.   }
  88.   if (!g_application.Initialize())
  89.   {
  90.     fprintf(stderr, "ERROR: Unable to Initialize. Exiting\n");
  91.     return -1;
  92.   }
  93.  
  94.   // Start scanning the Video Library for changes...
  95. //  g_application.StartVideoScan("");
  96.  
  97.   // Run xbmc
  98.   while (!g_application.m_bStop)
  99.   {
  100.     //-----------------------------------------
  101.     // Animate and render a frame
  102.     //-----------------------------------------
  103.     try
  104.     {
  105.       g_application.Process();
  106.       //reset exception count
  107.       processExceptionCount = 0;
  108.  
  109.     }
  110.     catch (...)
  111.     {
  112.       CLog::Log(LOGERROR, "exception in CApplication::Process()");
  113.       processExceptionCount++;
  114.       //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
  115.       if (processExceptionCount > MAX_EXCEPTION_COUNT)
  116.       {
  117.         CLog::Log(LOGERROR, "CApplication::Process(), too many exceptions");
  118.         throw;
  119.       }
  120.     }
  121.  
  122.     // If scanning the Video Library has finished then ask XBMC to quit...
  123.   //  if (!g_application.IsVideoScanning()) g_application.getApplicationMessenger().Quit();
  124.  
  125.     // Sleep for a little bit so we don't hog the CPU...
  126.     Sleep(50);
  127.     // printf(".");
  128.   } // !g_application.m_bStop
  129.  
  130.   g_application.Destroy();
  131.  
  132.   printf("\n\nExiting XBMC Server...\n");
  133.  
  134.   CLog::Log(LOGNOTICE, "Exiting XBMC Server..." );
  135.  
  136.   return g_application.m_ExitCode;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement