struct Upnp_Event becomes UpnpEvent. One less externally visible data structure.

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@359 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2008-05-03 15:35:14 +00:00
parent 2e4a96f034
commit 98a45e17b5
13 changed files with 255 additions and 112 deletions

View File

@ -22,6 +22,7 @@ upnpinclude_HEADERS = \
inc/ActionComplete.h \
inc/ActionRequest.h \
inc/Discovery.h \
inc/Event.h \
inc/EventSubscribe.h \
inc/FileInfo.h \
inc/StateVarComplete.h \
@ -123,6 +124,7 @@ libupnp_la_SOURCES += \
libupnp_la_SOURCES += src/api/ActionComplete.c
libupnp_la_SOURCES += src/api/ActionRequest.c
libupnp_la_SOURCES += src/api/Discovery.c
libupnp_la_SOURCES += src/api/Event.c
libupnp_la_SOURCES += src/api/EventSubscribe.c
libupnp_la_SOURCES += src/api/FileInfo.c
libupnp_la_SOURCES += src/api/StateVarComplete.c

View File

@ -13,10 +13,8 @@ extern "C" {
typedef struct {} UpnpActionRequest;
#include "String.h" // for UpnpString
#include "ixml.h" // for IXML_Document
#include "String.h" // for UpnpString
#include <netinet/in.h> // for in_addr

51
upnp/inc/Event.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef EVENT_H
#define EVENT_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** Returned along with a {\bf UPNP_EVENT_RECEIVED} callback. */
typedef struct {} UpnpEvent;
#include "ixml.h" // for IXML_Document
#include "String.h" // for UpnpString
/** Constructor */
UpnpEvent *UpnpEvent_new();
/** Destructor */
void UpnpEvent_delete(UpnpEvent *p);
/** Copy Constructor */
UpnpEvent *UpnpEvent_dup(const UpnpEvent *p);
/** Assignment operator */
void UpnpEvent_assign(UpnpEvent *q, const UpnpEvent *p);
/** The event sequence number. */
int UpnpEvent_get_EventKey(const UpnpEvent *p);
void UpnpEvent_set_EventKey(UpnpEvent *p, int n);
/** The DOM tree representing the changes generating the event. */
IXML_Document *UpnpEvent_get_ChangedVariables(const UpnpEvent *p);
void UpnpEvent_set_ChangedVariables(UpnpEvent *p, IXML_Document *d);
/** The subscription ID for this subscription. */
UpnpString *UpnpEvent_get_SID(const UpnpEvent *p);
void UpnpEvent_set_SID(UpnpEvent *p, const UpnpString *s);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* EVENT_H */

View File

@ -519,6 +519,7 @@
#include "ActionComplete.h"
#include "ActionRequest.h"
#include "Discovery.h"
#include "Event.h"
#include "EventSubscribe.h"
#include "FileInfo.h"
#include "StateVarComplete.h"
@ -634,7 +635,7 @@ enum Upnp_EventType_e {
UPNP_EVENT_SUBSCRIPTION_REQUEST,
/** Received by a control point when an event arrives. The {\bf
* Event} parameter contains a {\bf Upnp_Event} structure
* Event} parameter contains a {\bf UpnpEvent} structure
* with the information about the event. */
UPNP_EVENT_RECEIVED,
@ -735,20 +736,6 @@ enum Upnp_DescType_e {
typedef enum Upnp_DescType_e Upnp_DescType;
/** Returned along with a {\bf UPNP_EVENT_RECEIVED} callback. */
struct Upnp_Event
{
/** The subscription ID for this subscription. */
Upnp_SID Sid;
/** The event sequence number. */
int EventKey;
/** The DOM tree representing the changes generating the event. */
IXML_Document *ChangedVariables;
};
/** Returned along with a {\bf UPNP_EVENT_SUBSCRIPTION_REQUEST}
* callback. */

View File

@ -548,17 +548,18 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
case UPNP_EVENT_RECEIVED:
{
struct Upnp_Event *e_event = (struct Upnp_Event *)Event;
UpnpEvent *e_event = (UpnpEvent *)Event;
char *xmlbuff = NULL;
xmlbuff = ixmlPrintNode( (IXML_Node *) e_event->ChangedVariables );
xmlbuff = ixmlPrintNode(
(IXML_Node *) UpnpEvent_get_ChangedVariables(e_event));
SampleUtil_Print(
"SID = %s\n"
"EventKey = %d\n"
"ChangedVars = %s\n",
e_event->Sid,
e_event->EventKey,
xmlbuff );
ixmlFreeDOMString( xmlbuff );
UpnpString_get_String(UpnpEvent_get_SID(e_event)),
UpnpEvent_get_EventKey(e_event),
xmlbuff);
ixmlFreeDOMString(xmlbuff);
}
break;

View File

@ -937,34 +937,38 @@ TvStateUpdate( char *UDN,
* changes -- The DOM document representing the changes
*
********************************************************************************/
void
TvCtrlPointHandleEvent( Upnp_SID sid,
int evntkey,
IXML_Document * changes )
void TvCtrlPointHandleEvent(
const UpnpString *sid,
int evntkey,
IXML_Document *changes)
{
struct TvDeviceNode *tmpdevnode;
int service;
struct TvDeviceNode *tmpdevnode;
int service;
const char *aux_sid = NULL;
ithread_mutex_lock( &DeviceListMutex );
ithread_mutex_lock(&DeviceListMutex);
tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( strcmp( tmpdevnode->device.TvService[service].SID, sid ) ==
0 ) {
SampleUtil_Print( "Received Tv %s Event: %d for SID %s",
TvServiceName[service], evntkey, sid );
tmpdevnode = GlobalDeviceList;
while (tmpdevnode) {
for (service = 0; service < TV_SERVICE_SERVCOUNT; ++service) {
aux_sid = UpnpString_get_String(sid);
if (strcmp(tmpdevnode->device.TvService[service].SID, aux_sid) == 0) {
SampleUtil_Print("Received Tv %s Event: %d for SID %s",
TvServiceName[service],
evntkey,
aux_sid);
TvStateUpdate(
tmpdevnode->device.UDN,
service,
changes,
(char **)&tmpdevnode->device.TvService[service].VariableStrVal);
break;
}
}
tmpdevnode = tmpdevnode->next;
}
TvStateUpdate( tmpdevnode->device.UDN, service, changes,
( char ** )&tmpdevnode->device.
TvService[service].VariableStrVal );
break;
}
}
tmpdevnode = tmpdevnode->next;
}
ithread_mutex_unlock( &DeviceListMutex );
ithread_mutex_unlock(&DeviceListMutex);
}
/********************************************************************************
@ -1148,9 +1152,11 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
/* GENA Stuff */
case UPNP_EVENT_RECEIVED: {
struct Upnp_Event *e_event = ( struct Upnp_Event * )Event;
TvCtrlPointHandleEvent( e_event->Sid, e_event->EventKey,
e_event->ChangedVariables );
UpnpEvent *e_event = (UpnpEvent *)Event;
TvCtrlPointHandleEvent(
UpnpEvent_get_SID(e_event),
UpnpEvent_get_EventKey(e_event),
UpnpEvent_get_ChangedVariables(e_event));
break;
}

View File

@ -143,7 +143,7 @@ int TvCtrlPointPrintDevice(int);
void TvCtrlPointAddDevice(IXML_Document *, const char *, int);
void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString);
void TvStateUpdate(char*,int, IXML_Document * , char **);
void TvCtrlPointHandleEvent(Upnp_SID, int, IXML_Document *);
void TvCtrlPointHandleEvent(const UpnpString *, int, IXML_Document *);
void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int);
int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *);
void TvCtrlPointVerifyTimeouts(int);

