Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1212 from Memphiz/pythonserverctrl

Add method for allowing python to start and stop our servers...
  • Loading branch information...
commit decdfb93c27eef8a1ef6d2105ace00861f8169e8 2 parents b138b87 + f0e3806
@Memphiz authored
View
121 xbmc/Application.cpp
@@ -1365,6 +1365,100 @@ bool CApplication::Initialize()
return true;
}
+bool CApplication::StartServer(enum ESERVERS eServer, bool bStart, bool bWait/* = false*/)
+{
+ bool ret = true;
+ bool oldSetting = false;
+
+ switch(eServer)
+ {
+ case ES_WEBSERVER:
+ oldSetting = g_guiSettings.GetBool("services.webserver");
+ g_guiSettings.SetBool("services.webserver", bStart);
+
+ if (bStart)
+ ret = StartWebServer();
+ else
+ StopWebServer();
+
+ if (!ret)
+ {
+ g_guiSettings.SetBool("services.webserver", oldSetting);
+ }
+ break;
+ case ES_AIRPLAYSERVER:
+ oldSetting = g_guiSettings.GetBool("services.esenabled");
+ g_guiSettings.SetBool("services.airplay", bStart);
+
+ if (bStart)
+ ret = StartAirplayServer();
+ else
+ StopAirplayServer(bWait);
+
+ if (!ret)
+ {
+ g_guiSettings.SetBool("services.esenabled", oldSetting);
+ }
+ break;
+ case ES_JSONRPCSERVER:
+ oldSetting = g_guiSettings.GetBool("services.esenabled");
+ g_guiSettings.SetBool("services.esenabled", bStart);
+
+ if (bStart)
+ ret = StartJSONRPCServer();
+ else
+ StopJSONRPCServer(bWait);
+
+ if (!ret)
+ {
+ g_guiSettings.SetBool("services.esenabled", oldSetting);
+ }
+ break;
+ case ES_UPNPSERVER:
+ g_guiSettings.SetBool("services.upnpserver", bStart);
+ if (bStart)
+ StartUPnPServer();
+ else
+ StopUPnPServer();
+ break;
+ case ES_UPNPRENDERER:
+ g_guiSettings.SetBool("services.upnprenderer", bStart);
+ if (bStart)
+ StartUPnPRenderer();
+ else
+ StopUPnPRenderer();
+ break;
+ case ES_EVENTSERVER:
+ oldSetting = g_guiSettings.GetBool("services.esenabled");
+ g_guiSettings.SetBool("services.esenabled", bStart);
+
+ if (bStart)
+ ret = StartEventServer();
+ else
+ StopEventServer(bWait, false);
+
+ if (!ret)
+ {
+ g_guiSettings.SetBool("services.esenabled", oldSetting);
+ }
+
+ break;
+ case ES_ZEROCONF:
+ g_guiSettings.SetBool("services.zeroconf", bStart);
+ if (bStart)
+ StartZeroconf();
+ else
+ StopZeroconf();
+ break;
+ default:
+ ret = false;
+ break;
+ }
+ g_settings.Save();
+
+ return ret;
+}
+
bool CApplication::StartWebServer()
{
#ifdef HAS_WEB_SERVER
@@ -1427,8 +1521,9 @@ void CApplication::StopWebServer()
#endif
}
-void CApplication::StartAirplayServer()
+bool CApplication::StartAirplayServer()
{
+ bool ret = false;
#ifdef HAS_AIRPLAY
if (g_guiSettings.GetBool("services.airplay") && m_network.IsAvailable())
{
@@ -1453,22 +1548,28 @@ void CApplication::StartAirplayServer()
txt["model"] = "AppleTV2,1";
txt["srcvers"] = AIRPLAY_SERVER_VERSION_STR;
CZeroconf::GetInstance()->PublishService("servers.airplay", "_airplay._tcp", g_infoManager.GetLabel(SYSTEM_FRIENDLY_NAME), listenPort, txt);
+ ret = true;
}
}
+ if (ret)
#endif
-#ifdef HAS_AIRTUNES
- if (g_guiSettings.GetBool("services.airplay") && m_network.IsAvailable())
{
- int listenPort = g_advancedSettings.m_airTunesPort;
- CStdString password = g_guiSettings.GetString("services.airplaypassword");
- bool usePassword = g_guiSettings.GetBool("services.useairplaypassword");
-
- if (!CAirTunesServer::StartServer(listenPort, true, usePassword, password))
+#ifdef HAS_AIRTUNES
+ if (g_guiSettings.GetBool("services.airplay") && m_network.IsAvailable())
{
- CLog::Log(LOGERROR, "Failed to start AirTunes Server");
+ int listenPort = g_advancedSettings.m_airTunesPort;
+ CStdString password = g_guiSettings.GetString("services.airplaypassword");
+ bool usePassword = g_guiSettings.GetBool("services.useairplaypassword");
+
+ if (!CAirTunesServer::StartServer(listenPort, true, usePassword, password))
+ {
+ CLog::Log(LOGERROR, "Failed to start AirTunes Server");
+ }
+ ret = true;
}
- }
#endif
+ }
+ return ret;
}
void CApplication::StopAirplayServer(bool bWait)
View
17 xbmc/Application.h
@@ -108,6 +108,18 @@ class CBackgroundPlayer : public CThread
class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMsgTargetCallback
{
public:
+
+ enum ESERVERS
+ {
+ ES_WEBSERVER = 1,
+ ES_AIRPLAYSERVER,
+ ES_JSONRPCSERVER,
+ ES_UPNPRENDERER,
+ ES_UPNPSERVER,
+ ES_EVENTSERVER,
+ ES_ZEROCONF
+ };
+
CApplication(void);
virtual ~CApplication(void);
virtual bool Initialize();
@@ -123,9 +135,12 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
bool DestroyWindow();
void StartServices();
void StopServices();
+
+ bool StartServer(enum ESERVERS eServer, bool bStart, bool bWait = false);
+
bool StartWebServer();
void StopWebServer();
- void StartAirplayServer();
+ bool StartAirplayServer();
void StopAirplayServer(bool bWait);
bool StartJSONRPCServer();
void StopJSONRPCServer(bool bWait);
View
59 xbmc/interfaces/python/xbmcmodule/xbmcmodule.cpp
@@ -939,6 +939,53 @@ namespace PYXBMC
return Py_BuildValue((char*)"b", exists);
}
+ // startServer() method
+ PyDoc_STRVAR(startServer__doc__,
+ "startServer(typ, bStart, bWait) -- start or stop a server.\n"
+ "\n"
+ "typ : integer - use SERVER_* constants\n"
+ "\n"
+ "bStart : bool - start (True) or stop (False) a server\n"
+ "\n"
+ "bWait : [opt] bool - wait on stop before returning (not supported by all servers)\n"
+ "\n"
+ "returnValue : bool - True or False\n"
+ "example:\n"
+ " - xbmc.startServer(xbmc.SERVER_AIRPLAYSERVER, False)\n");
+
+ PyObject* XBMC_StartServer(PyObject *self, PyObject *args, PyObject *kwds)
+ {
+ static const char *keywords[] = {
+ "typ",
+ "bStart",
+ "bWait",
+ NULL};
+
+ int iTyp = 0;
+ char bStart = false;
+ char bWait = false;
+ bool ret = false;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args,
+ kwds,
+ (char*)"ib|b",
+ (char**)keywords,
+ &iTyp,
+ &bStart,
+ &bWait))
+ {
+ return NULL;
+ }
+
+ {
+ CPyThreadState save;
+ ret = g_application.StartServer((CApplication::ESERVERS)iTyp, bStart != 0, bWait != 0);
+ }
+
+ return Py_BuildValue((char*)"b", ret);
+ }
+
// define c functions to be used in python here
PyMethodDef xbmcMethods[] = {
{(char*)"output", (PyCFunction)XBMC_Output, METH_VARARGS|METH_KEYWORDS, output__doc__},
@@ -985,6 +1032,8 @@ namespace PYXBMC
{(char*)"skinHasImage", (PyCFunction)XBMC_SkinHasImage, METH_VARARGS|METH_KEYWORDS, skinHasImage__doc__},
+ {(char*)"startServer", (PyCFunction)XBMC_StartServer, METH_VARARGS|METH_KEYWORDS, startServer__doc__},
+
{NULL, NULL, 0, NULL}
};
@@ -1076,6 +1125,16 @@ namespace PYXBMC
PyModule_AddIntConstant(pXbmcModule, (char*)"PLAYER_CORE_MPLAYER", EPC_MPLAYER);
PyModule_AddIntConstant(pXbmcModule, (char*)"PLAYER_CORE_PAPLAYER", EPC_PAPLAYER);
+ // server constants for startServer method
+ PyModule_AddIntConstant(pXbmcModule, (char*)"SERVER_WEBSERVER", CApplication::ES_WEBSERVER);
+ PyModule_AddIntConstant(pXbmcModule, (char*)"SERVER_AIRPLAYSERVER", CApplication::ES_AIRPLAYSERVER);
+ PyModule_AddIntConstant(pXbmcModule, (char*)"SERVER_UPNPSERVER", CApplication::ES_UPNPSERVER);
+ PyModule_AddIntConstant(pXbmcModule, (char*)"SERVER_UPNPRENDERER", CApplication::ES_UPNPRENDERER);
+ PyModule_AddIntConstant(pXbmcModule, (char*)"SERVER_EVENTSERVER", CApplication::ES_EVENTSERVER);
+ PyModule_AddIntConstant(pXbmcModule, (char*)"SERVER_JSONRPCSERVER", CApplication::ES_JSONRPCSERVER);
+ PyModule_AddIntConstant(pXbmcModule, (char*)"SERVER_ZEROCONF", CApplication::ES_ZEROCONF);
+
+
// dvd state constants
PyModule_AddIntConstant(pXbmcModule, (char*)"TRAY_OPEN", TRAY_OPEN);
PyModule_AddIntConstant(pXbmcModule, (char*)"DRIVE_NOT_READY", DRIVE_NOT_READY);
Please sign in to comment.
Something went wrong with that request. Please try again.