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

📄 upnp_tv_device.c

📁 Upnp开发包文件
💻 C
📖 第 1 页 / 共 5 页
字号:
 *    IXML_Document **out - action result document *    char **errorString - errorString (in case action was unsuccessful) * *****************************************************************************/intTvDeviceIncreaseContrast( IN IXML_Document * in,                          OUT IXML_Document ** out,                          OUT char **errorString ){    return IncrementContrast( 1, in, out, errorString );}/****************************************************************************** * TvDeviceDecreaseContrast * * Description:  *      Decrease the contrast. * * Parameters: *           *    IXML_Document * in -  action request document *    IXML_Document **out - action result document *    char **errorString - errorString (in case action was unsuccessful) * *****************************************************************************/intTvDeviceDecreaseContrast( IXML_Document * in,                          IXML_Document ** out,                          char **errorString ){    return IncrementContrast( -1, in, out, errorString );}/****************************************************************************** * TvDeviceSetBrightness * * Description:  *       Change the brightness, update the TvDevice picture service *       state table, and notify all subscribed control points of the *       updated state. * * Parameters: *   brightness -- The brightness value to change to. * *****************************************************************************/intTvDeviceSetBrightness( IN IXML_Document * in,                       OUT IXML_Document ** out,                       OUT char **errorString ){    char *value = NULL;    int brightness = -1;    ( *out ) = NULL;    ( *errorString ) = NULL;    if( !( value = SampleUtil_GetFirstDocumentItem( in, "Brightness" ) ) ) {        ( *errorString ) = "Invalid Brightness";        return UPNP_E_INVALID_PARAM;    }    brightness = atoi( value );    if( brightness < MIN_BRIGHTNESS || brightness > MAX_BRIGHTNESS ) {        SampleUtil_Print( "error: can't change to brightness %d\n",                          brightness );        ( *errorString ) = "Invalid Brightness";        return UPNP_E_INVALID_PARAM;    }    /*       Vendor-specific code to set the volume goes here      */    if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,                                    TV_PICTURE_BRIGHTNESS, value ) ) {        if( UpnpAddToActionResponse( out, "SetBrightness",                                     TvServiceType[TV_SERVICE_PICTURE],                                     "NewBrightness",                                     value ) != UPNP_E_SUCCESS ) {            ( *out ) = NULL;            ( *errorString ) = "Internal Error";            free( value );            return UPNP_E_INTERNAL_ERROR;        }        free( value );        return UPNP_E_SUCCESS;    } else {        free( value );        ( *errorString ) = "Internal Error";        return UPNP_E_INTERNAL_ERROR;    }}/****************************************************************************** * IncrementBrightness * * Description:  *       Increment the brightness.  Read the current brightness from the state *       table, add the increment, and then change the brightness. * * Parameters: *   incr -- The increment by which to change the brightness. *    *    IXML_Document * in -  action request document *    IXML_Document **out - action result document *    char **errorString - errorString (in case action was unsuccessful) *****************************************************************************/intIncrementBrightness( IN int incr,                     IN IXML_Document * in,                     OUT IXML_Document ** out,                     OUT char **errorString ){    int curbrightness,      newbrightness;    char *actionName = NULL;    char value[TV_MAX_VAL_LEN];    if( incr > 0 ) {        actionName = "IncreaseBrightness";    } else {        actionName = "DecreaseBrightness";    }    ithread_mutex_lock( &TVDevMutex );    curbrightness = atoi( tv_service_table[TV_SERVICE_PICTURE].                          VariableStrVal[TV_PICTURE_BRIGHTNESS] );    ithread_mutex_unlock( &TVDevMutex );    newbrightness = curbrightness + incr;    if( newbrightness < MIN_BRIGHTNESS || newbrightness > MAX_BRIGHTNESS ) {        SampleUtil_Print( "error: can't change to brightness %d\n",                          newbrightness );        ( *errorString ) = "Invalid Brightness";        return UPNP_E_INVALID_PARAM;    }    /*       Vendor-specific code to set the channel goes here      */    sprintf( value, "%d", newbrightness );    if( TvDeviceSetServiceTableVar( TV_SERVICE_PICTURE,                                    TV_PICTURE_BRIGHTNESS, value ) ) {        if( UpnpAddToActionResponse( out, actionName,                                     TvServiceType[TV_SERVICE_PICTURE],                                     "Brightness",                                     value ) != UPNP_E_SUCCESS ) {            ( *out ) = NULL;            ( *errorString ) = "Internal Error";            return UPNP_E_INTERNAL_ERROR;        }        return UPNP_E_SUCCESS;    } else {        ( *errorString ) = "Internal Error";        return UPNP_E_INTERNAL_ERROR;    }}/****************************************************************************** * TvDeviceIncreaseBrightness * * Description:  *       Increase brightness. * * Parameters: * *    IXML_Document * in -  action request document *    IXML_Document **out - action result document *    char **errorString - errorString (in case action was unsuccessful) * *****************************************************************************/intTvDeviceIncreaseBrightness( IN IXML_Document * in,                            OUT IXML_Document ** out,                            OUT char **errorString ){    return IncrementBrightness( 1, in, out, errorString );}/****************************************************************************** * TvDeviceDecreaseBrightness * * Description:  *       Decrease brightnesss. * * Parameters: *    IXML_Document * in -  action request document *    IXML_Document **out - action result document *    char **errorString - errorString (in case action was unsuccessful) * *****************************************************************************/intTvDeviceDecreaseBrightness( IN IXML_Document * in,                            OUT IXML_Document ** out,                            OUT char **errorString ){    return IncrementBrightness( -1, in, out, errorString );}/****************************************************************************** * TvDeviceCallbackEventHandler * * Description:  *       The callback handler registered with the SDK while registering *       root device.  Dispatches the request to the appropriate procedure *       based on the value of EventType. The four requests handled by the  *       device are:  *                   1) Event Subscription requests.   *                   2) Get Variable requests.  *                   3) Action requests. * * Parameters: * *   EventType -- The type of callback event *   Event -- Data structure containing event data *   Cookie -- Optional data specified during callback registration * *****************************************************************************/intTvDeviceCallbackEventHandler( Upnp_EventType EventType,                              void *Event,                              void *Cookie ){    switch ( EventType ) {        case UPNP_EVENT_SUBSCRIPTION_REQUEST:            TvDeviceHandleSubscriptionRequest( ( struct                                                 Upnp_Subscription_Request                                                 * )Event );            break;        case UPNP_CONTROL_GET_VAR_REQUEST:            TvDeviceHandleGetVarRequest( ( struct Upnp_State_Var_Request                                           * )Event );            break;        case UPNP_CONTROL_ACTION_REQUEST:            TvDeviceHandleActionRequest( ( struct Upnp_Action_Request * )                                         Event );            break;            /*               ignore these cases, since this is not a control point              */        case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:        case UPNP_DISCOVERY_SEARCH_RESULT:        case UPNP_DISCOVERY_SEARCH_TIMEOUT:        case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:        case UPNP_CONTROL_ACTION_COMPLETE:        case UPNP_CONTROL_GET_VAR_COMPLETE:        case UPNP_EVENT_RECEIVED:        case UPNP_EVENT_RENEWAL_COMPLETE:        case UPNP_EVENT_SUBSCRIBE_COMPLETE:        case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:            break;        default:            SampleUtil_Print                ( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",                  EventType );    }    /*       Print a summary of the event received      */    SampleUtil_PrintEvent( EventType, Event );    return ( 0 );}/****************************************************************************** * TvDeviceStop * * Description:  *       Stops the device. Uninitializes the sdk.  * * Parameters: * *****************************************************************************/intTvDeviceStop(  ){    UpnpUnRegisterRootDevice( device_handle );    UpnpFinish(  );    SampleUtil_Finish(  );    ithread_mutex_destroy( &TVDevMutex );    return UPNP_E_SUCCESS;}/****************************************************************************** * TvDeviceStart * * Description:  *      Initializes the UPnP Sdk, registers the device, and sends out  *      advertisements.   * * Parameters: * *   ip_address - ip address to initialize the sdk (may be NULL) *                if null, then the first non null loopback address is used. *   port       - port number to initialize the sdk (may be 0) *                if zero, then a random number is used. *   desc_doc_name - name of description document. *                   may be NULL. Default is tvdevicedesc.xml *   web_dir_path  - path of web directory. *                   may be NULL. Default is ./web (for Linux) or ../tvdevice/web *                   for windows. *   pfun          - print function to use.   * *****************************************************************************/intTvDeviceStart( char *ip_address,               unsigned short port,               char *desc_doc_name,               char *web_dir_path,               print_string pfun ){    int ret = UPNP_E_SUCCESS;    char desc_doc_url[DESC_URL_SIZE];    ithread_mutex_init( &TVDevMutex, NULL );    SampleUtil_Initialize( pfun );    SampleUtil_Print        ( "Initializing UPnP Sdk with \n \t ipaddress = %s port = %d\n",          ip_address, port );    if( ( ret = UpnpInit( ip_address, port ) ) != UPNP_E_SUCCESS ) {        SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );        UpnpFinish(  );        return ret;    }    if( ip_address == NULL ) {        ip_address = UpnpGetServerIpAddress(  );    }    if( port == 0 ) {        port = UpnpGetServerPort(  );    }    SampleUtil_Print( "UPnP Initialized\n \t ipaddress= %s port = %d\n",                      ip_address, port );    if( desc_doc_name == NULL )        desc_doc_name = "tvdevicedesc.xml";    if( web_dir_path == NULL )        web_dir_path = DEFAULT_WEB_DIR;    snprintf( desc_doc_url, DESC_URL_SIZE, "http://%s:%d/%s", ip_address,              port, desc_doc_name );    SampleUtil_Print( "Specifying the webserver root directory -- %s\n",                      web_dir_path );    if( ( ret =          UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) {        SampleUtil_Print            ( "Error specifying webserver root directory -- %s: %d\n",              web_dir_path, ret );        UpnpFinish(  );        return ret;    }    SampleUtil_Print        ( "Registering the RootDevice\n\t with desc_doc_url: %s\n",          desc_doc_url );    if( ( ret = UpnpRegisterRootDevice( desc_doc_url,                                        TvDeviceCallbackEventHandler,                                        &device_handle, &device_handle ) )        != UPNP_E_SUCCESS ) {        SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );        UpnpFinish(  );        return ret;    } else {        SampleUtil_Print( "RootDevice Registered\n" );        SampleUtil_Print( "Initializing State Table\n" );        TvDeviceStateTableInit( desc_doc_url );        SampleUtil_Print( "State Table Initialized\n" );        if( ( ret =              UpnpSendAdvertisement( device_handle, default_advr_expire ) )            != UPNP_E_SUCCESS ) {            SampleUtil_Print( "Error sending advertisements : %d\n", ret );            UpnpFinish(  );            return ret;        }        SampleUtil_Print( "Advertisements Sent\n" );    }    return UPNP_E_SUCCESS;}

⌨️ 快捷键说明

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