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

📄 upnp_tv_device.c

📁 upnpsdk-1.0.4.tar.gz Intel UPnP SDK Source
💻 C
📖 第 1 页 / 共 3 页
字号:
	printf("error: can't change to tint %d\n", tint);	return(0);    }    /* Vendor-specific code to set the tint goes here */    sprintf(value, "%d", tint);    ret = TvDeviceSetServiceTableVar(TV_SERVICE_PICTURE, TV_PICTURE_TINT, value);    return(ret);}/******************************************************************************** * TvDeviceIncrTint * * Description:  *       Increment the tint.  Read the current tint from the state *       table, add the increment, and then change the tint. * * Parameters: *   incr -- The increment by which to change the tint. * ********************************************************************************/int TvDeviceIncrTint(int incr) {    int curtint, newtint;    int ret;    pthread_mutex_lock(&TVDevMutex);    curtint = atoi(tv_service_table[TV_SERVICE_PICTURE].VariableStrVal[TV_PICTURE_TINT]);    pthread_mutex_unlock(&TVDevMutex);    newtint = curtint + incr;    ret = TvDeviceSetTint(newtint);    return(ret);}/******************************************************************************** * TvDeviceSetContrast * * Description:  *       Change the contrast, update the TvDevice picture service *       state table, and notify all subscribed control points of the *       updated state. * * Parameters: *   contrast -- The contrast value to change to. * ********************************************************************************/int TvDeviceSetContrast(int contrast) {    char value[TV_MAX_VAL_LEN];    int ret=0;    if (contrast < 1  ||  contrast > 10) {	printf("error: can't change to contrast %d\n", contrast);	return(0);    }    /* Vendor-specific code to set the contrast goes here */    sprintf(value, "%d", contrast);    ret = TvDeviceSetServiceTableVar(TV_SERVICE_PICTURE, TV_PICTURE_CONTRAST, value);    return(ret);}/******************************************************************************** * TvDeviceIncrContrast * * Description:  *       Increment the contrast.  Read the current contrast from the state *       table, add the increment, and then change the contrast. * * Parameters: *   incr -- The increment by which to change the contrast. * ********************************************************************************/int TvDeviceIncrContrast(int incr) {    int curcontrast, newcontrast;    int ret;    /* Get the current contrast value from the       state table */    pthread_mutex_lock(&TVDevMutex);    curcontrast = atoi(tv_service_table[TV_SERVICE_PICTURE].VariableStrVal[TV_PICTURE_CONTRAST]);    pthread_mutex_unlock(&TVDevMutex);    newcontrast = curcontrast + incr;    ret = TvDeviceSetContrast(newcontrast);    return(ret);}/******************************************************************************** * 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. * ********************************************************************************/int TvDeviceSetBrightness(int brightness) {    char value[TV_MAX_VAL_LEN];    int ret=0;    if (brightness < 1  ||  brightness > 10) {	printf("error: can't change to brightness %d\n", brightness);	return(0);    }    /* Vendor-specific code to set the brightness goes here */    sprintf(value, "%d", brightness);    ret = TvDeviceSetServiceTableVar(TV_SERVICE_PICTURE, TV_PICTURE_BRIGHTNESS, value);    return(ret);}/******************************************************************************** * TvDeviceIncrBrightness * * 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. * ********************************************************************************/int TvDeviceIncrBrightness(int incr) {    int curbrightness, newbrightness;    int ret;    pthread_mutex_lock(&TVDevMutex);    curbrightness = atoi(tv_service_table[TV_SERVICE_PICTURE].VariableStrVal[TV_PICTURE_BRIGHTNESS]);    pthread_mutex_unlock(&TVDevMutex);    newbrightness = curbrightness + incr;    ret = TvDeviceSetBrightness(newbrightness);    return(ret);}/******************************************************************************** * TvDeviceCallbackEventHandler * * Description:  *       The callback handler registered with the SDK while registering *       root device or sending a search request.  Detects the type of  *       callback, and passes the request on to the appropriate procedure. * * Parameters: *   EventType -- The type of callback event *   Event -- Data structure containing event data *   Cookie -- Optional data specified during callback registration * ********************************************************************************/int TvDeviceCallbackEventHandler(Upnp_EventType EventType, 			 void *Event, 			 void *Cookie){    /* Print a summary of the event received */    SampleUtil_PrintEvent(EventType, Event);      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:	    printf("Error in TvDeviceCallbackEventHandler: unknown event type %d\n", EventType);    }    return(0);}/******************************************************************************** * TvDeviceCommandLoop * * Description:  *       Function that receives commands from the user at the command prompt *       during the lifetime of the device, and calls the appropriate *       functions for those commands. * * Parameters: *    None * ********************************************************************************/void* TvDeviceCommandLoop(void *args){    int stoploop=0;    char cmdline[100];    char cmd[100];    while (!stoploop) {	sprintf(cmdline, " ");	sprintf(cmd, " ");	printf("\n>> ");	// Get a command line	fgets(cmdline, 100, stdin);	sscanf(cmdline, "%s", cmd);	if (strcasecmp(cmd, "exit") == 0) {	    printf("Shutting down...\n");	    UpnpUnRegisterRootDevice(device_handle);	    UpnpFinish();	    exit(0);	} else {	    printf("\n   Unknown command: %s\n\n", cmd);	    printf("   Valid Commands:\n");	    printf("     Exit\n\n");	}    }    return NULL;}int main(int argc, char** argv){    int ret=1;    int port;    char *ip_address=NULL, *desc_doc_name=NULL, *web_dir_path=NULL;    char desc_doc_url[200];    pthread_t cmdloop_thread;    int code;    int sig;    sigset_t sigs_to_catch;    if (argc!=5) {	printf("wrong number of arguments\n Usage: %s ipaddress port desc_doc_name web_dir_path\n", argv[0]);	printf("\tipaddress:     IP address of the device (must match desc. doc)\n");	printf("\t\te.g.: 192.168.0.4\n");	printf("\tport:          Port number to use for receiving UPnP messages (must match desc. doc)\n");	printf("\t\te.g.: 5431\n");	printf("\tdesc_doc_name: name of device description document\n");	printf("\t\te.g.: tvdevicedesc.xml\n");	printf("\tweb_dir_path: Filesystem path where web files related to the device are stored\n");	printf("\t\te.g.: /upnp/sample/tvdevice/web\n");	exit(1);    }    ip_address=argv[1];      sscanf(argv[2],"%d",&port);    desc_doc_name=argv[3];      web_dir_path=argv[4];      sprintf(desc_doc_url, "http://%s:%d/%s", ip_address, port, desc_doc_name);    printf("Intializing UPnP \n\twith desc_doc_url=%s\n\t", desc_doc_url);    printf("\t     ipaddress=%s port=%d\n", ip_address, port);    printf("\t     web_dir_path=%s\n", web_dir_path);    if ((ret = UpnpInit(ip_address, port)) != UPNP_E_SUCCESS) {	printf("Error with UpnpInit -- %d\n", ret);	UpnpFinish();	exit(1);    }    printf("UPnP Initialized\n");       printf("Specifying the webserver root directory -- %s\n", web_dir_path);    if ((ret = UpnpSetWebServerRootDir(web_dir_path)) != UPNP_E_SUCCESS) {	printf("Error specifying webserver root directory -- %s: %d\n", web_dir_path, ret);	UpnpFinish();	exit(1);    }    printf("Registering the RootDevice\n");    if ((ret = UpnpRegisterRootDevice(desc_doc_url, TvDeviceCallbackEventHandler, &device_handle, &device_handle)) != UPNP_E_SUCCESS) {	printf("Error registering the rootdevice : %d\n", ret);	UpnpFinish();	exit(1);    } else {	printf("RootDevice Registered\n");     	printf("Initializing State Table\n");	TvDeviceStateTableInit(desc_doc_url);	printf("State Table Initialized\n");	if ((ret = UpnpSendAdvertisement(device_handle, default_advr_expire)) != UPNP_E_SUCCESS) {	    printf("Error sending advertisements : %d\n", ret);	    UpnpFinish();	    exit(1);	}	printf("Advertisements Sent\n");    }       /* start a command loop thread */    code = pthread_create( &cmdloop_thread, NULL, TvDeviceCommandLoop,			   NULL );    /* Catch Ctrl-C and properly shutdown */    sigemptyset(&sigs_to_catch);    sigaddset(&sigs_to_catch, SIGINT);    sigwait(&sigs_to_catch, &sig);    printf("Shutting down on signal %d...\n", sig);    UpnpUnRegisterRootDevice(device_handle);    UpnpFinish();    exit(0);}

⌨️ 快捷键说明

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