Server Class Reference

Provides methods to initialize and shutdown and to retrieve various information about the server. More...

#include <server.h>

Inheritance diagram for Server:
Singleton< Server > zmm::Object

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< ServergetInstance ()
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< ContentDirectoryServicecds
 ContentDirectoryService instance.
zmm::Ref
< ConnectionManagerService
cmgr
 ConnectionManagerService instance.
mt_atomic_t _ref_count

Static Protected Attributes

static zmm::Ref< Storagestorage = nil
static zmm::Ref< Mutexmutex
static zmm::Ref< Serverinstance
static bool singletonActive

Detailed Description

Provides methods to initialize and shutdown and to retrieve various information about the server.

Definition at line 48 of file src/server.h.


Constructor & Destructor Documentation

Server::Server (  ) 

Definition at line 76 of file server.cc.

References server_shutdown_flag.


Member Function Documentation

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.

static zmm::Ref<Server > Singleton< Server >::getInstance (  )  [inline, static, inherited]
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 (  ) 

Returns the virtual web server URL.

A special virtual URL is registered with the internal web server, all content and all ui requests are server from there and are handled by the web callbacks.

Definition at line 352 of file server.cc.

References virtual_url.

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]

Definition at line 87 of file object.cc.

References FREE.

void * Object::operator new ( size_t  size  )  [static, inherited]

Definition at line 83 of file object.cc.

References MALLOC.

virtual void Singleton< Server >::registerSingleton (  )  [inline, protected, virtual, inherited]

Definition at line 94 of file singleton.h.

void Object::release (  )  [inherited]
void Object::retain (  )  [inherited]
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]

Definition at line 64 of file server.cc.

References nil, and storage.

Referenced by upnp_init().

void Server::upnp_actions ( zmm::Ref< ActionRequest request  )  [protected]

Dispatched an ActionRequest between the services.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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().


Field Documentation

mt_atomic_t zmm::Object::_ref_count [protected, inherited]
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().

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().

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().

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.

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().

zmm::Ref<Server > Singleton< Server >::instance [static, protected, inherited]

Definition at line 91 of file singleton.h.

zmm::Ref<Mutex> Singleton< Server >::mutex [static, protected, inherited]

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().

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().

Name of the virtual web server directory.

All requests going to /content/ will be handled by our web callback functions.

Todo:
Is there any need that this is a variable? A constant should be sufficient here.

Definition at line 151 of file src/server.h.

Referenced by init(), and upnp_init().

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().


The documentation for this class was generated from the following files:

Generated on Fri Mar 26 20:16:57 2010 for MediaTomb by  doxygen 1.6.1