Example #1
0
int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *sr_event)
{
	unsigned int i = 0;
	int cmp1 = 0;
	int cmp2 = 0;
	const char *l_serviceId = NULL;
	const char *l_udn = NULL;
	const char *l_sid = NULL;

	/* lock state mutex */
	ithread_mutex_lock(&TVDevMutex);

	l_serviceId = UpnpString_get_String(UpnpSubscriptionRequest_get_ServiceId(sr_event));
	l_udn = UpnpSubscriptionRequest_get_UDN_cstr(sr_event);
	l_sid = UpnpSubscriptionRequest_get_SID_cstr(sr_event);
	for (i = 0; i < TV_SERVICE_SERVCOUNT; ++i) {
		cmp1 = strcmp(l_udn, tv_service_table[i].UDN);
		cmp2 = strcmp(l_serviceId, tv_service_table[i].ServiceId);
		if (cmp1 == 0 && cmp2 == 0) {
#if 0
			PropSet = NULL;

			for (j = 0; j < tv_service_table[i].VariableCount; ++j) {
				/* add each variable to the property set */
				/* for initial state dump */
				UpnpAddToPropertySet(&PropSet,
						     tv_service_table[i].
						     VariableName[j],
						     tv_service_table[i].
						     VariableStrVal[j]);
			}

			/* dump initial state  */
			UpnpAcceptSubscriptionExt(device_handle,
						  l_udn,
						  l_serviceId, PropSet, l_sid);
			/* free document */
			Document_free(PropSet);
#endif
			UpnpAcceptSubscription(device_handle,
					       l_udn,
					       l_serviceId,
					       (const char **)
					       tv_service_table[i].VariableName,
					       (const char **)
					       tv_service_table
					       [i].VariableStrVal,
					       tv_service_table[i].
					       VariableCount, l_sid);
		}
	}

	ithread_mutex_unlock(&TVDevMutex);

	return 1;
}
int cConnectionManager::Subscribe(Upnp_Subscription_Request* request){
  IXML_Document* PropertySet = NULL;

  std::string protocolInfo = tools::StringListToCSV(mMediaServer->GetManager().GetSupportedProtocolInfos());

  /* The protocol infos which this server supports */
  UpnpAddToPropertySet(&PropertySet, "SourceProtocolInfo", protocolInfo.c_str());
  /* Not set, this field is only used by Media Renderers */
  UpnpAddToPropertySet(&PropertySet, "SinkProtocolInfo", "");
  /* The current connection IDs of all virtual connections */
  UpnpAddToPropertySet(&PropertySet, "CurrentConnectionIDs", GetConnectionIDsCVS().c_str());
  // Accept subscription
  int ret = UpnpAcceptSubscriptionExt(this->mDeviceHandle, request->UDN, request->ServiceId, PropertySet, request->Sid);

  if(ret != UPNP_E_SUCCESS){
    esyslog("UPnP\tSubscription failed (Error code: %d)", ret);
  }

  ixmlDocument_free(PropertySet);
  return ret;
}
bool cConnectionManager::OnConnectionChange(){
  IXML_Document* PropertySet = NULL;
  UpnpAddToPropertySet(&PropertySet, "CurrentConnectionIDs", GetConnectionIDsCVS().c_str());
  int ret = UpnpNotifyExt(mDeviceHandle, mMediaServer->GetDeviceUUID().c_str(), mServiceDescription.serviceID.c_str(), PropertySet);
  ixmlDocument_free(PropertySet);

  if(ret != UPNP_E_SUCCESS){
      esyslog("UPnP\tState change notification failed (Error code: %d)",ret);
      return false;
  }

  return true;
}