diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/server.cpp | 54 | ||||
-rw-r--r-- | server/server.h | 65 |
2 files changed, 84 insertions, 35 deletions
diff --git a/server/server.cpp b/server/server.cpp index 03750bd..d98c78b 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -50,7 +50,7 @@ cUPnPServer::~cUPnPServer() { bool cUPnPServer::init(void){ - MESSAGE("Loading configuration..."); + MESSAGE(VERBOSE_SDK, "Loading configuration..."); cUPnPConfig* config = cUPnPConfig::get(); this->enable(config->mEnable == 1 ? true : false); if(!config->mAutoSetup){ @@ -80,7 +80,7 @@ bool cUPnPServer::init(void){ } } - MESSAGE("Initializing Intel UPnP SDK on %s:%d",inet_ntoa(this->mServerAddr->sin_addr), ntohs(this->mServerAddr->sin_port)); + MESSAGE(VERBOSE_SDK, "Initializing Intel UPnP SDK on %s:%d",inet_ntoa(this->mServerAddr->sin_addr), ntohs(this->mServerAddr->sin_port)); int ret = 0; ret = UpnpInit(inet_ntoa(this->mServerAddr->sin_addr), ntohs(this->mServerAddr->sin_port)); @@ -98,18 +98,18 @@ bool cUPnPServer::init(void){ ERROR("Unable to set IP address"); } this->mServerAddr->sin_port = htons(UpnpGetServerPort()); - MESSAGE("Initializing succesfully at %s:%d", UpnpGetServerIpAddress(), UpnpGetServerPort()); + MESSAGE(VERBOSE_SDK, "Initializing succesfully at %s:%d", UpnpGetServerIpAddress(), UpnpGetServerPort()); } - MESSAGE("Setting maximum packet size for SOAP requests"); + MESSAGE(VERBOSE_CUSTOM_OUTPUT, "Setting maximum packet size for SOAP requests"); UpnpSetMaxContentLength(UPNP_SOAP_MAX_LEN); //set the root directory of the webserver cString WebserverRootDir = cString::sprintf("%s%s", cPluginUpnp::getConfigDirectory(), UPNP_WEB_SERVER_ROOT_DIR); - MESSAGE("Set web server root dir: %s", *WebserverRootDir ); + MESSAGE(VERBOSE_SDK, "Set web server root dir: %s", *WebserverRootDir ); this->mWebServer = cUPnPWebServer::getInstance(WebserverRootDir); - MESSAGE("Initializing web server."); + MESSAGE(VERBOSE_SDK, "Initializing web server."); if (!this->mWebServer->init()) { ERROR("Error while setting web server root dir - Errorcode: %d", ret); return false; @@ -120,7 +120,7 @@ bool cUPnPServer::init(void){ this->mDeviceDescription = cString(cDlna::getInstance()->getDeviceDescription(URLBase),true); - MESSAGE("Register Media Server Device"); + MESSAGE(VERBOSE_SDK, "Register Media Server Device"); ret = UpnpRegisterRootDevice2(UPNPREG_BUF_DESC, this->mDeviceDescription, sizeof(this->mDeviceDescription), 1, &cUPnPServer::upnpActionCallback, @@ -131,14 +131,14 @@ bool cUPnPServer::init(void){ return false; } - MESSAGE("Unregister server to cleanup previously started servers"); + MESSAGE(VERBOSE_CUSTOM_OUTPUT, "Unregister server to cleanup previously started servers"); ret = UpnpUnRegisterRootDevice(this->mDeviceHandle); if (ret != UPNP_E_SUCCESS) { WARNING("Unregistering old devices failed"); return false; } - MESSAGE("Register Media Server Device"); + MESSAGE(VERBOSE_CUSTOM_OUTPUT, "Register Media Server Device"); ret = UpnpRegisterRootDevice2(UPNPREG_BUF_DESC, this->mDeviceDescription, sizeof(this->mDeviceDescription), 1, &cUPnPServer::upnpActionCallback, @@ -149,16 +149,16 @@ bool cUPnPServer::init(void){ return false; } - MESSAGE("Initializing media database"); + MESSAGE(VERBOSE_SDK, "Initializing media database"); this->mMediaDatabase = new cMediaDatabase; if(!this->mMediaDatabase->init()){ ERROR("Error while initializing database"); return false; } - MESSAGE("Initializing connection manager"); + MESSAGE(VERBOSE_SDK, "Initializing connection manager"); cUPnPServer::mConnectionManager = new cConnectionManager(this->mDeviceHandle); - MESSAGE("Initializing content directory"); + MESSAGE(VERBOSE_SDK, "Initializing content directory"); cUPnPServer::mContentDirectory = new cContentDirectory(this->mDeviceHandle, this->mMediaDatabase); if(!cUPnPServer::mContentDirectory->Start()){ ERROR("Unable to start content directory thread"); @@ -166,7 +166,7 @@ bool cUPnPServer::init(void){ } //send first advertisments - MESSAGE("Send first advertisements to publish start in network"); + MESSAGE(VERBOSE_SDK, "Send first advertisements to publish start in network"); ret = UpnpSendAdvertisement(this->mDeviceHandle, UPNP_ANNOUNCE_MAX_AGE); if (ret != UPNP_E_SUCCESS) { ERROR("Error while sending first advertisments - Errorcode: %d", ret); @@ -177,20 +177,20 @@ bool cUPnPServer::init(void){ } bool cUPnPServer::uninit(void) { - MESSAGE("Shuting down content directory"); + MESSAGE(VERBOSE_SDK, "Shuting down content directory"); delete cUPnPServer::mContentDirectory; cUPnPServer::mContentDirectory = NULL; - MESSAGE("Shuting down connection manager"); + MESSAGE(VERBOSE_SDK, "Shuting down connection manager"); delete cUPnPServer::mConnectionManager; cUPnPServer::mConnectionManager = NULL; - MESSAGE("Closing metadata database"); + MESSAGE(VERBOSE_SDK, "Closing metadata database"); delete this->mMediaDatabase; this->mMediaDatabase = NULL; - MESSAGE("Closing the web server"); + MESSAGE(VERBOSE_SDK, "Closing the web server"); this->mWebServer->uninit(); delete this->mWebServer; - MESSAGE("Close Intel SDK"); + MESSAGE(VERBOSE_SDK, "Close Intel SDK"); // unregiser media server device from UPnP SDK int ret = UpnpUnRegisterRootDevice(this->mDeviceHandle); if (ret != UPNP_E_SUCCESS) { @@ -200,7 +200,7 @@ bool cUPnPServer::uninit(void) { ret = UpnpFinish(); if (ret == UPNP_E_SUCCESS) { - MESSAGE("Close Intel SDK Successfull"); + MESSAGE(VERBOSE_SDK, "Close Intel SDK Successfull"); return true; } else { ERROR("Intel SDK unintialized or already closed - Errorcode: %d", ret); @@ -277,7 +277,7 @@ bool cUPnPServer::autoDetectSettings(void){ char** Ifaces = getNetworkInterfaces(&count); int i=0; bool ret = false; - MESSAGE("AUTODETECT: Found %d possible interfaces.", sizeof(Ifaces)); + MESSAGE(VERBOSE_CUSTOM_OUTPUT, "AUTODETECT: Found %d possible interfaces.", sizeof(Ifaces)); while(Ifaces[i]){ if(strcmp(Ifaces[i],"lo")!=0){ // true || false == true @@ -288,7 +288,7 @@ bool cUPnPServer::autoDetectSettings(void){ } delete [] Ifaces; if(!ret){ - MESSAGE("AUTODETECT: No suitable interface. Giving up."); + MESSAGE(VERBOSE_CUSTOM_OUTPUT, "AUTODETECT: No suitable interface. Giving up."); return false; } this->setServerPort(0); @@ -299,8 +299,8 @@ bool cUPnPServer::start(void){ if(!this->isRunning()){ // Put all the stuff which shall be started with the server in here // if the startup failed due any reason return false! - MESSAGE("Starting UPnP Server on %s:%d",inet_ntoa(this->getServerAddress()->sin_addr), ntohs(this->getServerAddress()->sin_port)); - MESSAGE("Using DLNA version: %s", DLNA_PROTOCOL_VERSION_STR); + MESSAGE(VERBOSE_SDK, "Starting UPnP Server on %s:%d",inet_ntoa(this->getServerAddress()->sin_addr), ntohs(this->getServerAddress()->sin_port)); + MESSAGE(VERBOSE_SDK, "Using DLNA version: %s", DLNA_PROTOCOL_VERSION_STR); this->mIsRunning = true; // Start Media database thread this->mMediaDatabase->Start(); @@ -310,7 +310,7 @@ bool cUPnPServer::start(void){ void cUPnPServer::stop(void){ if(this->isRunning()){ - MESSAGE("Call upnpServer STOP"); + MESSAGE(VERBOSE_SDK, "Call upnpServer STOP"); this->uninit(); this->mIsRunning = false; } @@ -318,7 +318,7 @@ void cUPnPServer::stop(void){ } bool cUPnPServer::restart(void){ - MESSAGE("Call upnpServer RESTART"); + MESSAGE(VERBOSE_SDK, "Call upnpServer RESTART"); this->stop(); return this->start(); } @@ -331,11 +331,11 @@ bool cUPnPServer::setInterface(const char* Interface){ if(Interface != NULL) this->mInterface = Interface; if(*this->mInterface!=NULL){ - MESSAGE("Try to retrieve address for NIC %s",Interface); + MESSAGE(VERBOSE_CUSTOM_OUTPUT, "Try to retrieve address for NIC %s",Interface); const sockaddr_in* ipAddress = getIPFromInterface(Interface); if(ipAddress!=NULL){ memcpy(&this->mServerAddr->sin_addr,&ipAddress->sin_addr,sizeof(ipAddress->sin_addr)); - MESSAGE("NIC %s has the following IP: %s", *this->mInterface, inet_ntoa(this->mServerAddr->sin_addr)); + MESSAGE(VERBOSE_CUSTOM_OUTPUT, "NIC %s has the following IP: %s", *this->mInterface, inet_ntoa(this->mServerAddr->sin_addr)); this->stop(); return true; } diff --git a/server/server.h b/server/server.h index 72ed2c8..c2a0e9a 100644 --- a/server/server.h +++ b/server/server.h @@ -20,6 +20,13 @@ #include "../upnpcomponents/contentdirectory.h" #include "../upnp.h" +/** + * The UPnP Server + * + * This is the core of the UPnP server. This handles all the components which + * are needed for a UPnP media server. Incoming messages are passed through it + * and it determines what to do. + */ class cUPnPServer { friend class cPluginUpnp; public: @@ -42,7 +49,10 @@ public: * * This switch indicates if the server is startable or not * - * If it is set to FALSE, any invocation of start() will do nothing. + * If it is set to false, any invocation of start() will do nothing. + * + * @param enabled if \bc true, the server will be enabled. If \bc false it is + * disabled. */ void enable(bool enabled); /** @@ -50,7 +60,9 @@ public: * * This will start the UPnP server activities as a background task. * - * @return 1 when the server started successfully, 0 otherwise + * @return returns + * - \bc true, when the server started successfully + * - \bc false, otherwise */ bool start(void); /** @@ -60,7 +72,9 @@ public: * It will stop the server functionalities, clear everything and * start it again. * - * @return 1 when the server restarted successfully, 0 otherwise + * @return returns + * - \bc true, when the server restarted successfully + * - \bc false, otherwise */ bool restart(void); /** @@ -70,6 +84,16 @@ public: * any clients and open ports will be closed. */ void stop(void); + /** + * Automatically detect settings + * + * This will automatically detect the network settings if the autodetection + * is turned on. + * + * @return returns + * - \bc true, if autoDetection was successful + * - \bc false, otherwise + */ bool autoDetectSettings(void); /** * Get the server address @@ -82,7 +106,7 @@ public: /** * Get the interface the server listens to * - * Returns the network interface + * @return the network interface */ const char* getInterface(void) const { return this->mInterface; } /** @@ -98,13 +122,20 @@ public: * Returns 1 when the port is valid, 0 otherwise * * @param port The port of the server - * @return 1 if the new server address is set, 0 otherwise + * @return returns + * - \bc true, if the new server port is set + * - \bc false, otherwise */ bool setServerPort(unsigned short port); /** * The Interface to listen on * * Sets the listener interface, for instance 'eth1' or 'wlan0' + * + * @param Interface The interface of the server + * @return returns + * - \bc true, if the new server address is set + * - \bc false, otherwise */ bool setInterface(const char* Interface); /** @@ -115,7 +146,12 @@ public: * changes through the system. * * This method should only be used in cases of fixed IP addresses - * for example when no DHCP server is available. + * for example when no DHCP server is available. + * + * @param Address The address of the server + * @return returns + * - \bc true, if the new server address is set + * - \bc false, otherwise */ bool setAddress(const char* Address); /** @@ -123,6 +159,11 @@ public: * * If this is set to true, the setup will get it's information via * auto detection + * + * @param enable \bc true enables and \bc false disables the auto detection + * @return returns + * - \bc true, if the new server address is set + * - \bc false, otherwise */ bool setAutoDetection(bool enable); /** @@ -130,7 +171,9 @@ public: * * This indicates if the server is currently enabled. * - * @return 1 if the server is enabled, 0 otherwise + * @return returns + * - \bc true, if the server is enabled + * - \bc false, otherwise */ bool isEnabled(void) const { return this->mIsEnabled; } /** @@ -138,13 +181,19 @@ public: * * If the server is enabled, this indicates if it is running. * - * @return 1 if the server is running, 0 otherwise + * @return returns + * - \bc true if the server is running + * - \bc false, otherwise */ bool isRunning(void) const { return this->mIsRunning; } /** * Is auto detection enabled or not * * Returns true or false if auto detection is enabled or not + * + * @return returns + * - \bc true, if autodetection is enabled + * - \bc false, otherwise */ bool isAutoDetectionEnabled() { return this->mIsAutoDetectionEnabled; } protected: |