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

📄 upnp_tv_ctrlpt.c

📁 upnpsdk-1.0.4.tar.gz Intel UPnP SDK Source
💻 C
📖 第 1 页 / 共 4 页
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2000 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.///////////////////////////////////////////////////////////////////////////////// $Revision: 1.1.1.4 $// $Date: 2001/06/15 00:21:32 $//#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. */pthread_mutex_t DeviceListMutex = PTHREAD_MUTEX_INITIALIZER;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 = 1800;/* The first node in the global device list, or NULL   if empty */struct TvDeviceNode *GlobalDeviceList=NULL;/* Tags for valid commands issued at the command prompt */enum cmdloop_tvcmds {    PRTHELP=0,    POWON,    POWOFF,    SETCHAN,    SETVOL,    SETCOL,    SETTINT,    SETCONT,    SETBRT,    CTRLACTION,    PICTACTION,    CTRLGETVAR,    PICTGETVAR,    PRTDEV,    LSTDEV,    REFRESH,    EXITCMD};/* Data structure for parsing commands from   the command line */struct cmdloop_commands  {    char  *str;         // the string     int    cmdnum;      // the command    char  *args;        // the args} cmdloop_commands;/* Mappings between command text names, command tag,   and required command arguments for command line   commands */static struct cmdloop_commands cmdloop_cmdlist[]= {    {"Help", PRTHELP,             ""},     {"ListDev", LSTDEV,           ""},    {"Refresh", REFRESH,          ""},    {"PrintDev", PRTDEV,          "<devnum>"},    {"PowerOn", POWON,            "<devnum>"},     {"PowerOff", POWOFF,          "<devnum>"},    {"SetChannel", SETCHAN,       "<devnum> <channel (int)>"},    {"SetVolume", SETVOL,         "<devnum> <volume (int)>"},    {"SetColor", SETCOL,          "<devnum> <color (int)>"},    {"SetTint", SETTINT,          "<devnum> <tint (int)>"},    {"SetContrast", SETCONT,      "<devnum> <contrast (int)>"},    {"SetBrightness", SETBRT,     "<devnum> <brightness (int)>"},    {"CtrlAction",  CTRLACTION,   "<devnum> <action (string)>"},    {"PictAction",  PICTACTION,   "<devnum> <action (string)>"},    {"CtrlGetVar",  CTRLGETVAR,   "<devnum> <varname (string)>"},    {"PictGetVar",  PICTGETVAR,   "<devnum> <varname (string)>"},    {"Exit", EXITCMD,             ""}};/******************************************************************************** * TvCtrlPointPrintHelp * * Description:  *       Print help info for this application. * * Parameters: *   None * ********************************************************************************/int TvCtrlPointPrintHelp() {    printf("\n\n");    printf("******************************\n");    printf("* TV Control Point Help Info *\n");    printf("******************************\n");    printf("\n\n");    printf("This sample control point application automatically searches\n");    printf("for and subscribes to the services of television device emulator\n");    printf("devices, described in the tvdevicedesc.xml description document.\n");    printf("\n\n");    printf("Commands:\n\n");    printf("  Help\n");    printf("       Print this help info.\n\n");    printf("  ListDev\n");    printf("       Print the current list of TV Device Emulators that this\n");    printf("         control point is aware of.  Each device is preceded by a\n");    printf("         device number which corresponds to the devnum argument of\n");    printf("         commands listed below.\n\n");    printf("  Refresh\n");    printf("       Delete all of the devices from the device list and issue new\n");    printf("         search request to rebuild the list from scratch.\n\n");    printf("  PrintDev       <devnum>\n");    printf("       Print the state table for the device <devnum>.\n");    printf("         e.g., 'PrintDev 1' prints the state table for the first\n");    printf("         device in the device list.\n\n");    printf("  PowerOn        <devnum>\n");    printf("       Sends the PowerOn action to the Control Service of\n");    printf("         device <devnum>.\n\n");    printf("  PowerOff       <devnum>\n");    printf("       Sends the PowerOff action to the Control Service of\n");    printf("         device <devnum>.\n\n");    printf("  SetChannel     <devnum> <channel>\n");    printf("       Sends the SetChannel action to the Control Service of\n");    printf("         device <devnum>, requesting the channel to be changed\n");    printf("         to <channel>.\n\n");    printf("  SetVolume      <devnum> <volume>\n");    printf("       Sends the SetVolume action to the Control Service of\n");    printf("         device <devnum>, requesting the volume to be changed\n");    printf("         to <volume>.\n\n");    printf("  SetColor       <devnum> <color>\n");    printf("       Sends the SetColor action to the Control Service of\n");    printf("         device <devnum>, requesting the color to be changed\n");    printf("         to <color>.\n\n");    printf("  SetTint        <devnum> <tint>\n");    printf("       Sends the SetTint action to the Control Service of\n");    printf("         device <devnum>, requesting the tint to be changed\n");    printf("         to <tint>.\n\n");    printf("  SetContrast    <devnum> <contrast>\n");    printf("       Sends the SetContrast action to the Control Service of\n");    printf("         device <devnum>, requesting the contrast to be changed\n");    printf("         to <contrast>.\n\n");    printf("  SetBrightness  <devnum> <brightness>\n");    printf("       Sends the SetBrightness action to the Control Service of\n");    printf("         device <devnum>, requesting the brightness to be changed\n");    printf("         to <brightness>.\n\n");    printf("  CtrlAction     <devnum> <action>\n");    printf("       Sends an action request specified by the string <action>\n");    printf("         to the Control Service of device <devnum>.  This command\n");    printf("         only works for actions that have no arguments.\n");    printf("         (e.g., \"CtrlAction 1 IncreaseChannel\")\n\n");    printf("  PictAction     <devnum> <action>\n");    printf("       Sends an action request specified by the string <action>\n");    printf("         to the Picture Service of device <devnum>.  This command\n");    printf("         only works for actions that have no arguments.\n");    printf("         (e.g., \"PictAction 1 DecreaseContrast\")\n\n");    printf("  CtrlGetVar     <devnum> <varname>\n");    printf("       Requests the value of a variable specified by the string <varname>\n");    printf("         from the Control Service of device <devnum>.\n");    printf("         (e.g., \"CtrlGetVar 1 Volume\")\n\n");    printf("  PictGetVar     <devnum> <action>\n");    printf("       Requests the value of a variable specified by the string <varname>\n");    printf("         from the Picture Service of device <devnum>.\n");    printf("         (e.g., \"PictGetVar 1 Tint\")\n\n");    printf("  Exit\n");    printf("       Exits the control point application.\n");    return(1);}/******************************************************************************** * 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 * ********************************************************************************/int TvCtrlPointDeleteNode(struct TvDeviceNode *node) {    int ret=UPNP_E_SUCCESS;    int service, var;    if (!node) {	printf("error in TvCtrlPointDeleteNode: node is empty\n");	return(1);    }    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) {	    ret=UpnpUnSubscribe(ctrlpt_handle, node->device.TvService[service].SID);	    if (ret==UPNP_E_SUCCESS)		printf("Unsubscribed from Tv %s EventURL with SID=%s\n", TvServiceName[service], node->device.TvService[service].SID);	    else		printf("Error unsubscribing to Tv %s EventURL -- %d\n", TvServiceName[service], ret);	}	for (var = 0; var < TvVarCount[service]; var++) {	    if(node->device.TvService[service].VariableStrVal[var]) 		free(node->device.TvService[service].VariableStrVal[var]);	}    }    free(node);    node = NULL;    return(1);}/******************************************************************************** * TvCtrlPointRemoveDevice * * Description:  *       Remove a device from the global device list. * * Parameters: *   UDN -- The Unique Device Name for the device to remove * ********************************************************************************/int TvCtrlPointRemoveDevice(char* UDN) {    struct TvDeviceNode *curdevnode, *prevdevnode;    int ret=0;    pthread_mutex_lock(&DeviceListMutex);    curdevnode = GlobalDeviceList;      if (!curdevnode) {	printf("Warning in TvCtrlPointRemoveDevice -- Device list empty\n");    } else {	if (strcmp(curdevnode->device.UDN,UDN) == 0) {	    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;	    }	}    }    pthread_mutex_unlock(&DeviceListMutex);    return ret;}/******************************************************************************** * TvCtrlPointRemoveAll * * Description:  *       Remove all devices from the global device list. * * Parameters: *   None * ********************************************************************************/int TvCtrlPointRemoveAll() {    struct TvDeviceNode *curdevnode, *next;    pthread_mutex_lock(&DeviceListMutex);    curdevnode = GlobalDeviceList;    GlobalDeviceList = NULL;      while (curdevnode) {	next = curdevnode->next;	TvCtrlPointDeleteNode(curdevnode);	curdevnode = next;    }    pthread_mutex_unlock(&DeviceListMutex);    return(1);}/******************************************************************************** * TvCtrlPointRefresh * * Description:  *       Clear the current global device list and issue new search *	 requests to build it up again from scratch. * * Parameters: *   None * ********************************************************************************/int TvCtrlPointRefresh() {    int ret;    TvCtrlPointRemoveAll();    /* Search for device with particular UDN,        waiting for up to 5 seconds for the response */    /* ret = UpnpSearchAsync(ctrlpt_handle, 5, "uuid:Upnp-TVEmulator-1_0-1234567890001", NULL); */    /* Search for all devices of type tvdevice version 1,        waiting for up to 5 seconds for the response */    /*ret = UpnpSearchAsync(ctrlpt_handle, 5, TvDeviceType, NULL);*/    /* Search for all services of type tvcontrol version 1,        waiting for up to 5 seconds for the response */    /* ret = UpnpSearchAsync(ctrlpt_handle, 5, TvServiceType[TV_SERVICE_CONTROL], NULL); */    /* Search for all root devices,        waiting for up to 5 seconds for the response */    ret = UpnpSearchAsync(ctrlpt_handle, 5, "upnp:rootdevice", NULL);        if (ret != UPNP_E_SUCCESS)	printf("Error sending search request%d\n", ret);    return(1);}/******************************************************************************** * 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. * ********************************************************************************/int TvCtrlPointGetVar(int service, int devnum, char* varname){    struct TvDeviceNode *devnode;    int ret=0;    Upnp_DOMString StVarVal = NULL;    pthread_mutex_lock(&DeviceListMutex);    if (!TvCtrlPointGetDevice(devnum, &devnode)) {	ret = 0;;    } else {

⌨️ 快捷键说明

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