File: Messages.cpp

package info (click to toggle)
android-file-transfer 4.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,496 kB
  • sloc: cpp: 12,909; python: 140; lex: 47; xml: 26; sh: 13; makefile: 6
file content (68 lines) | stat: -rw-r--r-- 1,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <mtp/ptp/Messages.h>
#include <algorithm>
#include <sstream>
#include <ctype.h>

namespace mtp { namespace msg
{
	bool DeviceInfo::Supports(OperationCode opcode) const
	{
		auto i = std::find(OperationsSupported.begin(), OperationsSupported.end(), opcode);
		return i != OperationsSupported.end();
	}

	bool DeviceInfo::Supports(DeviceProperty property) const
	{
		auto i = std::find(DevicePropertiesSupported.begin(), DevicePropertiesSupported.end(), property);
		return i != DevicePropertiesSupported.end();
	}

	bool DeviceInfo::Supports(EventCode event) const
	{
		auto i = std::find(EventsSupported.begin(), EventsSupported.end(), event);
		return i != EventsSupported.end();
	}

	bool DeviceInfo::Supports(ObjectFormat format) const
	{
		auto i = std::find(ImageFormats.begin(), ImageFormats.end(), format);
		return i != ImageFormats.end();
	}

	bool DeviceInfo::Matches(const std::string & haystack, const std::string & needle)
	{ return strcasestr(haystack.c_str(), needle.c_str()); }

	bool DeviceInfo::Matches(const std::string & filter) const
	{
		if (filter.empty())
			return true;
		auto fsname = GetFilesystemFriendlyName();
		return Matches(fsname, filter);
	}


	namespace
	{
		std::string Strip(std::string str)
		{
			str.erase(std::remove_if(str.begin(), str.end(), isspace), str.end());
			return str;
		}
	}

	std::string DeviceInfo::GetFilesystemFriendlyName() const
	{
		std::stringstream ss;
		ss << Strip(Manufacturer);
		ss << '-';
		ss << Strip(Model);
		ss << '-';
		ss << Strip(SerialNumber);
		return ss.str();
	}

	bool ObjectPropertiesSupported::Supports(ObjectProperty prop) const
	{ return std::find(ObjectPropertyCodes.begin(), ObjectPropertyCodes.end(), prop) != ObjectPropertyCodes.end(); }


}}