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

📄 upnp_tv_ctrlpt.c

📁 Upnp开发包文件
💻 C
📖 第 1 页 / 共 4 页
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2000-2003 Intel Corporation // All rights reserved. //// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: //// * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither name of Intel Corporation nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission.// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE./////////////////////////////////////////////////////////////////////////////#include "upnp_tv_ctrlpt.h"/*   Mutex for protecting the global device list   in a multi-threaded, asynchronous environment.   All functions should lock this mutex before reading   or writing the device list.  */ithread_mutex_t DeviceListMutex;UpnpClient_Handle ctrlpt_handle = -1;char TvDeviceType[] = "urn:schemas-upnp-org:device:tvdevice:1";char *TvServiceType[] = {    "urn:schemas-upnp-org:service:tvcontrol:1",    "urn:schemas-upnp-org:service:tvpicture:1"};char *TvServiceName[] = { "Control", "Picture" };/*   Global arrays for storing variable names and counts for    TvControl and TvPicture services  */char *TvVarName[TV_SERVICE_SERVCOUNT][TV_MAXVARS] = {    {"Power", "Channel", "Volume", ""},    {"Color", "Tint", "Contrast", "Brightness"}};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;/******************************************************************************** * TvCtrlPointDeleteNode * * Description:  *       Delete a device node from the global device list.  Note that this *       function is NOT thread safe, and should be called from another *       function that has already locked the global device list. * * Parameters: *   node -- The device node * ********************************************************************************/intTvCtrlPointDeleteNode( struct TvDeviceNode *node ){    int rc,      service,      var;    if( NULL == node ) {        SampleUtil_Print( "ERROR: TvCtrlPointDeleteNode: Node is empty" );        return TV_ERROR;    }    for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {        /*           If we have a valid control SID, then unsubscribe          */        if( strcmp( node->device.TvService[service].SID, "" ) != 0 ) {            rc = UpnpUnSubscribe( ctrlpt_handle,                                  node->device.TvService[service].SID );            if( UPNP_E_SUCCESS == rc ) {                SampleUtil_Print                    ( "Unsubscribed from Tv %s EventURL with SID=%s",                      TvServiceName[service],                      node->device.TvService[service].SID );            } else {                SampleUtil_Print                    ( "Error unsubscribing to Tv %s EventURL -- %d",                      TvServiceName[service], rc );            }        }        for( var = 0; var < TvVarCount[service]; var++ ) {            if( node->device.TvService[service].VariableStrVal[var] ) {                free( node->device.TvService[service].                      VariableStrVal[var] );            }        }    }    //Notify New Device Added    SampleUtil_StateUpdate( NULL, NULL, node->device.UDN, DEVICE_REMOVED );    free( node );    node = NULL;    return TV_SUCCESS;}/******************************************************************************** * TvCtrlPointRemoveDevice * * Description:  *       Remove a device from the global device list. * * Parameters: *   UDN -- The Unique Device Name for the device to remove * ********************************************************************************/intTvCtrlPointRemoveDevice( char *UDN ){    struct TvDeviceNode *curdevnode,     *prevdevnode;    ithread_mutex_lock( &DeviceListMutex );    curdevnode = GlobalDeviceList;    if( !curdevnode ) {        SampleUtil_Print            ( "WARNING: TvCtrlPointRemoveDevice: Device list empty" );    } else {        if( 0 == strcmp( curdevnode->device.UDN, UDN ) ) {            GlobalDeviceList = curdevnode->next;            TvCtrlPointDeleteNode( curdevnode );        } else {            prevdevnode = curdevnode;            curdevnode = curdevnode->next;            while( curdevnode ) {                if( strcmp( curdevnode->device.UDN, UDN ) == 0 ) {                    prevdevnode->next = curdevnode->next;                    TvCtrlPointDeleteNode( curdevnode );                    break;                }                prevdevnode = curdevnode;                curdevnode = curdevnode->next;            }        }    }    ithread_mutex_unlock( &DeviceListMutex );    return TV_SUCCESS;}/******************************************************************************** * TvCtrlPointRemoveAll * * Description:  *       Remove all devices from the global device list. * * Parameters: *   None * ********************************************************************************/intTvCtrlPointRemoveAll( void ){    struct TvDeviceNode *curdevnode,     *next;    ithread_mutex_lock( &DeviceListMutex );    curdevnode = GlobalDeviceList;    GlobalDeviceList = NULL;    while( curdevnode ) {        next = curdevnode->next;        TvCtrlPointDeleteNode( curdevnode );        curdevnode = next;    }    ithread_mutex_unlock( &DeviceListMutex );    return TV_SUCCESS;}/******************************************************************************** * TvCtrlPointRefresh * * Description:  *       Clear the current global device list and issue new search *	 requests to build it up again from scratch. * * Parameters: *   None * ********************************************************************************/intTvCtrlPointRefresh( void ){    int rc;    TvCtrlPointRemoveAll(  );    /*       Search for all devices of type tvdevice version 1,        waiting for up to 5 seconds for the response      */    rc = UpnpSearchAsync( ctrlpt_handle, 5, TvDeviceType, NULL );    if( UPNP_E_SUCCESS != rc ) {        SampleUtil_Print( "Error sending search request%d", rc );        return TV_ERROR;    }    return TV_SUCCESS;}/******************************************************************************** * TvCtrlPointGetVar * * Description:  *       Send a GetVar request to the specified service of a device. * * Parameters: *   service -- The service *   devnum -- The number of the device (order in the list, *             starting with 1) *   varname -- The name of the variable to request. * ********************************************************************************/intTvCtrlPointGetVar( int service,                   int devnum,                   char *varname ){    struct TvDeviceNode *devnode;    int rc;    ithread_mutex_lock( &DeviceListMutex );    rc = TvCtrlPointGetDevice( devnum, &devnode );    if( TV_SUCCESS == rc ) {        rc = UpnpGetServiceVarStatusAsync( ctrlpt_handle,                                           devnode->device.                                           TvService[service].ControlURL,                                           varname,                                           TvCtrlPointCallbackEventHandler,                                           NULL );        if( rc != UPNP_E_SUCCESS ) {            SampleUtil_Print                ( "Error in UpnpGetServiceVarStatusAsync -- %d", rc );            rc = TV_ERROR;        }    }    ithread_mutex_unlock( &DeviceListMutex );    return rc;}intTvCtrlPointGetPower( int devnum ){    return TvCtrlPointGetVar( TV_SERVICE_CONTROL, devnum, "Power" );}intTvCtrlPointGetChannel( int devnum ){    return TvCtrlPointGetVar( TV_SERVICE_CONTROL, devnum, "Channel" );}intTvCtrlPointGetVolume( int devnum ){    return TvCtrlPointGetVar( TV_SERVICE_CONTROL, devnum, "Volume" );}intTvCtrlPointGetColor( int devnum ){    return TvCtrlPointGetVar( TV_SERVICE_PICTURE, devnum, "Color" );}intTvCtrlPointGetTint( int devnum ){    return TvCtrlPointGetVar( TV_SERVICE_PICTURE, devnum, "Tint" );}intTvCtrlPointGetContrast( int devnum ){    return TvCtrlPointGetVar( TV_SERVICE_PICTURE, devnum, "Contrast" );}intTvCtrlPointGetBrightness( int devnum ){    return TvCtrlPointGetVar( TV_SERVICE_PICTURE, devnum, "Brightness" );}/******************************************************************************** * TvCtrlPointSendAction * * Description:  *       Send an Action request to the specified service of a device. * * Parameters: *   service -- The service *   devnum -- The number of the device (order in the list, *             starting with 1) *   actionname -- The name of the action. *   param_name -- An array of parameter names *   param_val -- The corresponding parameter values *   param_count -- The number of parameters * ********************************************************************************/intTvCtrlPointSendAction( int service,                       int devnum,                       char *actionname,                       char **param_name,                       char **param_val,                       int param_count ){    struct TvDeviceNode *devnode;

⌨️ 快捷键说明

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