View File

@ -1745,8 +1745,7 @@ TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT c
* Cookie -- Optional data specified during callback registration
*
*****************************************************************************/
int
TvDeviceCallbackEventHandler( Upnp_EventType EventType, void *Event, void *Cookie )
int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
{
switch ( EventType ) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST:

View File

@ -937,34 +937,38 @@ TvStateUpdate( char *UDN,
* changes -- The DOM document representing the changes
*
********************************************************************************/
void
TvCtrlPointHandleEvent( Upnp_SID sid,
int evntkey,
IXML_Document * changes )
void TvCtrlPointHandleEvent(
const UpnpString *sid,
int evntkey,
IXML_Document *changes)
{
struct TvDeviceNode *tmpdevnode;
int service;
struct TvDeviceNode *tmpdevnode;
int service;
const char *aux_sid = NULL;
ithread_mutex_lock( &DeviceListMutex );
ithread_mutex_lock(&DeviceListMutex);
tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
if( strcmp( tmpdevnode->device.TvService[service].SID, sid ) ==
0 ) {
SampleUtil_Print( "Received Tv %s Event: %d for SID %s",
TvServiceName[service], evntkey, sid );
tmpdevnode = GlobalDeviceList;
while (tmpdevnode) {
for (service = 0; service < TV_SERVICE_SERVCOUNT; ++service) {
aux_sid = UpnpString_get_String(sid);
if (strcmp(tmpdevnode->device.TvService[service].SID, aux_sid) == 0) {
SampleUtil_Print("Received Tv %s Event: %d for SID %s",
TvServiceName[service],
evntkey,
aux_sid);
TvStateUpdate(
tmpdevnode->device.UDN,
service,
changes,
(char **)&tmpdevnode->device.TvService[service].VariableStrVal);
break;
}
}
tmpdevnode = tmpdevnode->next;
}
TvStateUpdate( tmpdevnode->device.UDN, service, changes,
( char ** )&tmpdevnode->device.
TvService[service].VariableStrVal );
break;
}
}
tmpdevnode = tmpdevnode->next;
}
ithread_mutex_unlock( &DeviceListMutex );
ithread_mutex_unlock(&DeviceListMutex);
}
/********************************************************************************
@ -1148,9 +1152,11 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
/* GENA Stuff */
case UPNP_EVENT_RECEIVED: {
struct Upnp_Event *e_event = ( struct Upnp_Event * )Event;
TvCtrlPointHandleEvent( e_event->Sid, e_event->EventKey,
e_event->ChangedVariables );
UpnpEvent *e_event = (UpnpEvent *)Event;
TvCtrlPointHandleEvent(
UpnpEvent_get_SID(e_event),
UpnpEvent_get_EventKey(e_event),
UpnpEvent_get_ChangedVariables(e_event));
break;
}

View File

@ -143,7 +143,7 @@ int TvCtrlPointPrintDevice(int);
void TvCtrlPointAddDevice(IXML_Document *, const char *, int);
void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString);
void TvStateUpdate(char*,int, IXML_Document * , char **);
void TvCtrlPointHandleEvent(Upnp_SID, int, IXML_Document *);
void TvCtrlPointHandleEvent(const UpnpString *, int, IXML_Document *);
void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int);
int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *);
void TvCtrlPointVerifyTimeouts(int);

View File

@ -1747,8 +1747,7 @@ TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT c
* Cookie -- Optional data specified during callback registration
*
*****************************************************************************/
int
TvDeviceCallbackEventHandler( Upnp_EventType EventType, void *Event, void *Cookie )
int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
{
switch ( EventType ) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST:

105
upnp/src/api/Event.c Normal file
View File

@ -0,0 +1,105 @@
#include "config.h"
#include "Event.h"
#include <stdlib.h> // for calloc(), free()
struct SUpnpEvent
{
int m_eventKey;
IXML_Document *m_changedVariables;
UpnpString *m_SID;
};
UpnpEvent *UpnpEvent_new()
{
struct SUpnpEvent *p = calloc(1, sizeof (struct SUpnpEvent));
#if 0
p->m_eventKey = 0;
p->m_changedVariables = NULL;
#endif
p->m_SID = UpnpString_new();
return (UpnpEvent *)p;
}
void UpnpEvent_delete(UpnpEvent *p)
{
struct SUpnpEvent *q = (struct SUpnpEvent *)p;
q->m_eventKey = 0;
q->m_changedVariables = NULL;
UpnpString_delete(q->m_SID);
q->m_SID = NULL;
free(p);
}
UpnpEvent *UpnpEvent_dup(const UpnpEvent *p)
{
UpnpEvent *q = UpnpEvent_new();
UpnpEvent_assign(q, p);
return q;
}
void UpnpEvent_assign(UpnpEvent *q, const UpnpEvent *p)
{
if (q != p) {
UpnpEvent_set_EventKey(q, UpnpEvent_get_EventKey(p));
UpnpEvent_set_ChangedVariables(q, UpnpEvent_get_ChangedVariables(p));
UpnpEvent_set_SID(q, UpnpEvent_get_SID(p));
}
}
int UpnpEvent_get_EventKey(const UpnpEvent *p)
{
return ((struct SUpnpEvent *)p)->m_eventKey;
}
void UpnpEvent_set_EventKey(UpnpEvent *p, int n)
{
((struct SUpnpEvent *)p)->m_eventKey = n;
}
IXML_Document *UpnpEvent_get_ChangedVariables(const UpnpEvent *p)
{
return ((struct SUpnpEvent *)p)->m_changedVariables;
}
void UpnpEvent_set_ChangedVariables(UpnpEvent *p, IXML_Document *d)
{
ixmlDocument_free(((struct SUpnpEvent *)p)->m_changedVariables);
((struct SUpnpEvent *)p)->m_changedVariables = d;
}
UpnpString *UpnpEvent_get_SID(const UpnpEvent *p)
{
return ((struct SUpnpEvent *)p)->m_SID;
}
void UpnpEvent_set_SID(UpnpEvent *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpEvent *)p)->m_SID);
((struct SUpnpEvent *)p)->m_SID = UpnpString_dup(s);
}

View File

@ -770,11 +770,11 @@ exit_function:
****************************************************************************/
void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event)
{
struct Upnp_Event event_struct;
UpnpEvent *event_struct = UpnpEvent_new();
IXML_Document *ChangedVars = NULL;
int eventKey;
token sid;
ClientSubscription *subscription = NULL;
IXML_Document *ChangedVars;
struct Handle_Info *handle_info;
void *cookie;
Upnp_FunPtr callback;
@ -788,8 +788,7 @@ void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event
// get SID
if (httpmsg_find_hdr(event, HDR_SID, &sid_hdr) == NULL) {
error_respond(info, HTTP_PRECONDITION_FAILED, event);
return;
goto exit_function;
}
sid.buff = sid_hdr.buf;
sid.size = sid_hdr.length;
@ -798,24 +797,21 @@ void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event
if (httpmsg_find_hdr(event, HDR_SEQ, &seq_hdr) == NULL ||
matchstr(seq_hdr.buf, seq_hdr.length, "%d%0", &eventKey) != PARSE_OK) {
error_respond( info, HTTP_BAD_REQUEST, event );
return;
goto exit_function;
}
// get NT and NTS headers
if (httpmsg_find_hdr(event, HDR_NT, &nt_hdr) == NULL ||
httpmsg_find_hdr(event, HDR_NTS, &nts_hdr) == NULL) {
error_respond( info, HTTP_BAD_REQUEST, event );
return;
goto exit_function;
}
// verify NT and NTS headers
if (memptr_cmp(&nt_hdr, "upnp:event") != 0 ||
memptr_cmp(&nts_hdr, "upnp:propchange") != 0) {
error_respond(info, HTTP_PRECONDITION_FAILED, event);
return;
goto exit_function;
}
// parse the content (should be XML)
@ -823,8 +819,7 @@ void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event
event->msg.length == 0 ||
ixmlParseBufferEx(event->entity.buf, &ChangedVars) != IXML_SUCCESS) {
error_respond(info, HTTP_BAD_REQUEST, event);
return;
goto exit_function;
}
HandleLock();
@ -833,9 +828,7 @@ void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event
if (GetClientHandleInfo(&client_handle, &handle_info) != HND_CLIENT) {
error_respond(info, HTTP_PRECONDITION_FAILED, event);
HandleUnlock();
ixmlDocument_free(ChangedVars);
return;
goto exit_function;
}
// get subscription based on SID
@ -859,9 +852,7 @@ void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event
error_respond(info, HTTP_PRECONDITION_FAILED, event);
SubscribeUnlock();
HandleUnlock();
ixmlDocument_free(ChangedVars);
return;
goto exit_function;
}
subscription = GetClientSubActualSID(handle_info->ClientSubList, &sid);
@ -869,18 +860,14 @@ void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event
error_respond( info, HTTP_PRECONDITION_FAILED, event );
SubscribeUnlock();
HandleUnlock();
ixmlDocument_free( ChangedVars );
return;
goto exit_function;
}
SubscribeUnlock();
} else {
error_respond( info, HTTP_PRECONDITION_FAILED, event );
HandleUnlock();
ixmlDocument_free( ChangedVars );
return;
goto exit_function;
}
}
@ -888,9 +875,9 @@ void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event
error_respond(info, HTTP_OK, event);
// fill event struct
strcpy(event_struct.Sid, UpnpString_get_String(UpnpClientSubscription_get_SID(subscription)));
event_struct.EventKey = eventKey;
event_struct.ChangedVariables = ChangedVars;
UpnpEvent_set_EventKey(event_struct, eventKey);
UpnpEvent_set_ChangedVariables(event_struct, ChangedVars);
UpnpEvent_set_SID(event_struct, UpnpClientSubscription_get_SID(subscription));
// copy callback
callback = handle_info->Callback;
@ -902,9 +889,11 @@ void gena_process_notification_event(IN SOCKINFO *info, IN http_message_t *event
// In future, should find a way of mainting
// that the handle is not unregistered in the middle of a
// callback
callback(UPNP_EVENT_RECEIVED, &event_struct, cookie);
callback(UPNP_EVENT_RECEIVED, event_struct, cookie);
exit_function:
ixmlDocument_free(ChangedVars);
UpnpEvent_delete(event_struct);
}
#endif // INCLUDE_CLIENT_APIS