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

📄 upnp_tv_device.c

📁 Upnp开发包文件
💻 C
📖 第 1 页 / 共 5 页
字号:
/////////////////////////////////////////////////////////////////////////////// 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_device.h"#define DEFAULT_WEB_DIR "./web"#define DESC_URL_SIZE 200/*   Device type for tv device  */char TvDeviceType[] = "urn:schemas-upnp-org:device:tvdevice:1";/*   Service types for tv services */char *TvServiceType[] = { "urn:schemas-upnp-org:service:tvcontrol:1",    "urn:schemas-upnp-org:service:tvpicture:1"};/*   Global arrays for storing Tv Control Service   variable names, values, and defaults  */char *tvc_varname[] = { "Power", "Channel", "Volume" };char tvc_varval[TV_CONTROL_VARCOUNT][TV_MAX_VAL_LEN];char *tvc_varval_def[] = { "1", "1", "5" };/*   Global arrays for storing Tv Picture Service   variable names, values, and defaults  */char *tvp_varname[] = { "Color", "Tint", "Contrast", "Brightness" };char tvp_varval[TV_PICTURE_VARCOUNT][TV_MAX_VAL_LEN];char *tvp_varval_def[] = { "5", "5", "5", "5" };/*   The amount of time (in seconds) before advertisements   will expire  */int default_advr_expire = 100;/*   Global structure for storing the state table for this device  */struct TvService tv_service_table[2];/*   Device handle supplied by UPnP SDK  */UpnpDevice_Handle device_handle = -1;/*   Mutex for protecting the global state table data   in a multi-threaded, asynchronous environment.   All functions should lock this mutex before reading   or writing the state table data.  */ithread_mutex_t TVDevMutex;//Color constants#define MAX_COLOR 10#define MIN_COLOR 1//Brightness constants#define MAX_BRIGHTNESS 10#define MIN_BRIGHTNESS 1//Power constants#define POWER_ON 1#define POWER_OFF 0//Tint constants#define MAX_TINT 10#define MIN_TINT 1//Volume constants#define MAX_VOLUME 10#define MIN_VOLUME 1//Contrast constants#define MAX_CONTRAST 10#define MIN_CONTRAST 1//Channel constants#define MAX_CHANNEL 100#define MIN_CHANNEL 1/****************************************************************************** * SetServiceTable * * Description:  *       Initializes the service table for the specified service. *       Note that  *       knowledge of the service description is *       assumed.  * Parameters: *   int serviceType - one of TV_SERVICE_CONTROL or, TV_SERVICE_PICTURE *   const char * UDN - UDN of device containing service *   const char * serviceId - serviceId of service *   const char * serviceTypeS - service type (as specified in Description *                                             Document)  *   struct TvService *out - service containing table to be set. * *****************************************************************************/intSetServiceTable( IN int serviceType,                 IN const char *UDN,                 IN const char *serviceId,                 IN const char *serviceTypeS,                 INOUT struct TvService *out ){    unsigned int i = 0;    strcpy( out->UDN, UDN );    strcpy( out->ServiceId, serviceId );    strcpy( out->ServiceType, serviceTypeS );    switch ( serviceType ) {        case TV_SERVICE_CONTROL:            out->VariableCount = TV_CONTROL_VARCOUNT;            for( i = 0;                 i < tv_service_table[TV_SERVICE_CONTROL].VariableCount;                 i++ ) {                tv_service_table[TV_SERVICE_CONTROL].VariableName[i]                    = tvc_varname[i];                tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[i]                    = tvc_varval[i];                strcpy( tv_service_table[TV_SERVICE_CONTROL].                        VariableStrVal[i], tvc_varval_def[i] );            }            break;        case TV_SERVICE_PICTURE:            out->VariableCount = TV_PICTURE_VARCOUNT;            for( i = 0;                 i < tv_service_table[TV_SERVICE_PICTURE].VariableCount;                 i++ ) {                tv_service_table[TV_SERVICE_PICTURE].VariableName[i] =                    tvp_varname[i];                tv_service_table[TV_SERVICE_PICTURE].VariableStrVal[i] =                    tvp_varval[i];                strcpy( tv_service_table[TV_SERVICE_PICTURE].                        VariableStrVal[i], tvp_varval_def[i] );            }            break;        default:            assert( 0 );    }    return SetActionTable( serviceType, out );}/****************************************************************************** * SetActionTable * * Description:  *       Initializes the action table for the specified service. *       Note that  *       knowledge of the service description is *       assumed.  Action names are hardcoded. * Parameters: *   int serviceType - one of TV_SERVICE_CONTROL or, TV_SERVICE_PICTURE *   struct TvService *out - service containing action table to set. * *****************************************************************************/intSetActionTable( IN int serviceType,                INOUT struct TvService *out ){    if( serviceType == TV_SERVICE_CONTROL ) {        out->ActionNames[0] = "PowerOn";        out->actions[0] = TvDevicePowerOn;        out->ActionNames[1] = "PowerOff";        out->actions[1] = TvDevicePowerOff;        out->ActionNames[2] = "SetChannel";        out->actions[2] = TvDeviceSetChannel;        out->ActionNames[3] = "IncreaseChannel";        out->actions[3] = TvDeviceIncreaseChannel;        out->ActionNames[4] = "DecreaseChannel";        out->actions[4] = TvDeviceDecreaseChannel;        out->ActionNames[5] = "SetVolume";        out->actions[5] = TvDeviceSetVolume;        out->ActionNames[6] = "IncreaseVolume";        out->actions[6] = TvDeviceIncreaseVolume;        out->ActionNames[7] = "DecreaseVolume";        out->actions[7] = TvDeviceDecreaseVolume;        out->ActionNames[8] = NULL;        return 1;    } else if( serviceType == TV_SERVICE_PICTURE ) {        out->ActionNames[0] = "SetColor";        out->ActionNames[1] = "IncreaseColor";        out->ActionNames[2] = "DecreaseColor";        out->actions[0] = TvDeviceSetColor;        out->actions[1] = TvDeviceIncreaseColor;        out->actions[2] = TvDeviceDecreaseColor;        out->ActionNames[3] = "SetTint";        out->ActionNames[4] = "IncreaseTint";        out->ActionNames[5] = "DecreaseTint";        out->actions[3] = TvDeviceSetTint;        out->actions[4] = TvDeviceIncreaseTint;        out->actions[5] = TvDeviceDecreaseTint;        out->ActionNames[6] = "SetBrightness";        out->ActionNames[7] = "IncreaseBrightness";        out->ActionNames[8] = "DecreaseBrightness";        out->actions[6] = TvDeviceSetBrightness;        out->actions[7] = TvDeviceIncreaseBrightness;        out->actions[8] = TvDeviceDecreaseBrightness;        out->ActionNames[9] = "SetContrast";        out->ActionNames[10] = "IncreaseContrast";        out->ActionNames[11] = "DecreaseContrast";        out->actions[9] = TvDeviceSetContrast;        out->actions[10] = TvDeviceIncreaseContrast;        out->actions[11] = TvDeviceDecreaseContrast;        return 1;    }    return 0;}/****************************************************************************** * TvDeviceStateTableInit * * Description:  *       Initialize the device state table for  * 	 this TvDevice, pulling identifier info *       from the description Document.  Note that  *       knowledge of the service description is *       assumed.  State table variables and default *       values are currently hardcoded in this file *       rather than being read from service description *       documents. * * Parameters: *   DescDocURL -- The description document URL * *****************************************************************************/intTvDeviceStateTableInit( IN char *DescDocURL ){    IXML_Document *DescDoc = NULL;    int ret = UPNP_E_SUCCESS;    char *servid_ctrl = NULL,     *evnturl_ctrl = NULL,     *ctrlurl_ctrl = NULL;    char *servid_pict = NULL,     *evnturl_pict = NULL,     *ctrlurl_pict = NULL;    char *udn = NULL;    //Download description document    if( UpnpDownloadXmlDoc( DescDocURL, &DescDoc ) != UPNP_E_SUCCESS ) {        SampleUtil_Print( "TvDeviceStateTableInit -- Error Parsing %s\n",                          DescDocURL );        ret = UPNP_E_INVALID_DESC;        goto error_handler;    }    udn = SampleUtil_GetFirstDocumentItem( DescDoc, "UDN" );    /*       Find the Tv Control Service identifiers      */    if( !SampleUtil_FindAndParseService( DescDoc, DescDocURL,                                         TvServiceType[TV_SERVICE_CONTROL],                                         &servid_ctrl, &evnturl_ctrl,                                         &ctrlurl_ctrl ) ) {        SampleUtil_Print( "TvDeviceStateTableInit -- Error: Could not find"                          " Service: %s\n",                          TvServiceType[TV_SERVICE_CONTROL] );        ret = UPNP_E_INVALID_DESC;        goto error_handler;    }    //set control service table    SetServiceTable( TV_SERVICE_CONTROL, udn, servid_ctrl,                     TvServiceType[TV_SERVICE_CONTROL],                     &tv_service_table[TV_SERVICE_CONTROL] );    /*       Find the Tv Picture Service identifiers      */    if( !SampleUtil_FindAndParseService( DescDoc, DescDocURL,                                         TvServiceType[TV_SERVICE_PICTURE],                                         &servid_pict, &evnturl_pict,                                         &ctrlurl_pict ) ) {        SampleUtil_Print( "TvDeviceStateTableInit -- Error: Could not find"                          " Service: %s\n",                          TvServiceType[TV_SERVICE_PICTURE] );        ret = UPNP_E_INVALID_DESC;        goto error_handler;    }    //set picture service table    SetServiceTable( TV_SERVICE_PICTURE, udn, servid_pict,                     TvServiceType[TV_SERVICE_PICTURE],                     &tv_service_table[TV_SERVICE_PICTURE] );  error_handler:    //clean up    if( udn )        free( udn );    if( servid_ctrl )        free( servid_ctrl );    if( evnturl_ctrl )        free( evnturl_ctrl );    if( ctrlurl_ctrl )        free( ctrlurl_ctrl );    if( servid_pict )        free( servid_pict );    if( evnturl_pict )        free( evnturl_pict );    if( ctrlurl_pict )        free( ctrlurl_pict );    if( DescDoc )        ixmlDocument_free( DescDoc );    return ( ret );}/****************************************************************************** * TvDeviceHandleSubscriptionRequest * * Description:  *       Called during a subscription request callback.  If the *       subscription request is for this device and either its *       control service or picture service, then accept it. * * Parameters: *   sr_event -- The subscription request event structure * *****************************************************************************/intTvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request                                   *sr_event ){    unsigned int i = 0;         //,j=0;    // IXML_Document *PropSet=NULL;    //lock state mutex    ithread_mutex_lock( &TVDevMutex );    for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {        if( ( strcmp( sr_event->UDN, tv_service_table[i].UDN ) == 0 ) &&            ( strcmp( sr_event->ServiceId, tv_service_table[i].ServiceId )              == 0 ) ) {            /*               PropSet = NULL;               for (j=0; j< tv_service_table[i].VariableCount; j++)               {               //add each variable to the property set               //for initial state dump               UpnpAddToPropertySet(&PropSet,                tv_service_table[i].VariableName[j],               tv_service_table[i].VariableStrVal[j]);               }               //dump initial state                UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN,                sr_event->ServiceId,               PropSet,sr_event->Sid);               //free document               Document_free(PropSet);             */

⌨️ 快捷键说明

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