📄 upnp_tv_ctrlpt.c
字号:
//ret = UpnpGetServiceVarStatusAsync( ctrlpt_handle, devnode->device.TvService[service].ControlURL, varname, TvCtrlPointCallbackEventHandler, NULL); ret = UpnpGetServiceVarStatus(ctrlpt_handle, devnode->device.TvService[service].ControlURL, varname, &StVarVal); if (ret != UPNP_E_SUCCESS) { printf("Error in UpnpGetServiceVarStatusAsync -- %d\n", ret); } else { printf(" %s \n", StVarVal); UpnpDOMString_free(StVarVal); } } pthread_mutex_unlock(&DeviceListMutex); return(ret);}/******************************************************************************** * 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 * ********************************************************************************/int TvCtrlPointSendAction(int service, int devnum, char *actionname, char **param_name, char **param_val, int param_count){ struct TvDeviceNode *devnode; char ActionXml[250]; char tmpstr[100]; Upnp_Document actionNode=NULL; int ret=0; int param; pthread_mutex_lock(&DeviceListMutex); if (!TvCtrlPointGetDevice(devnum, &devnode)) { ret = 0;; } else { /*sprintf(ActionXml, "<u:%s xmlns:u=\"%s\">", actionname, TvServiceType[service]); for (param = 0; param < param_count; param++) { sprintf(tmpstr, "<%s>%s</%s>", param_name[param], param_val[param], param_name[param]); strcat(ActionXml, tmpstr); } sprintf(tmpstr, "</u:%s>", actionname); strcat(ActionXml, tmpstr); actionNode = UpnpParse_Buffer( ActionXml);*/ if( param_count== 0) //UpnpAddToAction(&actionNode,actionname,TvServiceType[service],NULL,NULL); OR actionNode = UpnpMakeAction(actionname,TvServiceType[service],0,NULL); else for (param = 0; param < param_count; param++) { if( UpnpAddToAction(&actionNode,actionname,TvServiceType[service],param_name[param], param_val[param]) != UPNP_E_SUCCESS) { printf("Error in adding action parameter !!!!!!!!!!!!!!!!\n"); return -1; } } ret = UpnpSendActionAsync( ctrlpt_handle, devnode->device.TvService[service].ControlURL, TvServiceType[service], devnode->device.UDN, actionNode, TvCtrlPointCallbackEventHandler, NULL); if (ret != UPNP_E_SUCCESS) printf("Error in UpnpSendActionAsync -- %d\n", ret); } pthread_mutex_unlock(&DeviceListMutex); if (actionNode) UpnpDocument_free(actionNode); return(ret);}/******************************************************************************** * TvCtrlPointSendSetChannel * * Description: * Send a SetChannel action to a device in * the global device list. * * Parameters: * devnum -- The number of the device (order in the list, * starting with 1) * channel -- The channel to change to * ********************************************************************************/int TvCtrlPointSendSetChannel(int devnum, int channel){ int ret=0; char param_name_a[50]; char param_val_a[50]; char *param_name = param_name_a; char *param_val = param_val_a; sprintf(param_name_a, "Channel"); sprintf(param_val_a, "%d", channel); ret = TvCtrlPointSendAction(TV_SERVICE_CONTROL, devnum, "SetChannel", ¶m_name, ¶m_val, 1); return(ret);}/******************************************************************************** * TvCtrlPointSendSetVolume * * Description: * Send a SetVolume action to a device in * the global device list. * * Parameters: * devnum -- The number of the device (order in the list, * starting with 1) * volume -- The volume to change to * ********************************************************************************/int TvCtrlPointSendSetVolume(int devnum, int volume){ int ret=0; char param_name_a[50]; char param_val_a[50]; char *param_name = param_name_a; char *param_val = param_val_a; sprintf(param_name_a, "Volume"); sprintf(param_val_a, "%d", volume); ret = TvCtrlPointSendAction(TV_SERVICE_CONTROL, devnum, "SetVolume", ¶m_name, ¶m_val, 1); return(ret);}/******************************************************************************** * TvCtrlPointSendSetColor * * Description: * Send a SetColor action to a device in * the global device list. * * Parameters: * devnum -- The number of the device (order in the list, * starting with 1) * color -- The color to change to * ********************************************************************************/int TvCtrlPointSendSetColor(int devnum, int color){ int ret=0; char param_name_a[50]; char param_val_a[50]; char *param_name = param_name_a; char *param_val = param_val_a; sprintf(param_name_a, "Color"); sprintf(param_val_a, "%d", color); ret = TvCtrlPointSendAction(TV_SERVICE_PICTURE, devnum, "SetColor", ¶m_name, ¶m_val, 1); return(ret);}/******************************************************************************** * TvCtrlPointSendSetTint * * Description: * Send a SetTint action to a device in * the global device list. * * Parameters: * devnum -- The number of the device (order in the list, * starting with 1) * tint -- The tint to change to * ********************************************************************************/int TvCtrlPointSendSetTint(int devnum, int tint){ int ret=0; char param_name_a[50]; char param_val_a[50]; char *param_name = param_name_a; char *param_val = param_val_a; sprintf(param_name_a, "Tint"); sprintf(param_val_a, "%d", tint); ret = TvCtrlPointSendAction(TV_SERVICE_PICTURE, devnum, "SetTint", ¶m_name, ¶m_val, 1); return(ret);}/******************************************************************************** * TvCtrlPointSendSetContrast * * Description: * Send a SetContrast action to a device in * the global device list. * * Parameters: * devnum -- The number of the device (order in the list, * starting with 1) * contrast -- The contrast to change to * ********************************************************************************/int TvCtrlPointSendSetContrast(int devnum, int contrast){ int ret=0; char param_name_a[50]; char param_val_a[50]; char *param_name = param_name_a; char *param_val = param_val_a; sprintf(param_name_a, "Contrast"); sprintf(param_val_a, "%d", contrast); ret = TvCtrlPointSendAction(TV_SERVICE_PICTURE, devnum, "SetContrast", ¶m_name, ¶m_val, 1); return(ret);}/******************************************************************************** * TvCtrlPointSendSetBrightness * * Description: * Send a SetBrightness action to a device in * the global device list. * * Parameters: * devnum -- The number of the device (order in the list, * starting with 1) * brightness -- The brightness to change to * ********************************************************************************/int TvCtrlPointSendSetBrightness(int devnum, int brightness){ int ret=0; char param_name_a[50]; char param_val_a[50]; char *param_name = param_name_a; char *param_val = param_val_a; sprintf(param_name_a, "Brightness"); sprintf(param_val_a, "%d", brightness); ret = TvCtrlPointSendAction(TV_SERVICE_PICTURE, devnum, "SetBrightness", ¶m_name, ¶m_val, 1); return(ret);}/******************************************************************************** * TvCtrlPointGetDevice * * Description: * Given a list number, returns the pointer to the device * node at that position in the global device list. Note * that this function is not thread safe. It must be called * from a function that has locked the global device list. * * Parameters: * devnum -- The number of the device (order in the list, * starting with 1) * devnode -- The output device node pointer * ********************************************************************************/int TvCtrlPointGetDevice(int devnum, struct TvDeviceNode **devnode) { int count = devnum; struct TvDeviceNode *tmpdevnode=NULL; if (count) tmpdevnode = GlobalDeviceList; while (--count && tmpdevnode) { tmpdevnode = tmpdevnode->next; } if (tmpdevnode) { *devnode = tmpdevnode; return(1); } else { printf("Error finding TvDevice number -- %d\n", devnum); return(0); }}/******************************************************************************** * TvCtrlPointPrintList * * Description: * Print the universal device names for each device in the global device list * * Parameters: * None * ********************************************************************************/int TvCtrlPointPrintList() { struct TvDeviceNode *tmpdevnode; int i=0; pthread_mutex_lock(&DeviceListMutex); printf("\nTvCtrlPointPrintList:\n"); tmpdevnode = GlobalDeviceList; while (tmpdevnode) { printf(" %3d -- %s\n", ++i, tmpdevnode->device.UDN); tmpdevnode = tmpdevnode->next; } printf("\n"); pthread_mutex_unlock(&DeviceListMutex); return(1);}/******************************************************************************** * TvCtrlPointPrintDevice * * Description: * Print the identifiers and state table for a device from * the global device list. * * Parameters: * devnum -- The number of the device (order in the list, * starting with 1) * ********************************************************************************/int TvCtrlPointPrintDevice(int devnum) { struct TvDeviceNode *tmpdevnode; int i=0, service, var; char spacer[15]; if (devnum <= 0) { printf("Error in TvCtrlPointPrintDevice: invalid devnum = %d\n", devnum); return(0); } pthread_mutex_lock(&DeviceListMutex); printf("\nTvCtrlPointPrintDevice:\n"); tmpdevnode = GlobalDeviceList; while (tmpdevnode) { i++; if (i == devnum) break; tmpdevnode = tmpdevnode->next; } if (!tmpdevnode) { printf("Error in TvCtrlPointPrintDevice: invalid devnum = %d -- actual device count = %d\n", devnum, i); } else { printf(" TvDevice -- %d\n", devnum); printf(" | \n"); printf(" +- UDN = %s\n", tmpdevnode->device.UDN); printf(" +- DescDocURL = %s\n", tmpdevnode->device.DescDocURL); printf(" +- FriendlyName = %s\n", tmpdevnode->device.FriendlyName); printf(" +- PresURL = %s\n", tmpdevnode->device.PresURL); printf(" +- Adver. TimeOut = %d\n", tmpdevnode->device.AdvrTimeOut); for (service=0; service<TV_SERVICE_SERVCOUNT; service++) { if (service < TV_SERVICE_SERVCOUNT-1) sprintf(spacer, " | "); else sprintf(spacer, " "); printf(" | \n"); printf(" +- Tv %s Service\n", TvServiceName[service]); printf("%s+- ServiceId = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceId); printf("%s+- ServiceType = %s\n", spacer, tmpdevnode->device.TvService[service].ServiceType); printf("%s+- EventURL = %s\n", spacer, tmpdevnode->device.TvService[service].EventURL); printf("%s+- ControlURL = %s\n", spacer, tmpdevnode->device.TvService[service].ControlURL); printf("%s+- SID = %s\n", spacer, tmpdevnode->device.TvService[service].SID); printf("%s+- ServiceStateTable\n", spacer); for (var=0; var<TvVarCount[service]; var++) { printf("%s +- %-10s = %s\n", spacer, TvVarName[service][var], tmpdevnode->device.TvService[service].VariableStrVal[var]); } } } printf("\n"); pthread_mutex_unlock(&DeviceListMutex); return(1);}/********************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -