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

View File

@ -38,8 +38,10 @@
#define DEFAULT_WEB_DIR "./web"
#define DESC_URL_SIZE 200
/*
Device type for tv device
*/
@ -372,20 +374,18 @@ TvDeviceStateTableInit( IN char *DescDocURL )
int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event)
{
unsigned int i = 0;
//unsigned int j = 0;
int cmp1 = 0;
int cmp2 = 0;
const char *l_serviceId = NULL;
const char *l_udn = NULL;
const char *l_sid = NULL;
// IXML_Document *PropSet = NULL;
// lock state mutex
ithread_mutex_lock(&TVDevMutex);
l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event));
l_udn = UpnpString_get_String(UpnpSubscriptionRequest_get_UDN(sr_event));
l_sid = UpnpString_get_String(UpnpSubscriptionRequest_get_SID(sr_event));
l_udn = UpnpSubscriptionRequest_get_UDN_cstr(sr_event);
l_sid = UpnpSubscriptionRequest_get_SID_cstr(sr_event);
for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) {
cmp1 = strcmp(l_udn, tv_service_table[i].UDN);
cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId);
@ -443,8 +443,7 @@ int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event
* cgv_event -- The control get variable request event structure
*
*****************************************************************************/
int
TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
int TvDeviceHandleGetVarRequest(INOUT UpnpStateVarRequest *cgv_event)
{
unsigned int i = 0;
unsigned int j = 0;
@ -460,13 +459,14 @@ TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event));
const char *serviceID =
UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event));
if( ( strcmp( devUDN, tv_service_table[i].UDN ) == 0 ) &&
( strcmp( serviceID, tv_service_table[i].ServiceId ) == 0 ) ) {
if (strcmp(devUDN, tv_service_table[i].UDN) == 0 &&
strcmp(serviceID, tv_service_table[i].ServiceId) == 0) {
// check variable name
for (j = 0; j < tv_service_table[i].VariableCount; j++) {
const char *stateVarName =
UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event));
if( strcmp( stateVarName, tv_service_table[i].VariableName[j] ) == 0 ) {
const char *stateVarName = UpnpString_get_String(
UpnpStateVarRequest_get_StateVarName(cgv_event));
if (strcmp(stateVarName,
tv_service_table[i].VariableName[j]) == 0) {
getvar_succeeded = 1;
UpnpStateVarRequest_set_CurrentVal(cgv_event,
tv_service_table[i].VariableStrVal[j]);
@ -475,7 +475,6 @@ TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
}
}
}
if (getvar_succeeded) {
UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
} else {
@ -504,12 +503,9 @@ TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
* ca_event -- The control action request event structure
*
*****************************************************************************/
int
TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
int TvDeviceHandleActionRequest(INOUT UpnpActionRequest *ca_event)
{
/*
Defaults if action not found
*/
/* Defaults if action not found. */
int action_found = 0;
int i = 0;
int service = -1;
@ -526,22 +522,25 @@ TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
devUDN = UpnpString_get_String(UpnpActionRequest_get_DevUDN( ca_event));
serviceID = UpnpString_get_String(UpnpActionRequest_get_ServiceID( ca_event));
actionName = UpnpString_get_String(UpnpActionRequest_get_ActionName(ca_event));
if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN ) == 0 ) &&
( strcmp( serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId ) == 0 ) ) {
/* Request for action in the TvDevice Control Service */
if (strcmp(devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN) == 0 &&
strcmp(serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId) == 0) {
/* Request for action in the TvDevice Control Service. */
service = TV_SERVICE_CONTROL;
} else if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN ) == 0 ) &&
( strcmp( serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId ) == 0 ) ) {
/* Request for action in the TvDevice Picture Service */
} else if (strcmp(devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN) == 0 &&
strcmp(serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId) == 0) {
/* Request for action in the TvDevice Picture Service. */
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
* service table. These are set at initialization. */
for( i = 0; i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL; i++ ) {
for (i = 0;
i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL;
i++) {
if (!strcmp(actionName, tv_service_table[service].ActionNames[i])) {
if( ( !strcmp( tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[TV_CONTROL_POWER], "1" ) ) ||
( !strcmp( actionName, "PowerOn" ) ) ) {
if (!strcmp(tv_service_table[TV_SERVICE_CONTROL].
VariableStrVal[TV_CONTROL_POWER], "1") ||
!strcmp(actionName, "PowerOn")) {
retCode = tv_service_table[service].actions[i](
UpnpActionRequest_get_ActionRequest(ca_event),
&actionResult,
@ -568,18 +567,13 @@ TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
UpnpActionRequest_strcpy_ErrStr(ca_event, errorString);
switch (retCode) {
case UPNP_E_INVALID_PARAM:
{
UpnpActionRequest_set_ErrCode(ca_event, 402);
break;
}
case UPNP_E_INTERNAL_ERROR:
default:
{
UpnpActionRequest_set_ErrCode(ca_event, 501);
break;
}
}
}
}
@ -1807,8 +1801,7 @@ int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Co
* Parameters:
*
*****************************************************************************/
int
TvDeviceStop()
int TvDeviceStop(void)
{
UpnpUnRegisterRootDevice( device_handle );
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,
char *web_dir_path, print_string pfun);
int TvDeviceStop();
int TvDeviceStop(void);
#ifdef __cplusplus
}

View File

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

View File

@ -376,20 +376,18 @@ TvDeviceStateTableInit( IN char *DescDocURL )
int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event)
{
unsigned int i = 0;
//unsigned int j = 0;
int cmp1 = 0;
int cmp2 = 0;
const char *l_serviceId = NULL;
const char *l_udn = NULL;
const char *l_sid = NULL;
// IXML_Document *PropSet = NULL;
// lock state mutex
ithread_mutex_lock(&TVDevMutex);
l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event));
l_udn = UpnpString_get_String(UpnpSubscriptionRequest_get_UDN(sr_event));
l_sid = UpnpString_get_String(UpnpSubscriptionRequest_get_SID(sr_event));
l_udn = UpnpSubscriptionRequest_get_UDN_cstr(sr_event);
l_sid = UpnpSubscriptionRequest_get_SID_cstr(sr_event);
for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) {
cmp1 = strcmp(l_udn, tv_service_table[i].UDN);
cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId);
@ -447,8 +445,7 @@ int TvDeviceHandleSubscriptionRequest(IN const UpnpSubscriptionRequest *sr_event
* cgv_event -- The control get variable request event structure
*
*****************************************************************************/
int
TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
int TvDeviceHandleGetVarRequest(INOUT UpnpStateVarRequest *cgv_event)
{
unsigned int i = 0;
unsigned int j = 0;
@ -464,13 +461,14 @@ TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event));
const char *serviceID =
UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event));
if( ( strcmp( devUDN, tv_service_table[i].UDN ) == 0 ) &&
( strcmp( serviceID, tv_service_table[i].ServiceId ) == 0 ) ) {
if (strcmp(devUDN, tv_service_table[i].UDN) == 0 &&
strcmp(serviceID, tv_service_table[i].ServiceId) == 0) {
// check variable name
for (j = 0; j < tv_service_table[i].VariableCount; j++) {
const char *stateVarName =
UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event));
if( strcmp( stateVarName, tv_service_table[i].VariableName[j] ) == 0 ) {
const char *stateVarName = UpnpString_get_String(
UpnpStateVarRequest_get_StateVarName(cgv_event));
if (strcmp(stateVarName,
tv_service_table[i].VariableName[j]) == 0) {
getvar_succeeded = 1;
UpnpStateVarRequest_set_CurrentVal(cgv_event,
tv_service_table[i].VariableStrVal[j]);
@ -479,7 +477,6 @@ TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
}
}
}
if (getvar_succeeded) {
UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
} else {
@ -508,12 +505,9 @@ TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
* ca_event -- The control action request event structure
*
*****************************************************************************/
int
TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
int TvDeviceHandleActionRequest(INOUT UpnpActionRequest *ca_event)
{
/*
Defaults if action not found
*/
/* Defaults if action not found. */
int action_found = 0;
int i = 0;
int service = -1;
@ -530,22 +524,25 @@ TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
devUDN = UpnpString_get_String(UpnpActionRequest_get_DevUDN( ca_event));
serviceID = UpnpString_get_String(UpnpActionRequest_get_ServiceID( ca_event));
actionName = UpnpString_get_String(UpnpActionRequest_get_ActionName(ca_event));
if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN ) == 0 ) &&
( strcmp( serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId ) == 0 ) ) {
/* Request for action in the TvDevice Control Service */
if (strcmp(devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN) == 0 &&
strcmp(serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId) == 0) {
/* Request for action in the TvDevice Control Service. */
service = TV_SERVICE_CONTROL;
} else if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN ) == 0 ) &&
( strcmp( serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId ) == 0 ) ) {
/* Request for action in the TvDevice Picture Service */
} else if (strcmp(devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN) == 0 &&
strcmp(serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId) == 0) {
/* Request for action in the TvDevice Picture Service. */
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
* service table. These are set at initialization. */
for( i = 0; i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL; i++ ) {
for (i = 0;
i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL;
i++) {
if (!strcmp(actionName, tv_service_table[service].ActionNames[i])) {
if( ( !strcmp( tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[TV_CONTROL_POWER], "1" ) ) ||
( !strcmp( actionName, "PowerOn" ) ) ) {
if (!strcmp(tv_service_table[TV_SERVICE_CONTROL].
VariableStrVal[TV_CONTROL_POWER], "1") ||
!strcmp(actionName, "PowerOn")) {
retCode = tv_service_table[service].actions[i](
UpnpActionRequest_get_ActionRequest(ca_event),
&actionResult,
@ -572,18 +569,13 @@ TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
UpnpActionRequest_strcpy_ErrStr(ca_event, errorString);
switch (retCode) {
case UPNP_E_INVALID_PARAM:
{
UpnpActionRequest_set_ErrCode(ca_event, 402);
break;
}
case UPNP_E_INTERNAL_ERROR:
default:
{
UpnpActionRequest_set_ErrCode(ca_event, 501);
break;
}
}
}
}
@ -1811,8 +1803,7 @@ int TvDeviceCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Co
* Parameters:
*
*****************************************************************************/
int
TvDeviceStop(void)
int TvDeviceStop(void)
{
UpnpUnRegisterRootDevice( device_handle );
UpnpFinish();
@ -1860,7 +1851,8 @@ TvDeviceStart( char *ip_address,
SampleUtil_Print(
"Initializing UPnP Sdk with\n"
"\tipaddress = %s port = %u\n",
ip_address, port );
ip_address ? ip_address : "{NULL}",
port);
ret = UpnpInit( ip_address, port );
if( ret != UPNP_E_SUCCESS ) {
@ -1875,7 +1867,8 @@ TvDeviceStart( char *ip_address,
SampleUtil_Print(
"UPnP Initialized\n"
"\tipaddress = %s port = %u\n",
ip_address, port );
ip_address ? ip_address : "{NULL}",
port);
if( desc_doc_name == NULL ) {
desc_doc_name = "tvdevicedesc.xml";