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

📄 upnp_z256_device.c.back

📁 upnpsdk-1.0.4.tar.gz Intel UPnP SDK Source
💻 BACK
📖 第 1 页 / 共 2 页
字号:
 *       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 Z256DeviceCallbackEventHandler(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:        Z256DeviceHandleSubscriptionRequest(            (struct Upnp_Subscription_Request *) Event);        break;    case UPNP_CONTROL_GET_VAR_REQUEST:        Z256DeviceHandleGetVarRequest(            (struct Upnp_State_Var_Request *) Event);        break;    case UPNP_CONTROL_ACTION_REQUEST:        Z256DeviceHandleActionRequest(            (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 Z256DeviceCallbackEventHandler: unknown event type %d\n", EventType);    }    return(0);}/******************************************************************************** * Z256DeviceStateTableInit * * Description: *       Initialize the device state table for *       this Z256Device, pulling identifier info *       from the description Document.  Note that *       knowledge of the service description is *       assumed.  State table variables and default *       values are currently hard coded in this file *       rather than being read from service description *       documents. * * Parameters: *   DescDocURL -- The description document URL * ********************************************************************************/int Z256DeviceStateTableInit(char* DescDocURL){    Upnp_Document DescDoc=NULL;    int ret = UPNP_E_SUCCESS;    char *servid_ctrl=NULL, *evnturl_ctrl=NULL, *ctrlurl_ctrl=NULL;    char *servid_pict=NULL, *evnturl_pict=NULL, *ctrlurl_pict=NULL;    char *udn=NULL;    int i;    if (UpnpDownloadXmlDoc(DescDocURL, &DescDoc) != UPNP_E_SUCCESS) {        printf("Z256DeviceStateTableInit -- Error Parsing %s\n", DescDocURL);        ret = UPNP_E_INVALID_DESC;    }    /* Find the Z256 Control Service identifiers */    if (!SampleUtil_FindAndParseService(DescDoc, DescDocURL, Z256ServiceType[Z256_SERVICE_CONTROL], &servid_ctrl, &evnturl_ctrl, &ctrlurl_ctrl)) {        printf("Z256DeviceStateTableInit -- Error: Could not find Service: %s\n", Z256ServiceType[Z256_SERVICE_CONTROL]);        if (servid_ctrl) free(servid_ctrl);        if (evnturl_ctrl) free(evnturl_ctrl);        if (ctrlurl_ctrl) free(ctrlurl_ctrl);        return(UPNP_E_INVALID_DESC);    }    /* Find the Z256 Picture Service identifiers */    if (!SampleUtil_FindAndParseService(DescDoc, DescDocURL, Z256ServiceType[Z256_SERVICE_PICTURE], &servid_pict, &evnturl_pict, &ctrlurl_pict)) {        printf("Z256DeviceStateTableInit -- Error: Could not find Service: %s\n", Z256ServiceType[Z256_SERVICE_PICTURE]);        if (servid_ctrl) free(servid_ctrl);        if (evnturl_ctrl) free(evnturl_ctrl);        if (ctrlurl_ctrl) free(ctrlurl_ctrl);        if (servid_pict) free(servid_pict);        if (evnturl_pict) free(evnturl_pict);        if (ctrlurl_pict) free(ctrlurl_pict);        return(UPNP_E_INVALID_DESC);    }    udn = SampleUtil_GetFirstDocumentItem(DescDoc, "UDN");    strcpy(z256_service_table[Z256_SERVICE_CONTROL].UDN, udn);    strcpy(z256_service_table[Z256_SERVICE_CONTROL].ServiceId, servid_ctrl);    strcpy(z256_service_table[Z256_SERVICE_CONTROL].ServiceType, Z256ServiceType[Z256_SERVICE_CONTROL]);    z256_service_table[Z256_SERVICE_CONTROL].VariableCount=Z256_CONTROL_VARCOUNT;    for (i=0; i<z256_service_table[Z256_SERVICE_CONTROL].VariableCount; i++) {        z256_service_table[Z256_SERVICE_CONTROL].VariableName[i] = tvc_varname[i];        z256_service_table[Z256_SERVICE_CONTROL].VariableStrVal[i] = tvc_varval[i];        strcpy(z256_service_table[Z256_SERVICE_CONTROL].VariableStrVal[i], tvc_varval_def[i]);    }    strcpy(z256_service_table[Z256_SERVICE_PICTURE].UDN, udn);    strcpy(z256_service_table[Z256_SERVICE_PICTURE].ServiceId, servid_pict);    strcpy(z256_service_table[Z256_SERVICE_PICTURE].ServiceType, Z256ServiceType[Z256_SERVICE_PICTURE]);    z256_service_table[Z256_SERVICE_PICTURE].VariableCount=Z256_PICTURE_VARCOUNT;    for (i=0; i<z256_service_table[Z256_SERVICE_PICTURE].VariableCount; i++) {        z256_service_table[Z256_SERVICE_PICTURE].VariableName[i] = tvp_varname[i];        z256_service_table[Z256_SERVICE_PICTURE].VariableStrVal[i] = tvp_varval[i];        strcpy(z256_service_table[Z256_SERVICE_PICTURE].VariableStrVal[i], tvp_varval_def[i]);    }    if (udn) free(udn);    if (servid_ctrl) free(servid_ctrl);    if (evnturl_ctrl) free(evnturl_ctrl);    if (ctrlurl_ctrl) free(ctrlurl_ctrl);    if (servid_pict) free(servid_pict);    if (evnturl_pict) free(evnturl_pict);    if (ctrlurl_pict) free(ctrlurl_pict);    return(ret);}/******************************************************************************** * Z256DeviceCommandLoop * * 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* Z256DeviceCommandLoop(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);/* ################## UPnP 檬扁拳 UpnpInit(ip_address, port) ########### */    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");/* ##################################################################### *//* ################# UpnpSetWebServerRootDir(web_dir_path) ############# */    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);    }/* ##################################################################### *//* ##################### UpnpRegisterRootDevice() ###################### */    printf("Registering the RootDevice\n");    if ((ret = UpnpRegisterRootDevice(desc_doc_url, Z256DeviceCallbackEventHandler, &device_handle, &device_handle)) != UPNP_E_SUCCESS) {        printf("Error registering the rootdevice : %d\n", ret);        UpnpFinish();        exit(1);    } else {        printf("RootDevice Registered\n");/* ##################################################################### *//* ################## Z256DeviceStateTableInit(desc_doc_url) ########### */        printf("Initializing State Table\n");        Z256DeviceStateTableInit(desc_doc_url);        printf("State Table Initialized\n");/* ##################################################################### *//* ###### UpnpSendAdvertisement(device_handle, default_advr_expire)##### */	        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, Z256DeviceCommandLoop,                           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) ############ */    UpnpUnRegisterRootDevice(device_handle);/* ##################################################################### *//* ############################ UpnpFinish() ########################### */    UpnpFinish();/* ##################################################################### */    exit(0);}

⌨️ 快捷键说明

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