📄 upnp_z256_device.c.back
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2004 RPA Network///////////////////////////////////////////////////////////////////////////////// $Revision: 1.0.0.0 $// $Date: 2004/02/23 $//#include "upnp_z256_device.h"char Z256DeviceType[] = "urn:schemas-upnp-org:device:tvdevice:1";char *Z256ServiceType[] = {"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[Z256_CONTROL_VARCOUNT][Z256_MAX_VAL_LEN];char *tvc_varval_def[] = {"0", "1", "5"};/* Global arrays for storing Tv Picture Service variable names, values, and defaults */char *tvp_varname[] = {"Color","Tint","Contrast","Brightness"};char tvp_varval[Z256_PICTURE_VARCOUNT][Z256_MAX_VAL_LEN];char *tvp_varval_def[] = {"5","5","5","5"};/* The amount of time before advertisements will expire */int default_advr_expire=1800;/* Global structure for storing the state table for this device */struct Z256Service z256_service_table[2];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. */pthread_mutex_t Z256DevMutex= PTHREAD_MUTEX_INITIALIZER;/******************************************************************************** * Z256DeviceHandleSubscriptionRequest * * 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 * ********************************************************************************/int Z256DeviceHandleSubscriptionRequest(struct Upnp_Subscription_Request *sr_event){ int i,j; Upnp_Document PropSet; pthread_mutex_lock(&Z256DevMutex); for (i=0; i<Z256_SERVICE_SERVCOUNT; i++) { if ((strcmp(sr_event->UDN,z256_service_table[i].UDN) == 0) && (strcmp(sr_event->ServiceId,z256_service_table[i].ServiceId) == 0)) { /* This is a request for the Z256Device Control Service */ /* UpnpAcceptSubscription(device_handle, sr_event->UDN, sr_event->ServiceId, (char **)z256_service_table[i].VariableName, (char **)z256_service_table[i].VariableStrVal, z256_service_table[i].VariableCount, sr_event->Sid);*/ //Another way of doing the same thing. PropSet = NULL; for (j=0; j< z256_service_table[i].VariableCount; j++) UpnpAddToPropertySet(&PropSet, z256_service_table[i].VariableName[j],z256_service_table[i].VariableStrVal[j]); UpnpAcceptSubscriptionExt(device_handle, sr_event->UDN, sr_event->ServiceId,PropSet,sr_event->Sid); UpnpDocument_free(PropSet); } } pthread_mutex_unlock(&Z256DevMutex); return(1);}/******************************************************************************** * Z256DeviceHandleGetVarRequest * * Description: * Called during a get variable request callback. If the * request is for this device and either its control service * or picture service, then respond with the variable value. * * Parameters: * cgv_event -- The control get variable request event structure * ********************************************************************************/int Z256DeviceHandleGetVarRequest(struct Upnp_State_Var_Request *cgv_event){ int i, j; int getvar_succeeded = 0; cgv_event->CurrentVal = NULL; pthread_mutex_lock(&Z256DevMutex); for (i=0; i<Z256_SERVICE_SERVCOUNT; i++) { if ((strcmp(cgv_event->DevUDN,z256_service_table[i].UDN)==0) && (strcmp(cgv_event->ServiceID,z256_service_table[i].ServiceId)==0)) { /* Request for variable in the Z256Device Service */ for (j=0; j< z256_service_table[i].VariableCount; j++) { if (strcmp(cgv_event->StateVarName, z256_service_table[i].VariableName[j])==0) { getvar_succeeded = 1; cgv_event->CurrentVal = (Upnp_DOMString) malloc(sizeof(z256_service_table[i].VariableStrVal[j])); strcpy(cgv_event->CurrentVal, z256_service_table[i].VariableStrVal[j]); break; } } } } if (getvar_succeeded) { cgv_event->ErrCode = UPNP_E_SUCCESS; } else { printf("Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n"); printf(" Unknown variable name = %s\n", cgv_event->StateVarName); cgv_event->ErrCode = 404; strcpy(cgv_event->ErrStr, "Invalid Variable"); } pthread_mutex_unlock(&Z256DevMutex); return(cgv_event->ErrCode == UPNP_E_SUCCESS);}/******************************************************************************** * Z256DeviceHandleActionRequest * * Description: * Called during an action request callback. If the * request is for this device and either its control service * or picture service, then perform the action and respond. * * Parameters: * ca_event -- The control action request event structure * ********************************************************************************/int Z256DeviceHandleActionRequest(struct Upnp_Action_Request *ca_event){ char result_str[500]; char service_type[500]; char *value=NULL; /* Defaults if action not found */ int action_succeeded = -1; int err=401; ca_event->ErrCode = 0; ca_event->ActionResult = NULL; if ((strcmp(ca_event->DevUDN,z256_service_table[Z256_SERVICE_CONTROL].UDN)==0) && (strcmp(ca_event->ServiceID,z256_service_table[Z256_SERVICE_CONTROL].ServiceId)==0)) { /* Request for action in the Z256Device Control Service */ strcpy(service_type, z256_service_table[Z256_SERVICE_CONTROL].ServiceType); if (strcmp(ca_event->ActionName, "PowerOn") == 0) { action_succeeded = Z256DevicePowerOn(); } else if (strcmp(ca_event->ActionName, "PowerOff") == 0) { action_succeeded = Z256DevicePowerOff(); } else if (strcmp(ca_event->ActionName, "SetChannel") == 0) { if ((value = SampleUtil_GetFirstDocumentItem(ca_event->ActionRequest, "Channel"))) { action_succeeded = Z256DeviceSetChannel(atoi(value)); } else { // invalid args error err = 402; action_succeeded = 0; } } else if (strcmp(ca_event->ActionName, "IncreaseChannel") == 0) { action_succeeded = Z256DeviceIncrChannel(1); } else if (strcmp(ca_event->ActionName, "DecreaseChannel") == 0) { action_succeeded = Z256DeviceIncrChannel(-1); } else if (strcmp(ca_event->ActionName, "SetVolume") == 0) { if ((value = SampleUtil_GetFirstDocumentItem(ca_event->ActionRequest, "Volume"))) { action_succeeded = Z256DeviceSetVolume(atoi(value)); } else { // invalid args error err = 402; action_succeeded = 0; } } else if (strcmp(ca_event->ActionName, "IncreaseVolume") == 0) { action_succeeded = Z256DeviceIncrVolume(1); } else if (strcmp(ca_event->ActionName, "DecreaseVolume") == 0) { action_succeeded = Z256DeviceIncrVolume(-1); } } else if ((strcmp(ca_event->DevUDN,z256_service_table[Z256_SERVICE_PICTURE].UDN)==0) && (strcmp(ca_event->ServiceID,z256_service_table[Z256_SERVICE_PICTURE].ServiceId)==0)) { /* Request for action in the Z256Device Picture Service */ strcpy(service_type, z256_service_table[Z256_SERVICE_PICTURE].ServiceType); if (strcmp(ca_event->ActionName, "SetColor") == 0) { if ((value = SampleUtil_GetFirstDocumentItem(ca_event->ActionRequest, "Color"))) { action_succeeded = Z256DeviceSetColor(atoi(value)); } else { // invalid args error err = 402; action_succeeded = 0; } } else if (strcmp(ca_event->ActionName, "IncreaseColor") == 0) { action_succeeded = Z256DeviceIncrColor(1); } else if (strcmp(ca_event->ActionName, "DecreaseColor") == 0) { action_succeeded = Z256DeviceIncrColor(-1); } else if (strcmp(ca_event->ActionName, "SetTint") == 0) { if ((value = SampleUtil_GetFirstDocumentItem(ca_event->ActionRequest, "Tint"))) { action_succeeded = Z256DeviceSetTint(atoi(value)); } else { // invalid args error err = 402; action_succeeded = 0; } } else if (strcmp(ca_event->ActionName, "IncreaseTint") == 0) { action_succeeded = Z256DeviceIncrTint(1); } else if (strcmp(ca_event->ActionName, "DecreaseTint") == 0) { action_succeeded = Z256DeviceIncrTint(-1); } else if (strcmp(ca_event->ActionName, "SetContrast") == 0) { if ((value = SampleUtil_GetFirstDocumentItem(ca_event->ActionRequest, "Contrast"))) { action_succeeded = Z256DeviceSetContrast(atoi(value)); } else { // invalid args error err = 402; action_succeeded = 0; } } else if (strcmp(ca_event->ActionName, "IncreaseContrast") == 0) { action_succeeded = Z256DeviceIncrContrast(1); } else if (strcmp(ca_event->ActionName, "DecreaseContrast") == 0) { action_succeeded = Z256DeviceIncrContrast(-1); } else if (strcmp(ca_event->ActionName, "SetBrightness") == 0) { if ((value = SampleUtil_GetFirstDocumentItem(ca_event->ActionRequest, "Brightness"))) { action_succeeded = Z256DeviceSetBrightness(atoi(value)); } else { // invalid args error err = 402; action_succeeded = 0; } } else if (strcmp(ca_event->ActionName, "IncreaseBrightness") == 0) { action_succeeded = Z256DeviceIncrBrightness(1); } else if (strcmp(ca_event->ActionName, "DecreaseBrightness") == 0) { action_succeeded = Z256DeviceIncrBrightness(-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);}/******************************************************************************** * Z256DeviceCallbackEventHandler * * Description:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -