db/upnp: add UpnpMakeAction() helper function
This commit is contained in:
		| @@ -424,6 +424,7 @@ libdb_plugins_a_SOURCES += \ | |||||||
| 	src/db/upnp/ixmlwrap.cxx src/db/upnp/ixmlwrap.hxx \ | 	src/db/upnp/ixmlwrap.cxx src/db/upnp/ixmlwrap.hxx \ | ||||||
| 	src/db/upnp/upnpplib.cxx src/db/upnp/upnpplib.hxx \ | 	src/db/upnp/upnpplib.cxx src/db/upnp/upnpplib.hxx \ | ||||||
| 	src/db/upnp/Util.cxx src/db/upnp/Util.hxx \ | 	src/db/upnp/Util.cxx src/db/upnp/Util.hxx \ | ||||||
|  | 	src/db/upnp/Action.hxx \ | ||||||
| 	src/db/upnp/WorkQueue.hxx \ | 	src/db/upnp/WorkQueue.hxx \ | ||||||
| 	src/db/upnp/Object.hxx | 	src/db/upnp/Object.hxx | ||||||
| DB_LIBS += \ | DB_LIBS += \ | ||||||
|   | |||||||
							
								
								
									
										56
									
								
								src/db/upnp/Action.hxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								src/db/upnp/Action.hxx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright (C) 2003-2014 The Music Player Daemon Project | ||||||
|  |  * http://www.musicpd.org | ||||||
|  |  * | ||||||
|  |  * This program is free software; you can redistribute it and/or modify | ||||||
|  |  * it under the terms of the GNU General Public License as published by | ||||||
|  |  * the Free Software Foundation; either version 2 of the License, or | ||||||
|  |  * (at your option) any later version. | ||||||
|  |  * | ||||||
|  |  * This program is distributed in the hope that it will be useful, | ||||||
|  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  |  * GNU General Public License for more details. | ||||||
|  |  * | ||||||
|  |  * You should have received a copy of the GNU General Public License along | ||||||
|  |  * with this program; if not, write to the Free Software Foundation, Inc., | ||||||
|  |  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #ifndef MPD_UPNP_ACTION_HXX | ||||||
|  | #define MPD_UPNP_ACTION_HXX | ||||||
|  |  | ||||||
|  | #include "Compiler.h" | ||||||
|  |  | ||||||
|  | #include <upnp/upnptools.h> | ||||||
|  |  | ||||||
|  | static inline constexpr unsigned | ||||||
|  | CountNameValuePairs() | ||||||
|  | { | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template<typename... Args> | ||||||
|  | static inline constexpr unsigned | ||||||
|  | CountNameValuePairs(gcc_unused const char *name, gcc_unused const char *value, | ||||||
|  | 		    Args... args) | ||||||
|  | { | ||||||
|  | 	return 1 + CountNameValuePairs(args...); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * A wrapper for UpnpMakeAction() that counts the number of name/value | ||||||
|  |  * pairs and adds the nullptr sentinel. | ||||||
|  |  */ | ||||||
|  | template<typename... Args> | ||||||
|  | static inline IXML_Document * | ||||||
|  | MakeActionHelper(const char *action_name, const char *service_type, | ||||||
|  | 		 Args... args) | ||||||
|  | { | ||||||
|  | 	const unsigned n = CountNameValuePairs(args...); | ||||||
|  | 	return UpnpMakeAction(action_name, service_type, n, | ||||||
|  | 			      args..., | ||||||
|  | 			      nullptr, nullptr); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #endif | ||||||
| @@ -24,12 +24,11 @@ | |||||||
| #include "ixmlwrap.hxx" | #include "ixmlwrap.hxx" | ||||||
| #include "Directory.hxx" | #include "Directory.hxx" | ||||||
| #include "Util.hxx" | #include "Util.hxx" | ||||||
|  | #include "Action.hxx" | ||||||
| #include "util/Error.hxx" | #include "util/Error.hxx" | ||||||
|  |  | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
|  |  | ||||||
| #include <upnp/upnptools.h> |  | ||||||
|  |  | ||||||
| ContentDirectoryService::ContentDirectoryService(const UPnPDevice &device, | ContentDirectoryService::ContentDirectoryService(const UPnPDevice &device, | ||||||
| 						 const UPnPService &service) | 						 const UPnPService &service) | ||||||
| 	:m_actionURL(caturl(device.URLBase, service.controlURL)), | 	:m_actionURL(caturl(device.URLBase, service.controlURL)), | ||||||
| @@ -80,17 +79,15 @@ ContentDirectoryService::readDirSlice(UpnpClient_Handle hdl, | |||||||
| 	char ofbuf[100], cntbuf[100]; | 	char ofbuf[100], cntbuf[100]; | ||||||
| 	sprintf(ofbuf, "%d", offset); | 	sprintf(ofbuf, "%d", offset); | ||||||
| 	sprintf(cntbuf, "%d", count); | 	sprintf(cntbuf, "%d", count); | ||||||
| 	int argcnt = 6; |  | ||||||
| 	// Some devices require an empty SortCriteria, else bad params | 	// Some devices require an empty SortCriteria, else bad params | ||||||
| 	IXML_Document *request = | 	IXML_Document *request = | ||||||
| 		UpnpMakeAction("Browse", m_serviceType.c_str(), argcnt, | 		MakeActionHelper("Browse", m_serviceType.c_str(), | ||||||
| 			       "ObjectID", objectId, | 				 "ObjectID", objectId, | ||||||
| 			       "BrowseFlag", "BrowseDirectChildren", | 				 "BrowseFlag", "BrowseDirectChildren", | ||||||
| 			       "Filter", "*", | 				 "Filter", "*", | ||||||
| 			       "SortCriteria", "", | 				 "SortCriteria", "", | ||||||
| 			       "StartingIndex", ofbuf, | 				 "StartingIndex", ofbuf, | ||||||
| 			       "RequestedCount", cntbuf, | 				 "RequestedCount", cntbuf); | ||||||
| 			       nullptr, nullptr); |  | ||||||
| 	if (request == nullptr) { | 	if (request == nullptr) { | ||||||
| 		error.Set(upnp_domain, "UpnpMakeAction() failed"); | 		error.Set(upnp_domain, "UpnpMakeAction() failed"); | ||||||
| 		return false; | 		return false; | ||||||
| @@ -165,18 +162,15 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, | |||||||
| 	while (offset < total) { | 	while (offset < total) { | ||||||
| 		char ofbuf[100]; | 		char ofbuf[100]; | ||||||
| 		sprintf(ofbuf, "%d", offset); | 		sprintf(ofbuf, "%d", offset); | ||||||
| 		// Create request |  | ||||||
| 		int argcnt = 6; |  | ||||||
|  |  | ||||||
| 		IXML_Document *request = | 		IXML_Document *request = | ||||||
| 			UpnpMakeAction("Search", m_serviceType.c_str(), argcnt, | 			MakeActionHelper("Search", m_serviceType.c_str(), | ||||||
| 				       "ContainerID", objectId, | 					 "ContainerID", objectId, | ||||||
| 				       "SearchCriteria", ss, | 					 "SearchCriteria", ss, | ||||||
| 				       "Filter", "*", | 					 "Filter", "*", | ||||||
| 				       "SortCriteria", "", | 					 "SortCriteria", "", | ||||||
| 				       "StartingIndex", ofbuf, | 					 "StartingIndex", ofbuf, | ||||||
| 				       "RequestedCount", "0", // Setting a value here gets twonky into fits | 					 "RequestedCount", "0"); // Setting a value here gets twonky into fits | ||||||
| 				       nullptr, nullptr); |  | ||||||
| 		if (request == 0) { | 		if (request == 0) { | ||||||
| 			error.Set(upnp_domain, "UpnpMakeAction() failed"); | 			error.Set(upnp_domain, "UpnpMakeAction() failed"); | ||||||
| 			return false; | 			return false; | ||||||
| @@ -270,16 +264,14 @@ ContentDirectoryService::getMetadata(UpnpClient_Handle hdl, | |||||||
| 				     Error &error) | 				     Error &error) | ||||||
| { | { | ||||||
| 	// Create request | 	// Create request | ||||||
| 	int argcnt = 6; |  | ||||||
| 	IXML_Document *request = | 	IXML_Document *request = | ||||||
| 		UpnpMakeAction("Browse", m_serviceType.c_str(), argcnt, | 		MakeActionHelper("Browse", m_serviceType.c_str(), | ||||||
| 			       "ObjectID", objectId, | 				 "ObjectID", objectId, | ||||||
| 			       "BrowseFlag", "BrowseMetadata", | 				 "BrowseFlag", "BrowseMetadata", | ||||||
| 			       "Filter", "*", | 				 "Filter", "*", | ||||||
| 			       "SortCriteria", "", | 				 "SortCriteria", "", | ||||||
| 			       "StartingIndex", "0", | 				 "StartingIndex", "0", | ||||||
| 			       "RequestedCount", "1", | 				 "RequestedCount", "1"); | ||||||
| 			       nullptr, nullptr); |  | ||||||
| 	if (request == nullptr) { | 	if (request == nullptr) { | ||||||
| 		error.Set(upnp_domain, "UpnpMakeAction() failed"); | 		error.Set(upnp_domain, "UpnpMakeAction() failed"); | ||||||
| 		return false; | 		return false; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann