📄 upnp_tv_device.c
字号:
action_succeeded = TvDeviceIncrTint(-1); } else if (strcmp(ca_event->ActionName, "SetContrast") == 0) { if ((value = SampleUtil_GetFirstDocumentItem(ca_event->ActionRequest, "Contrast"))) { action_succeeded = TvDeviceSetContrast(atoi(value)); } else { // invalid args error err = 402; action_succeeded = 0; } } else if (strcmp(ca_event->ActionName, "IncreaseContrast") == 0) { action_succeeded = TvDeviceIncrContrast(1); } else if (strcmp(ca_event->ActionName, "DecreaseContrast") == 0) { action_succeeded = TvDeviceIncrContrast(-1); } else if (strcmp(ca_event->ActionName, "SetBrightness") == 0) { if ((value = SampleUtil_GetFirstDocumentItem(ca_event->ActionRequest, "Brightness"))) { action_succeeded = TvDeviceSetBrightness(atoi(value)); } else { // invalid args error err = 402; action_succeeded = 0; } } else if (strcmp(ca_event->ActionName, "IncreaseBrightness") == 0) { action_succeeded = TvDeviceIncrBrightness(1); } else if (strcmp(ca_event->ActionName, "DecreaseBrightness") == 0) { action_succeeded = TvDeviceIncrBrightness(-1); } } else { printf("Error in UPNP_CONTROL_ACTION_REQUEST callback:\n"); printf(" Unknown UDN = %s or ServiceId = %s\n", ca_event->DevUDN, ca_event->ServiceID ); } if (action_succeeded > 0) { ca_event->ErrCode = UPNP_E_SUCCESS; sprintf(result_str, "<u:%sResponse xmlns:u=\"%s\"> </u:%sResponse>", ca_event->ActionName, service_type, ca_event->ActionName); ca_event->ActionResult = UpnpParse_Buffer(result_str); } else if (action_succeeded == -1) { printf("Error in UPNP_CONTROL_ACTION_REQUEST callback:\n"); printf(" Unknown ActionName = %s\n", ca_event->ActionName); ca_event->ErrCode = 401; strcpy(ca_event->ErrStr, "Invalid Action"); ca_event->ActionResult = NULL; } else { printf("Error in UPNP_CONTROL_ACTION_REQUEST callback:\n"); printf(" Failure while running %s\n", ca_event->ActionName); ca_event->ErrCode = err; strcpy(ca_event->ErrStr, "Invalid Args"); ca_event->ActionResult = NULL; } if (value) free(value); return(ca_event->ErrCode);}/******************************************************************************** * TvDeviceSetServiceTableVar * * Description: * Update the TvDevice service state table, and notify all subscribed * control points of the updated state. Note that since this function * blocks on the mutex TVDevMutex, to avoid a hang this function should * not be called within any other function that currently has this mutex * locked. * * Parameters: * service -- The service number (TV_SERVICE_CONTROL or TV_SERVICE_PICTURE) * variable -- The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL, * TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT, * TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS) * value -- The string representation of the new value * ********************************************************************************/int TvDeviceSetServiceTableVar(unsigned int service, unsigned int variable, char *value) { Upnp_Document PropSet= NULL; if ((service >= TV_SERVICE_SERVCOUNT) || (variable >= tv_service_table[service].VariableCount) || (strlen(value) >= TV_MAX_VAL_LEN)) { return(0); } pthread_mutex_lock(&TVDevMutex); strcpy(tv_service_table[service].VariableStrVal[variable], value); // Using the first utility api /*UpnpAddToPropertySet(&PropSet, tv_service_table[service].VariableName[variable], tv_service_table[service].VariableStrVal[variable]); UpnpNotifyExt(device_handle, tv_service_table[service].UDN, tv_service_table[service].ServiceId,PropSet); UpnpDocument_free(PropSet); */ //Using second utility API PropSet= UpnpCreatePropertySet(1,tv_service_table[service].VariableName[variable], tv_service_table[service].VariableStrVal[variable]); UpnpNotifyExt(device_handle, tv_service_table[service].UDN, tv_service_table[service].ServiceId,PropSet); UpnpDocument_free(PropSet); /* Send updated power setting notification to subscribed control points */ /* UpnpNotify(device_handle, tv_service_table[service].UDN, tv_service_table[service].ServiceId, (char **)&tv_service_table[service].VariableName[variable], (char **)&tv_service_table[service].VariableStrVal[variable], 1); */ pthread_mutex_unlock(&TVDevMutex); return(1);}/******************************************************************************** * TvDeviceSetPower * * Description: * Turn the power on/off, update the TvDevice control service * state table, and notify all subscribed control points of the * updated state. * * Parameters: * on -- If 1, turn power on. If 0, turn power off. * ********************************************************************************/int TvDeviceSetPower(int on) { char value[TV_MAX_VAL_LEN]; int ret=0; if (on != 0 && on != 1) { printf("error: can't set power to value %d\n", on); return(0); } /* Vendor-specific code to turn the power on/off goes here */ sprintf(value, "%d", on); ret = TvDeviceSetServiceTableVar(TV_SERVICE_CONTROL, TV_CONTROL_POWER, value); return(ret);}/******************************************************************************** * TvDevicePowerOn * * Description: * Turn the power on. * * Parameters: * ********************************************************************************/int TvDevicePowerOn() { return(TvDeviceSetPower(1));}/******************************************************************************** * TvDevicePowerOff * * Description: * Turn the power off. * * Parameters: * ********************************************************************************/int TvDevicePowerOff() { return(TvDeviceSetPower(0));}/******************************************************************************** * TvDeviceSetChannel * * Description: * Change the channel, update the TvDevice control service * state table, and notify all subscribed control points of the * updated state. * * Parameters: * channel -- The channel number to change to. * ********************************************************************************/int TvDeviceSetChannel(int channel) { char value[TV_MAX_VAL_LEN]; int ret=0; if (channel < 1 || channel > 100) { printf("error: can't change to channel %d\n", channel); return(0); } /* Vendor-specific code to set the channel goes here */ sprintf(value, "%d", channel); ret = TvDeviceSetServiceTableVar(TV_SERVICE_CONTROL, TV_CONTROL_CHANNEL, value); return(ret);}/******************************************************************************** * TvDeviceIncrChannel * * Description: * Increment the channel. Read the current channel from the state * table, add the increment, and then change the channel. * * Parameters: * incr -- The increment by which to change the channel. * ********************************************************************************/int TvDeviceIncrChannel(int incr) { int curchannel, newchannel; int ret; pthread_mutex_lock(&TVDevMutex); curchannel = atoi(tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[TV_CONTROL_CHANNEL]); pthread_mutex_unlock(&TVDevMutex); newchannel = curchannel + incr; ret = TvDeviceSetChannel(newchannel); return(ret);}/******************************************************************************** * TvDeviceSetVolume * * Description: * Change the volume, update the TvDevice control service * state table, and notify all subscribed control points of the * updated state. * * Parameters: * volume -- The volume value to change to. * ********************************************************************************/int TvDeviceSetVolume(int volume) { char value[TV_MAX_VAL_LEN]; int ret=0; if (volume < 0 || volume > 10) { printf("error: can't change to volume %d\n", volume); return(0); } /* Vendor-specific code to set the volume goes here */ sprintf(value, "%d", volume); ret = TvDeviceSetServiceTableVar(TV_SERVICE_CONTROL, TV_CONTROL_VOLUME, value); return(ret);}/******************************************************************************** * TvDeviceIncrVolume * * Description: * Increment the volume. Read the current volume from the state * table, add the increment, and then change the volume. * * Parameters: * incr -- The increment by which to change the volume. * ********************************************************************************/int TvDeviceIncrVolume(int incr) { int curvolume, newvolume; int ret; pthread_mutex_lock(&TVDevMutex); curvolume = atoi(tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[TV_CONTROL_VOLUME]); pthread_mutex_unlock(&TVDevMutex); newvolume = curvolume + incr; ret = TvDeviceSetVolume(newvolume); return(ret);}/******************************************************************************** * TvDeviceSetColor * * Description: * Change the color, update the TvDevice picture service * state table, and notify all subscribed control points of the * updated state. * * Parameters: * color -- The color value to change to. * ********************************************************************************/int TvDeviceSetColor(int color) { char value[TV_MAX_VAL_LEN]; int ret=0; if (color < 1 || color > 10) { printf("error: can't change to color %d\n", color); return(0); } /* Vendor-specific code to set the color goes here */ sprintf(value, "%d", color); ret = TvDeviceSetServiceTableVar(TV_SERVICE_PICTURE, TV_PICTURE_COLOR, value); return(ret);}/******************************************************************************** * TvDeviceIncrColor * * Description: * Increment the color. Read the current color from the state * table, add the increment, and then change the color. * * Parameters: * incr -- The increment by which to change the color. * ********************************************************************************/int TvDeviceIncrColor(int incr) { int curcolor, newcolor; int ret; pthread_mutex_lock(&TVDevMutex); curcolor = atoi(tv_service_table[TV_SERVICE_PICTURE].VariableStrVal[TV_PICTURE_COLOR]); pthread_mutex_unlock(&TVDevMutex); newcolor = curcolor + incr; ret = TvDeviceSetColor(newcolor); return(ret);}/******************************************************************************** * TvDeviceSetTint * * Description: * Change the tint, update the TvDevice picture service * state table, and notify all subscribed control points of the * updated state. * * Parameters: * tint -- The tint value to change to. * ********************************************************************************/int TvDeviceSetTint(int tint) { char value[TV_MAX_VAL_LEN]; int ret=0; if (tint < 1 || tint > 10) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -