Merge of similar files.

This commit is contained in:
Marcelo Roberto Jimenez 2010-10-04 15:35:59 -03:00
parent 4f5d0e1d70
commit 6d8aa815ea
5 changed files with 326 additions and 351 deletions

View File

@ -29,9 +29,14 @@
* *
******************************************************************************/ ******************************************************************************/
#include "upnp_tv_ctrlpt.h" #include "upnp_tv_ctrlpt.h"
/*
#include "upnp.h"
/*!
Mutex for protecting the global device list Mutex for protecting the global device list
in a multi-threaded, asynchronous environment. in a multi-threaded, asynchronous environment.
All functions should lock this mutex before reading All functions should lock this mutex before reading
@ -48,7 +53,7 @@ char *TvServiceType[] = {
}; };
char *TvServiceName[] = { "Control", "Picture" }; char *TvServiceName[] = { "Control", "Picture" };
/* /*!
Global arrays for storing variable names and counts for Global arrays for storing variable names and counts for
TvControl and TvPicture services TvControl and TvPicture services
*/ */
@ -59,12 +64,12 @@ char *TvVarName[TV_SERVICE_SERVCOUNT][TV_MAXVARS] = {
char TvVarCount[TV_SERVICE_SERVCOUNT] = char TvVarCount[TV_SERVICE_SERVCOUNT] =
{ TV_CONTROL_VARCOUNT, TV_PICTURE_VARCOUNT }; { TV_CONTROL_VARCOUNT, TV_PICTURE_VARCOUNT };
/* /*!
Timeout to request during subscriptions Timeout to request during subscriptions
*/ */
int default_timeout = 1801; int default_timeout = 1801;
/* /*!
The first node in the global device list, or NULL if empty The first node in the global device list, or NULL if empty
*/ */
struct TvDeviceNode *GlobalDeviceList = NULL; struct TvDeviceNode *GlobalDeviceList = NULL;
@ -1071,6 +1076,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
SampleUtil_Print( SampleUtil_Print(
"Error in Discovery Callback -- %d", errCode); "Error in Discovery Callback -- %d", errCode);
} }
location = UpnpString_get_String(UpnpDiscovery_get_Location(d_event)); location = UpnpString_get_String(UpnpDiscovery_get_Location(d_event));
errCode = UpnpDownloadXmlDoc(location, &DescDoc); errCode = UpnpDownloadXmlDoc(location, &DescDoc);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
@ -1335,8 +1341,9 @@ int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionP
SampleUtil_Print( SampleUtil_Print(
"UPnP Initialized\n" "UPnP Initialized\n"
"\tipaddress= %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address, port); ip_address ? ip_address : "{NULL}",
port);
SampleUtil_Print("Registering Control Point"); SampleUtil_Print("Registering Control Point");
rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler, rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler,

View File

@ -38,8 +38,10 @@
#define DEFAULT_WEB_DIR "./web" #define DEFAULT_WEB_DIR "./web"
#define DESC_URL_SIZE 200 #define DESC_URL_SIZE 200
/* /*
Device type for tv device Device type for tv device
*/ */
@ -372,20 +374,18 @@ TvDeviceStateTableInit( IN char *DescDocURL )
int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event) int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event)
{ {
unsigned int i = 0; unsigned int i = 0;
//unsigned int j = 0;
int cmp1 = 0; int cmp1 = 0;
int cmp2 = 0; int cmp2 = 0;
const char *l_serviceId = NULL; const char *l_serviceId = NULL;
const char *l_udn = NULL; const char *l_udn = NULL;
const char *l_sid = NULL; const char *l_sid = NULL;
// IXML_Document *PropSet = NULL;
// lock state mutex // lock state mutex
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock(&TVDevMutex);
l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event)); l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event));
l_udn = UpnpString_get_String(UpnpSubscriptionRequest_get_UDN(sr_event)); l_udn = UpnpSubscriptionRequest_get_UDN_cstr(sr_event);
l_sid = UpnpString_get_String(UpnpSubscriptionRequest_get_SID(sr_event)); l_sid = UpnpSubscriptionRequest_get_SID_cstr(sr_event);
for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) { for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) {
cmp1 = strcmp(l_udn, tv_service_table[i].UDN); cmp1 = strcmp(l_udn, tv_service_table[i].UDN);
cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId); cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId);
@ -425,7 +425,7 @@ int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event
} }
} }
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock(&TVDevMutex);
return 1; return 1;
} }
@ -443,53 +443,52 @@ int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event
* cgv_event -- The control get variable request event structure * cgv_event -- The control get variable request event structure
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceHandleGetVarRequest(INOUT UpnpStateVarRequest *cgv_event)
TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
{ {
unsigned int i = 0; unsigned int i = 0;
unsigned int j = 0; unsigned int j = 0;
int getvar_succeeded = 0; int getvar_succeeded = 0;
UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL); UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock(&TVDevMutex);
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { for (i = 0; i < TV_SERVICE_SERVCOUNT; i++) {
// check udn and service id // check udn and service id
const char *devUDN = const char *devUDN =
UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event)); UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event));
const char *serviceID = const char *serviceID =
UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event)); UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event));
if( ( strcmp( devUDN, tv_service_table[i].UDN ) == 0 ) && if (strcmp(devUDN, tv_service_table[i].UDN) == 0 &&
( strcmp( serviceID, tv_service_table[i].ServiceId ) == 0 ) ) { strcmp(serviceID, tv_service_table[i].ServiceId) == 0) {
// check variable name // check variable name
for( j = 0; j < tv_service_table[i].VariableCount; j++ ) { for (j = 0; j < tv_service_table[i].VariableCount; j++) {
const char *stateVarName = const char *stateVarName = UpnpString_get_String(
UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)); UpnpStateVarRequest_get_StateVarName(cgv_event));
if( strcmp( stateVarName, tv_service_table[i].VariableName[j] ) == 0 ) { if (strcmp(stateVarName,
getvar_succeeded = 1; tv_service_table[i].VariableName[j]) == 0) {
UpnpStateVarRequest_set_CurrentVal(cgv_event, getvar_succeeded = 1;
tv_service_table[i].VariableStrVal[j] ); UpnpStateVarRequest_set_CurrentVal(cgv_event,
break; tv_service_table[i].VariableStrVal[j]);
} break;
} }
} }
} }
}
if (getvar_succeeded) {
UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
} else {
SampleUtil_Print(
"Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n"
" Unknown variable name = %s\n",
UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)));
UpnpStateVarRequest_set_ErrCode(cgv_event, 404);
UpnpStateVarRequest_strcpy_ErrStr(cgv_event, "Invalid Variable");
}
if( getvar_succeeded ) { ithread_mutex_unlock(&TVDevMutex);
UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
} else {
SampleUtil_Print(
"Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n"
" Unknown variable name = %s\n",
UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)) );
UpnpStateVarRequest_set_ErrCode(cgv_event, 404);
UpnpStateVarRequest_strcpy_ErrStr(cgv_event, "Invalid Variable" );
}
ithread_mutex_unlock( &TVDevMutex ); return UpnpStateVarRequest_get_ErrCode(cgv_event) == UPNP_E_SUCCESS;
return UpnpStateVarRequest_get_ErrCode(cgv_event) == UPNP_E_SUCCESS;
} }
/****************************************************************************** /******************************************************************************
@ -504,86 +503,81 @@ TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
* ca_event -- The control action request event structure * ca_event -- The control action request event structure
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceHandleActionRequest(INOUT UpnpActionRequest *ca_event)
TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
{ {
/* /* Defaults if action not found. */
Defaults if action not found int action_found = 0;
*/ int i = 0;
int action_found = 0; int service = -1;
int i = 0; int retCode = 0;
int service = -1; char *errorString = NULL;
int retCode = 0; const char *devUDN = NULL;
char *errorString = NULL; const char *serviceID = NULL;
const char *devUDN = NULL; const char *actionName = NULL;
const char *serviceID = NULL; IXML_Document *actionResult = NULL;
const char *actionName = NULL;
IXML_Document *actionResult = NULL;
UpnpActionRequest_set_ErrCode(ca_event, 0); UpnpActionRequest_set_ErrCode(ca_event, 0);
UpnpActionRequest_set_ActionResult(ca_event, NULL); UpnpActionRequest_set_ActionResult(ca_event, NULL);
devUDN = UpnpString_get_String(UpnpActionRequest_get_DevUDN( ca_event)); devUDN = UpnpString_get_String(UpnpActionRequest_get_DevUDN( ca_event));
serviceID = UpnpString_get_String(UpnpActionRequest_get_ServiceID( ca_event)); serviceID = UpnpString_get_String(UpnpActionRequest_get_ServiceID( ca_event));
actionName = UpnpString_get_String(UpnpActionRequest_get_ActionName(ca_event)); actionName = UpnpString_get_String(UpnpActionRequest_get_ActionName(ca_event));
if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN ) == 0 ) && if (strcmp(devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN) == 0 &&
( strcmp( serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId ) == 0 ) ) { strcmp(serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId) == 0) {
/* Request for action in the TvDevice Control Service */ /* Request for action in the TvDevice Control Service. */
service = TV_SERVICE_CONTROL; service = TV_SERVICE_CONTROL;
} else if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN ) == 0 ) && } else if (strcmp(devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN) == 0 &&
( strcmp( serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId ) == 0 ) ) { strcmp(serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId) == 0) {
/* Request for action in the TvDevice Picture Service */ /* Request for action in the TvDevice Picture Service. */
service = TV_SERVICE_PICTURE; service = TV_SERVICE_PICTURE;
} }
/* Find and call appropriate procedure based on action name /* Find and call appropriate procedure based on action name.
* Each action name has an associated procedure stored in the * Each action name has an associated procedure stored in the
* service table. These are set at initialization. */ * service table. These are set at initialization. */
for( i = 0; i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL; i++ ) { for (i = 0;
if( !strcmp( actionName, tv_service_table[service].ActionNames[i] ) ) { i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL;
if( ( !strcmp( tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[TV_CONTROL_POWER], "1" ) ) || i++) {
( !strcmp( actionName, "PowerOn" ) ) ) { if (!strcmp(actionName, tv_service_table[service].ActionNames[i])) {
retCode = tv_service_table[service].actions[i]( if (!strcmp(tv_service_table[TV_SERVICE_CONTROL].
UpnpActionRequest_get_ActionRequest(ca_event), VariableStrVal[TV_CONTROL_POWER], "1") ||
&actionResult, !strcmp(actionName, "PowerOn")) {
&errorString ); retCode = tv_service_table[service].actions[i](
UpnpActionRequest_set_ActionResult(ca_event, actionResult); UpnpActionRequest_get_ActionRequest(ca_event),
} else { &actionResult,
errorString = "Power is Off"; &errorString);
retCode = UPNP_E_INTERNAL_ERROR; UpnpActionRequest_set_ActionResult(ca_event, actionResult);
} } else {
action_found = 1; errorString = "Power is Off";
break; retCode = UPNP_E_INTERNAL_ERROR;
} }
} action_found = 1;
break;
}
}
if( !action_found ) { if (!action_found) {
UpnpActionRequest_set_ActionResult(ca_event, NULL); UpnpActionRequest_set_ActionResult(ca_event, NULL);
UpnpActionRequest_strcpy_ErrStr(ca_event, "Invalid Action" ); UpnpActionRequest_strcpy_ErrStr(ca_event, "Invalid Action");
UpnpActionRequest_set_ErrCode(ca_event, 401); UpnpActionRequest_set_ErrCode(ca_event, 401);
} else { } else {
if( retCode == UPNP_E_SUCCESS ) { if (retCode == UPNP_E_SUCCESS) {
UpnpActionRequest_set_ErrCode(ca_event, UPNP_E_SUCCESS); UpnpActionRequest_set_ErrCode(ca_event, UPNP_E_SUCCESS);
} else { } else {
// copy the error string // copy the error string
UpnpActionRequest_strcpy_ErrStr(ca_event, errorString ); UpnpActionRequest_strcpy_ErrStr(ca_event, errorString);
switch ( retCode ) { switch (retCode) {
case UPNP_E_INVALID_PARAM: case UPNP_E_INVALID_PARAM:
{ UpnpActionRequest_set_ErrCode(ca_event, 402);
UpnpActionRequest_set_ErrCode(ca_event, 402); break;
break; case UPNP_E_INTERNAL_ERROR:
} default:
case UPNP_E_INTERNAL_ERROR: UpnpActionRequest_set_ErrCode(ca_event, 501);
default: break;
{ }
UpnpActionRequest_set_ErrCode(ca_event, 501); }
break; }
}
} return UpnpActionRequest_get_ErrCode(ca_event);
}
}
return UpnpActionRequest_get_ErrCode(ca_event);
} }
/****************************************************************************** /******************************************************************************
@ -1759,43 +1753,43 @@ TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT c
*****************************************************************************/ *****************************************************************************/
int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie) int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
{ {
switch ( EventType ) { switch (EventType) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
TvDeviceHandleSubscriptionRequest((UpnpSubscriptionRequest *)Event); TvDeviceHandleSubscriptionRequest((UpnpSubscriptionRequest *)Event);
break; break;
case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_GET_VAR_REQUEST:
TvDeviceHandleGetVarRequest( (UpnpStateVarRequest *)Event ); TvDeviceHandleGetVarRequest((UpnpStateVarRequest *)Event);
break; break;
case UPNP_CONTROL_ACTION_REQUEST: case UPNP_CONTROL_ACTION_REQUEST:
TvDeviceHandleActionRequest( (UpnpActionRequest *)Event ); TvDeviceHandleActionRequest((UpnpActionRequest *)Event);
break; break;
/* /*
ignore these cases, since this is not a control point ignore these cases, since this is not a control point
*/ */
case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
case UPNP_DISCOVERY_SEARCH_RESULT: case UPNP_DISCOVERY_SEARCH_RESULT:
case UPNP_DISCOVERY_SEARCH_TIMEOUT: case UPNP_DISCOVERY_SEARCH_TIMEOUT:
case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:
case UPNP_CONTROL_ACTION_COMPLETE: case UPNP_CONTROL_ACTION_COMPLETE:
case UPNP_CONTROL_GET_VAR_COMPLETE: case UPNP_CONTROL_GET_VAR_COMPLETE:
case UPNP_EVENT_RECEIVED: case UPNP_EVENT_RECEIVED:
case UPNP_EVENT_RENEWAL_COMPLETE: case UPNP_EVENT_RENEWAL_COMPLETE:
case UPNP_EVENT_SUBSCRIBE_COMPLETE: case UPNP_EVENT_SUBSCRIBE_COMPLETE:
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
break; break;
default: default:
SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n", SampleUtil_Print("Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
EventType ); EventType);
} }
/* Print a summary of the event received */ /* Print a summary of the event received */
SampleUtil_PrintEvent( EventType, Event ); SampleUtil_PrintEvent(EventType, Event);
return 0; return 0;
} }
/****************************************************************************** /******************************************************************************
@ -1807,8 +1801,7 @@ int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Co
* Parameters: * Parameters:
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceStop(void)
TvDeviceStop()
{ {
UpnpUnRegisterRootDevice( device_handle ); UpnpUnRegisterRootDevice( device_handle );
UpnpFinish(); UpnpFinish();

View File

@ -623,7 +623,7 @@ int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OU
int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name, int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name,
char *web_dir_path, print_string pfun); char *web_dir_path, print_string pfun);
int TvDeviceStop(); int TvDeviceStop(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -143,8 +143,7 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
* UDN -- The Unique Device Name for the device to remove * UDN -- The Unique Device Name for the device to remove
* *
********************************************************************************/ ********************************************************************************/
int int TvCtrlPointRemoveDevice(const char *UDN)
TvCtrlPointRemoveDevice(const char *UDN)
{ {
struct TvDeviceNode *curdevnode; struct TvDeviceNode *curdevnode;
struct TvDeviceNode *prevdevnode; struct TvDeviceNode *prevdevnode;
@ -1019,10 +1018,10 @@ void TvCtrlPointHandleSubscribeUpdate(
ithread_mutex_unlock( &DeviceListMutex ); ithread_mutex_unlock( &DeviceListMutex );
} }
void void TvCtrlPointHandleGetVar(
TvCtrlPointHandleGetVar( const char *controlURL, const char *controlURL,
const char *varName, const char *varName,
const DOMString varValue ) const DOMString varValue)
{ {
struct TvDeviceNode *tmpdevnode; struct TvDeviceNode *tmpdevnode;
@ -1033,9 +1032,9 @@ TvCtrlPointHandleGetVar( const char *controlURL,
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while (tmpdevnode) { while (tmpdevnode) {
for (service = 0; service < TV_SERVICE_SERVCOUNT; service++) { for (service = 0; service < TV_SERVICE_SERVCOUNT; service++) {
if (strcmp(tmpdevnode->device.TvService[service].ControlURL, controlURL ) == 0 ) { if (strcmp(tmpdevnode->device.TvService[service].ControlURL, controlURL) == 0) {
SampleUtil_StateUpdate( SampleUtil_StateUpdate(
varName, varValue, tmpdevnode->device.UDN, GET_VAR_COMPLETE ); varName, varValue, tmpdevnode->device.UDN, GET_VAR_COMPLETE);
break; break;
} }
} }
@ -1072,6 +1071,7 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
IXML_Document *DescDoc = NULL; IXML_Document *DescDoc = NULL;
const char *location = NULL; const char *location = NULL;
int errCode = UpnpDiscovery_get_ErrCode(d_event); int errCode = UpnpDiscovery_get_ErrCode(d_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Discovery Callback -- %d", errCode); "Error in Discovery Callback -- %d", errCode);
@ -1087,19 +1087,15 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
TvCtrlPointAddDevice( TvCtrlPointAddDevice(
DescDoc, location, UpnpDiscovery_get_Expires(d_event)); DescDoc, location, UpnpDiscovery_get_Expires(d_event));
} }
if (DescDoc) {
if( DescDoc ) {
ixmlDocument_free(DescDoc); ixmlDocument_free(DescDoc);
} }
TvCtrlPointPrintList(); TvCtrlPointPrintList();
break; break;
} }
case UPNP_DISCOVERY_SEARCH_TIMEOUT: case UPNP_DISCOVERY_SEARCH_TIMEOUT:
/* Nothing to do here... */ /* Nothing to do here... */
break; break;
case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: { case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: {
UpnpDiscovery *d_event = (UpnpDiscovery *)Event; UpnpDiscovery *d_event = (UpnpDiscovery *)Event;
int errCode = UpnpDiscovery_get_ErrCode(d_event); int errCode = UpnpDiscovery_get_ErrCode(d_event);
@ -1110,16 +1106,12 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
SampleUtil_Print( SampleUtil_Print(
"Error in Discovery ByeBye Callback -- %d", errCode); "Error in Discovery ByeBye Callback -- %d", errCode);
} }
SampleUtil_Print("Received ByeBye for Device: %s", deviceId); SampleUtil_Print("Received ByeBye for Device: %s", deviceId);
TvCtrlPointRemoveDevice(deviceId); TvCtrlPointRemoveDevice(deviceId);
SampleUtil_Print("After byebye:"); SampleUtil_Print("After byebye:");
TvCtrlPointPrintList(); TvCtrlPointPrintList();
break; break;
} }
/* SOAP Stuff */ /* SOAP Stuff */
case UPNP_CONTROL_ACTION_COMPLETE: { case UPNP_CONTROL_ACTION_COMPLETE: {
UpnpActionComplete *a_event = (UpnpActionComplete *)Event; UpnpActionComplete *a_event = (UpnpActionComplete *)Event;
@ -1129,29 +1121,24 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
"Error in Action Complete Callback -- %d", "Error in Action Complete Callback -- %d",
errCode); errCode);
} }
/* No need for any processing here, just print out results. /* No need for any processing here, just print out results.
* Service state table updates are handled by events. */ * Service state table updates are handled by events. */
break; break;
} }
case UPNP_CONTROL_GET_VAR_COMPLETE: { case UPNP_CONTROL_GET_VAR_COMPLETE: {
UpnpStateVarComplete *sv_event = (UpnpStateVarComplete *)Event; UpnpStateVarComplete *sv_event = (UpnpStateVarComplete *)Event;
int errCode = UpnpStateVarComplete_get_ErrCode(sv_event); int errCode = UpnpStateVarComplete_get_ErrCode(sv_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Get Var Complete Callback -- %d", "Error in Get Var Complete Callback -- %d", errCode);
errCode );
} else { } else {
TvCtrlPointHandleGetVar( TvCtrlPointHandleGetVar(
UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)), UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)),
UpnpString_get_String(UpnpStateVarComplete_get_StateVarName(sv_event)), UpnpString_get_String(UpnpStateVarComplete_get_StateVarName(sv_event)),
UpnpStateVarComplete_get_CurrentVal(sv_event) ); UpnpStateVarComplete_get_CurrentVal(sv_event));
} }
break; break;
} }
/* GENA Stuff */ /* GENA Stuff */
case UPNP_EVENT_RECEIVED: { case UPNP_EVENT_RECEIVED: {
UpnpEvent *e_event = (UpnpEvent *)Event; UpnpEvent *e_event = (UpnpEvent *)Event;
@ -1161,26 +1148,23 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
UpnpEvent_get_ChangedVariables(e_event)); UpnpEvent_get_ChangedVariables(e_event));
break; break;
} }
case UPNP_EVENT_SUBSCRIBE_COMPLETE: case UPNP_EVENT_SUBSCRIBE_COMPLETE:
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
case UPNP_EVENT_RENEWAL_COMPLETE: { case UPNP_EVENT_RENEWAL_COMPLETE: {
UpnpEventSubscribe *es_event = (UpnpEventSubscribe *)Event; UpnpEventSubscribe *es_event = (UpnpEventSubscribe *)Event;
errCode = UpnpEventSubscribe_get_ErrCode(es_event); errCode = UpnpEventSubscribe_get_ErrCode(es_event);
if (errCode != UPNP_E_SUCCESS) { if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print( SampleUtil_Print(
"Error in Event Subscribe Callback -- %d", "Error in Event Subscribe Callback -- %d", errCode);
errCode);
} else { } else {
TvCtrlPointHandleSubscribeUpdate( TvCtrlPointHandleSubscribeUpdate(
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)), UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
UpnpString_get_String(UpnpEventSubscribe_get_SID(es_event)), UpnpString_get_String(UpnpEventSubscribe_get_SID(es_event)),
UpnpEventSubscribe_get_TimeOut(es_event)); UpnpEventSubscribe_get_TimeOut(es_event));
} }
break; break;
} }
case UPNP_EVENT_AUTORENEWAL_FAILED: case UPNP_EVENT_AUTORENEWAL_FAILED:
case UPNP_EVENT_SUBSCRIPTION_EXPIRED: { case UPNP_EVENT_SUBSCRIPTION_EXPIRED: {
UpnpEventSubscribe *es_event = (UpnpEventSubscribe *)Event; UpnpEventSubscribe *es_event = (UpnpEventSubscribe *)Event;
@ -1192,7 +1176,6 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)), UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
&TimeOut, &TimeOut,
newSID); newSID);
if (errCode == UPNP_E_SUCCESS) { if (errCode == UPNP_E_SUCCESS) {
SampleUtil_Print("Subscribed to EventURL with SID=%s", newSID); SampleUtil_Print("Subscribed to EventURL with SID=%s", newSID);
TvCtrlPointHandleSubscribeUpdate( TvCtrlPointHandleSubscribeUpdate(
@ -1204,7 +1187,6 @@ int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void
} }
break; break;
} }
/* ignore these cases, since this is not a device */ /* ignore these cases, since this is not a device */
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_GET_VAR_REQUEST:

