⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upnp_tv_ctrlpt.c

📁 Upnp开发包文件
💻 C
📖 第 1 页 / 共 4 页
字号:
    ret =        UpnpResolveURL( ( baseURL ? baseURL : location ), relURL,                        presURL );    if( UPNP_E_SUCCESS != ret )        SampleUtil_Print( "Error generating presURL from %s + %s", baseURL,                          relURL );    if( strcmp( deviceType, TvDeviceType ) == 0 ) {        SampleUtil_Print( "Found Tv device" );        // Check if this device is already in the list        tmpdevnode = GlobalDeviceList;        while( tmpdevnode ) {            if( strcmp( tmpdevnode->device.UDN, UDN ) == 0 ) {                found = 1;                break;            }            tmpdevnode = tmpdevnode->next;        }        if( found ) {            // The device is already there, so just update             // the advertisement timeout field            tmpdevnode->device.AdvrTimeOut = expires;        } else {            for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {                if( SampleUtil_FindAndParseService                    ( DescDoc, location, TvServiceType[service],                      &serviceId[service], &eventURL[service],                      &controlURL[service] ) ) {                    SampleUtil_Print( "Subscribing to EventURL %s...",                                      eventURL[service] );                    ret =                        UpnpSubscribe( ctrlpt_handle, eventURL[service],                                       &TimeOut[service],                                       eventSID[service] );                    if( ret == UPNP_E_SUCCESS ) {                        SampleUtil_Print                            ( "Subscribed to EventURL with SID=%s",                              eventSID[service] );                    } else {                        SampleUtil_Print                            ( "Error Subscribing to EventURL -- %d", ret );                        strcpy( eventSID[service], "" );                    }                } else {                    SampleUtil_Print( "Error: Could not find Service: %s",                                      TvServiceType[service] );                }            }            /*               Create a new device node              */            deviceNode =                ( struct TvDeviceNode * )                malloc( sizeof( struct TvDeviceNode ) );            strcpy( deviceNode->device.UDN, UDN );            strcpy( deviceNode->device.DescDocURL, location );            strcpy( deviceNode->device.FriendlyName, friendlyName );            strcpy( deviceNode->device.PresURL, presURL );            deviceNode->device.AdvrTimeOut = expires;            for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {                strcpy( deviceNode->device.TvService[service].ServiceId,                        serviceId[service] );                strcpy( deviceNode->device.TvService[service].ServiceType,                        TvServiceType[service] );                strcpy( deviceNode->device.TvService[service].ControlURL,                        controlURL[service] );                strcpy( deviceNode->device.TvService[service].EventURL,                        eventURL[service] );                strcpy( deviceNode->device.TvService[service].SID,                        eventSID[service] );                for( var = 0; var < TvVarCount[service]; var++ ) {                    deviceNode->device.TvService[service].                        VariableStrVal[var] =                        ( char * )malloc( TV_MAX_VAL_LEN );                    strcpy( deviceNode->device.TvService[service].                            VariableStrVal[var], "" );                }            }            deviceNode->next = NULL;            // Insert the new device node in the list            if( ( tmpdevnode = GlobalDeviceList ) ) {                while( tmpdevnode ) {                    if( tmpdevnode->next ) {                        tmpdevnode = tmpdevnode->next;                    } else {                        tmpdevnode->next = deviceNode;                        break;                    }                }            } else {                GlobalDeviceList = deviceNode;            }            //Notify New Device Added            SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN,                                    DEVICE_ADDED );        }    }    ithread_mutex_unlock( &DeviceListMutex );    if( deviceType )        free( deviceType );    if( friendlyName )        free( friendlyName );    if( UDN )        free( UDN );    if( baseURL )        free( baseURL );    if( relURL )        free( relURL );    for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {        if( serviceId[service] )            free( serviceId[service] );        if( controlURL[service] )            free( controlURL[service] );        if( eventURL[service] )            free( eventURL[service] );    }}/******************************************************************************** * TvStateUpdate * * Description:  *       Update a Tv state table.  Called when an event is *       received.  Note: this function is NOT thread save.  It must be *       called from another function that has locked the global device list. * * Parameters: *   UDN     -- The UDN of the parent device. *   Service -- The service state table to update *   ChangedVariables -- DOM document representing the XML received *                       with the event *   State -- pointer to the state table for the Tv  service *            to update * ********************************************************************************/voidTvStateUpdate( char *UDN,               int Service,               IXML_Document * ChangedVariables,               char **State ){    IXML_NodeList *properties,     *variables;    IXML_Element *property,     *variable;    int length,      length1;    int i,      j;    char *tmpstate = NULL;    SampleUtil_Print( "Tv State Update (service %d): ", Service );    /*       Find all of the e:property tags in the document      */    properties =        ixmlDocument_getElementsByTagName( ChangedVariables,                                           "e:property" );    if( NULL != properties ) {        length = ixmlNodeList_length( properties );        for( i = 0; i < length; i++ ) { /* Loop through each property change found */            property =                ( IXML_Element * ) ixmlNodeList_item( properties, i );            /*               For each variable name in the state table, check if this               is a corresponding property change              */            for( j = 0; j < TvVarCount[Service]; j++ ) {                variables =                    ixmlElement_getElementsByTagName( property,                                                      TvVarName[Service]                                                      [j] );                /*                   If a match is found, extract the value, and update the state table                  */                if( variables ) {                    length1 = ixmlNodeList_length( variables );                    if( length1 ) {                        variable =                            ( IXML_Element * )                            ixmlNodeList_item( variables, 0 );                        tmpstate = SampleUtil_GetElementValue( variable );                        if( tmpstate ) {                            strcpy( State[j], tmpstate );                            SampleUtil_Print                                ( " Variable Name: %s New Value:'%s'",                                  TvVarName[Service][j], State[j] );                        }                        if( tmpstate )                            free( tmpstate );                        tmpstate = NULL;                    }                    ixmlNodeList_free( variables );                    variables = NULL;                }            }        }        ixmlNodeList_free( properties );    }}/******************************************************************************** * TvCtrlPointHandleEvent * * Description:  *       Handle a UPnP event that was received.  Process the event and update *       the appropriate service state table. * * Parameters: *   sid -- The subscription id for the event *   eventkey -- The eventkey number for the event *   changes -- The DOM document representing the changes * ********************************************************************************/voidTvCtrlPointHandleEvent( Upnp_SID sid,                        int evntkey,                        IXML_Document * changes ){    struct TvDeviceNode *tmpdevnode;    int service;    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 );                TvStateUpdate( tmpdevnode->device.UDN, service, changes,                               ( char ** )&tmpdevnode->device.                               TvService[service].VariableStrVal );                break;            }        }        tmpdevnode = tmpdevnode->next;    }    ithread_mutex_unlock( &DeviceListMutex );}/******************************************************************************** * TvCtrlPointHandleSubscribeUpdate * * Description:  *       Handle a UPnP subscription update that was received.  Find the  *       service the update belongs to, and update its subscription *       timeout. * * Parameters: *   eventURL -- The event URL for the subscription *   sid -- The subscription id for the subscription *   timeout  -- The new timeout for the subscription * ********************************************************************************/voidTvCtrlPointHandleSubscribeUpdate( char *eventURL,                                  Upnp_SID sid,                                  int timeout ){    struct TvDeviceNode *tmpdevnode;    int service;    ithread_mutex_lock( &DeviceListMutex );    tmpdevnode = GlobalDeviceList;    while( tmpdevnode ) {        for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {            if( strcmp                ( tmpdevnode->device.TvService[service].EventURL,                  eventURL ) == 0 ) {                SampleUtil_Print                    ( "Received Tv %s Event Renewal for eventURL %s",                      TvServiceName[service], eventURL );                strcpy( tmpdevnode->device.TvService[service].SID, sid );                break;            }        }        tmpdevnode = tmpdevnode->next;    }    ithread_mutex_unlock( &DeviceListMutex );}voidTvCtrlPointHandleGetVar( char *controlURL,                         char *varName,                         DOMString varValue ){    struct TvDeviceNode *tmpdevnode;    int service;    ithread_mutex_lock( &DeviceListMutex );    tmpdevnode = GlobalDeviceList;    while( tmpdevnode ) {        for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {            if( strcmp                ( tmpdevnode->device.TvService[service].ControlURL,                  controlURL ) == 0 ) {                SampleUtil_StateUpdate( varName, varValue,                                        tmpdevnode->device.UDN,                                        GET_VAR_COMPLETE );                break;            }        }        tmpdevnode = tmpdevnode->next;    }    ithread_mutex_unlock( &DeviceListMutex );}/******************************************************************************** * TvCtrlPointCallbackEventHandler * * Description:  *       The callback handler registered with the SDK while registering *       the control point.  Detects the type of callback, and passes the  *       request on to the appropriate function. * * Parameters: *   EventType -- The type of callback event *   Event -- Data structure containing event data

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -