#include <cybergarage/util/cstring.h>
#include <cybergarage/util/cmutex.h>
#include <cybergarage/util/ccond.h>
#include <cybergarage/xml/cxml.h>
#include <cybergarage/net/cinterface.h>
#include <cybergarage/upnp/cdevice.h>
#include <cybergarage/upnp/cargument.h>
#include <cybergarage/upnp/cupnp_status.h>
#include <cybergarage/upnp/ssdp/cssdp_server.h>
#include <cybergarage/upnp/event/cevent.h>
#include <cybergarage/upnp/event/cnotify.h>
#define cg_upnp_controlpoint_adddevice | ( | ctrlPoint, | |||
dev | ) | cg_upnp_devicelist_add(ctrlPoint->deviceList, dev) |
Add a device to the control point's list of devices. Do not call this from user applications.
ctrlPoint | The control point in use | |
dev | The device to add |
#define cg_upnp_controlpoint_addeventlistener | ( | ctrlPoint, | |||
listener | ) | (cg_upnp_eventlistenerlist_add(ctrlPoint->eventListeners, listener)) |
Set an event listener for the control point. Use this function to get event notifications to user-space applications.
ctrlPoint | The control point in question | |
listener | A callback function that is of type CG_UPNP_EVENT_LISTENER |
#define cg_upnp_controlpoint_getdevicelistener | ( | ctrlPoint | ) | (ctrlPoint->deviceListener) |
Get the device listener for the control point.
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_getdevices | ( | ctrlPoint | ) | cg_upnp_devicelist_gets(ctrlPoint->deviceList) |
Get the head of the control point's list of devices (use for iteration)
ctrlPoint | The control point in use |
#define cg_upnp_controlpoint_geteventlistener | ( | ctrlPoint | ) | (ctrlPoint->eventListeners->next->listener) |
Get the single event listener for the control point.
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_geteventlisteners | ( | ctrlPoint | ) | (ctrlPoint->eventListeners) |
Get the list of event listeners for the control point.
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_geteventport | ( | ctrlPoint | ) | (ctrlPoint->httpEventPort) |
Get the IP port number for the control point's event reception
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_geteventsuburi | ( | ctrlPoint | ) | cg_string_getvalue(ctrlPoint->httpEventURI) |
Get the URI used for the control point's event subscription notifications
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_gethttplistener | ( | ctrlPoint | ) | (ctrlPoint->httpListener) |
Get the HTTP listener function for the control point.
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_gethttpserverlist | ( | ctrlPoint | ) | (ctrlPoint->httpServerList) |
Get the list of HTTP servers associated to the control point
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_getndevices | ( | ctrlPoint | ) | cg_upnp_devicelist_size(ctrlPoint->deviceList) |
Get the number of devices known by the control point
ctrlPoint | The control point in use |
#define cg_upnp_controlpoint_getssdplistener | ( | ctrlPoint | ) | (ctrlPoint->ssdpListener) |
Get the SSDP message listener for the control point.
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_getssdpresponselistener | ( | ctrlPoint | ) | (ctrlPoint->ssdpResListener) |
Get the SSDP response listener for the control point.
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_getssdpresponseport | ( | ctrlPoint | ) | (ctrlPoint->ssdpResPort) |
Get the IP port number used for the control point's SSDP responses
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_getssdpresponseserverlist | ( | ctrlPoint | ) | (ctrlPoint->ssdpResServerList) |
Get the list of SSDP response servers associated to the control point
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_getssdpsearchmx | ( | ctrlPoint | ) | (ctrlPoint->ssdpSearchMx) |
Get the MX-parameter used for SSDP searches
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_getssdpserverlist | ( | ctrlPoint | ) | (ctrlPoint->ssdpServerList) |
Get the list of SSDP servers associated to the control point
ctrlPoint | The control point in question |
#define cg_upnp_controlpoint_getuserdata | ( | dev | ) | (ctrlPoint->userData) |
Get the user data pointer (arbitrary user data) from the control point.
dev | The control point in question |
#define CG_UPNP_CONTROLPOINT_HTTP_EVENT_DEFAULT_PORT 39500 |
Definition for HTTP event default port
#define CG_UPNP_CONTROLPOINT_HTTP_EVENTSUB_URI "/eventSub" |
Definition for default controlpoint event callback "location"
#define cg_upnp_controlpoint_removeeventlistener | ( | ctrlPoint, | |||
listener | ) | (cg_upnp_eventlistenerlist_remove(ctrlPoint->eventListeners, listener)) |
Remove an event listener from the control point.
ctrlPoint | The control point in question | |
listener | The callback function to remove, that is of type CG_UPNP_EVENT_LISTENER |
#define cg_upnp_controlpoint_setdevicelistener | ( | ctrlPoint, | |||
func | ) | (ctrlPoint->deviceListener = func) |
Set device listener for the control point.
ctrlPoint | The control point | |
func | A callback function that is type CG_UPNP_DEVICE_LISTENER or NULL |
#define cg_upnp_controlpoint_seteventlistener | ( | ctrlPoint, | |||
evlistener | ) |
Value:
do {\ if (evlistener == NULL) \ cg_upnp_eventlistenerlist_remove(ctrlPoint->eventListeners, ctrlPoint->eventListeners->next->listener); \ else \ cg_upnp_eventlistenerlist_add(ctrlPoint->eventListeners, evlistener); \ } while(0)
ctrlPoint | The control point in question | |
evlistener | The callback function to set, that is of type CG_UPNP_EVENT_LISTENER, or NULL |
#define cg_upnp_controlpoint_seteventport | ( | ctrlPoint, | |||
port | ) | (ctrlPoint->httpEventPort = port) |
Set the IP port number for the control point's event reception
ctrlPoint | The control point in question | |
port | The IP port number |
#define cg_upnp_controlpoint_seteventsuburi | ( | ctrlPoint, | |||
uri | ) | cg_string_setvalue(ctrlPoint->httpEventURI, uri) |
Set the URI used for the control point's event subscription notifications
ctrlPoint | The control point in question | |
uri | The URI to set |
#define cg_upnp_controlpoint_sethttplistener | ( | ctrlPoint, | |||
func | ) | (ctrlPoint->httpListener = func) |
Set an HTTP listener function to the control point. Use this function to get HTTP requests to user-space applications.
ctrlPoint | The control point in question | |
func | The listener function, that is of type CG_HTTP_LISTENER |
#define cg_upnp_controlpoint_setssdplistener | ( | ctrlPoint, | |||
func | ) | (ctrlPoint->ssdpListener = func) |
Set an SSDP message listener for the control point. Use this function to get SSDP messages to user-space applications.
ctrlPoint | The control point in question | |
func | A callback function that is of type CG_UPNP_SSDP_LISTNER |
#define cg_upnp_controlpoint_setssdpresponselistener | ( | ctrlPoint, | |||
func | ) | (ctrlPoint->ssdpResListener = func) |
Set an SSDP response listener for the control point. Use this function to get SSDP responses to user-space applications.
ctrlPoint | The control point in question | |
func | A callback function that is of type CG_UPNP_SSDP_RESPONSE_LISTNER |
#define cg_upnp_controlpoint_setssdpresponseport | ( | ctrlPoint, | |||
port | ) | (ctrlPoint->ssdpResPort = port) |
Set the IP port number used for the control point's SSDP responses
ctrlPoint | The control point in question | |
port | The IP port number |
#define cg_upnp_controlpoint_setssdpsearchmx | ( | ctrlPoint, | |||
value | ) | (ctrlPoint->ssdpSearchMx = value) |
Set the MX-parameter used for SSDP searches i.e. Set the time to wait (in seconds) for device responses to an M-SEARCH
ctrlPoint | The control point in question | |
value | MX; Time to wait |
#define cg_upnp_controlpoint_setuserdata | ( | ctrlPoint, | |||
value | ) | (ctrlPoint->userData = value) |
Set the user data pointer (arbitrary user data) to the control point.
ctrlPoint | The control point in question | |
value | Arbitrary user data |
#define CG_UPNP_CONTROLPOINT_SSDP_DEFAULT_SEARCH_MX 3 |
Definition for SSDP default search MX
#define CG_UPNP_CONTROLPOINT_SSDP_MIN_DELAY 20 |
Definition for control point SSDP minimum delay
#define CG_UPNP_CONTROLPOINT_SSDP_RESPONSE_DEFAULT_PORT 39400 |
Definition for control point default response port
#define CG_UPNP_CONTROLPOINT_SSDP_RESPONSE_PORT_MAX_TRIES_INDEX 80 |
Definition for numeric constant to specify the max tries to open a SSDP Response Port (rosfran.borges)
typedef void(*) CG_UPNP_DEVICE_LISTENER(char *udn, CgUpnpDeviceStatus status) |
Prototype for control point's device listener callback.
udn | The UDN of the device, that the status update concerns | |
status | The new status |
typedef struct _CgUpnpControlPoint CgUpnpControlPoint |
typedef enum _CgUpnpDeviceStatus CgUpnpDeviceStatus |
Device listener status parameters.
CgUpnpDeviceStatusAdded means a device has been added to local cache. CgUpnpDeviceStatusUpdated means a device description has been updated because its IP address or description has changed. The user should renew any active subscriptions if this has been received.
CgUpnpDeviceStatusInvalid is basically the same as CgUpnpDeviceStatusRemoved, but CgUpnpDeviceStatusRemoved is sent only when a device leaves the network in a proper way (i.e. with UPnP ByeBye messages). The user should immediately cease using the device, because it will be removed in both cases.
enum _CgUpnpDeviceStatus |
Device listener status parameters.
CgUpnpDeviceStatusAdded means a device has been added to local cache. CgUpnpDeviceStatusUpdated means a device description has been updated because its IP address or description has changed. The user should renew any active subscriptions if this has been received.
CgUpnpDeviceStatusInvalid is basically the same as CgUpnpDeviceStatusRemoved, but CgUpnpDeviceStatusRemoved is sent only when a device leaves the network in a proper way (i.e. with UPnP ByeBye messages). The user should immediately cease using the device, because it will be removed in both cases.
void cg_upnp_controlpoint_adddevicebyssdppacket | ( | CgUpnpControlPoint * | ctrlPoint, | |
CgUpnpSSDPPacket * | ssdpPkt | |||
) |
Add a device on the basis of an SSDP packet. Do not call this from user applications.
ctrlPoint | The control point, whose device list to handle | |
ssdpPkt | The received SSDP packet |
void cg_upnp_controlpoint_delete | ( | CgUpnpControlPoint * | ctrlPoint | ) |
Destroy the given control point
ctrlPoint | The control point struct to destroy |
void cg_upnp_controlpoint_expirationhandler | ( | CgThread * | thread | ) |
Worker thread for handling expirations.
thread | the thread in question |
CgUpnpDevice* cg_upnp_controlpoint_getdevicebyexacttype | ( | CgUpnpControlPoint * | ctrlPoint, | |
char * | exacttype | |||
) |
Find a device from the control point by the exact type of the device. This function searches for devices, whose *complete type string* matches the given string, including version number. For example: "urn:schemas-upnp-org:device:FooDevice:1". If you need to disregard the version, use cg_upnp_controlpoint_getdevicebytype
ctrlPoint | Controlpoint in question | |
exacttype | Type of the device |
CgUpnpDevice* cg_upnp_controlpoint_getdevicebytype | ( | CgUpnpControlPoint * | ctrlPoint, | |
char * | type | |||
) |
Find a device from the controlpoint by the type of the device. This function searches for devices, whose *type part* (i.e. not including the version) of the device type string matches the given string. For example: "urn:schemas-upnp-org:device:FooDevice". If you need to know the version of a device, use cg_upnp_devicetype_getversion
ctrlPoint | Controlpoint in question | |
type | Type of the device |
CgUpnpDevice* cg_upnp_controlpoint_getdevicebyudn | ( | CgUpnpControlPoint * | ctrlPoint, | |
char * | udn | |||
) |
Find a device from the controlpoint by the UDN of the device.
ctrlPoint | Controlpoint in question | |
udn | Type of the device |
char* cg_upnp_controlpoint_geteventsubcallbackurl | ( | CgUpnpControlPoint * | ctrlPoint, | |
char * | ifaddr, | |||
char * | buf, | |||
int | bufLen | |||
) |
Get the event subscription callback URI
ctrlPoint | The control point in question | |
ifaddr | Interface address | |
buf | Buffer used to store callback url | |
bufLen | Buffer length |
void cg_upnp_controlpoint_httprequestreceived | ( | CgHttpRequest * | httpReq | ) |
The function that calls all HTTP listener callback functions. Do not call this from applications.
httpReq | The received HTTP request |
BOOL cg_upnp_controlpoint_ipchanged | ( | CgUpnpControlPoint * | ctrlpoint | ) |
Notify the control point that any IP of the host has been changed.
ctrlpoint | The control point in use |
BOOL cg_upnp_controlpoint_lock | ( | CgUpnpControlPoint * | ctrlPoint | ) |
Lock the control point's mutex. The control point should be ALWAYS locked, when a CgUpnpDevice*, CgUpnpService*, CgUpnpAction* or other pointer has been taken into use from the stack. This effectively prevents devices/services from being updated/ removed or added while the control point is locked. You should release the lock as soon as possible with cg_upnp_controlpoint_unlock
ctrlPoint | The control point in question |
CgUpnpControlPoint* cg_upnp_controlpoint_new | ( | ) |
Create a new control point. Does not start any threads.
BOOL cg_upnp_controlpoint_parsescservicescpd | ( | CgUpnpService * | service | ) |
Parse the service description from the service's SCPD URL. Do not call this from user applications.
service | The service in question |
BOOL cg_upnp_controlpoint_parseservicesfordevice | ( | CgUpnpDevice * | dev, | |
CgUpnpSSDPPacket * | ssdpPkt | |||
) |
Parse the device's services using the received SSDP packet. Do not call this from user applications.
dev | The device in question | |
ssdpPkt | An SSDP packet |
void cg_upnp_controlpoint_removedevicebyssdppacket | ( | CgUpnpControlPoint * | ctrlPoint, | |
CgUpnpSSDPPacket * | ssdpPkt | |||
) |
Remove a device on the basis of an SSDP packet. Do not call this from user applications.
ctrlPoint | The control point, whose device list to handle | |
ssdpPkt | The received SSDP packet |
BOOL cg_upnp_controlpoint_resubscribe | ( | CgUpnpControlPoint * | ctrlPoint, | |
CgUpnpService * | service, | |||
long | timeout | |||
) |
Re-subscribe to a service's events (i.e. renew subscription)
ctrlPoint | The control point in use | |
service | The service to subscribe to | |
timeout | Timeout for subscription expiration/renewal |
BOOL cg_upnp_controlpoint_resubscribeall | ( | CgUpnpControlPoint * | ctrlPoint, | |
CgUpnpDevice * | dev, | |||
long | timeout | |||
) |
Re-subscribe to all of the device's services' events (i.e. renew subscription)
ctrlPoint | The control point in use | |
dev | The device to subscribe to | |
timeout | Timeout for subscription expiration/renewal |
BOOL cg_upnp_controlpoint_search | ( | CgUpnpControlPoint * | ctrlPoint, | |
char * | target | |||
) |
Do an M-SEARCH to look for devices in the network.
ctrlPoint | The control point in question | |
target | The Search Target parameter (ex. "ssdp:all") |
BOOL cg_upnp_controlpoint_start | ( | CgUpnpControlPoint * | ctrlPoint | ) |
Activate the control point. Starts listening for SSDP messages etc. You must call this function before you can actually use a control point.
ctrlPoint | The control point to start |
BOOL cg_upnp_controlpoint_stop | ( | CgUpnpControlPoint * | ctrlPoint | ) |
Stop the control point. Stops sending/receiveing/responding to any messages.
ctrlPoint | The control point to stop |
BOOL cg_upnp_controlpoint_subscribe | ( | CgUpnpControlPoint * | ctrlPoint, | |
CgUpnpService * | service, | |||
long | timeout | |||
) |
Subscribe to a service's events
ctrlPoint | The control point in use | |
service | The service to subscribe to | |
timeout | Timeout for subscription expiration/renewal |
BOOL cg_upnp_controlpoint_subscribeall | ( | CgUpnpControlPoint * | ctrlPoint, | |
CgUpnpDevice * | dev, | |||
long | timeout | |||
) |
Subscribe to all of the device's services' events
ctrlPoint | The control point in use | |
dev | The device to subscribe to | |
timeout | Timeout for subscription expiration/renewal |
BOOL cg_upnp_controlpoint_unlock | ( | CgUpnpControlPoint * | ctrlPoint | ) |
Release a previously locked control point mutex. See cg_upnp_controlpoint_lock for a more detailed description on the control point locking mechanism.
ctrlPoint | The control point in question |
BOOL cg_upnp_controlpoint_unsubscribe | ( | CgUpnpControlPoint * | ctrlPoint, | |
CgUpnpService * | service | |||
) |
Unsubscribe to a service's events (i.e. cancel subscription)
ctrlPoint | The control point in use | |
service | The service to unsubscribe to |
BOOL cg_upnp_controlpoint_unsubscribeall | ( | CgUpnpControlPoint * | ctrlPoint, | |
CgUpnpDevice * | dev | |||
) |
Unsubscribe to all of the device's services' events (i.e. cancel subscription)
ctrlPoint | The control point in use | |
dev | The device to unsubscribe to |
void cg_upnp_controlpoint_updatestatetablefromproperty | ( | CgUpnpService * | service, | |
CgUpnpProperty * | prop | |||
) |
When an event is received, update also the associated service's state table to include the evented state variable.
service | The service, whose state table to update | |
prop | The evented property from which to update |