View File

@ -376,20 +376,18 @@ TvDeviceStateTableInit( IN char *DescDocURL )
int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event) int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event)
{ {
unsigned int i = 0; unsigned int i = 0;
//unsigned int j = 0;
int cmp1 = 0; int cmp1 = 0;
int cmp2 = 0; int cmp2 = 0;
const char *l_serviceId = NULL; const char *l_serviceId = NULL;
const char *l_udn = NULL; const char *l_udn = NULL;
const char *l_sid = NULL; const char *l_sid = NULL;
// IXML_Document *PropSet = NULL;
// lock state mutex // lock state mutex
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock(&TVDevMutex);
l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event)); l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event));
l_udn = UpnpString_get_String(UpnpSubscriptionRequest_get_UDN(sr_event)); l_udn = UpnpSubscriptionRequest_get_UDN_cstr(sr_event);
l_sid = UpnpString_get_String(UpnpSubscriptionRequest_get_SID(sr_event)); l_sid = UpnpSubscriptionRequest_get_SID_cstr(sr_event);
for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) { for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) {
cmp1 = strcmp(l_udn, tv_service_table[i].UDN); cmp1 = strcmp(l_udn, tv_service_table[i].UDN);
cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId); cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId);
@ -429,7 +427,7 @@ int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event
} }
} }
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock(&TVDevMutex);
return 1; return 1;
} }
@ -447,53 +445,52 @@ int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event
* cgv_event -- The control get variable request event structure * cgv_event -- The control get variable request event structure
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceHandleGetVarRequest(INOUT UpnpStateVarRequest *cgv_event)
TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
{ {
unsigned int i = 0; unsigned int i = 0;
unsigned int j = 0; unsigned int j = 0;
int getvar_succeeded = 0; int getvar_succeeded = 0;
UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL); UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock(&TVDevMutex);
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { for (i = 0; i < TV_SERVICE_SERVCOUNT; i++) {
// check udn and service id // check udn and service id
const char *devUDN = const char *devUDN =
UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event)); UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event));
const char *serviceID = const char *serviceID =
UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event)); UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event));
if( ( strcmp( devUDN, tv_service_table[i].UDN ) == 0 ) && if (strcmp(devUDN, tv_service_table[i].UDN) == 0 &&
( strcmp( serviceID, tv_service_table[i].ServiceId ) == 0 ) ) { strcmp(serviceID, tv_service_table[i].ServiceId) == 0) {
// check variable name // check variable name
for( j = 0; j < tv_service_table[i].VariableCount; j++ ) { for (j = 0; j < tv_service_table[i].VariableCount; j++) {
const char *stateVarName = const char *stateVarName = UpnpString_get_String(
UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)); UpnpStateVarRequest_get_StateVarName(cgv_event));
if( strcmp( stateVarName, tv_service_table[i].VariableName[j] ) == 0 ) { if (strcmp(stateVarName,
getvar_succeeded = 1; tv_service_table[i].VariableName[j]) == 0) {
UpnpStateVarRequest_set_CurrentVal(cgv_event, getvar_succeeded = 1;
tv_service_table[i].VariableStrVal[j] ); UpnpStateVarRequest_set_CurrentVal(cgv_event,
break; tv_service_table[i].VariableStrVal[j]);
} break;
} }
} }
} }
}
if (getvar_succeeded) {
UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
} else {
SampleUtil_Print(
"Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n"
" Unknown variable name = %s\n",
UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)));
UpnpStateVarRequest_set_ErrCode(cgv_event, 404);
UpnpStateVarRequest_strcpy_ErrStr(cgv_event, "Invalid Variable");
}
if( getvar_succeeded ) { ithread_mutex_unlock(&TVDevMutex);
UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
} else {
SampleUtil_Print(
"Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n"
" Unknown variable name = %s\n",
UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)) );
UpnpStateVarRequest_set_ErrCode(cgv_event, 404);
UpnpStateVarRequest_strcpy_ErrStr(cgv_event, "Invalid Variable" );
}
ithread_mutex_unlock( &TVDevMutex ); return UpnpStateVarRequest_get_ErrCode(cgv_event) == UPNP_E_SUCCESS;
return UpnpStateVarRequest_get_ErrCode(cgv_event) == UPNP_E_SUCCESS;
} }
/****************************************************************************** /******************************************************************************
@ -508,86 +505,81 @@ TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
* ca_event -- The control action request event structure * ca_event -- The control action request event structure
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceHandleActionRequest(INOUT UpnpActionRequest *ca_event)
TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
{ {
/* /* Defaults if action not found. */
Defaults if action not found int action_found = 0;
*/ int i = 0;
int action_found = 0; int service = -1;
int i = 0; int retCode = 0;
int service = -1; char *errorString = NULL;
int retCode = 0; const char *devUDN = NULL;
char *errorString = NULL; const char *serviceID = NULL;
const char *devUDN = NULL; const char *actionName = NULL;
const char *serviceID = NULL; IXML_Document *actionResult = NULL;
const char *actionName = NULL;
IXML_Document *actionResult = NULL;
UpnpActionRequest_set_ErrCode(ca_event, 0); UpnpActionRequest_set_ErrCode(ca_event, 0);
UpnpActionRequest_set_ActionResult(ca_event, NULL); UpnpActionRequest_set_ActionResult(ca_event, NULL);
devUDN = UpnpString_get_String(UpnpActionRequest_get_DevUDN( ca_event)); devUDN = UpnpString_get_String(UpnpActionRequest_get_DevUDN( ca_event));
serviceID = UpnpString_get_String(UpnpActionRequest_get_ServiceID( ca_event)); serviceID = UpnpString_get_String(UpnpActionRequest_get_ServiceID( ca_event));
actionName = UpnpString_get_String(UpnpActionRequest_get_ActionName(ca_event)); actionName = UpnpString_get_String(UpnpActionRequest_get_ActionName(ca_event));
if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN ) == 0 ) && if (strcmp(devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN) == 0 &&
( strcmp( serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId ) == 0 ) ) { strcmp(serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId) == 0) {
/* Request for action in the TvDevice Control Service */ /* Request for action in the TvDevice Control Service. */
service = TV_SERVICE_CONTROL; service = TV_SERVICE_CONTROL;
} else if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN ) == 0 ) && } else if (strcmp(devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN) == 0 &&
( strcmp( serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId ) == 0 ) ) { strcmp(serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId) == 0) {
/* Request for action in the TvDevice Picture Service */ /* Request for action in the TvDevice Picture Service. */
service = TV_SERVICE_PICTURE; service = TV_SERVICE_PICTURE;
} }
/* Find and call appropriate procedure based on action name /* Find and call appropriate procedure based on action name.
* Each action name has an associated procedure stored in the * Each action name has an associated procedure stored in the
* service table. These are set at initialization. */ * service table. These are set at initialization. */
for( i = 0; i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL; i++ ) { for (i = 0;
if( !strcmp( actionName, tv_service_table[service].ActionNames[i] ) ) { i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL;
if( ( !strcmp( tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[TV_CONTROL_POWER], "1" ) ) || i++) {
( !strcmp( actionName, "PowerOn" ) ) ) { if (!strcmp(actionName, tv_service_table[service].ActionNames[i])) {
retCode = tv_service_table[service].actions[i]( if (!strcmp(tv_service_table[TV_SERVICE_CONTROL].
UpnpActionRequest_get_ActionRequest(ca_event), VariableStrVal[TV_CONTROL_POWER], "1") ||
&actionResult, !strcmp(actionName, "PowerOn")) {
&errorString ); retCode = tv_service_table[service].actions[i](
UpnpActionRequest_set_ActionResult(ca_event, actionResult); UpnpActionRequest_get_ActionRequest(ca_event),
} else { &actionResult,
errorString = "Power is Off"; &errorString);
retCode = UPNP_E_INTERNAL_ERROR; UpnpActionRequest_set_ActionResult(ca_event, actionResult);
} } else {
action_found = 1; errorString = "Power is Off";
break; retCode = UPNP_E_INTERNAL_ERROR;
} }
} action_found = 1;
break;
}
}
if( !action_found ) { if (!action_found) {
UpnpActionRequest_set_ActionResult(ca_event, NULL); UpnpActionRequest_set_ActionResult(ca_event, NULL);
UpnpActionRequest_strcpy_ErrStr(ca_event, "Invalid Action" ); UpnpActionRequest_strcpy_ErrStr(ca_event, "Invalid Action");
UpnpActionRequest_set_ErrCode(ca_event, 401); UpnpActionRequest_set_ErrCode(ca_event, 401);
} else { } else {
if( retCode == UPNP_E_SUCCESS ) { if (retCode == UPNP_E_SUCCESS) {
UpnpActionRequest_set_ErrCode(ca_event, UPNP_E_SUCCESS); UpnpActionRequest_set_ErrCode(ca_event, UPNP_E_SUCCESS);
} else { } else {
// copy the error string // copy the error string
UpnpActionRequest_strcpy_ErrStr(ca_event, errorString ); UpnpActionRequest_strcpy_ErrStr(ca_event, errorString);
switch ( retCode ) { switch (retCode) {
case UPNP_E_INVALID_PARAM: case UPNP_E_INVALID_PARAM:
{ UpnpActionRequest_set_ErrCode(ca_event, 402);
UpnpActionRequest_set_ErrCode(ca_event, 402); break;
break; case UPNP_E_INTERNAL_ERROR:
} default:
case UPNP_E_INTERNAL_ERROR: UpnpActionRequest_set_ErrCode(ca_event, 501);
default: break;
{ }
UpnpActionRequest_set_ErrCode(ca_event, 501); }
break; }
}
} return UpnpActionRequest_get_ErrCode(ca_event);
}
}
return UpnpActionRequest_get_ErrCode(ca_event);
} }
/****************************************************************************** /******************************************************************************
@ -1763,43 +1755,43 @@ TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT c
*****************************************************************************/ *****************************************************************************/
int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie) int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
{ {
switch ( EventType ) { switch (EventType) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
TvDeviceHandleSubscriptionRequest((UpnpSubscriptionRequest *)Event); TvDeviceHandleSubscriptionRequest((UpnpSubscriptionRequest *)Event);
break; break;
case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_GET_VAR_REQUEST:
TvDeviceHandleGetVarRequest( (UpnpStateVarRequest *)Event ); TvDeviceHandleGetVarRequest((UpnpStateVarRequest *)Event);
break; break;
case UPNP_CONTROL_ACTION_REQUEST: case UPNP_CONTROL_ACTION_REQUEST:
TvDeviceHandleActionRequest( (UpnpActionRequest *)Event ); TvDeviceHandleActionRequest((UpnpActionRequest *)Event);
break; break;
/* /*
ignore these cases, since this is not a control point ignore these cases, since this is not a control point
*/ */
case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
case UPNP_DISCOVERY_SEARCH_RESULT: case UPNP_DISCOVERY_SEARCH_RESULT:
case UPNP_DISCOVERY_SEARCH_TIMEOUT: case UPNP_DISCOVERY_SEARCH_TIMEOUT:
case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:
case UPNP_CONTROL_ACTION_COMPLETE: case UPNP_CONTROL_ACTION_COMPLETE:
case UPNP_CONTROL_GET_VAR_COMPLETE: case UPNP_CONTROL_GET_VAR_COMPLETE:
case UPNP_EVENT_RECEIVED: case UPNP_EVENT_RECEIVED:
case UPNP_EVENT_RENEWAL_COMPLETE: case UPNP_EVENT_RENEWAL_COMPLETE:
case UPNP_EVENT_SUBSCRIBE_COMPLETE: case UPNP_EVENT_SUBSCRIBE_COMPLETE:
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
break; break;
default: default:
SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n", SampleUtil_Print("Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
EventType ); EventType);
} }
/* Print a summary of the event received */ /* Print a summary of the event received */
SampleUtil_PrintEvent( EventType, Event ); SampleUtil_PrintEvent(EventType, Event);
return 0; return 0;
} }
/****************************************************************************** /******************************************************************************
@ -1811,8 +1803,7 @@ int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Co
* Parameters: * Parameters:
* *
*****************************************************************************/ *****************************************************************************/
int int TvDeviceStop(void)
TvDeviceStop(void)
{ {
UpnpUnRegisterRootDevice( device_handle ); UpnpUnRegisterRootDevice( device_handle );
UpnpFinish(); UpnpFinish();
@ -1860,7 +1851,8 @@ TvDeviceStart( char *ip_address,
SampleUtil_Print( SampleUtil_Print(
"Initializing UPnP Sdk with\n" "Initializing UPnP Sdk with\n"
"\tipaddress = %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address, port ); ip_address ? ip_address : "{NULL}",
port);
ret = UpnpInit( ip_address, port ); ret = UpnpInit( ip_address, port );
if( ret != UPNP_E_SUCCESS ) { if( ret != UPNP_E_SUCCESS ) {
@ -1874,8 +1866,9 @@ TvDeviceStart( char *ip_address,
SampleUtil_Print( SampleUtil_Print(
"UPnP Initialized\n" "UPnP Initialized\n"
"\tipaddress= %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address, port ); ip_address ? ip_address : "{NULL}",
port);
if( desc_doc_name == NULL ) { if( desc_doc_name == NULL ) {
desc_doc_name = "tvdevicedesc.xml"; desc_doc_name = "tvdevicedesc.xml";