Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add method for allowing python to start and stop our servers... #1212

Merged
merged 2 commits into from

2 participants

@Memphiz
Owner

... well basically what the topic says. This is a feature request of at-visions.

Sry - fatfingered the first PR description g

@jmarshallnz
Owner

Need to decide if you want to modify the gui settings or not with these methods. If you do, then shouldn't you be saving afterwards? If you don't, then modifying them to begin with is something that is not required - or do the StartWebServer et. al. check these?

@Memphiz
Owner

They check the guisetting... mhhh but as of the feature request i would say we should save it yes.

@Memphiz
Owner

does this look right (last commit)?

@jmarshallnz
Owner

Changes look fine.

@Memphiz
Owner

squashed - will assign to august milestone for now.

@Memphiz Memphiz was assigned
Memphiz added some commits
@Memphiz Memphiz [add] - add wrapper method for starting/stopping servers (jsonrpc, ze…
…roconf, upnprenderer, upnpserver, airplay, eventserver, webserver)
419ca50
@Memphiz Memphiz [python] - expose the startServer method to python for allowing scrip…
…ts to starting, stopping our servers
f0e3806
@Memphiz Memphiz merged commit decdfb9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 1, 2012
  1. @Memphiz

    [add] - add wrapper method for starting/stopping servers (jsonrpc, ze…

    Memphiz authored
    …roconf, upnprenderer, upnpserver, airplay, eventserver, webserver)
  2. @Memphiz

    [python] - expose the startServer method to python for allowing scrip…

    Memphiz authored
    …ts to starting, stopping our servers
This page is out of date. Refresh to see the latest.
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);
Something went wrong with that request. Please try again.