Provides methods to initialize and shutdown and to retrieve various information about the server. More...
#include <server.h>
Public Member Functions | |
| Server () | |
| virtual void | init () |
| Initializes the server. | |
| void | upnp_init (zmm::String interface, zmm::String ip_address, int port) |
| Initializes UPnP portion, only ip or interface can be given. | |
| virtual void | shutdown () |
| Cleanup routine to shutdown the server. | |
| zmm::String | getVirtualURL () |
| Returns the virtual web server URL. | |
| int | upnp_callback (Upnp_EventType eventtype, void *event, void *cookie) |
| Dispatch incoming UPnP events. | |
| UpnpDevice_Handle | getDeviceHandle () |
| Returns the device handle. | |
| zmm::String | getIP () |
| Returns the IP address of the server. | |
| zmm::String | getPort () |
| Returns the port of the server. | |
| bool | getShutdownStatus () |
| Tells if the server is about to be terminated. | |
| void | retain () |
| void | release () |
| int | getRefCount () |
Static Public Member Functions | |
| static void | static_cleanup_callback () |
| static zmm::Ref< Server > | getInstance () |
| static void * | operator new (size_t size) |
| static void | operator delete (void *ptr) |
Protected Member Functions | |
| void | upnp_actions (zmm::Ref< ActionRequest > request) |
| Dispatched an ActionRequest between the services. | |
| void | upnp_subscriptions (zmm::Ref< SubscriptionRequest > request) |
| Dispatched a SubscriptionRequest between the services. | |
| virtual void | registerSingleton () |
Protected Attributes | |
| bool | server_shutdown_flag |
| This flag is set to true by the upnp_cleanup() function. | |
| UpnpDevice_Handle | device_handle |
| Handle for our upnp device. | |
| zmm::String | serverUDN |
| Unique Device Number of the server. | |
| zmm::String | virtual_directory |
| Name of the virtual web server directory. | |
| zmm::String | virtual_url |
| Full virtual web server url. | |
| zmm::String | device_description_document |
| Device description document is created on the fly and stored here. | |
| int | alive_advertisement |
| Time interval to send ssdp:alive advertisements. | |
| zmm::Ref< ContentDirectoryService > | cds |
| ContentDirectoryService instance. | |
| zmm::Ref < ConnectionManagerService > | cmgr |
| ConnectionManagerService instance. | |
| mt_atomic_t | _ref_count |
Static Protected Attributes | |
| static zmm::Ref< Storage > | storage = nil |
| static zmm::Ref< Mutex > | mutex |
| static zmm::Ref< Server > | instance |
| static bool | singletonActive |
Provides methods to initialize and shutdown and to retrieve various information about the server.
Definition at line 48 of file src/server.h.
| Server::Server | ( | ) |
Definition at line 76 of file server.cc.
References server_shutdown_flag.
| UpnpDevice_Handle Server::getDeviceHandle | ( | ) |
Returns the device handle.
This function returns the handle for our device (it is needed to take care of subscriptions)
Definition at line 427 of file server.cc.
References device_handle.
Definition at line 62 of file singleton.h.
Referenced by CdsResourceManager::addResources_getUrlBase(), init(), main(), ConnectionManagerService::process_subscription_request(), ContentDirectoryService::process_subscription_request(), static_upnp_callback(), ConnectionManagerService::subscription_update(), ContentDirectoryService::subscription_update(), upnp_init(), and web_read().
| zmm::String Server::getIP | ( | ) |
Returns the IP address of the server.
Returns a string representation of the IP where the server is running. This is useful for constructing URL's, etc.
Definition at line 432 of file server.cc.
References UpnpGetServerIpAddress().
| zmm::String Server::getPort | ( | ) |
Returns the port of the server.
Returns a string representation of the server port. Allthough the port is also specified in the config, we can never be sure that we actually get that port after startup. This function returns the port on which the server is actually running.
Definition at line 437 of file server.cc.
References UpnpGetServerPort().
| int Object::getRefCount | ( | ) | [inherited] |
Definition at line 78 of file object.cc.
References zmm::Object::_ref_count, and atomic_get().
| bool Server::getShutdownStatus | ( | ) |
Tells if the server is about to be terminated.
This function returns true if the server is about to be terminated. This is the case when upnp_clean() was called.
Definition at line 314 of file server.cc.
References server_shutdown_flag.
| String Server::getVirtualURL | ( | ) |
| void Server::init | ( | ) | [virtual] |
Initializes the server.
This function reads information from the config and initializes various variables (like server UDN and so forth).
Reimplemented from Singleton< Server >.
Definition at line 81 of file server.cc.
References _, alive_advertisement, cds, CFG_SERVER_ALIVE_INTERVAL, CFG_SERVER_UDN, cmgr, DESC_CDS_SERVICE_ID, DESC_CDS_SERVICE_TYPE, DESC_CM_SERVICE_ID, DESC_CM_SERVICE_TYPE, Singleton< Server >::getInstance(), SERVER_VIRTUAL_DIR, serverUDN, ConnectionManagerService::setStaticArgs(), ContentDirectoryService::setStaticArgs(), and virtual_directory.
| void Object::operator delete | ( | void * | ptr | ) | [static, inherited] |
| void * Object::operator new | ( | size_t | size | ) | [static, inherited] |
Definition at line 94 of file singleton.h.
| void Object::release | ( | ) | [inherited] |
Definition at line 66 of file object.cc.
References zmm::Object::_ref_count, atomic_dec(), and zmm::Object::mutex.
Referenced by zmm::ArrayBase::clear(), zmm::String::operator=(), DSOHash< zmm::Array< CacheObject > >::releaseData(), DSBHash< VT >::releaseData(), DSOHash< zmm::Array< CacheObject > >::remove(), zmm::ArrayBase::remove(), zmm::ArrayBase::removeUnordered(), zmm::ArrayBase::set(), zmm::ArrayBase::~ArrayBase(), DSOHash< zmm::Array< CacheObject > >::~DSOHash(), zmm::ObjectQueue< AutoscanDirectory >::~ObjectQueue(), zmm::ObjectStack< Element >::~ObjectStack(), and zmm::String::~String().
| void Object::retain | ( | ) | [inherited] |
Definition at line 58 of file object.cc.
References zmm::Object::_ref_count, atomic_inc(), and zmm::Object::mutex.
Referenced by zmm::ArrayBase::append(), zmm::ObjectQueue< AutoscanDirectory >::enqueue(), zmm::ArrayBase::insert(), zmm::String::operator=(), zmm::ObjectStack< Element >::push(), DSOHash< zmm::Array< CacheObject > >::put(), DSBHash< VT >::put(), zmm::ArrayBase::set(), and zmm::String::String().
| void Server::shutdown | ( | ) | [virtual] |
Cleanup routine to shutdown the server.
Unregisters the device with the SDK, shuts down the update manager task, storage task, content manager.
Reimplemented from Singleton< Server >.
Definition at line 319 of file server.cc.
References _, _UpnpException, device_handle, log_debug, nil, server_shutdown_flag, storage, UPNP_E_SUCCESS, UpnpFinish(), and UpnpUnRegisterRootDevice().
| void Server::static_cleanup_callback | ( | ) | [static] |
| void Server::upnp_actions | ( | zmm::Ref< ActionRequest > | request | ) | [protected] |
Dispatched an ActionRequest between the services.
| request | Incoming ActionRequest. |
Currently we only support two services (ContentDirectoryService and ConnectionManagerService), this function looks at the service id of the request and calls the process_action_request() for the appropriate service.
Definition at line 442 of file server.cc.
References _, _UpnpException, cds, cmgr, DESC_CDS_SERVICE_ID, DESC_CM_SERVICE_ID, log_debug, serverUDN, and UPNP_E_BAD_REQUEST.
Referenced by upnp_callback().
| int Server::upnp_callback | ( | Upnp_EventType | eventtype, | |
| void * | event, | |||
| void * | cookie | |||
| ) |
Dispatch incoming UPnP events.
| eventtype | Upnp_EventType, identifying what kind of event came in. | |
| event | Pointer to the event. | |
| cookie | Unused. |
This function is called when a UPnP event is received, it then looks at the event type (either an action invocation or a subscription request) and dispatches the event accordingly. The event that is coming from the SDK is converted to our internal data structures (ActionRequest or SubscriptionRequest) and is then passed on to the appropriate request handler - to upnp_actions() or upnp_subscriptions()
Definition at line 358 of file server.cc.
References AUTOLOCK, zmm::String::c_str(), UpnpException::getErrorCode(), zmm::Exception::getMessage(), log_debug, log_info, log_warning, Singleton< Server >::mutex, NULL, upnp_actions(), UPNP_CONTROL_ACTION_REQUEST, UPNP_E_BAD_REQUEST, UPNP_E_SUCCESS, UPNP_EVENT_SUBSCRIPTION_REQUEST, and upnp_subscriptions().
| void Server::upnp_init | ( | zmm::String | interface, | |
| zmm::String | ip_address, | |||
| int | port | |||
| ) |
Initializes UPnP portion, only ip or interface can be given.
| interface | to bind to | |
| ip | address to bind to | |
| port | Port where the server will be listening for requests. |
Reads information from the config and creates a device description document. Initializes the UPnP SDK, sets up the virutal web server directories and registers web callbacks. Starts the update manager task.
Definition at line 113 of file server.cc.
References _, _Exception, _UpnpException, alive_advertisement, zmm::String::c_str(), CFG_SERVER_APPEND_PRESENTATION_URL_TO, CFG_SERVER_CUSTOM_HTTP_HEADERS, CFG_SERVER_IP, CFG_SERVER_NETWORK_INTERFACE, CFG_SERVER_PORT, CFG_SERVER_PRESENTATION_URL, CFG_SERVER_WEBROOT, device_handle, Singleton< Server >::getInstance(), interfaceToIP(), zmm::String::length(), log_debug, log_info, nil, NULL, register_web_callbacks(), static_cleanup_callback(), static_upnp_callback(), storage, string_ok(), UPNP_E_SUCCESS, UpnpAddCustomHTTPHeader(), UpnpAddVirtualDir(), UpnpGetServerIpAddress(), UpnpGetServerPort(), UpnpInit(), UPNPREG_BUF_DESC, UpnpRegisterRootDevice2(), UpnpSendAdvertisement(), UpnpSetWebServerRootDir(), UpnpUnRegisterRootDevice(), UpnpXML_RenderDeviceDescription(), virtual_directory, and virtual_url.
| void Server::upnp_subscriptions | ( | zmm::Ref< SubscriptionRequest > | request | ) | [protected] |
Dispatched a SubscriptionRequest between the services.
| request | Incoming SubscriptionRequest. |
Currently we only support two services (ContentDirectoryService and ConnectionManagerService), this function looks at the service id of the request and calls the process_subscription_request() for the appropriate service.
Definition at line 483 of file server.cc.
References _, _UpnpException, cds, cmgr, DESC_CDS_SERVICE_ID, DESC_CM_SERVICE_ID, serverUDN, and UPNP_E_BAD_REQUEST.
Referenced by upnp_callback().
mt_atomic_t zmm::Object::_ref_count [protected, inherited] |
Definition at line 54 of file object.h.
Referenced by zmm::Object::getRefCount(), zmm::Object::Object(), zmm::Object::release(), and zmm::Object::retain().
int Server::alive_advertisement [protected] |
Time interval to send ssdp:alive advertisements.
The value is read from the configuration.
Definition at line 171 of file src/server.h.
Referenced by init(), and upnp_init().
zmm::Ref<ContentDirectoryService> Server::cds [protected] |
ContentDirectoryService instance.
The ContentDirectoryService class is instantiated in the constructor. The class is responsible for processing an ActionRequest or a SubscriptionRequest.
Definition at line 178 of file src/server.h.
Referenced by init(), upnp_actions(), and upnp_subscriptions().
zmm::Ref<ConnectionManagerService> Server::cmgr [protected] |
ConnectionManagerService instance.
The ConnectionManagerService class is instantiated in the constructor. The class is responsible for processing an ActionRequest or a SubscriptionRequest.
Definition at line 185 of file src/server.h.
Referenced by init(), upnp_actions(), and upnp_subscriptions().
zmm::String Server::device_description_document [protected] |
Device description document is created on the fly and stored here.
All necessary values for the device description document are read from the configuration and the device desc doc is created on the fly.
Definition at line 166 of file src/server.h.
UpnpDevice_Handle Server::device_handle [protected] |
Handle for our upnp device.
This variable is returned by the getDeviceHandle() function.
Definition at line 137 of file src/server.h.
Referenced by getDeviceHandle(), shutdown(), and upnp_init().
Definition at line 91 of file singleton.h.
Reimplemented from zmm::Object.
Definition at line 90 of file singleton.h.
Referenced by upnp_callback().
bool Server::server_shutdown_flag [protected] |
This flag is set to true by the upnp_cleanup() function.
Definition at line 132 of file src/server.h.
Referenced by getShutdownStatus(), Server(), and shutdown().
zmm::String Server::serverUDN [protected] |
Unique Device Number of the server.
The UDN is read from the config, it must be unique and persistent over reboots.
Definition at line 143 of file src/server.h.
Referenced by init(), upnp_actions(), and upnp_subscriptions().
bool Singleton< Server >::singletonActive [static, protected, inherited] |
Definition at line 92 of file singleton.h.
Ref< Storage > Server::storage = nil [static, protected] |
Definition at line 129 of file src/server.h.
Referenced by shutdown(), static_cleanup_callback(), and upnp_init().
zmm::String Server::virtual_directory [protected] |
Name of the virtual web server directory.
All requests going to /content/ will be handled by our web callback functions.
Definition at line 151 of file src/server.h.
Referenced by init(), and upnp_init().
zmm::String Server::virtual_url [protected] |
Full virtual web server url.
The URL is constructed upon server initialization, since the real port is not known before. The value of this variable is returned by the getVirtualURL() function.
Definition at line 158 of file src/server.h.
Referenced by getVirtualURL(), and upnp_init().
1.6.1