diff --git a/ChangeLog b/ChangeLog index b977dda..0fd0596 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ Version 1.8.0 ******************************************************************************* +2010-11-22 Marcelo Jimenez + + Template object for ssdp_ResultData. + 2010-11-10 Fabrice Fontaine Support for "polling" select in sock_read_write. diff --git a/upnp/Makefile.am b/upnp/Makefile.am index bf75491..a6459b0 100644 --- a/upnp/Makefile.am +++ b/upnp/Makefile.am @@ -21,6 +21,7 @@ upnpincludedir = $(includedir)/upnp upnpinclude_HEADERS = \ inc/ActionComplete.h \ inc/ActionRequest.h \ + inc/Callback.h \ inc/Discovery.h \ inc/Event.h \ inc/EventSubscribe.h \ diff --git a/upnp/inc/Callback.h b/upnp/inc/Callback.h new file mode 100644 index 0000000..1c8ab30 --- /dev/null +++ b/upnp/inc/Callback.h @@ -0,0 +1,153 @@ + +#ifndef CALLBACK_H +#define CALLBACK_H + +/*! + * \file + */ + +/*! + * \brief The reason code for an event callback. + * + * The \b Event parameter will be different depending on the reason for the + * callback. The descriptions for each event type describe the contents of the + * \b Event parameter. + */ +enum Upnp_EventType_e { + /* + * Control callbacks + */ + + /*! Received by a device when a control point issues a control + * request. The \b Event parameter contains a pointer to a \b + * UpnpActionRequest structure containing the action. The application + * stores the results of the action in this structure. */ + UPNP_CONTROL_ACTION_REQUEST, + + /*! A \b UpnpSendActionAsync call completed. The \b Event + * parameter contains a pointer to a \b UpnpActionComplete structure + * with the results of the action. */ + UPNP_CONTROL_ACTION_COMPLETE, + + /*! Received by a device when a query for a single service variable + * arrives. The \b Event parameter contains a pointer to a \b + * UpnpStateVarRequest structure containing the name of the variable + * and value. */ + UPNP_CONTROL_GET_VAR_REQUEST, + + /*! A \b UpnpGetServiceVarStatus call completed. The \b Event + * parameter contains a pointer to a \b UpnpStateVarComplete structure + * containing the value for the variable. */ + UPNP_CONTROL_GET_VAR_COMPLETE, + + /* + * Discovery callbacks + */ + + /*! Received by a control point when a new device or service is available. + * The \b Event parameter contains a pointer to a \b + * UpnpDiscovery structure with the information about the device + * or service. */ + UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, + + /*! Received by a control point when a device or service shuts down. The \b + * Event parameter contains a pointer to a \b UpnpDiscovery + * structure containing the information about the device or + * service. */ + UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE, + + /*! Received by a control point when a matching device or service responds. + * The \b Event parameter contains a pointer to a \b + * UpnpDiscovery structure containing the information about + * the reply to the search request. */ + UPNP_DISCOVERY_SEARCH_RESULT, + + /*! Received by a control point when the search timeout expires. The + * SDK generates no more callbacks for this search after this + * event. The \b Event parameter is \c NULL. */ + UPNP_DISCOVERY_SEARCH_TIMEOUT, + + /* + * Eventing callbacks + */ + + /*! Received by a device when a subscription arrives. + * The \b Event parameter contains a pointer to a \b + * UpnpSubscriptionRequest structure. At this point, the + * subscription has already been accepted. \b UpnpAcceptSubscription + * needs to be called to confirm the subscription and transmit the + * initial state table. This can be done during this callback. The SDK + * generates no events for a subscription unless the device + * application calls \b UpnpAcceptSubscription. + */ + UPNP_EVENT_SUBSCRIPTION_REQUEST, + + /*! Received by a control point when an event arrives. The \b + * Event parameter contains a \b UpnpEvent structure + * with the information about the event. */ + UPNP_EVENT_RECEIVED, + + /*! A \b UpnpRenewSubscriptionAsync call completed. The status of + * the renewal is in the \b Event parameter as a \b + * Upnp_Event_Subscription structure. */ + UPNP_EVENT_RENEWAL_COMPLETE, + + /*! A \b UpnpSubscribeAsync call completed. The status of the + * subscription is in the \b Event parameter as a \b + * Upnp_Event_Subscription structure. */ + UPNP_EVENT_SUBSCRIBE_COMPLETE, + + /*! A \b UpnpUnSubscribeAsync call completed. The status of the + * subscription is in the \b Event parameter as a \b + * UpnpEventSubscribe structure. */ + UPNP_EVENT_UNSUBSCRIBE_COMPLETE, + + /*! The auto-renewal of a client subscription failed. + * The \b Event parameter is a \b UpnpEventSubscribe structure + * with the error code set appropriately. The subscription is no longer + * valid. */ + UPNP_EVENT_AUTORENEWAL_FAILED, + + /*! A client subscription has expired. This will only occur + * if auto-renewal of subscriptions is disabled. + * The \b Event parameter is a \b UpnpEventSubscribe + * structure. The subscription is no longer valid. */ + UPNP_EVENT_SUBSCRIPTION_EXPIRED +}; + +typedef enum Upnp_EventType_e Upnp_EventType; + +/*! + * All callback functions share the same prototype, documented below. + * Note that any memory passed to the callback function + * is valid only during the callback and should be copied if it + * needs to persist. This callback function needs to be thread + * safe. The context of the callback is always on a valid thread + * context and standard synchronization methods can be used. Note, + * however, because of this the callback cannot call SDK functions + * unless explicitly noted. + * + * \verbatim + int CallbackFxn(Upnp_EventType EventType, void *Event, void *Cookie); + \endverbatim + * + * where \b EventType is the event that triggered the callback, + * \b Event is a structure that denotes event-specific information for that + * event, and \b Cookie is the user data passed when the callback was + * registered. + * + * See \b Upnp_EventType for more information on the callback values and + * the associated \b Event parameter. + * + * The return value of the callback is currently ignored. It may be used + * in the future to communicate results back to the SDK. + */ +typedef int (*Upnp_FunPtr)( + /*! [in] .*/ + Upnp_EventType EventType, + /*! [in] .*/ + const void *Event, + /*! [in] .*/ + void *Cookie); + +#endif /* CALLBACK_H */ diff --git a/upnp/inc/Discovery.h b/upnp/inc/Discovery.h index 988e47f..c01c5d0 100644 --- a/upnp/inc/Discovery.h +++ b/upnp/inc/Discovery.h @@ -1,9 +1,7 @@ - #ifndef DISCOVERY_H #define DISCOVERY_H - /*! * \file * @@ -33,6 +31,5 @@ #include "TemplateInclude.h" - #endif /* DISCOVERY_H */ diff --git a/upnp/inc/upnp.h b/upnp/inc/upnp.h index 6053220..773589f 100644 --- a/upnp/inc/upnp.h +++ b/upnp/inc/upnp.h @@ -452,117 +452,6 @@ typedef int UpnpClient_Handle; */ typedef int UpnpDevice_Handle; -/*! - * \brief The reason code for an event callback. - * - * The \b Event parameter will be different depending on the reason for the - * callback. The descriptions for each event type describe the contents of the - * \b Event parameter. - */ -enum Upnp_EventType_e { - /* - * Control callbacks - */ - - /*! Received by a device when a control point issues a control - * request. The \b Event parameter contains a pointer to a \b - * UpnpActionRequest structure containing the action. The application - * stores the results of the action in this structure. */ - UPNP_CONTROL_ACTION_REQUEST, - - /*! A \b UpnpSendActionAsync call completed. The \b Event - * parameter contains a pointer to a \b UpnpActionComplete structure - * with the results of the action. */ - UPNP_CONTROL_ACTION_COMPLETE, - - /*! Received by a device when a query for a single service variable - * arrives. The \b Event parameter contains a pointer to a \b - * UpnpStateVarRequest structure containing the name of the variable - * and value. */ - UPNP_CONTROL_GET_VAR_REQUEST, - - /*! A \b UpnpGetServiceVarStatus call completed. The \b Event - * parameter contains a pointer to a \b UpnpStateVarComplete structure - * containing the value for the variable. */ - UPNP_CONTROL_GET_VAR_COMPLETE, - - /* - * Discovery callbacks - */ - - /*! Received by a control point when a new device or service is available. - * The \b Event parameter contains a pointer to a \b - * UpnpDiscovery structure with the information about the device - * or service. */ - UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, - - /*! Received by a control point when a device or service shuts down. The \b - * Event parameter contains a pointer to a \b UpnpDiscovery - * structure containing the information about the device or - * service. */ - UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE, - - /*! Received by a control point when a matching device or service responds. - * The \b Event parameter contains a pointer to a \b - * UpnpDiscovery structure containing the information about - * the reply to the search request. */ - UPNP_DISCOVERY_SEARCH_RESULT, - - /*! Received by a control point when the search timeout expires. The - * SDK generates no more callbacks for this search after this - * event. The \b Event parameter is \c NULL. */ - UPNP_DISCOVERY_SEARCH_TIMEOUT, - - /* - * Eventing callbacks - */ - - /*! Received by a device when a subscription arrives. - * The \b Event parameter contains a pointer to a \b - * UpnpSubscriptionRequest structure. At this point, the - * subscription has already been accepted. \b UpnpAcceptSubscription - * needs to be called to confirm the subscription and transmit the - * initial state table. This can be done during this callback. The SDK - * generates no events for a subscription unless the device - * application calls \b UpnpAcceptSubscription. - */ - UPNP_EVENT_SUBSCRIPTION_REQUEST, - - /*! Received by a control point when an event arrives. The \b - * Event parameter contains a \b UpnpEvent structure - * with the information about the event. */ - UPNP_EVENT_RECEIVED, - - /*! A \b UpnpRenewSubscriptionAsync call completed. The status of - * the renewal is in the \b Event parameter as a \b - * Upnp_Event_Subscription structure. */ - UPNP_EVENT_RENEWAL_COMPLETE, - - /*! A \b UpnpSubscribeAsync call completed. The status of the - * subscription is in the \b Event parameter as a \b - * Upnp_Event_Subscription structure. */ - UPNP_EVENT_SUBSCRIBE_COMPLETE, - - /*! A \b UpnpUnSubscribeAsync call completed. The status of the - * subscription is in the \b Event parameter as a \b - * UpnpEventSubscribe structure. */ - UPNP_EVENT_UNSUBSCRIBE_COMPLETE, - - /*! The auto-renewal of a client subscription failed. - * The \b Event parameter is a \b UpnpEventSubscribe structure - * with the error code set appropriately. The subscription is no longer - * valid. */ - UPNP_EVENT_AUTORENEWAL_FAILED, - - /*! A client subscription has expired. This will only occur - * if auto-renewal of subscriptions is disabled. - * The \b Event parameter is a \b UpnpEventSubscribe - * structure. The subscription is no longer valid. */ - UPNP_EVENT_SUBSCRIPTION_EXPIRED -}; - -typedef enum Upnp_EventType_e Upnp_EventType; - /*! * \brief Holds the subscription identifier for a subscription between a * client and a device. @@ -618,39 +507,7 @@ enum Upnp_DescType_e { typedef enum Upnp_DescType_e Upnp_DescType; - -/*! - * All callback functions share the same prototype, documented below. - * Note that any memory passed to the callback function - * is valid only during the callback and should be copied if it - * needs to persist. This callback function needs to be thread - * safe. The context of the callback is always on a valid thread - * context and standard synchronization methods can be used. Note, - * however, because of this the callback cannot call SDK functions - * unless explicitly noted. - * - * \verbatim - int CallbackFxn(Upnp_EventType EventType, void *Event, void *Cookie); - \endverbatim - * - * where \b EventType is the event that triggered the callback, - * \b Event is a structure that denotes event-specific information for that - * event, and \b Cookie is the user data passed when the callback was - * registered. - * - * See \b Upnp_EventType for more information on the callback values and - * the associated \b Event parameter. - * - * The return value of the callback is currently ignored. It may be used - * in the future to communicate results back to the SDK. - */ -typedef int (*Upnp_FunPtr)( - /*! [in] .*/ - Upnp_EventType EventType, - /*! [in] .*/ - void *Event, - /*! [in] .*/ - void *Cookie); +#include "Callback.h" /* @} Constants and Types */ diff --git a/upnp/sample/common/sample_util.c b/upnp/sample/common/sample_util.c index 797bd8f..1af0969 100644 --- a/upnp/sample/common/sample_util.c +++ b/upnp/sample/common/sample_util.c @@ -320,7 +320,7 @@ void SampleUtil_PrintEventType(Upnp_EventType S) } } -int SampleUtil_PrintEvent(Upnp_EventType EventType, void *Event) +int SampleUtil_PrintEvent(Upnp_EventType EventType, const void *Event) { ithread_mutex_lock(&display_mutex); diff --git a/upnp/sample/common/sample_util.h b/upnp/sample/common/sample_util.h index 7308e23..a169ca1 100644 --- a/upnp/sample/common/sample_util.h +++ b/upnp/sample/common/sample_util.h @@ -128,7 +128,7 @@ int SampleUtil_PrintEvent( /*! [in] The type of callback event. */ Upnp_EventType EventType, /*! [in] The callback event structure. */ - void *Event); + const void *Event); /*! * \brief This routine finds the first occurance of a service in a DOM diff --git a/upnp/sample/common/tv_ctrlpt.c b/upnp/sample/common/tv_ctrlpt.c index 1ba8538..03356e2 100644 --- a/upnp/sample/common/tv_ctrlpt.c +++ b/upnp/sample/common/tv_ctrlpt.c @@ -986,7 +986,7 @@ void TvCtrlPointHandleGetVar( * Cookie -- Optional data specified during callback registration * ********************************************************************************/ -int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie) +int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, const void *Event, void *Cookie) { int errCode = 0; @@ -995,7 +995,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void /* SSDP Stuff */ case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_SEARCH_RESULT: { - UpnpDiscovery *d_event = (UpnpDiscovery *)Event; + const UpnpDiscovery *d_event = (UpnpDiscovery *)Event; IXML_Document *DescDoc = NULL; const char *location = NULL; int errCode = UpnpDiscovery_get_ErrCode(d_event); diff --git a/upnp/sample/common/tv_ctrlpt.h b/upnp/sample/common/tv_ctrlpt.h index c6ce7e6..70be1c6 100644 --- a/upnp/sample/common/tv_ctrlpt.h +++ b/upnp/sample/common/tv_ctrlpt.h @@ -166,7 +166,7 @@ void TvStateUpdate( void TvCtrlPointHandleEvent(const char *, int, IXML_Document *); void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int); -int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *); +int TvCtrlPointCallbackEventHandler(Upnp_EventType, const void *, void *); /*! * \brief Checks the advertisement each device in the global device list. diff --git a/upnp/sample/common/tv_device.c b/upnp/sample/common/tv_device.c index dde7cbc..93946f4 100644 --- a/upnp/sample/common/tv_device.c +++ b/upnp/sample/common/tv_device.c @@ -1308,7 +1308,7 @@ int TvDeviceDecreaseBrightness(IXML_Document *in, IXML_Document **out, const cha return IncrementBrightness(-1, in, out, errorString); } -int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie) +int TvDeviceCallbackEventHandler(Upnp_EventType EventType, const void *Event, void *Cookie) { switch (EventType) { case UPNP_EVENT_SUBSCRIPTION_REQUEST: diff --git a/upnp/sample/common/tv_device.h b/upnp/sample/common/tv_device.h index c4a9bec..17eb8b6 100644 --- a/upnp/sample/common/tv_device.h +++ b/upnp/sample/common/tv_device.h @@ -249,7 +249,7 @@ int TvDeviceCallbackEventHandler( /*! [in] The type of callback event. */ Upnp_EventType, /*! [in] Data structure containing event data. */ - void *Event, + const void *Event, /*! [in] Optional data specified during callback registration. */ void *Cookie); diff --git a/upnp/src/ssdp/ssdp_ResultData.c b/upnp/src/ssdp/ssdp_ResultData.c index 8a5c25e..8986f15 100644 --- a/upnp/src/ssdp/ssdp_ResultData.c +++ b/upnp/src/ssdp/ssdp_ResultData.c @@ -1,100 +1,22 @@ +/*! + * \file + * + * \brief SSDPResultData object implementation. + * + * \author Marcelo Roberto Jimenez + */ + #include "config.h" +#define TEMPLATE_GENERATE_SOURCE #include "ssdp_ResultData.h" -#include /* for calloc(), free() */ - -struct SSSDPResultData -{ - UpnpDiscovery *m_param; - void *m_cookie; - Upnp_FunPtr m_ctrlpt_callback; -}; - -SSDPResultData *SSDPResultData_new() -{ - struct SSSDPResultData *p = calloc(1, sizeof (struct SSSDPResultData)); - - p->m_param = UpnpDiscovery_new(); -#if 0 - p->m_cookie = NULL; - p->m_ctrlpt_callback = NULL; -#endif - - return (SSDPResultData *)p; -} - -void SSDPResultData_delete(SSDPResultData *p) -{ - struct SSSDPResultData *q = (struct SSSDPResultData *)p; - - if (!q) return; - - UpnpDiscovery_delete(q->m_param); - q->m_param = NULL; - - q->m_cookie = NULL; - - q->m_ctrlpt_callback = NULL; - - free(p); -} - -SSDPResultData *SSDPResultData_dup(const SSDPResultData *p) -{ - SSDPResultData *q = SSDPResultData_new(); - - SSDPResultData_assign(q, p); - - return q; -} - -void SSDPResultData_assign(SSDPResultData *q, const SSDPResultData *p) -{ - if (q != p) { - SSDPResultData_set_Param(q, SSDPResultData_get_Param(p)); - SSDPResultData_set_Cookie(q, SSDPResultData_get_Cookie(p)); - SSDPResultData_set_CtrlptCallback(q, SSDPResultData_get_CtrlptCallback(p)); - } -} - -UpnpDiscovery *SSDPResultData_get_Param(const SSDPResultData *p) -{ - return ((struct SSSDPResultData *)p)->m_param; -} - -void SSDPResultData_set_Param(SSDPResultData *p, const UpnpDiscovery *d) -{ - UpnpDiscovery_assign(((struct SSSDPResultData *)p)->m_param, d); -} - -void *SSDPResultData_get_Cookie(const SSDPResultData *p) -{ - return ((struct SSSDPResultData *)p)->m_cookie; -} - -void SSDPResultData_set_Cookie(SSDPResultData *p, void *c) -{ - ((struct SSSDPResultData *)p)->m_cookie = c; -} - -Upnp_FunPtr SSDPResultData_get_CtrlptCallback(const SSDPResultData *p) -{ - return ((struct SSSDPResultData *)p)->m_ctrlpt_callback; -} - -void SSDPResultData_set_CtrlptCallback(SSDPResultData *p, Upnp_FunPtr f) -{ - ((struct SSSDPResultData *)p)->m_ctrlpt_callback = f; -} - void SSDPResultData_Callback(const SSDPResultData *p) { - struct SSSDPResultData *q = (struct SSSDPResultData *)p; - q->m_ctrlpt_callback( - UPNP_DISCOVERY_SEARCH_RESULT, - q->m_param, - q->m_cookie); + Upnp_FunPtr callback = SSDPResultData_get_CtrlptCallback(p); + callback(UPNP_DISCOVERY_SEARCH_RESULT, + SSDPResultData_get_Param(p), + SSDPResultData_get_Cookie(p)); } diff --git a/upnp/src/ssdp/ssdp_ResultData.h b/upnp/src/ssdp/ssdp_ResultData.h index 65fedb9..09628c1 100644 --- a/upnp/src/ssdp/ssdp_ResultData.h +++ b/upnp/src/ssdp/ssdp_ResultData.h @@ -1,42 +1,43 @@ - #ifndef SSDP_RESULTDATA_H #define SSDP_RESULTDATA_H +/*! + * \file + * + * \brief SSDPResultData object declararion. + * + * \author Marcelo Roberto Jimenez + */ -/** Structure to contain Discovery response */ -typedef struct s_SSDPResultData SSDPResultData; +/******************************************************************************/ +#ifdef TEMPLATE_GENERATE_SOURCE +#undef TEMPLATE_GENERATE_SOURCE -#include "Discovery.h" /* for UpnpDiscovery */ -#include "upnp.h" /* for Upnp_FunPtr */ + #include "Discovery.h" /* for UpnpDiscovery */ +#define TEMPLATE_GENERATE_SOURCE +#else /* TEMPLATE_GENERATE_SOURCE */ -/** Constructor */ -SSDPResultData *SSDPResultData_new(); + #include "Discovery.h" /* for UpnpDiscovery */ -/** Destructor */ -void SSDPResultData_delete(SSDPResultData *p); +#endif /* TEMPLATE_GENERATE_SOURCE */ -/** Copy Constructor */ -SSDPResultData *SSDPResultData_dup(const SSDPResultData *p); +/******************************************************************************/ -/** Assignment operator */ -void SSDPResultData_assign(SSDPResultData *q, const SSDPResultData *p); +#include "Callback.h" /* for Upnp_FunPtr */ -/** */ -UpnpDiscovery *SSDPResultData_get_Param(const SSDPResultData *p); -void SSDPResultData_set_Param(SSDPResultData *p, const UpnpDiscovery *d); +#define CLASS SSDPResultData -/** */ -void *SSDPResultData_get_Cookie(const SSDPResultData *p); -void SSDPResultData_set_Cookie(SSDPResultData *p, void *c); +#define EXPAND_CLASS_MEMBERS(CLASS) \ + EXPAND_CLASS_MEMBER_OBJECT(CLASS, Param, UpnpDiscovery) \ + EXPAND_CLASS_MEMBER_INT(CLASS, Cookie, void *) \ + EXPAND_CLASS_MEMBER_INT(CLASS, CtrlptCallback, Upnp_FunPtr) \ -/** */ -Upnp_FunPtr SSDPResultData_get_CtrlptCallback(const SSDPResultData *p); -void SSDPResultData_set_CtrlptCallback(SSDPResultData *p, Upnp_FunPtr f); +#include "TemplateInclude.h" -/** */ +/*! */ void SSDPResultData_Callback(const SSDPResultData *p); #endif /* SSDP_RESULTDATA_H */