示例#1
0
CgUpnpAvRenderer* cg_upnpav_dmr_new()
{
  CgUpnpAvRenderer* dmr;
  char* lastChange;

  dmr = (CgUpnpAvRenderer*)malloc(sizeof(CgUpnpAvRenderer));

  dmr->dev = cg_upnp_device_new();
  if (!dmr->dev) {
    free(dmr);
    return NULL;
  }

  if (cg_upnp_device_parsedescription(dmr->dev, CG_UPNPAV_DMR_DEVICE_DESCRIPTION, cg_strlen(CG_UPNPAV_DMR_DEVICE_DESCRIPTION)) == FALSE) {
    cg_upnp_device_delete(dmr->dev);
    free(dmr);
    return NULL;
  }

  if (cg_upnpav_dmr_conmgr_init(dmr) == FALSE) {
    cg_upnp_device_delete(dmr->dev);
    free(dmr);
    return NULL;
  }

  if (cg_upnpav_dmr_renderingctrl_init(dmr) == FALSE) {
    cg_upnp_device_delete(dmr->dev);
    free(dmr);
    return NULL;
  }

  if (cg_upnpav_dmr_avtransport_init(dmr) == FALSE) {
    cg_upnp_device_delete(dmr->dev);
    free(dmr);
    return NULL;
  }

  dmr->mutex = cg_mutex_new();
  if (!dmr->mutex) {
    cg_upnpav_dmr_delete(dmr);
    return NULL;
  }

  cg_upnp_device_setactionlistener(dmr->dev, cg_upnpav_dmr_actionreceived);
  cg_upnp_device_setquerylistener(dmr->dev, cg_upnpav_dmr_queryreceived);
  cg_upnp_device_sethttplistener(dmr->dev, cg_upnpav_dmr_device_httprequestrecieved);

  cg_upnpav_dmr_setactionlistener(dmr, NULL);
  cg_upnpav_dmr_setquerylistener(dmr, NULL);
  cg_upnpav_dmr_sethttplistener(dmr, NULL);

  cg_upnp_device_setuserdata(dmr->dev, dmr);
  cg_upnp_device_updateudn(dmr->dev);

  dmr->protocolInfoList = cg_upnpav_protocolinfolist_new();

  cg_upnpav_dmr_setavtransportlastchange(dmr, "<Event xmlns = "urn:schemas-upnp-org:metadata-1-0/AVT/"/>");

  cg_upnpav_dmr_setsourceprotocolinfo(dmr, "");
  cg_upnpav_dmr_setcurrentconnectionids(dmr, "0");

  lastChange = "<Event xmlns = "urn:schemas-upnp-org:metadata-1-0/RCS/">"
               "<InstanceID val="0">"
               "<Volume val="100" channel="RF"/>"
               "<Volume val="100" channel="LF"/>"
               "</InstanceID>"
               "</Event>";

  cg_upnpav_dmr_setrenderingcontrollastchange(dmr, lastChange);

  return dmr;
}
CgUpnpAvServer *cg_upnpav_dms_new()
{
    CgUpnpAvServer *dms;

    dms = (CgUpnpAvServer *)malloc(sizeof(CgUpnpAvServer));

    dms->dev = cg_upnp_device_new();
    if (!dms->dev) {
        free(dms);
        return NULL;
    }

    if (cg_upnp_device_parsedescription(dms->dev, CG_UPNPAV_DMS_DEVICE_DESCRIPTION, cg_strlen(CG_UPNPAV_DMS_DEVICE_DESCRIPTION)) == FALSE) {
        cg_upnp_device_delete(dms->dev);
        free(dms);
        return NULL;
    }

    if (cg_upnpav_dms_conmgr_init(dms) == FALSE) {
        cg_upnp_device_delete(dms->dev);
        free(dms);
        return NULL;
    }

    if (cg_upnpav_dms_condir_init(dms) == FALSE) {
        cg_upnp_device_delete(dms->dev);
        free(dms);
        return NULL;
    }

    if (cg_upnpav_dms_medrec_init(dms) == FALSE) {
        cg_upnp_device_delete(dms->dev);
        free(dms);
        return NULL;
    }

    dms->rootContent = cg_upnpav_content_new();
    cg_upnpav_content_settype(dms->rootContent, CG_UPNPAV_CONTENT_CONTAINER);
    cg_upnpav_content_settitle(dms->rootContent, CG_UPNPAV_ROOT_CONTENT_TITLE);
    cg_upnpav_content_setid(dms->rootContent, CG_UPNPAV_ROOT_CONTENT_ID);
    cg_upnpav_content_setparentid(dms->rootContent, CG_UPNPAV_ROOT_CONTENT_PARENTID);

    if (!dms->rootContent) {
        cg_upnpav_dms_delete(dms);
        return NULL;
    }

    dms->mutex = cg_mutex_new();
    if (!dms->mutex) {
        cg_upnpav_dms_delete(dms);
        return NULL;
    }

    dms->networkInterfaceList = cg_net_interfacelist_new();
    if (!dms->networkInterfaceList) {
        cg_upnpav_dms_delete(dms);
        return NULL;
    }

    cg_upnp_device_setactionlistener(dms->dev, cg_upnpav_dms_actionreceived);
    cg_upnp_device_setquerylistener(dms->dev, cg_upnpav_dms_queryreceived);
    cg_upnp_device_sethttplistener(dms->dev, cg_upnpav_dms_device_httprequestrecieved);

    cg_upnpav_dms_setactionlistener(dms, NULL);
    cg_upnpav_dms_setquerylistener(dms, NULL);
    cg_upnpav_dms_sethttplistener(dms, NULL);

    cg_upnp_device_setuserdata(dms->dev, dms);
    cg_upnp_device_updateudn(dms->dev);

    dms->protocolInfoList = cg_upnpav_protocolinfolist_new();

    return dms;
}